summaryrefslogtreecommitdiffstats
path: root/includes/maps.php
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2011-05-02 22:52:56 -0700
committerPatrick Davison <snapwilliam@gmail.com>2011-05-02 22:52:56 -0700
commitf9333b70547ae514ecc848fb195011a11897ee68 (patch)
tree5ea7abc10c215c2a4ca837f1fa90ebef874b9490 /includes/maps.php
parent6554ac5bcacd25b6062d298a0e0b7ed6982282ba (diff)
downloadpathery-f9333b70547ae514ecc848fb195011a11897ee68.tar.xz
Improved map validation.
Diffstat (limited to 'includes/maps.php')
-rw-r--r--includes/maps.php40
1 files changed, 19 insertions, 21 deletions
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.