From f5d9568541feab221a366075517d99d5c17a57c6 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Wed, 30 Nov 2011 01:23:38 -0800 Subject: Favicon. Support for multi tele-outs + efficiency improvements. --- includes/maps.php | 57 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'includes') diff --git a/includes/maps.php b/includes/maps.php index 4ff205f..2e80eb1 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -734,7 +734,6 @@ function findTiles ($mapMatrix, $search) { // Returns: ARRAY( blocked, path, start, end ) -//!! X and Y are reversed here... function findPath($mapMatrix, $start = '0,1', $target = 'f') { //Remove last period if existing. @@ -774,7 +773,7 @@ function findPath($mapMatrix, $start = '0,1', $target = 'f') { //Is this tile even on the map? if (!isset($mapMatrix[$y][$x])) { - continue; + continue 1; } $path = ''; @@ -819,6 +818,7 @@ function findPath($mapMatrix, $start = '0,1', $target = 'f') { if (count($seed) < 2) { $r['blocked'] = true; $r['path'] = $seed[$key][3].$i; + $r['start'] = $v[2]; $r['end'] = "$x,$y"; return $r; } @@ -847,6 +847,9 @@ function GetTile($mapMatrix, $id) // [path] path-string. [blocked] boolean, [moves] int. function routePath($mygrid, $start = '', $validate = false) { + //Our response + $r = array('start' => NULL, 'path' => NULL, 'blocked' => true); + //Locate the start locations. $start = findTiles($mygrid, "s"); @@ -889,23 +892,32 @@ function routePath($mygrid, $start = '', $validate = false) { $target[] = $teleout[$tin]; } + //Prepare vars for iteration; + $tpath = ''; + $movesoffset = 0; + //Loop through all the targets. foreach($target as $t) { - //Path from where we are, to the target. - $p = Findpath ($mygrid, $start, $t); - //echo "FP: ".$p['path']; - //echo "T: $t"; - //It's possible to start from multiple places; - //so mark where we ended up starting from. + //FindPath from where we are, to the target. + $p = Findpath($mygrid, $start, $t); + + //Mark where we ended up starting from. if ($r['start'] == '') $r['start'] = $p['start']; - + //Could be blocked right already. + $blocked = $p['blocked']; do { + //Exit if path is blocked. + if ($blocked) { + $r['blocked'] = true; + return $r; + } + //Make sure there is a teleport to search. if (! is_array($teleport)) break 1; + //Search through the path to find first teleport hit, if any. - $pathary = str_split($p['path']); //As per usual, it's best to assume that you've failed. @@ -916,32 +928,27 @@ function routePath($mygrid, $start = '', $validate = false) { //$r['z'] .= ';'.$f++; if ($port == $char) { //Disable teleport - //$teleport[$ktel] = ''; unset($teleport[$ktel]); - //$teleport = array_values($teleport); //We found it $foundtele = true; break 2; } } } - if ($foundtele == false) { + if ($foundtele == false) break 1; - } - $outchar = $teleout[$port]; if ($position === false) continue; - //Where is the tele $out location. - // == String/array, messy.. needs a bit of changes to fix though. - $out = findTiles($mygrid, $outchar); - $out = explode(".", $out); - $out = $out[0]; - if ($x['blocked']) $blocked = true; //Optional? - - //New path starting from our out-location. - $z = Findpath($mygrid, $out, $t); + + + //Find the teleport outs + $teleouts = findTiles($mygrid, $outchar); + + //New path starting from an out-location. + $z = Findpath($mygrid, $teleouts, $t); if ($z['blocked']) $blocked = true; //Optional? + $out = $z['start']; //Deactivate teleport $teleactive[$port] = false; @@ -971,11 +978,9 @@ function routePath($mygrid, $start = '', $validate = false) { } $r['blocked'] = $blocked; $r['path'] = $tpath; - //$moves = count_chars($tpath, 0); $moves = countmoves($tpath); $moves += $movesoffset; $r['moves'] = $moves; - //$r['moves'] = print_r($moves); return $r; } //For use with routepath; -- cgit v1.2.3