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