summaryrefslogtreecommitdiffstats
path: root/includes/mapclass.php
blob: ddf08cd48d9c3168a9b4cde86d7b2a126f3c0f9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?
// MAP CLASS OBJECT
// Snap - 12/14/2012

//Remember, $this->value NOT $this->$value;

//Our psuedo enums.
define("TileType", 0);
define("TileValue", 1);

define("TileEmpty", 'o');
define("TileStart", 's');
define("TileFinish", 'f');
define("TileCheckpoint", 'c');
define("TileRock", 'r');
define("TileTeleportIn", 't');
define("TileTeleportOut", 'u');
define("TileUnbuildable", 'q');
define("TileSinglePath", 'x');

class map {
	public $name;
	public $tiles;
	
	public $teleports;
	public $checkpoints;
	public $height;
	public $width;
	public $isBlind;
	public $isMultiPath;
	
	public $code;
	
	public function __construct($code = NULL) {
		if ($code !== NULL)
			$this->applyMapFromOldCode($code);
		//echo "Construct complete";
	}
	
	public function applyMapFromOldCode($code) {
		//echo "decoding mapcode: [$code]";
		unset($this->tiles);
		
		$tmp = explode( ":", $code);
		$headers = explode( '.', $tmp[0]);
		$splitCode = explode( '.', $tmp[1]);

		$dimensions = explode( 'x', $headers[0]);
		$this->width = $dimensions[0];
		$this->height = $dimensions[1];
		$this->name = $headers[5];	//Map Name
		
		//Make assumptions:
		$this->isMultiPath = false;
		$this->isBlind = false;
		$this->teleports = 0;
		$this->checkpoints = 0;
		
		$t = -1;
		$index = 0;
		for ($y = 0; $y < $this->height; $y++) {		//Number of Rows
			for ($x = 0; $x < $this->width; $x++) {		//Number of Columns
				$t++;
				$next = substr($splitCode[$index], 0, strlen($splitCode[$index]) - 1);
				
				//Are we at the next target, if there is one.
				if ($next == $t AND $next != '') {
					
					//Update tile.
					$type = substr($splitCode[$index], -1, 1);
					
					$value = '';
					// Count checkpoints and etc.
					switch ($type) {
						case 'S':
						$this->isMultiPath = true;
						$value = 1;
						$type = 's';
						break;
						case 'R':
						$value = 1;
						$type = 'r';
						break;
						case 'q':
						$value = 2;
						$type = 'r';
						break;
						//Probably a more intelligent way to do this; but it works:
						case 'a': $value = ''; $type = 'c'; break;
						case 'b': $value = 2; $type = 'c'; break;
						case 'c': $value = 3; $type = 'c'; break;
						case 'd': $value = 4; $type = 'c'; break;
						case 'e': $value = 5; $type = 'c'; break;	

						case 't': $value = ''; $type = 't'; break;
						case 'm': $value = 2; $type = 't'; break;
						case 'g': $value = 3; $type = 't'; break;
						case 'i': $value = 4; $type = 't'; break;
						case 'k': $value = 5; $type = 't'; break;
						
						case 'u': $value = ''; $type = 'u'; break;
						case 'n': $value = 2; $type = 'u'; break;
						case 'h': $value = 3; $type = 'u'; break;
						case 'j': $value = 4; $type = 'u'; break;
						case 'l': $value = 5; $type = 'u'; break;
					}
					
					$this->tiles[$y][$x][TileType] = $type;
					$this->tiles[$y][$x][TileValue] = $value;
					$index++;
					//Start from 0 again.
					$t = -1;

				} else {
					$this->tiles[$y][$x][TileType] = 'o';	//Empty Tile
				}
			}
		}
	}

	//Creates the map based on a new code.
	public function applyMapFromNewCode($code) {
		$this->code = $code;
	}
	
	//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:
	}
	
	//Other "Magical" functions.
	public function __toString() {
		return $this->name;
	}
	
}














?>