From 7a087e906f120f61cbe51f98b0e76079b0f9c13f Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Wed, 12 Dec 2012 18:38:23 -0800 Subject: RouteMultiPath() function added for cleaner code. Added validation support for RouteMultiPath() for a single 2nd-start location path. --- includes/mapoftheday.php | 2 +- includes/maps.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'includes') diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index 4f4032a..ad9167f 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file 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. -- cgit v1.2.3