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