From f9333b70547ae514ecc848fb195011a11897ee68 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Mon, 2 May 2011 22:52:56 -0700 Subject: Improved map validation. --- includes/maps.php | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'includes') diff --git a/includes/maps.php b/includes/maps.php index 8cee2b3..0f6dfd8 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -291,8 +291,8 @@ function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = $grid[0][4] = $numBlocks; $grid[0][5] = count($teleport); - //Confirm the map isn't broken to start-out. - $path = routePath($grid); + //Validate map + $path = routePath($grid, '', true); //Only repeat if it's blocked. } while ($path['blocked'] == true); @@ -367,7 +367,7 @@ function GenerateShapedMap($shape, $params) { } //echo "\n"; } - $path = routePath($mapMatrix); + $path = routePath($mapMatrix, '', true); //echo $path['blocked']."\n"; //Only repeat if it's blocked. } while ($path['blocked'] == true); @@ -768,7 +768,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 = '') { +function routePath($mygrid, $start = '', $validate = false) { //Locate the start locations. $start = findTiles($mygrid, "s"); @@ -776,16 +776,12 @@ function routePath($mygrid, $start = '') { //Checkpoint names $cpnames = Array("a", "b", "c", "d", "e"); - //Get the amount of checkpoints on this map. - $cpcount = 0; + + //Add the existing checkpoints to target array. foreach ($cpnames as $cpt) if (findTiles($mygrid, $cpt)) - $cpcount++; + $target[] = $cpt; - //Add the existing checkpoints to target array. - for($p = 0; $p < $cpcount; $p++) { - $target[] = $cpnames[$p]; - } //Our last target is the finish line. $target[] = 'f'; @@ -794,16 +790,6 @@ function routePath($mygrid, $start = '') { //All possible teleports in play. $tpnames = Array('t', 'm', 'g', 'i', 'k'); - //Find all the existing teleports. - $tpcount = 0; - foreach ($tpnames as $tpt) - if (findTiles($mygrid, $tpt)) - $tpcount++; - - //Save the existing teleports, to check for them later. - for($p = 0; $p < $tpcount; $p++) { - $teleport[] = $tpnames[$p]; - } //Where there's an in, there's an out. $teleout['t'] = 'u'; @@ -812,6 +798,18 @@ function routePath($mygrid, $start = '') { $teleout['i'] = 'j'; $teleout['k'] = 'l'; + //Find all the existing teleports. + foreach ($tpnames as $tpt) + if (findTiles($mygrid, $tpt)) + $teleport[] = $tpt; + + //If validate, add teleport in/out's. + if ($validate) { + $target = array_merge($target, $teleport); + foreach ($teleport as $tin) + $target[] = $teleout[$tin]; + } + //Loop through all the targets. foreach($target as $t) { //Path from where we are, to the target. -- cgit v1.2.3