diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2012-12-12 18:38:23 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2012-12-12 18:38:23 -0800 |
commit | 7a087e906f120f61cbe51f98b0e76079b0f9c13f (patch) | |
tree | 1909a24d2f22245140d8214a52ba615545c258e9 /includes/maps.php | |
parent | 84b050664c8c8968a9c264460016b68595702dc4 (diff) | |
download | pathery-7a087e906f120f61cbe51f98b0e76079b0f9c13f.tar.xz |
RouteMultiPath() function added for cleaner code.
Added validation support for RouteMultiPath() for a single 2nd-start location path.
Diffstat (limited to 'includes/maps.php')
-rw-r--r-- | includes/maps.php | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/includes/maps.php b/includes/maps.php index b6912a2..431f006 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -108,7 +108,8 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) $mapdata['example'] = $example;
$mapdata['mapid'] = $idprefix;
- $path = routePath($mapMatrix);
+ //TODO: del
+ //$path = routePath($mapMatrix);
$mapdata['code'] = GenerateMapCode($mapMatrix);
$width = (($j * 35) + 2).'px';
@@ -460,7 +461,8 @@ function GenerateShapedMap($shape, $params) { }
//echo "\n";
}
- $path = routePath($mapMatrix, true);
+ //$path = routePath($mapMatrix, true);
+ $path = routeMultiPath($mapMatrix, true);
//echo $path['blocked']."\n";
//Only repeat if it's blocked.
} while ($path['blocked'] == true);
@@ -889,6 +891,28 @@ function GetTile($mapMatrix, $id) return $toReturn;
}
*/
+
+function routeMultiPath($map, $validate = false) {
+ //Check both starting point groups for paths
+ $r['totalMoves'] = 0;
+ $r['blocked'] = false;
+ $containsNormalStart = (findTiles($map, "s") !== false);
+ $containsReverseStart = (findTiles($map, "S") !== false);
+ if($containsNormalStart) {
+ $r['path'][0] = routePath($map, $validate);
+ $r['totalMoves'] += $r['path'][0]['moves'];
+ $r['blocked'] = $r['path'][0]['blocked'];
+ }
+ if ($r['blocked'])
+ return $r;
+ if($containsReverseStart) {
+ //No need to run the "validation" twice;
+ $r['path'][1] = routePath($map, false, true);
+ $r['totalMoves'] += $r['path'][1]['moves'];
+ $r['blocked'] = $r['path'][1]['blocked'] || $r['blocked'];
+ }
+ return $r;
+}
//Routes a path through all checkpoints and teleports, returning an array.
// [path] path-string. [blocked] boolean, [moves] int.
|