author | tron |
Fri, 22 Jul 2005 07:02:20 +0000 | |
changeset 2163 | b17b313113a0 |
parent 2154 | f86c59e73a16 |
child 2186 | db48cf29b983 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
2 |
#include "openttd.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
3 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
4 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
507
diff
changeset
|
5 |
#include "map.h" |
2154
f86c59e73a16
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
6 |
#include "player.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
7 |
#include "tile.h" |
0 | 8 |
#include "viewport.h" |
9 |
#include "command.h" |
|
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
10 |
#include "variables.h" |
0 | 11 |
|
12 |
typedef struct TerraformerHeightMod { |
|
13 |
TileIndex tile; |
|
14 |
byte height; |
|
15 |
} TerraformerHeightMod; |
|
16 |
||
17 |
typedef struct TerraformerState { |
|
18 |
int height[4]; |
|
19 |
uint32 flags; |
|
20 |
||
21 |
int direction; |
|
22 |
int modheight_count; |
|
23 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
24 |
|
0 | 25 |
int32 cost; |
26 |
||
27 |
TileIndex *tile_table; |
|
28 |
TerraformerHeightMod *modheight; |
|
29 |
||
30 |
} TerraformerState; |
|
31 |
||
32 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
33 |
{ |
|
34 |
TileIndex *t; |
|
35 |
int count; |
|
36 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
37 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) |
0 | 38 |
return -1; |
39 |
||
40 |
t = ts->tile_table; |
|
41 |
for(count = ts->tile_table_count; count != 0; count--,t++) { |
|
42 |
if (*t == tile) |
|
43 |
return 0; |
|
44 |
} |
|
45 |
||
46 |
return 1; |
|
47 |
} |
|
48 |
||
49 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
50 |
{ |
|
51 |
TerraformerHeightMod *mod = ts->modheight; |
|
52 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
53 |
|
0 | 54 |
for(count = ts->modheight_count; count != 0; count--, mod++) { |
55 |
if (mod->tile == tile) |
|
56 |
return mod->height; |
|
57 |
} |
|
58 |
||
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
59 |
return TileHeight(tile); |
0 | 60 |
} |
61 |
||
62 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
63 |
{ |
|
64 |
int count; |
|
65 |
TileIndex *t; |
|
66 |
||
67 |
count = ts->tile_table_count; |
|
68 |
||
69 |
if (count >= 625) |
|
70 |
return; |
|
71 |
||
72 |
for(t = ts->tile_table; count != 0; count--,t++) { |
|
73 |
if (*t == tile) |
|
74 |
return; |
|
75 |
} |
|
76 |
||
77 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
78 |
} |
|
79 |
||
80 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
81 |
{ |
|
1981 | 82 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
83 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
84 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 85 |
TerraformAddDirtyTile(ts, tile); |
86 |
} |
|
87 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
88 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 89 |
{ |
90 |
int r; |
|
91 |
int32 ret; |
|
92 |
||
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
93 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
94 |
|
0 | 95 |
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0) |
96 |
return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
97 |
|
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
98 |
if (IsTileType(tile, MP_RAILWAY)) { |
0 | 99 |
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20}; |
100 |
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb}; |
|
345
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
101 |
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4}; |
0 | 102 |
|
103 |
// Nothing could be built at the steep slope - this avoids a bug |
|
104 |
// when you have a single diagonal track in one corner on a |
|
345
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
105 |
// basement and then you raise/lower the other corner. |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
106 |
int tileh = GetTileSlope(tile, NULL) & 0xF; |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
107 |
if (tileh == _railway_dangslopes[mode] || |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
108 |
tileh == _railway_dangslopes2[mode]) { |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
109 |
_terraform_err_tile = tile; |
0 | 110 |
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; |
111 |
return -1; |
|
112 |
} |
|
113 |
||
114 |
// If we have a single diagonal track there, the other side of |
|
115 |
// tile can be terraformed. |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
116 |
if ((_m[tile].m5&~0x40) == _railway_modes[mode]) |
0 | 117 |
return 0; |
118 |
} |
|
119 |
||
120 |
ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
121 |
||
122 |
if (ret == CMD_ERROR) { |
|
123 |
_terraform_err_tile = tile; |
|
124 |
return -1; |
|
125 |
} |
|
126 |
||
127 |
ts->cost += ret; |
|
128 |
||
129 |
if (ts->tile_table_count >= 625) |
|
130 |
return -1; |
|
131 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
132 |
||
133 |
return 0; |
|
134 |
} |
|
135 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
136 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 137 |
{ |
138 |
int nh; |
|
139 |
TerraformerHeightMod *mod; |
|
140 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
141 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
142 |
assert(tile < MapSize()); |
0 | 143 |
|
144 |
if (height < 0) { |
|
145 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
146 |
return false; |
|
147 |
} |
|
148 |
||
149 |
_error_message = STR_1004_TOO_HIGH; |
|
150 |
||
151 |
if (height > 0xF) |
|
152 |
return false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
153 |
|
0 | 154 |
nh = TerraformGetHeightOfTile(ts, tile); |
155 |
if (nh < 0 || height == nh) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
156 |
return false; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
157 |
|
1981 | 158 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
159 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
|
160 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
|
161 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
|
0 | 162 |
|
163 |
mod = ts->modheight; |
|
164 |
count = ts->modheight_count; |
|
165 |
||
166 |
for(;;) { |
|
167 |
if (count == 0) { |
|
168 |
if (ts->modheight_count >= 576) |
|
169 |
return false; |
|
170 |
ts->modheight_count++; |
|
171 |
break; |
|
172 |
} |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
173 |
if (mod->tile == tile) break; |
0 | 174 |
mod++; |
175 |
count--; |
|
176 |
} |
|
177 |
||
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
178 |
mod->tile = tile; |
0 | 179 |
mod->height = (byte)height; |
180 |
||
181 |
ts->cost += _price.terraform; |
|
182 |
||
183 |
{ |
|
184 |
int direction = ts->direction, r; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
185 |
const TileIndexDiffC *ttm; |
0 | 186 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
187 |
static const TileIndexDiffC _terraform_tilepos[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
188 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
189 |
{-2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
190 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
191 |
{ 0, -2} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
192 |
}; |
0 | 193 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
194 |
for(ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
195 |
tile += ToTileIndexDiff(*ttm); |
0 | 196 |
|
197 |
r = TerraformGetHeightOfTile(ts, tile); |
|
198 |
if (r != height && r-direction != height && r+direction != height) { |
|
199 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
200 |
return false; |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
return true; |
|
206 |
} |
|
207 |
||
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
208 |
/** Terraform land |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
209 |
* @param x,y coordinates to terraform |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
210 |
* @param p1 corners to terraform. |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
211 |
* @param p2 direction; eg up or down |
0 | 212 |
*/ |
213 |
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
214 |
{ |
|
215 |
TerraformerState ts; |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
216 |
TileIndex tile; |
0 | 217 |
int direction; |
218 |
||
219 |
TerraformerHeightMod modheight_data[576]; |
|
220 |
TileIndex tile_table_data[625]; |
|
221 |
||
222 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
223 |
||
224 |
_error_message = INVALID_STRING_ID; |
|
225 |
_terraform_err_tile = 0; |
|
226 |
||
227 |
ts.direction = direction = p2 ? 1 : -1; |
|
228 |
ts.flags = flags; |
|
229 |
ts.modheight_count = ts.tile_table_count = 0; |
|
230 |
ts.cost = 0; |
|
231 |
ts.modheight = modheight_data; |
|
232 |
ts.tile_table = tile_table_data; |
|
233 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
234 |
tile = TileVirtXY(x, y); |
0 | 235 |
|
1878
980fabc7d8a5
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
236 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
1981 | 237 |
if (tile + TileDiffXY(1, 1) > MapSize()) return CMD_ERROR; |
1878
980fabc7d8a5
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
238 |
|
0 | 239 |
if (p1 & 1) { |
1981 | 240 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
241 |
TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
|
0 | 242 |
return CMD_ERROR; |
243 |
} |
|
244 |
||
245 |
if (p1 & 2) { |
|
1981 | 246 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
247 |
TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
|
0 | 248 |
return CMD_ERROR; |
249 |
} |
|
250 |
||
251 |
if (p1 & 4) { |
|
1981 | 252 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
253 |
TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
|
0 | 254 |
return CMD_ERROR; |
255 |
} |
|
256 |
||
257 |
if (p1 & 8) { |
|
1981 | 258 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
259 |
TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
|
0 | 260 |
return CMD_ERROR; |
261 |
} |
|
262 |
||
263 |
if (direction == -1) { |
|
264 |
/* Check if tunnel would take damage */ |
|
265 |
int count; |
|
266 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
267 |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
268 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 269 |
uint z, t; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
270 |
TileIndex tile = *ti; |
0 | 271 |
|
1981 | 272 |
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
273 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
|
0 | 274 |
if (t <= z) z = t; |
1981 | 275 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
0 | 276 |
if (t <= z) z = t; |
1981 | 277 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
0 | 278 |
if (t <= z) z = t; |
279 |
||
280 |
if (!CheckTunnelInWay(tile, z*8)) |
|
281 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
if (flags & DC_EXEC) { |
|
286 |
/* Clear the landscape at the tiles */ |
|
287 |
{ |
|
288 |
int count; |
|
289 |
TileIndex *ti = ts.tile_table; |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
290 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 291 |
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
292 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
293 |
} |
0 | 294 |
|
295 |
/* change the height */ |
|
296 |
{ |
|
297 |
int count; |
|
298 |
TerraformerHeightMod *mod; |
|
299 |
||
300 |
mod = ts.modheight; |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
301 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
82d8bcc16ce2
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
302 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
303 |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
304 |
SetTileHeight(til, mod->height); |
0 | 305 |
TerraformAddDirtyTileAround(&ts, til); |
306 |
} |
|
307 |
} |
|
308 |
||
309 |
/* finally mark the dirty tiles dirty */ |
|
310 |
{ |
|
311 |
int count; |
|
312 |
TileIndex *ti = ts.tile_table; |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
313 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 314 |
MarkTileDirtyByTile(*ti); |
315 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
316 |
} |
0 | 317 |
} |
318 |
return ts.cost; |
|
319 |
} |
|
320 |
||
321 |
||
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
322 |
/** Levels a selected (rectangle) area of land |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
323 |
* @param x,y end tile of area-drag |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
324 |
* @param p1 start tile of area drag |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
325 |
* @param p2 unused |
0 | 326 |
*/ |
327 |
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
328 |
{ |
|
329 |
int size_x, size_y; |
|
330 |
int sx, sy; |
|
331 |
uint h, curh; |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
332 |
TileIndex tile; |
0 | 333 |
int32 ret, cost, money; |
334 |
||
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
335 |
if (p1 > MapSize()) return CMD_ERROR; |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
336 |
|
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
337 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
338 |
|
0 | 339 |
// remember level height |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
340 |
h = TileHeight(p1); |
0 | 341 |
|
342 |
ex >>= 4; ey >>= 4; |
|
343 |
||
344 |
// make sure sx,sy are smaller than ex,ey |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
345 |
sx = TileX(p1); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
346 |
sy = TileY(p1); |
0 | 347 |
if (ex < sx) intswap(ex, sx); |
348 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 349 |
tile = TileXY(sx, sy); |
0 | 350 |
|
351 |
size_x = ex-sx+1; |
|
352 |
size_y = ey-sy+1; |
|
353 |
||
354 |
money = GetAvailableMoneyForCommand(); |
|
355 |
cost = 0; |
|
356 |
||
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
357 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
358 |
curh = TileHeight(tile2); |
0 | 359 |
while (curh != h) { |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
360 |
ret = DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
361 |
if (CmdFailed(ret)) break; |
0 | 362 |
cost += ret; |
363 |
||
364 |
if (flags & DC_EXEC) { |
|
365 |
if ((money -= ret) < 0) { |
|
366 |
_additional_cash_required = ret; |
|
367 |
return cost - ret; |
|
368 |
} |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
369 |
DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 370 |
} |
371 |
||
372 |
curh += (curh > h) ? -1 : 1; |
|
373 |
} |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
374 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 375 |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
376 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 377 |
} |
378 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
379 |
/** Purchase a land area. Actually you only purchase one tile, so |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
380 |
* the name is a bit confusing ;p |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
381 |
* @param x,y the tile the player is purchasing |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
382 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
383 |
* @param p2 unused |
0 | 384 |
*/ |
385 |
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
386 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
387 |
TileIndex tile; |
0 | 388 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
389 |
|
0 | 390 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
391 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
392 |
tile = TileVirtXY(x, y); |
0 | 393 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
394 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 395 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
396 |
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 && |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
397 |
IsTileOwner(tile, _current_player)) |
0 | 398 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
399 |
||
400 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
401 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 402 |
|
403 |
if (flags & DC_EXEC) { |
|
404 |
ModifyTile(tile, |
|
405 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
406 |
3 /* map5 */ |
|
407 |
); |
|
408 |
} |
|
409 |
||
410 |
return cost + _price.purchase_land * 10; |
|
411 |
} |
|
412 |
||
413 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
414 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 415 |
{ |
0 | 416 |
static const int32 * _clear_price_table[] = { |
417 |
NULL, |
|
418 |
&_price.clear_1, &_price.clear_1,&_price.clear_1, |
|
419 |
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
|
420 |
&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2, |
|
421 |
&_price.clear_3,&_price.clear_3,&_price.clear_3,&_price.clear_3, |
|
422 |
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
|
423 |
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
|
424 |
&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2, |
|
425 |
}; |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
426 |
const int32 *price = _clear_price_table[_m[tile].m5 & 0x1F]; |
0 | 427 |
|
428 |
if (flags & DC_EXEC) |
|
429 |
DoClearSquare(tile); |
|
430 |
||
431 |
if (price == NULL) |
|
432 |
return 0; |
|
433 |
return *price; |
|
434 |
} |
|
435 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
436 |
/** Sell a land area. Actually you only sell one tile, so |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
437 |
* the name is a bit confusing ;p |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
438 |
* @param x,y the tile the player is selling |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
439 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
440 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
441 |
*/ |
0 | 442 |
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
443 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
444 |
TileIndex tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
445 |
|
0 | 446 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
447 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
448 |
tile = TileVirtXY(x, y); |
0 | 449 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
450 |
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR; |
1878
980fabc7d8a5
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
451 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
980fabc7d8a5
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
452 |
|
0 | 453 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
454 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 455 |
|
456 |
if (flags & DC_EXEC) |
|
457 |
DoClearSquare(tile); |
|
458 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
459 |
return - _price.purchase_land * 2; |
0 | 460 |
} |
461 |
||
462 |
||
463 |
#include "table/clear_land.h" |
|
464 |
||
465 |
||
466 |
void DrawClearLandTile(TileInfo *ti, byte set) |
|
467 |
{ |
|
468 |
DrawGroundSprite(0xF54 + _tileh_to_sprite[ti->tileh] + set * 19); |
|
469 |
} |
|
470 |
||
471 |
void DrawHillyLandTile(TileInfo *ti) |
|
472 |
{ |
|
473 |
if (ti->tileh != 0) { |
|
474 |
DrawGroundSprite(0xFA0 + _tileh_to_sprite[ti->tileh]); |
|
475 |
} else { |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
476 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 477 |
} |
478 |
} |
|
479 |
||
480 |
void DrawClearLandFence(TileInfo *ti, byte img) |
|
481 |
{ |
|
482 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
483 |
|
0 | 484 |
if (ti->tileh & 2) { |
485 |
z += 8; |
|
486 |
if (ti->tileh == 0x17) |
|
487 |
z += 8; |
|
488 |
} |
|
489 |
||
490 |
if (img & 0x38) { |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
491 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(img, 3, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 492 |
} |
493 |
||
494 |
if (img & 0x7) { |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
495 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(img, 0, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 496 |
} |
497 |
} |
|
498 |
||
499 |
static void DrawTile_Clear(TileInfo *ti) |
|
500 |
{ |
|
501 |
||
502 |
switch((ti->map5 & (7<<2)) >> 2) { |
|
503 |
case 0: |
|
504 |
DrawClearLandTile(ti, (ti->map5 & 3)); |
|
505 |
break; |
|
506 |
||
507 |
case 1: |
|
508 |
DrawHillyLandTile(ti); |
|
509 |
break; |
|
510 |
||
511 |
case 2: |
|
512 |
DrawGroundSprite(0xFB7 + _tileh_to_sprite[ti->tileh]); |
|
513 |
break; |
|
514 |
||
515 |
case 3: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
516 |
DrawGroundSprite( _clear_land_sprites_1[_m[ti->tile].m3&0xF] + _tileh_to_sprite[ti->tileh]); |
0 | 517 |
break; |
518 |
||
519 |
case 4: |
|
520 |
DrawGroundSprite( _clear_land_sprites_2[ti->map5&3] + _tileh_to_sprite[ti->tileh]); |
|
521 |
break; |
|
522 |
||
523 |
case 5: |
|
524 |
DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]); |
|
525 |
break; |
|
526 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
527 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
528 |
DrawClearLandFence(ti, _m[ti->tile].m4 >> 2); |
0 | 529 |
} |
530 |
||
1095 | 531 |
static uint GetSlopeZ_Clear(TileInfo *ti) |
532 |
{ |
|
533 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
|
534 |
} |
|
0 | 535 |
|
1095 | 536 |
static uint GetSlopeTileh_Clear(TileInfo *ti) |
39 | 537 |
{ |
538 |
return ti->tileh; |
|
539 |
} |
|
540 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
541 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 542 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
543 |
/* unused */ |
0 | 544 |
} |
545 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
546 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 547 |
{ |
548 |
/* unused */ |
|
549 |
} |
|
550 |
||
1293 | 551 |
void TileLoopClearHelper(TileIndex tile) |
0 | 552 |
{ |
1293 | 553 |
byte img_1; |
554 |
byte img_2; |
|
1571
9afc220894dd
(svn r2075) -Fix: added missing breaks in switches
truelight
parents:
1298
diff
changeset
|
555 |
static const byte img_by_map5[] = { 0, 0, 0, 2, 1, 1, 0, 0 }; |
1293 | 556 |
TileIndex dirty = INVALID_TILE; |
0 | 557 |
|
1293 | 558 |
switch (GetTileType(tile)) { |
559 |
case MP_CLEAR: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
560 |
img_1 = img_by_map5[(_m[tile].m5 & 0x1C) >> 2]; |
1293 | 561 |
break; |
562 |
||
563 |
case MP_TREES: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
564 |
if ((_m[tile].m2 & 0x30) == 0x20) |
1293 | 565 |
img_1 = 1; |
566 |
else |
|
567 |
img_1 = 0; |
|
1298 | 568 |
break; |
1293 | 569 |
|
570 |
default: |
|
571 |
img_1 = 0; |
|
572 |
break; |
|
0 | 573 |
} |
574 |
||
1293 | 575 |
switch (GetTileType(TILE_ADDXY(tile, 1, 0))) { |
576 |
case MP_CLEAR: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
577 |
img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 1, 0)].m5 & 0x1C) >> 2]; |
1293 | 578 |
break; |
579 |
||
580 |
case MP_TREES: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
581 |
if ((_m[TILE_ADDXY(tile, 1, 0)].m2 & 0x30) == 0x20) |
1293 | 582 |
img_2 = 1; |
583 |
else |
|
584 |
img_2 = 0; |
|
585 |
break; |
|
586 |
||
587 |
default: |
|
588 |
img_2 = 0; |
|
589 |
break; |
|
0 | 590 |
} |
591 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
592 |
if ((_m[tile].m4 & 0xE0) == 0) { |
1293 | 593 |
if ((img_1 & 2) != (img_2 & 2)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
594 |
_m[tile].m4 |= 3 << 5; |
0 | 595 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
596 |
} |
0 | 597 |
} else { |
598 |
if (img_1 == 1 && img_2 == 1) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
599 |
_m[tile].m4 &= ~(3 << 5); |
0 | 600 |
dirty = tile; |
601 |
} |
|
602 |
} |
|
603 |
||
1293 | 604 |
switch (GetTileType(TILE_ADDXY(tile, 0, 1))) { |
605 |
case MP_CLEAR: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
606 |
img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 0, 1)].m5 & 0x1C) >> 2]; |
1293 | 607 |
break; |
608 |
||
609 |
case MP_TREES: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
610 |
if ((_m[TILE_ADDXY(tile, 0, 1)].m2 & 0x30) == 0x20) |
1293 | 611 |
img_2 = 1; |
612 |
else |
|
613 |
img_2 = 0; |
|
614 |
break; |
|
615 |
||
616 |
default: |
|
617 |
img_2 = 0; |
|
618 |
break; |
|
0 | 619 |
} |
620 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
621 |
if ((_m[tile].m4 & 0x1C) == 0) { |
1293 | 622 |
if ((img_1 & 2) != (img_2 & 2)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
623 |
_m[tile].m4 |= 3 << 2; |
0 | 624 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
625 |
} |
0 | 626 |
} else { |
627 |
if (img_1 == 1 && img_2 == 1) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
628 |
_m[tile].m4 &= ~(3 << 2); |
0 | 629 |
dirty = tile; |
630 |
} |
|
631 |
} |
|
632 |
||
1293 | 633 |
if (dirty != INVALID_TILE) |
0 | 634 |
MarkTileDirtyByTile(dirty); |
635 |
} |
|
636 |
||
637 |
||
638 |
/* convert into snowy tiles */ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
639 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 640 |
{ |
641 |
int k; |
|
642 |
byte m5,tmp; |
|
643 |
||
644 |
/* distance from snow line, in steps of 8 */ |
|
645 |
k = GetTileZ(tile) - _opt.snow_line; |
|
646 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
647 |
m5 = _m[tile].m5 & 0x1C; |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
648 |
tmp = _m[tile].m5 & 3; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
649 |
|
0 | 650 |
if (k < -8) { |
651 |
/* snow_m2_down */ |
|
652 |
if (m5 != 0x10) |
|
653 |
return; |
|
654 |
if (tmp == 0) |
|
655 |
m5 = 3; |
|
656 |
} else if (k == -8) { |
|
657 |
/* snow_m1 */ |
|
658 |
if (m5 != 0x10) { |
|
659 |
m5 = 0x10; |
|
660 |
} else if (tmp != 0) { |
|
661 |
m5 = (tmp - 1) + 0x10; |
|
662 |
} else |
|
663 |
return; |
|
664 |
} else if (k < 8) { |
|
665 |
/* snow_0 */ |
|
666 |
if (m5 != 0x10) { |
|
667 |
m5 = 0x10; |
|
668 |
} else if (tmp != 1) { |
|
669 |
m5 = 1; |
|
670 |
if (tmp != 0) |
|
671 |
m5 = tmp - 1; |
|
672 |
m5 += 0x10; |
|
673 |
} else |
|
674 |
return; |
|
675 |
} else if (k == 8) { |
|
676 |
/* snow_p1 */ |
|
677 |
if (m5 != 0x10) { |
|
678 |
m5 = 0x10; |
|
679 |
} else if (tmp != 2) { |
|
680 |
m5 = 2; |
|
681 |
if (tmp <= 2) |
|
682 |
m5 = tmp + 1; |
|
683 |
m5 += 0x10; |
|
684 |
} else |
|
685 |
return; |
|
686 |
} else { |
|
687 |
/* snow_p2_up */ |
|
688 |
if (m5 != 0x10) { |
|
689 |
m5 = 0x10; |
|
690 |
} else if (tmp != 3) { |
|
691 |
m5 = tmp + 1 + 0x10; |
|
692 |
} else |
|
693 |
return; |
|
694 |
} |
|
695 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
696 |
_m[tile].m5 = m5; |
0 | 697 |
MarkTileDirtyByTile(tile); |
698 |
} |
|
699 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
700 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 701 |
{ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
702 |
if ( (_m[tile].m5 & 0x1C) == 0x14) |
0 | 703 |
return; |
704 |
||
705 |
if (GetMapExtraBits(tile) == 1) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
706 |
_m[tile].m5 = 0x17; |
0 | 707 |
} else { |
1981 | 708 |
if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 && |
709 |
GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 && |
|
710 |
GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 && |
|
711 |
GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1) |
|
712 |
return; |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
713 |
_m[tile].m5 = 0x15; |
0 | 714 |
} |
715 |
||
716 |
MarkTileDirtyByTile(tile); |
|
717 |
} |
|
718 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
719 |
static void TileLoop_Clear(TileIndex tile) |
0 | 720 |
{ |
721 |
byte m5,m3; |
|
722 |
||
723 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
724 |
|
0 | 725 |
if (_opt.landscape == LT_DESERT) { |
726 |
TileLoopClearDesert(tile); |
|
727 |
} else if (_opt.landscape == LT_HILLY) { |
|
728 |
TileLoopClearAlps(tile); |
|
729 |
} |
|
730 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
731 |
m5 = _m[tile].m5; |
0 | 732 |
if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) |
733 |
return; |
|
734 |
||
735 |
if ( (m5 & 0x1C) != 0xC) { |
|
736 |
if ( (m5 & 3) == 3) |
|
737 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
738 |
|
0 | 739 |
if (_game_mode != GM_EDITOR) { |
740 |
m5 += 0x20; |
|
741 |
if (m5 >= 0x20) { |
|
742 |
// Didn't overflow |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
743 |
_m[tile].m5 = m5; |
0 | 744 |
return; |
745 |
} |
|
746 |
/* did overflow, so continue */ |
|
747 |
} else { |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
748 |
m5 = (GB(Random(), 0, 8) > 21) ? 2 : 6; |
0 | 749 |
} |
750 |
m5++; |
|
751 |
} else if (_game_mode != GM_EDITOR) { |
|
752 |
/* handle farm field */ |
|
753 |
m5 += 0x20; |
|
754 |
if (m5 >= 0x20) { |
|
755 |
// Didn't overflow |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
756 |
_m[tile].m5 = m5; |
0 | 757 |
return; |
758 |
} |
|
759 |
/* overflowed */ |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
760 |
m3 = _m[tile].m3 + 1; |
0 | 761 |
assert( (m3 & 0xF) != 0); |
762 |
if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */ |
|
763 |
m3 &= ~0xF; |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
764 |
_m[tile].m3 = m3; |
0 | 765 |
} |
766 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
767 |
_m[tile].m5 = m5; |
0 | 768 |
MarkTileDirtyByTile(tile); |
769 |
} |
|
770 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
771 |
void GenerateClearTile(void) |
0 | 772 |
{ |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
773 |
uint i; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
774 |
TileIndex tile; |
0 | 775 |
|
776 |
/* add hills */ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1130
diff
changeset
|
777 |
i = ScaleByMapSize((Random() & 0x3FF) + 0x400); |
0 | 778 |
do { |
2051 | 779 |
tile = RandomTile(); |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
780 |
if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1); |
0 | 781 |
} while (--i); |
782 |
||
783 |
/* add grey squares */ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1130
diff
changeset
|
784 |
i = ScaleByMapSize((Random() & 0x7F) + 0x80); |
0 | 785 |
do { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
786 |
uint32 r = Random(); |
2051 | 787 |
tile = RandomTileSeed(r); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
788 |
if (IsTileType(tile, MP_CLEAR)) { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
789 |
uint j = GB(r, 16, 4) + 5; |
0 | 790 |
for(;;) { |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
791 |
TileIndex tile_new; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
792 |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
793 |
SB(_m[tile].m5, 2, 2, 2); |
0 | 794 |
do { |
795 |
if (--j == 0) goto get_out; |
|
900 | 796 |
tile_new = tile + TileOffsByDir(Random() & 3); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
797 |
} while (!IsTileType(tile_new, MP_CLEAR)); |
0 | 798 |
tile = tile_new; |
799 |
} |
|
800 |
get_out:; |
|
801 |
} |
|
802 |
} while (--i); |
|
803 |
} |
|
804 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
805 |
static void ClickTile_Clear(TileIndex tile) |
0 | 806 |
{ |
807 |
/* not used */ |
|
808 |
} |
|
809 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
810 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 811 |
{ |
812 |
return 0; |
|
813 |
} |
|
814 |
||
815 |
static const StringID _clear_land_str[4+8-1] = { |
|
816 |
STR_080B_ROUGH_LAND, |
|
817 |
STR_080A_ROCKS, |
|
818 |
STR_080E_FIELDS, |
|
819 |
STR_080F_SNOW_COVERED_LAND, |
|
820 |
STR_0810_DESERT, |
|
821 |
0, |
|
822 |
0, |
|
823 |
STR_080C_BARE_LAND, |
|
824 |
STR_080D_GRASS, |
|
825 |
STR_080D_GRASS, |
|
826 |
STR_080D_GRASS, |
|
827 |
}; |
|
828 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
829 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 830 |
{ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
831 |
int i = (_m[tile].m5>>2) & 7; |
0 | 832 |
if (i == 0) |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
833 |
i = (_m[tile].m5 & 3) + 8; |
0 | 834 |
td->str = _clear_land_str[i - 1]; |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
835 |
td->owner = GetTileOwner(tile); |
0 | 836 |
} |
837 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
838 |
static void ChangeTileOwner_Clear(TileIndex tile, byte old_player, byte new_player) |
0 | 839 |
{ |
840 |
return; |
|
841 |
} |
|
842 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
843 |
void InitializeClearLand(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
844 |
{ |
0 | 845 |
_opt.snow_line = _patches.snow_line_height * 8; |
846 |
} |
|
847 |
||
848 |
const TileTypeProcs _tile_type_clear_procs = { |
|
849 |
DrawTile_Clear, /* draw_tile_proc */ |
|
850 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
851 |
ClearTile_Clear, /* clear_tile_proc */ |
|
852 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
853 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
854 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
855 |
ClickTile_Clear, /* click_tile_proc */ |
|
856 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
857 |
TileLoop_Clear, /* tile_loop_clear */ |
|
858 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
859 |
NULL, /* get_produced_cargo_proc */ |
|
860 |
NULL, /* vehicle_enter_tile_proc */ |
|
861 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 862 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 863 |
}; |