summaryrefslogtreecommitdiffstats
path: root/includes/mapclass.php
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-01-26 01:08:50 -0800
committerPatrick Davison <snapwilliam@gmail.com>2013-01-26 01:08:50 -0800
commit8e348cfd94360aee814a2dd629b4279818ddfc58 (patch)
tree2962a4b3478381bacbef77e40a00cae1926e7458 /includes/mapclass.php
parent75bde8678d1f04aed2bedf75bb2db1bcc8dec5af (diff)
downloadpathery-8e348cfd94360aee814a2dd629b4279818ddfc58.tar.xz
New mapcode applied to the Mapclass.
Diffstat (limited to 'includes/mapclass.php')
-rw-r--r--includes/mapclass.php96
1 files changed, 89 insertions, 7 deletions
diff --git a/includes/mapclass.php b/includes/mapclass.php
index 03bbedd..21c7778 100644
--- a/includes/mapclass.php
+++ b/includes/mapclass.php
@@ -20,13 +20,19 @@ define("TileUnbuildable", 'q');
define("TileSinglePath", 'x');
class map {
- public $name;
public $tiles;
-
public $teleports;
public $checkpoints;
- public $height;
+
+ //These are headers actually used in the mapCode
public $width;
+ public $height;
+ public $walls;
+ public $name;
+ public $flags;
+ public $dateCreated;
+ public $dateExpires;
+
public $isBlind;
public $isMultiPath;
@@ -49,6 +55,7 @@ class map {
$dimensions = explode( 'x', $headers[0]);
$this->width = $dimensions[0];
$this->height = $dimensions[1];
+ $this->walls = substr($headers[3], 1);
$this->name = $headers[5]; //Map Name
//Make assumptions:
@@ -116,17 +123,92 @@ class map {
}
}
- //Creates the map based on a new code.
- public function applyMapFromNewCode($code) {
- $this->code = $code;
+ //From the newer mapcode.
+ public function applyMapFromCode($code) {
+ //echo "decoding mapcode: [$code]";
+ unset($this->tiles);
+
+ $tmp = explode( ":", $code);
+ $headers = explode( '.', $tmp[0]);
+ $splitCode = explode( '.', $tmp[1]);
+
+ $this->width = $headers[0];
+ $this->height = $headers[1];
+ $this->walls = $headers[2];
+ $this->name = $headers[3];
+ $this->flags = $headers[4];
+ $this->dateCreated = $headers[5];
+ $this->dateExpires = $headers[6];
+
+ //switch FLAGS.
+ $this->isBlind = false;
+
+ //Make assumptions:
+ $this->isMultiPath = false;
+ $this->teleports = 0;
+ $this->checkpoints = 0;
+
+ $distance = -1;
+ $index = 0;
+
+ //First Element
+ $codePart = explode(',', $splitCode[$index]);
+ $next = $codePart[0];
+
+ for ($y = 0; $y < $this->height; $y++) { //Number of Rows
+ for ($x = 0; $x < $this->width; $x++) { //Number of Columns
+ $distance++;
+ if ($distance == $next) {
+
+ $type = $codePart[1][0];
+ $value = substr($codePart[1], 1);
+ if ($value <= 1) $value = '';
+
+ $this->tiles[$y][$x][TileType] = $type;
+ $this->tiles[$y][$x][TileValue] = $value;
+
+ //Next Element
+ $index++;
+ $codePart = explode(',', $splitCode[$index]);
+ $next = $codePart[0];
+ if ($next == '') $next = 0;
+
+ //Start from 0 again.
+ $distance = -1;
+ } else {
+ $this->tiles[$y][$x][TileType] = TileEmpty;
+ }
+ }
+ }
}
-
+
//Outputs the new code.
public function getCode() {
//If we already have the code on hand...
if ($this->code)
return $this->code;
//Otherwise we need to build the code:
+ $headers[0] = $this->width;
+ $headers[1] = $this->height;
+ $headers[3] = $this->walls;
+ $headers[4] = $this->name;
+ $headers[5] = $this->flags;
+ $headers[6] = $this->dateCreated;
+ $headers[7] = $this->dateExpires;
+
+ $code = implode(".", $headers).':';
+
+ for ($y = 0; $y < $this->height; $y++) { //Number of Rows
+ for ($x = 0; $x < $this->width; $x++) { //Number of Columns
+ if ($this->tiles[$y][$x][TileType] !== TileEmpty) {
+ $code .= $position.','.$this->tiles[$y][$x][TileType].$this->tiles[$y][$x][TileValue].'.';
+ $position = -1;
+ }
+ $position++;
+ }
+ }
+ $this->code = $code;
+ return $code;
}
//Other "Magical" functions.