summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlueRaja <BlueRaja.admin@gmail.com>2012-08-25 04:58:04 -0500
committerBlueRaja <BlueRaja.admin@gmail.com>2012-08-25 04:58:04 -0500
commite2cfff284c4004d0d11609a22ee535fcf23dcdf9 (patch)
tree0356f12c2b52fb7798bd4e7c4cc59cc8401f7a50
parent5d40666d1cb667342b0ad1365a13c87923da0eb2 (diff)
downloadpathery-e2cfff284c4004d0d11609a22ee535fcf23dcdf9.tar.xz
Added single-path blocking towers functionality to routePath
-rw-r--r--do.php4
-rw-r--r--includes/maps.php44
-rw-r--r--pages/admin.php2
-rw-r--r--pages/gallery.php12
4 files changed, 34 insertions, 28 deletions
diff --git a/do.php b/do.php
index e0dc2eb..a39b689 100644
--- a/do.php
+++ b/do.php
@@ -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;