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