author | darkvater |
Sun, 05 Sep 2004 17:11:00 +0000 | |
changeset 160 | db200af4794a |
parent 91 | 6477ea0c240d |
child 193 | 0a7025304867 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "viewport.h" |
|
4 |
#include "command.h" |
|
5 |
#include "town.h" |
|
6 |
||
7 |
static int GetRandomTreeType(uint tile, uint seed) |
|
8 |
{ |
|
9 |
byte i; |
|
10 |
||
11 |
if (_opt.landscape == LT_NORMAL) { |
|
12 |
return seed * 12 >> 8; |
|
13 |
} else if (_opt.landscape == LT_HILLY) { |
|
14 |
return (seed >> 5) + 12; |
|
15 |
} else if (_opt.landscape == LT_DESERT) { |
|
16 |
i = GetMapExtraBits(tile); |
|
17 |
if (i == 0) { |
|
18 |
return (seed >> 6) + 28; |
|
19 |
} else if (i == 1) { |
|
20 |
if (seed > 12) |
|
21 |
return -1; |
|
22 |
return 27; |
|
23 |
} else { |
|
24 |
return (seed * 7 >> 8) + 20; |
|
25 |
} |
|
26 |
} else { |
|
27 |
return (seed * 9 >> 8) + 32; |
|
28 |
} |
|
29 |
} |
|
30 |
||
31 |
static void PlaceTree(uint tile, uint32 r, byte m5_or) |
|
32 |
{ |
|
33 |
int tree = GetRandomTreeType(tile, (r >> 24)); |
|
34 |
byte m5; |
|
35 |
||
36 |
if (tree >= 0) { |
|
37 |
m5 = (byte)(r >> 16); |
|
38 |
if(m5==7) m5--; |
|
39 |
||
40 |
_map5[tile] = m5 & 0x07; // growth state; |
|
41 |
_map5[tile] |= m5 & 0xC0; // amount of trees |
|
42 |
||
43 |
_map3_lo[tile] = tree; // set type of tree |
|
44 |
_map3_hi[tile] = 0; // no hedge |
|
45 |
||
46 |
// above snowline? |
|
47 |
if( (_opt.landscape == LT_HILLY) && (GetTileZ(tile) - _opt.snow_line > 0) ) |
|
48 |
{ |
|
49 |
_map2[tile] = 0xE0; // set land type to snow |
|
50 |
_map2[tile] |= (byte)(r >> 24)&0x07; // randomize counter |
|
51 |
} |
|
52 |
else |
|
53 |
{ |
|
54 |
_map2[tile] = (byte)(r >> 24)&0x1F; // randomize counter and ground |
|
55 |
} |
|
56 |
||
57 |
||
58 |
// make it tree class |
|
59 |
_map_type_and_height[tile] |= MP_TREES << 4; |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
static void DoPlaceMoreTrees(uint tile) |
|
64 |
{ |
|
65 |
int i = 1000; |
|
66 |
int x,y; |
|
67 |
uint cur_tile; |
|
68 |
int dist; |
|
69 |
||
70 |
do { |
|
71 |
uint32 r = Random(); |
|
72 |
x = (r & 0x1F) - 16; |
|
73 |
y = ((r>>8) & 0x1F) - 16; |
|
74 |
||
75 |
dist = myabs(x) + myabs(y); |
|
76 |
||
77 |
cur_tile=TILE_MASK(tile + TILE_XY(x,y)); |
|
78 |
||
79 |
if (dist <= 13 && IS_TILETYPE(cur_tile, MP_CLEAR)) { |
|
80 |
PlaceTree(cur_tile, r, dist <= 6 ? 0xC0 : 0); |
|
81 |
} |
|
82 |
} while (--i); |
|
83 |
} |
|
84 |
||
85 |
static void PlaceMoreTrees() |
|
86 |
{ |
|
87 |
int i = (Random() & 0x1F) + 25; |
|
88 |
do { |
|
89 |
DoPlaceMoreTrees(TILE_MASK(Random())); |
|
90 |
} while (--i); |
|
91 |
} |
|
92 |
||
93 |
void PlaceTreesRandomly() |
|
94 |
{ |
|
95 |
int i; |
|
96 |
uint32 r; |
|
97 |
uint tile; |
|
98 |
||
99 |
i = 1000; |
|
100 |
do { |
|
101 |
r = Random(); |
|
102 |
tile = TILE_MASK(r); |
|
103 |
if (IS_TILETYPE(tile, MP_CLEAR)) { |
|
104 |
PlaceTree(tile, r, 0); |
|
105 |
} |
|
106 |
} while (--i); |
|
107 |
||
108 |
/* place extra trees at rainforest area */ |
|
109 |
if (_opt.landscape == LT_DESERT) { |
|
110 |
i = 15000; |
|
111 |
||
112 |
do { |
|
113 |
r = Random(); |
|
114 |
tile = TILE_MASK(r); |
|
115 |
if (IS_TILETYPE(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) { |
|
116 |
PlaceTree(tile, r, 0); |
|
117 |
} |
|
118 |
} while (--i); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
void GenerateTrees() |
|
123 |
{ |
|
124 |
int i; |
|
125 |
||
126 |
if (_opt.landscape != LT_CANDY) { |
|
127 |
PlaceMoreTrees(); |
|
128 |
} |
|
129 |
||
130 |
i = _opt.landscape == LT_HILLY ? 15 : 6; |
|
131 |
do { |
|
132 |
PlaceTreesRandomly(); |
|
133 |
} while (--i); |
|
134 |
} |
|
135 |
||
136 |
/* Plant a tree |
|
137 |
* p1 = tree type, -1 means random. |
|
138 |
* p2 = end tile |
|
139 |
*/ |
|
140 |
||
141 |
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
142 |
{ |
|
143 |
TileInfo ti; |
|
144 |
int32 cost; |
|
145 |
int sx,sy,x,y; |
|
146 |
int treetype; |
|
147 |
||
148 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
149 |
||
150 |
// make sure sx,sy are smaller than ex,ey |
|
151 |
sx = GET_TILE_X(p2)*16; |
|
152 |
sy = GET_TILE_Y(p2)*16; |
|
153 |
if (ex < sx) intswap(ex, sx); |
|
154 |
if (ey < sy) intswap(ey, sy); |
|
155 |
||
156 |
cost = 0; // total cost |
|
157 |
||
158 |
for(x=sx; x<=ex; x+=16) { |
|
159 |
for(y=sy; y<=ey; y+=16) { |
|
160 |
FindLandscapeHeight(&ti, x, y); |
|
161 |
if (!EnsureNoVehicle(ti.tile)) |
|
162 |
continue; |
|
163 |
||
164 |
if (ti.type == MP_TREES) { |
|
165 |
// no more space for trees? |
|
166 |
if (_game_mode != GM_EDITOR && (ti.map5 & 0xC0) == 0xC0) { |
|
167 |
_error_message = STR_2803_TREE_ALREADY_HERE; |
|
168 |
continue; |
|
169 |
} |
|
170 |
||
171 |
if (flags & DC_EXEC) { |
|
172 |
_map5[ti.tile] = ti.map5 + 0x40; |
|
173 |
MarkTileDirtyByTile(ti.tile); |
|
174 |
} |
|
175 |
// 2x as expensive to add more trees to an existing tile |
|
176 |
cost += _price.build_trees * 2; |
|
177 |
} else { |
|
178 |
// don't allow building on rocks |
|
179 |
if (ti.type != MP_CLEAR || _map_owner[ti.tile] != OWNER_NONE || (ti.map5 & 0x1C) == 8) { |
|
180 |
_error_message = STR_2804_SITE_UNSUITABLE; |
|
181 |
continue; |
|
182 |
} |
|
183 |
||
184 |
// it's expensive to clear farmland |
|
185 |
if ((ti.map5 & 0x1F) == 0xF) cost += _price.clear_3; |
|
186 |
||
187 |
if (flags & DC_EXEC) { |
|
188 |
int m2; |
|
189 |
||
190 |
if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) { |
|
191 |
Town *t = ClosestTownFromTile(ti.tile, _patches.dist_local_authority); |
|
192 |
if (t != NULL) |
|
193 |
ChangeTownRating(t, 7, 220); |
|
194 |
} |
|
195 |
m2 = 0; |
|
196 |
if ( (ti.map5 & 0x1C) == 4 ) { |
|
197 |
m2 = 16; |
|
198 |
} else if ( (ti.map5 & 0x1C) == 16 ) { |
|
199 |
m2 = (ti.map5 << 6) | 0x20; |
|
200 |
} |
|
201 |
||
202 |
treetype = p1; |
|
203 |
if (treetype == -1) { |
|
204 |
treetype = GetRandomTreeType(ti.tile, Random()>>24); |
|
205 |
if (treetype==-1) treetype=27; |
|
206 |
} |
|
207 |
||
208 |
ModifyTile(ti.tile, |
|
209 |
MP_SETTYPE(MP_TREES) | |
|
210 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
|
211 |
m2, /* map2 */ |
|
212 |
treetype, /* map3lo */ |
|
213 |
_game_mode == GM_EDITOR ? 3 : 0 /* map5 */ |
|
214 |
); |
|
215 |
||
216 |
if (_game_mode == GM_EDITOR && IS_BYTE_INSIDE(treetype, 0x14, 0x1B)) { |
|
217 |
SetMapExtraBits(ti.tile, 2); |
|
218 |
} |
|
219 |
} |
|
220 |
cost += _price.build_trees; |
|
221 |
} |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
if (cost == 0) return CMD_ERROR; |
|
226 |
return cost; |
|
227 |
} |
|
228 |
||
229 |
typedef struct TreeListEnt { |
|
230 |
uint32 image; |
|
231 |
byte x,y; |
|
232 |
} TreeListEnt; |
|
233 |
||
234 |
||
235 |
#include "table/tree_land.h" |
|
236 |
||
237 |
||
238 |
static void DrawTile_Trees(TileInfo *ti) |
|
239 |
{ |
|
240 |
byte m2; |
|
241 |
const uint32 *s; |
|
242 |
const byte *d; |
|
243 |
byte z; |
|
244 |
TreeListEnt te[4]; |
|
245 |
||
246 |
m2 = _map2[ti->tile]; |
|
247 |
||
248 |
if ( (m2&0x30) == 0) { |
|
249 |
DrawClearLandTile(ti, 3); |
|
250 |
} else if ((m2&0x30) == 0x20) { |
|
251 |
DrawGroundSprite(_tree_sprites_1[m2 >> 6] + _tileh_to_sprite[ti->tileh]); |
|
252 |
} else { |
|
253 |
DrawHillyLandTile(ti); |
|
254 |
} |
|
255 |
||
256 |
DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2); |
|
257 |
||
258 |
z = ti->z; |
|
259 |
if (ti->tileh != 0) { |
|
260 |
z += 4; |
|
261 |
if (ti->tileh & 0x10) |
|
262 |
z += 4; |
|
263 |
} |
|
264 |
||
265 |
{ |
|
266 |
uint16 tmp = ti->x; |
|
267 |
int index; |
|
268 |
||
269 |
tmp = (tmp >> 2) | (tmp << 14); |
|
270 |
tmp -= ti->y; |
|
271 |
tmp = (tmp >> 3) | (tmp << 13); |
|
272 |
tmp -= ti->x; |
|
273 |
tmp = (tmp >> 1) | (tmp << 15); |
|
274 |
tmp += ti->y; |
|
275 |
||
276 |
d = _tree_layout_xy[(tmp & 0x30) >> 4]; |
|
277 |
||
278 |
index = ((tmp>>6)&3) + (_map3_lo[ti->tile]<<2); |
|
279 |
||
280 |
/* different tree styles above one of the grounds */ |
|
281 |
if ((m2 & 0xB0) == 0xA0 && index >= 48 && index < 80) |
|
282 |
index += 164 - 48; |
|
283 |
||
284 |
assert(index < lengthof(_tree_layout_sprite)); |
|
285 |
s = _tree_layout_sprite[index]; |
|
286 |
} |
|
287 |
||
288 |
StartSpriteCombine(); |
|
289 |
||
91
6477ea0c240d
(svn r92) Feature: invisible trees when in transparent mode (patch entry)
dominik
parents:
39
diff
changeset
|
290 |
if((_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) |
0 | 291 |
{ |
292 |
int i; |
|
293 |
||
294 |
/* put the trees to draw in a list */ |
|
295 |
i = (ti->map5 >> 6) + 1; |
|
296 |
do { |
|
297 |
uint32 image = s[0] + (--i==0 ? (ti->map5 & 7) : 3); |
|
298 |
if (!(_display_opt & DO_TRANS_BUILDINGS)) |
|
299 |
image = (image & 0x3FFF) | 0x3224000; |
|
300 |
te[i].image = image; |
|
301 |
te[i].x = d[0]; |
|
302 |
te[i].y = d[1]; |
|
303 |
s++; |
|
304 |
d+=2; |
|
305 |
} while (i); |
|
306 |
||
307 |
/* draw them in a sorted way */ |
|
308 |
for(;;) { |
|
309 |
byte min = 0xFF; |
|
310 |
TreeListEnt *tep = NULL; |
|
311 |
||
312 |
i = (ti->map5 >> 6) + 1; |
|
313 |
do { |
|
314 |
if (te[--i].image!=0 && (byte)(te[i].x + te[i].y) < min) { |
|
315 |
min = te[i].x + te[i].y; |
|
316 |
tep = &te[i]; |
|
317 |
} |
|
318 |
} while (i); |
|
319 |
||
320 |
if (tep == NULL) |
|
321 |
break; |
|
322 |
||
323 |
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z); |
|
324 |
tep->image = 0; |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
EndSpriteCombine(); |
|
329 |
} |
|
330 |
||
331 |
||
332 |
static uint GetSlopeZ_Trees(TileInfo *ti) { |
|
333 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
334 |
} |
|
335 |
||
39 | 336 |
static uint GetSlopeTileh_Trees(TileInfo *ti) { |
337 |
return ti->tileh; |
|
338 |
} |
|
339 |
||
0 | 340 |
static int32 ClearTile_Trees(uint tile, byte flags) { |
341 |
int num; |
|
342 |
||
343 |
if (flags & DC_EXEC && _current_player < MAX_PLAYERS) { |
|
344 |
Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
|
345 |
if (t != NULL) |
|
346 |
ChangeTownRating(t, -35, -1000); |
|
347 |
} |
|
348 |
||
349 |
num = (_map5[tile] >> 6) + 1; |
|
350 |
if ( (byte)(_map3_lo[tile]-0x14) <= (0x1A-0x14)) |
|
351 |
num <<= 2; |
|
352 |
||
353 |
if (flags & DC_EXEC) |
|
354 |
DoClearSquare(tile); |
|
355 |
||
356 |
return num * _price.remove_trees; |
|
357 |
} |
|
358 |
||
359 |
static void GetAcceptedCargo_Trees(uint tile, AcceptedCargo *ac) |
|
360 |
{ |
|
361 |
/* not used */ |
|
362 |
} |
|
363 |
||
364 |
static void GetTileDesc_Trees(uint tile, TileDesc *td) |
|
365 |
{ |
|
366 |
byte b; |
|
367 |
StringID str; |
|
368 |
||
369 |
td->owner = _map_owner[tile]; |
|
370 |
||
371 |
b = _map3_lo[tile]; |
|
372 |
(str=STR_2810_CACTUS_PLANTS, b==0x1B) || |
|
373 |
(str=STR_280F_RAINFOREST, IS_BYTE_INSIDE(b, 0x14, 0x1A+1)) || |
|
374 |
(str=STR_280E_TREES, true); |
|
375 |
td->str = str; |
|
376 |
} |
|
377 |
||
378 |
static void AnimateTile_Trees(uint tile) |
|
379 |
{ |
|
380 |
/* not used */ |
|
381 |
} |
|
382 |
||
383 |
static byte _desert_sounds[] = { |
|
384 |
66,67,68,72 |
|
385 |
}; |
|
386 |
||
387 |
static void TileLoopTreesDesert(uint tile) |
|
388 |
{ |
|
389 |
byte b; |
|
390 |
||
391 |
if ((b=GetMapExtraBits(tile)) == 2) { |
|
392 |
uint32 r; |
|
393 |
||
394 |
if (CHANCE16I(1,200,r=Random())) { |
|
395 |
SndPlayTileFx(_desert_sounds[(r >> 16) & 3], tile); |
|
396 |
} |
|
397 |
} else if (b == 1) { |
|
398 |
if ((_map2[tile] & 0x30) != 0x20) { |
|
399 |
_map2[tile] &= 0xF; |
|
400 |
_map2[tile] |= 0xE0; |
|
401 |
MarkTileDirtyByTile(tile); |
|
402 |
} |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
static void TileLoopTreesAlps(uint tile) |
|
407 |
{ |
|
408 |
byte tmp, m2; |
|
409 |
int k; |
|
410 |
||
411 |
/* distance from snow line, in steps of 8 */ |
|
412 |
k = GetTileZ(tile) - _opt.snow_line; |
|
413 |
||
414 |
tmp = _map5[tile] & 0xF0; |
|
415 |
||
416 |
if (k < -8) { |
|
417 |
/* snow_m2_down */ |
|
418 |
if ((tmp&0x30) != 0x20) |
|
419 |
return; |
|
420 |
m2 = 0; |
|
421 |
} else if (k == -8) { |
|
422 |
/* snow_m1 */ |
|
423 |
m2 = 0x20; |
|
424 |
if (tmp == m2) |
|
425 |
return; |
|
426 |
} else if (k < 8) { |
|
427 |
/* snow_0 */ |
|
428 |
m2 = 0x60; |
|
429 |
if (tmp == m2) |
|
430 |
return; |
|
431 |
} else if (k == 8) { |
|
432 |
/* snow_p1 */ |
|
433 |
m2 = 0xA0; |
|
434 |
if (tmp == m2) |
|
435 |
return; |
|
436 |
} else { |
|
437 |
/* snow_p2_up */ |
|
438 |
if (tmp == 0xC0) { |
|
439 |
uint32 r; |
|
440 |
if (CHANCE16I(1,200,r=Random())) { |
|
441 |
SndPlayTileFx( (r&0x80000000) ? 57 : 52, tile); |
|
442 |
} |
|
443 |
return; |
|
444 |
} else { |
|
445 |
m2 = 0xE0; |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
_map2[tile] &= 0xF; |
|
450 |
_map2[tile] |= m2; |
|
451 |
MarkTileDirtyByTile(tile); |
|
452 |
} |
|
453 |
||
454 |
static void TileLoop_Trees(uint tile) |
|
455 |
{ |
|
456 |
byte m5, m2; |
|
457 |
||
458 |
static const TileIndexDiff _tileloop_trees_dir[] = { |
|
459 |
TILE_XY(-1,-1), |
|
460 |
TILE_XY(0,-1), |
|
461 |
TILE_XY(1,-1), |
|
462 |
TILE_XY(-1,0), |
|
463 |
TILE_XY(1,0), |
|
464 |
TILE_XY(-1,1), |
|
465 |
TILE_XY(0,1), |
|
466 |
TILE_XY(1,1), |
|
467 |
}; |
|
468 |
||
469 |
if (_opt.landscape == LT_DESERT) { |
|
470 |
TileLoopTreesDesert(tile); |
|
471 |
} else if (_opt.landscape == LT_HILLY) { |
|
472 |
TileLoopTreesAlps(tile); |
|
473 |
} |
|
474 |
||
475 |
TileLoopClearHelper(tile); |
|
476 |
||
477 |
/* increase counter */ |
|
478 |
{ |
|
479 |
byte m2 = _map2[tile]; |
|
480 |
_map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF); |
|
481 |
if (m2 & 0xF) |
|
482 |
return; |
|
483 |
} |
|
484 |
||
485 |
m5 = _map5[tile]; |
|
486 |
if ((m5&7) == 3) { |
|
487 |
/* regular sized tree */ |
|
488 |
if (_opt.landscape == LT_DESERT && _map3_lo[tile]!=0x1B && GetMapExtraBits(tile)==1) { |
|
489 |
m5++; /* start destructing */ |
|
490 |
} else { |
|
491 |
switch(Random() & 0x7) { |
|
492 |
case 0: /* start destructing */ |
|
493 |
m5++; |
|
494 |
break; |
|
495 |
||
496 |
case 1: /* add a tree */ |
|
497 |
if (m5 < 0xC0) { |
|
498 |
m5 = (m5 + 0x40) & ~7; |
|
499 |
break; |
|
500 |
} |
|
501 |
/* fall through */ |
|
502 |
||
503 |
case 2: { /* add a neighbouring tree */ |
|
504 |
byte m3 = _map3_lo[tile]; |
|
505 |
||
506 |
tile += _tileloop_trees_dir[Random() & 7]; |
|
507 |
||
508 |
if (!IS_TILETYPE(tile, MP_CLEAR)) |
|
509 |
return; |
|
510 |
||
511 |
if ( (_map5[tile] & 0x1C) == 4) { |
|
512 |
_map2[tile] = 0x10; |
|
513 |
} else if ((_map5[tile] & 0x1C) == 16) { |
|
514 |
_map2[tile] = (_map5[tile] << 6) | 0x20; |
|
515 |
} else { |
|
516 |
if ((_map5[tile] & 0x1F) != 3) |
|
517 |
return; |
|
518 |
_map2[tile] = 0; |
|
519 |
} |
|
520 |
||
521 |
_map3_lo[tile] = m3; |
|
522 |
_map3_hi[tile] = 0; |
|
523 |
_map_type_and_height[tile] &= 0xF; |
|
524 |
_map_type_and_height[tile] |= MP_TREES << 4; |
|
525 |
||
526 |
m5 = 0; |
|
527 |
break; |
|
528 |
} |
|
529 |
||
530 |
default: |
|
531 |
return; |
|
532 |
} |
|
533 |
} |
|
534 |
} else if ((m5&7) == 6) { |
|
535 |
/* final stage of tree destruction */ |
|
536 |
if (m5 & 0xC0) { |
|
537 |
/* more than one tree, delete it? */ |
|
538 |
m5 = ((m5 - 6) - 0x40) + 3; |
|
539 |
} else { |
|
540 |
/* just one tree, change type into MP_CLEAR */ |
|
541 |
_map_type_and_height[tile] = (_map_type_and_height[tile]&~0xF0) | (MP_CLEAR<<4); |
|
542 |
||
543 |
m5 = 3; |
|
544 |
m2 = _map2[tile]; |
|
545 |
if ((m2&0x30) != 0) { |
|
546 |
m5 = (m2 >> 6) | 0x10; |
|
547 |
if (m2 != 0x20) |
|
548 |
m5 = 7; |
|
549 |
} |
|
550 |
_map_owner[tile] = OWNER_NONE; |
|
551 |
} |
|
552 |
} else { |
|
553 |
/* in the middle of a transition, change to next */ |
|
554 |
m5++; |
|
555 |
} |
|
556 |
||
557 |
_map5[tile] = m5; |
|
558 |
MarkTileDirtyByTile(tile); |
|
559 |
} |
|
560 |
||
561 |
void OnTick_Trees() |
|
562 |
{ |
|
563 |
uint32 r; |
|
564 |
uint tile; |
|
565 |
byte m; |
|
566 |
int tree; |
|
567 |
||
568 |
/* place a tree at a random rainforest spot */ |
|
569 |
if (_opt.landscape == LT_DESERT && |
|
570 |
(r=Random(),tile=TILE_MASK(r),GetMapExtraBits(tile)==2) && |
|
571 |
IS_TILETYPE(tile, MP_CLEAR) && |
|
572 |
(m=_map5[tile]&0x1C, m<=4) && |
|
573 |
(tree=GetRandomTreeType(tile, r>>24)) >= 0) { |
|
574 |
||
575 |
ModifyTile(tile, |
|
576 |
MP_SETTYPE(MP_TREES) | |
|
577 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
|
578 |
(m == 4 ? 0x10 : 0), |
|
579 |
tree, |
|
580 |
_map3_hi[tile] & ~3, |
|
581 |
0 |
|
582 |
); |
|
583 |
} |
|
584 |
||
585 |
// byte underflow |
|
586 |
if (--_trees_tick_ctr) |
|
587 |
return; |
|
588 |
||
589 |
/* place a tree at a random spot */ |
|
590 |
r = Random(); |
|
591 |
tile = TILE_MASK(r); |
|
592 |
if (IS_TILETYPE(tile, MP_CLEAR) && |
|
593 |
(m=_map5[tile]&0x1C, m==0 || m==4 || m==0x10) && |
|
594 |
(tree=GetRandomTreeType(tile, r>>24)) >= 0) { |
|
595 |
int m2; |
|
596 |
||
597 |
if (m == 0) { |
|
598 |
m2 = 0; |
|
599 |
} else if (m == 4) { |
|
600 |
m2 = 0x10; |
|
601 |
} else { |
|
602 |
m2 = (_map5[tile] << 6) | 0x20; |
|
603 |
} |
|
604 |
||
605 |
ModifyTile(tile, |
|
606 |
MP_SETTYPE(MP_TREES) | |
|
607 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
|
608 |
m2, |
|
609 |
tree, |
|
610 |
_map3_hi[tile] & ~3, |
|
611 |
0 |
|
612 |
); |
|
613 |
} |
|
614 |
} |
|
615 |
||
616 |
static void ClickTile_Trees(uint tile) |
|
617 |
{ |
|
618 |
/* not used */ |
|
619 |
} |
|
620 |
||
160
db200af4794a
(svn r161) -Fix: added missing file to project and solved wrong type bug
darkvater
parents:
91
diff
changeset
|
621 |
static uint32 GetTileTrackStatus_Trees(uint tile, TransportType mode) |
0 | 622 |
{ |
623 |
return 0; |
|
624 |
} |
|
625 |
||
626 |
static void ChangeTileOwner_Trees(uint tile, byte old_player, byte new_player) |
|
627 |
{ |
|
628 |
/* not used */ |
|
629 |
} |
|
630 |
||
631 |
void InitializeTrees() |
|
632 |
{ |
|
633 |
memset(_sign_list, 0, sizeof(_sign_list)); |
|
634 |
_trees_tick_ctr = 0; |
|
635 |
} |
|
636 |
||
637 |
||
638 |
const TileTypeProcs _tile_type_trees_procs = { |
|
639 |
DrawTile_Trees, /* draw_tile_proc */ |
|
640 |
GetSlopeZ_Trees, /* get_slope_z_proc */ |
|
641 |
ClearTile_Trees, /* clear_tile_proc */ |
|
642 |
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */ |
|
643 |
GetTileDesc_Trees, /* get_tile_desc_proc */ |
|
644 |
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */ |
|
645 |
ClickTile_Trees, /* click_tile_proc */ |
|
646 |
AnimateTile_Trees, /* animate_tile_proc */ |
|
647 |
TileLoop_Trees, /* tile_loop_clear */ |
|
648 |
ChangeTileOwner_Trees, /* change_tile_owner_clear */ |
|
649 |
NULL, /* get_produced_cargo_proc */ |
|
650 |
NULL, /* vehicle_enter_tile_proc */ |
|
651 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 652 |
GetSlopeTileh_Trees, /* get_slope_tileh_proc */ |
0 | 653 |
}; |