include "constants.php";
$image = imagecreatetruecolor(2500,1400);
$bg = imagecolorallocate($image,255,255,255);
imageFilledRectangle($image, 0, 0, 2500, 1400, $bg);
$blue = ImageColorAllocate($image, 112, 132, 151);
$inc = 0;
function newRoom($image,$room,$x,$y,$colour,$old,$extend = false) {
if (is_numeric($old)) {
$ox = $GLOBALS["point".$old]['x'];
$oy = $GLOBALS["point".$old]['y'];
imageLine($image,$x,$y,$ox,$oy,$colour);
if ($extend) {
$ox = $x;
$oy = $y;
$y += $extend;
imageLine($image,$x,$y,$ox,$oy,$colour);
}
}
$red = ImageColorAllocate($image, 255, 0, 0);
if ($room == $_GET['room']) imageFilledEllipse($image,$x,$y,7,7,$red);
else imageFilledEllipse($image,$x,$y,7,7,$colour);
$name = getInfo(name,rooms,"WHERE id='$room'");
$length = strlen($name);
$black = ImageColorAllocate($image, 0, 0, 0);
ImageString($image, 3, $x - ($length * 3), $y + 10, $name, $black);
$GLOBALS['inc']++;
}
function fillpath($image,$colour,$room,$exception) {
$x = $GLOBALS["point".$room]["x"];
$y = $GLOBALS["point".$room]["y"];
if (numRowsConditions(doors,"WHERE room='$room'") > 0) {
$num = numRowsConditions(doors,"WHERE room='$room'");
$count = 0;
$angle = 180/($num - 1);
$result = getRows(doors,"WHERE room='$room' ORDER BY id ASC");
while ($row = mysql_fetch_array($result)) {
$door = $row['id'];
$room2 = $row['room2'];
if (((!getInfo(hidden,rooms,"WHERE id='$room2'")) || ($_GET['room'] == $room2)) && (getInfo(place,rooms,"WHERE id='$room2'") == $GLOBALS['place'])) {
if (numRowsConditions(doors,"WHERE room='$room2'") <= 0) {
$d = 100;
$extend = rand(25,75);
}
else {
$d = 200;
$extend = rand(50,150);
}
$dx = $d * round(cos(deg2rad($angle * $count)));
$dy = $d * round(sin(deg2rad($angle * $count)));
if (!inArray($room2,$GLOBALS['rooms'])) {
//echo getInfo(name,rooms,"WHERE id='$room2'")."$x + $dx, $y + $dy
";
if ($inc % 2 == 0) $x -= rand(20,35);
else $x += rand(20,35);
newRoom($image,$room2,$x + $dx,$y + $dy,$colour,$room,$extend);
$GLOBALS['rooms'][] = $room2;
} else {
$x = $GLOBALS['points'][$room2]["x"];
$y = $GLOBALS['points'][$room2]["y"];
$ox = $GLOBALS['points'][$room]['x'];
$oy = $GLOBALS['points'][$room]['y'];
imageLine($image,$x,$y,$ox,$oy,$colour);
}
$store = "point".$room2;
if ($extend) {
$array["x"] = $x + $dx;
$array["y"] = $y + $dy + $extend;
} else {
$array["x"] = $x + $dx;
$array["y"] = $y + $dy;
}
global $$store;
if (!inArray($room2,$GLOBALS['roomscopy'])) {
$GLOBALS['points'][$room2] = $array;
}
$GLOBALS['roomscopy'] = $GLOBALS['rooms'];
if (!inArray($store,$GLOBALS)) $GLOBALS[$store] = $array;
/*
$max = count($GLOBALS['rooms']);
for ($i = 0;$i < $max;$i++) {
$whatroom = $GLOBALS['rooms'][$i];
echo $whatroom.': ';
print_r($GLOBALS['points'][$whatroom]);
echo '
';
}
*/
//echo "$room : $room2 X
";
fillpath($image,$colour,$room2,$door);
$count++;
}
}
}
}
/*
newCircle($image,400,300,$blue);
newCircle($image,500,396,$blue,400,300);
newCircle($image,200,396,$blue,400,300);
newCircle($image,400,206,$blue,400,300);
*/
$place = $_GET['id'];
$town = getInfo(town,places,"WHERE id='$place'");
if ((!getInfo(developed,towns,"WHERE id='$town'")) || (admin($user_name))) {
$entrance = getInfo(entrance,places,"WHERE id='$place'");
if (!$entrance) {
$entrance = getInfo(id,rooms,"WHERE place='$place' ORDER BY id ASC");
}
$name = getInfo(name,places,"WHERE id='$place'");
ImageString($image, 10, 20, 20, $name, $blue);
//Generate Out/Entrance
ImageString($image, 3, 690, 5, "OUT", $blue);
$point0['x'] = 700;
$point0['y'] = 18;
$temppoint['x'] = 700;
$temppoint['y'] = 35;
$points[$entrance] = $temppoint;
newRoom($image,$entrance,700,35,$blue,0);
$rooms[] = $entrance;
/*
$result = getRows(rooms,"WHERE place='$place'");
while ($row = mysql_fetch_array($result)) {
$room = $row['id'];
if (!outside($room)) $otherRooms[] = $room;
}
*/
//$max = count($otherRooms);
$result = getRows(doors,"WHERE room='$entrance' and room2!='out' ORDER BY room2 ASC");
$num = numRowsConditions(doors,"WHERE room='$entrance'");
//$num += $max;
$count = 0;
$angle = 180/($num - 2);
$store = "point".$entrance;
$array['x'] = 700;
$array['y'] = 35;
$$store = $array;
unset($array);
$x = 700;
$y = 35;
while ($row = mysql_fetch_array($result)) {
$door = $row['id'];
$room2 = $row['room2'];
if (numRowsConditions(doors,"WHERE room='$room2'") <= 0) {
$d = 150;
$extend = rand(50,150);
}
else {
$d = 200;
$extend = rand(50,200);
}
$dx = $d * round(cos(deg2rad($angle * $count)));
$dy = $d * round(sin(deg2rad($angle * $count)));
if (!inArray($room2,$rooms)) {
newRoom($image,$room2,$x + $dx,$y + $dy,$blue,$entrance,$extend);
$rooms[] = $room2;
}
$store = "point".$room2;
if ($extend) {
$array["x"] = $x + $dx;
$array["y"] = $y + $dy + $extend;
} else {
$array["x"] = $x + $dx;
$array["y"] = $y + $dy;
}
if (!inArray($room2,$points)) $points[$room2] = $array;
if (!inArray($store,$GLOBALS)) $GLOBALS[$store] = $array;
fillpath($image,$blue,$room2,$door);
$count++;
}
/*
for ($i = 0;$i < $max;$i++) {
$room2 = $otherRooms[$i];
echo getInfo(name,rooms,"wHERE id='$room2'").'
';
if (numRowsConditions(doors,"WHERE room='$room2'") <= 0) {
$d = 150;
$extend = rand(0,100);
}
else {
$d = 200;
$extend = rand(50,150);
}
$dx = $d * round(cos(deg2rad($angle * $count)));
$dy = $d * round(sin(deg2rad($angle * $count)));
if (!inArray($room2,$rooms)) {
newRoom($image,$room2,$x + $dx,$y + $dy,$blue,$entrance,$extend);
$rooms[] = $room2;
}
$store = "point".$room2;
if ($extend) {
$array["x"] = $x + $dx;
$array["y"] = $y + $dy + $extend;
} else {
$array["x"] = $x + $dx;
$array["y"] = $y + $dy;
}
$$store = $array;
fillpath($image,$blue,$room2,$door);
}
*/
header("Content-type: image/png");
imagePNG($image,'',9);
imageDestroy($image);
} else {
echo "You may not view the floorplans of undeveloped areas. Some are meant to be confusing and maze-like.";
}
?>