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