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