diff options
-rw-r--r-- | do.php | 4 | ||||
-rw-r--r-- | includes/maps.php | 44 | ||||
-rw-r--r-- | pages/admin.php | 2 | ||||
-rw-r--r-- | pages/gallery.php | 12 |
4 files changed, 34 insertions, 28 deletions
@@ -132,10 +132,10 @@ if ($_GET['r'] == 'getpath') { //$json = routePath($mygrid);
// New
- // !! Broken!
+ // TODO: Broken!
//Route the path
$json['path'][] = routePath($mygrid);
- $json['path'][] = routePath($mygrid, 'X');
+ $json['path'][] = routePath($mygrid, false, true);
// !! Tmp
//$moves = $json['moves'];
diff --git a/includes/maps.php b/includes/maps.php index f49900f..3ddd82f 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -100,7 +100,7 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) $mapdata['example'] = $example;
$mapdata['mapid'] = $idprefix;
- $path = routePath($mapMatrix, '');
+ $path = routePath($mapMatrix);
$mapdata['code'] = GenerateMapCode($mapMatrix);
$width = (($j * 35) + 2).'px';
@@ -371,7 +371,7 @@ function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = $grid[0][6] = $mapName;
//Validate map
- $path = routePath($grid, '', true);
+ $path = routePath($grid, true);
//Only repeat if it's blocked.
} while ($path['blocked'] == true);
@@ -452,7 +452,7 @@ function GenerateShapedMap($shape, $params) { }
//echo "\n";
}
- $path = routePath($mapMatrix, '', true);
+ $path = routePath($mapMatrix, true);
//echo $path['blocked']."\n";
//Only repeat if it's blocked.
} while ($path['blocked'] == true);
@@ -610,7 +610,6 @@ function GenerateMapByCode($code) { //Create $mapMatrix by iterating through $code (a string value).
//==$mapMatrix = array();
-
$tmp = explode( ":", $code);
$headers = explode( '.', $tmp[0]);
@@ -763,7 +762,7 @@ function findTiles ($mapMatrix, $search) { // Returns: ARRAY( blocked, path, start, end )
-function findPath($mapMatrix, $start = '0,1', $target = 'f') {
+function findPath($mapMatrix, $start = '0,1', $target = 'f', $isBlockedByX = false) {
//Remove last period if existing.
if (substr($start, -1) == '.')
@@ -781,6 +780,15 @@ function findPath($mapMatrix, $start = '0,1', $target = 'f') { $y = $v[1];
unset($mapMatrix[$y][$x]);
}
+
+ //When traversing forwards (the normal start square, 's'), we are blocked by 'x', so can pass through 'X'
+ //Similarly, when tranversing backwards ('S'), we are blocked by 'X', so can pass through 'x'
+ if($isBlockedByX) {
+ $passableWallChar = 'x';
+ } else {
+ $passableWallChar = 'X';
+ }
+
$index = count($seed);
@@ -821,13 +829,14 @@ function findPath($mapMatrix, $start = '0,1', $target = 'f') { $path = $mapMatrix[$y][$x];
case "o": //Available squares
- //!!
+ // !!
case "p":
- case "s": case "f": //Start and end tiles
- case "S": //!!
+ case "s": case "f": //Start and end tiles
+ case "S": //New start type
+ case $passableWallChar: //The walls we can walk through
case "a": case "b": case "c": case "d": case "e": //Checkpoints too
- case "u": case "n": case "h": case "j": case "l": //Teleport-out towers included!
+ case "u": case "n": case "h": case "j": case "l": //Teleport-out towers included!
//Plant Seed here
$seed[$index][0] = $x;
$seed[$index][1] = $y;
@@ -875,7 +884,7 @@ function GetTile($mapMatrix, $id) //Routes a path through all checkpoints and teleports, returning an array.
// [path] path-string. [blocked] boolean, [moves] int.
-function routePath($mygrid, $start = '', $validate = false) {
+function routePath($mygrid, $validate = false, $traverseBackwards = false) {
//Our response
$r = array('start' => NULL, 'path' => NULL, 'blocked' => true);
@@ -888,20 +897,17 @@ function routePath($mygrid, $start = '', $validate = false) { if (in_array("S", $tileLocations)) {
}
- $pathx = false;
// Tmp bad code..
- if ($start == 'X') {
- $pathx = true;
+ if ($traverseBackwards) {
$start = findTiles($mygrid, "S");
- } else
+ } else {
$start = findTiles($mygrid, "s");
+ }
-
-
//Checkpoint names
$cpnames = array("a", "b", "c", "d", "e");
- if ($pathx)
+ if ($traverseBackwards)
$cpnames = array("e", "d", "c", "b", "a");
//!! Improve the 'findTiles' function to prevent duplicate itterations.
@@ -947,7 +953,7 @@ function routePath($mygrid, $start = '', $validate = false) { //Loop through all the targets.
foreach($target as $t) {
//FindPath from where we are, to the target.
- $p = Findpath($mygrid, $start, $t);
+ $p = Findpath($mygrid, $start, $t, $traverseBackwards);
//Mark where we ended up starting from.
if ($r['start'] == '')
@@ -994,7 +1000,7 @@ function routePath($mygrid, $start = '', $validate = false) { $teleouts = findTiles($mygrid, $outchar);
//New path starting from an out-location.
- $z = Findpath($mygrid, $teleouts, $t);
+ $z = Findpath($mygrid, $teleouts, $t, $traverseBackwards);
if ($z['blocked']) $blocked = true; //Optional?
$out = $z['start'];
diff --git a/pages/admin.php b/pages/admin.php index 3685eec..983c4bc 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -164,7 +164,7 @@ function createThumbnail($mapMatrix, $idprefix, $width, $height) { $mapdata['example'] = $example;
$mapdata['mapid'] = $idprefix;
- $path = routePath($mapMatrix, '');
+ $path = routePath($mapMatrix);
$mapdata['code'] = GenerateMapCode($mapMatrix);
$width = (($j * 35) + 2).'px';
diff --git a/pages/gallery.php b/pages/gallery.php index a860a7c..2d540b6 100644 --- a/pages/gallery.php +++ b/pages/gallery.php @@ -29,16 +29,16 @@ include('./includes/maps.php'); include('./includes/mapoftheday.php'); -$openmaps[] = 'Souooooooooooooooooooooo'; -$openmaps[] = 'oooooooooooooooooooooooo'; -$openmaps[] = 'ooooooooooooooooeocooooo'; +$openmaps[] = 'Souxoooooooooooooooooooo'; +$openmaps[] = 'ooxooooooooooooooooooooo'; +$openmaps[] = 'oxooooooooooooooeocooooo'; $openmaps[] = 'oooooooooooooooooooooooo'; $openmaps[] = 'ooooooooooaoootooooooooo'; $openmaps[] = 'oooooooooooooooooooooooo'; $openmaps[] = 'oooooooooooooooooooooooo'; -$openmaps[] = 'oooooooooooooooooooooooo'; -$openmaps[] = 'oooooobdoooooooooooooooo'; -$openmaps[] = 'foooooooooooooooooooooos'; +$openmaps[] = 'ooooooXXoooooooooooooooo'; +$openmaps[] = 'oooooXbdoooooooooooooooo'; +$openmaps[] = 'fooooXooooooooooooooooos'; $myparams['checkpoints'] = 5; $myparams['teleports'] = 0; |