author | truelight |
Fri, 04 Feb 2005 13:23:29 +0000 | |
changeset 1279 | bc761aad52b3 |
parent 1209 | 2e00193652b2 |
child 1286 | 10b9fe28effc |
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" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
5 |
#include "tile.h" |
0 | 6 |
#include "viewport.h" |
7 |
#include "command.h" |
|
8 |
#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
|
9 |
#include "sound.h" |
0 | 10 |
|
11 |
static int GetRandomTreeType(uint tile, uint seed) |
|
12 |
{ |
|
13 |
byte i; |
|
14 |
||
15 |
if (_opt.landscape == LT_NORMAL) { |
|
16 |
return seed * 12 >> 8; |
|
17 |
} else if (_opt.landscape == LT_HILLY) { |
|
18 |
return (seed >> 5) + 12; |
|
19 |
} else if (_opt.landscape == LT_DESERT) { |
|
20 |
i = GetMapExtraBits(tile); |
|
21 |
if (i == 0) { |
|
22 |
return (seed >> 6) + 28; |
|
23 |
} else if (i == 1) { |
|
24 |
if (seed > 12) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
25 |
return -1; |
0 | 26 |
return 27; |
27 |
} else { |
|
28 |
return (seed * 7 >> 8) + 20; |
|
29 |
} |
|
30 |
} else { |
|
31 |
return (seed * 9 >> 8) + 32; |
|
32 |
} |
|
33 |
} |
|
34 |
||
35 |
static void PlaceTree(uint tile, uint32 r, byte m5_or) |
|
36 |
{ |
|
37 |
int tree = GetRandomTreeType(tile, (r >> 24)); |
|
38 |
byte m5; |
|
39 |
||
40 |
if (tree >= 0) { |
|
41 |
m5 = (byte)(r >> 16); |
|
407
ac158a606861
(svn r604) -Fix: [ 999669 ] Wrong trees (toyland's) in sub-tropical landscape style
tron
parents:
337
diff
changeset
|
42 |
if ((m5 & 0x7) == 7) m5--; // there is no growth state 7 |
0 | 43 |
|
44 |
_map5[tile] = m5 & 0x07; // growth state; |
|
45 |
_map5[tile] |= m5 & 0xC0; // amount of trees |
|
46 |
||
47 |
_map3_lo[tile] = tree; // set type of tree |
|
48 |
_map3_hi[tile] = 0; // no hedge |
|
49 |
||
50 |
// above snowline? |
|
51 |
if( (_opt.landscape == LT_HILLY) && (GetTileZ(tile) - _opt.snow_line > 0) ) |
|
52 |
{ |
|
53 |
_map2[tile] = 0xE0; // set land type to snow |
|
54 |
_map2[tile] |= (byte)(r >> 24)&0x07; // randomize counter |
|
55 |
} |
|
56 |
else |
|
57 |
{ |
|
58 |
_map2[tile] = (byte)(r >> 24)&0x1F; // randomize counter and ground |
|
59 |
} |
|
60 |
||
61 |
||
62 |
// make it tree class |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1035
diff
changeset
|
63 |
SetTileType(tile, MP_TREES); |
0 | 64 |
} |
65 |
} |
|
66 |
||
67 |
static void DoPlaceMoreTrees(uint tile) |
|
68 |
{ |
|
69 |
int i = 1000; |
|
70 |
int x,y; |
|
71 |
uint cur_tile; |
|
72 |
int dist; |
|
73 |
||
74 |
do { |
|
75 |
uint32 r = Random(); |
|
76 |
x = (r & 0x1F) - 16; |
|
77 |
y = ((r>>8) & 0x1F) - 16; |
|
78 |
||
79 |
dist = myabs(x) + myabs(y); |
|
80 |
||
828
f2466aac3160
(svn r1299) -Fix: [ 1092473 ] In SE, when trees are placed randomly, they are no
truelight
parents:
817
diff
changeset
|
81 |
cur_tile = TILE_MASK(tile + TILE_XY(x,y)); |
0 | 82 |
|
828
f2466aac3160
(svn r1299) -Fix: [ 1092473 ] In SE, when trees are placed randomly, they are no
truelight
parents:
817
diff
changeset
|
83 |
/* 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
|
84 |
on clear tiles, and NOT on farm-tiles or rocks */ |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
85 |
if (dist <= 13 && IsTileType(cur_tile, MP_CLEAR) && |
874
13d226a63762
(svn r1355) -Fix: [1092473] random trees in scenario editor do not overwrite rocks as well
darkvater
parents:
872
diff
changeset
|
86 |
(_map5[cur_tile] & 0x1F) != 0x0F && (_map5[cur_tile] & 0x1C) != 8) { |
0 | 87 |
PlaceTree(cur_tile, r, dist <= 6 ? 0xC0 : 0); |
88 |
} |
|
89 |
} while (--i); |
|
90 |
} |
|
91 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
92 |
static void PlaceMoreTrees(void) |
0 | 93 |
{ |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
94 |
int i = ScaleByMapSize((Random() & 0x1F) + 25); |
0 | 95 |
do { |
96 |
DoPlaceMoreTrees(TILE_MASK(Random())); |
|
97 |
} while (--i); |
|
98 |
} |
|
99 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
100 |
void PlaceTreesRandomly(void) |
0 | 101 |
{ |
102 |
int i; |
|
103 |
uint32 r; |
|
104 |
uint tile; |
|
105 |
||
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
106 |
i = ScaleByMapSize(1000); |
0 | 107 |
do { |
108 |
r = Random(); |
|
109 |
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
|
110 |
/* Only on clear tiles, and NOT on farm-tiles or rocks */ |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
111 |
if (IsTileType(tile, MP_CLEAR) && (_map5[tile] & 0x1F) != 0x0F && (_map5[tile] & 0x1C) != 8) { |
0 | 112 |
PlaceTree(tile, r, 0); |
113 |
} |
|
114 |
} while (--i); |
|
115 |
||
116 |
/* place extra trees at rainforest area */ |
|
117 |
if (_opt.landscape == LT_DESERT) { |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
118 |
i = ScaleByMapSize(15000); |
0 | 119 |
|
120 |
do { |
|
121 |
r = Random(); |
|
122 |
tile = TILE_MASK(r); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
123 |
if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) { |
0 | 124 |
PlaceTree(tile, r, 0); |
125 |
} |
|
126 |
} while (--i); |
|
127 |
} |
|
128 |
} |
|
129 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
130 |
void GenerateTrees(void) |
0 | 131 |
{ |
132 |
int i; |
|
133 |
||
134 |
if (_opt.landscape != LT_CANDY) { |
|
135 |
PlaceMoreTrees(); |
|
136 |
} |
|
137 |
||
138 |
i = _opt.landscape == LT_HILLY ? 15 : 6; |
|
139 |
do { |
|
140 |
PlaceTreesRandomly(); |
|
141 |
} while (--i); |
|
142 |
} |
|
143 |
||
144 |
/* Plant a tree |
|
145 |
* p1 = tree type, -1 means random. |
|
146 |
* p2 = end tile |
|
147 |
*/ |
|
148 |
||
149 |
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
150 |
{ |
|
151 |
TileInfo ti; |
|
152 |
int32 cost; |
|
153 |
int sx,sy,x,y; |
|
154 |
int treetype; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
155 |
|
0 | 156 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
157 |
||
158 |
// make sure sx,sy are smaller than ex,ey |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
915
diff
changeset
|
159 |
sx = TileX(p2) * 16; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
915
diff
changeset
|
160 |
sy = TileY(p2) * 16; |
0 | 161 |
if (ex < sx) intswap(ex, sx); |
162 |
if (ey < sy) intswap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
163 |
|
0 | 164 |
cost = 0; // total cost |
165 |
||
166 |
for(x=sx; x<=ex; x+=16) { |
|
167 |
for(y=sy; y<=ey; y+=16) { |
|
168 |
FindLandscapeHeight(&ti, x, y); |
|
169 |
if (!EnsureNoVehicle(ti.tile)) |
|
170 |
continue; |
|
171 |
||
172 |
if (ti.type == MP_TREES) { |
|
173 |
// no more space for trees? |
|
174 |
if (_game_mode != GM_EDITOR && (ti.map5 & 0xC0) == 0xC0) { |
|
175 |
_error_message = STR_2803_TREE_ALREADY_HERE; |
|
176 |
continue; |
|
177 |
} |
|
178 |
||
179 |
if (flags & DC_EXEC) { |
|
180 |
_map5[ti.tile] = ti.map5 + 0x40; |
|
181 |
MarkTileDirtyByTile(ti.tile); |
|
182 |
} |
|
183 |
// 2x as expensive to add more trees to an existing tile |
|
184 |
cost += _price.build_trees * 2; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
185 |
} 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
|
186 |
if (ti.type != MP_CLEAR || _map_owner[ti.tile] != OWNER_NONE) { |
0 | 187 |
_error_message = STR_2804_SITE_UNSUITABLE; |
188 |
continue; |
|
189 |
} |
|
190 |
||
191 |
// it's expensive to clear farmland |
|
192 |
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
|
193 |
else if ((ti.map5 & 0x1C) == 8) cost += _price.clear_2; |
0 | 194 |
|
195 |
if (flags & DC_EXEC) { |
|
196 |
int m2; |
|
197 |
||
198 |
if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) { |
|
199 |
Town *t = ClosestTownFromTile(ti.tile, _patches.dist_local_authority); |
|
200 |
if (t != NULL) |
|
1005 | 201 |
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM); |
0 | 202 |
} |
203 |
m2 = 0; |
|
204 |
if ( (ti.map5 & 0x1C) == 4 ) { |
|
205 |
m2 = 16; |
|
206 |
} 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
|
207 |
m2 = ((ti.map5 & 3) << 6) | 0x20; |
0 | 208 |
} |
209 |
||
210 |
treetype = p1; |
|
211 |
if (treetype == -1) { |
|
212 |
treetype = GetRandomTreeType(ti.tile, Random()>>24); |
|
213 |
if (treetype==-1) treetype=27; |
|
214 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
215 |
|
0 | 216 |
ModifyTile(ti.tile, |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
217 |
MP_SETTYPE(MP_TREES) | |
0 | 218 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
219 |
m2, /* map2 */ |
|
220 |
treetype, /* map3lo */ |
|
221 |
_game_mode == GM_EDITOR ? 3 : 0 /* map5 */ |
|
222 |
); |
|
223 |
||
224 |
if (_game_mode == GM_EDITOR && IS_BYTE_INSIDE(treetype, 0x14, 0x1B)) { |
|
225 |
SetMapExtraBits(ti.tile, 2); |
|
226 |
} |
|
227 |
} |
|
228 |
cost += _price.build_trees; |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
232 |
|
0 | 233 |
if (cost == 0) return CMD_ERROR; |
234 |
return cost; |
|
235 |
} |
|
236 |
||
237 |
typedef struct TreeListEnt { |
|
238 |
uint32 image; |
|
239 |
byte x,y; |
|
240 |
} TreeListEnt; |
|
241 |
||
242 |
||
243 |
#include "table/tree_land.h" |
|
244 |
||
245 |
||
246 |
static void DrawTile_Trees(TileInfo *ti) |
|
247 |
{ |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
248 |
uint16 m2; |
0 | 249 |
const uint32 *s; |
250 |
const byte *d; |
|
251 |
byte z; |
|
252 |
TreeListEnt te[4]; |
|
253 |
||
254 |
m2 = _map2[ti->tile]; |
|
255 |
||
256 |
if ( (m2&0x30) == 0) { |
|
257 |
DrawClearLandTile(ti, 3); |
|
258 |
} else if ((m2&0x30) == 0x20) { |
|
259 |
DrawGroundSprite(_tree_sprites_1[m2 >> 6] + _tileh_to_sprite[ti->tileh]); |
|
260 |
} else { |
|
261 |
DrawHillyLandTile(ti); |
|
262 |
} |
|
263 |
||
264 |
DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2); |
|
265 |
||
266 |
z = ti->z; |
|
267 |
if (ti->tileh != 0) { |
|
268 |
z += 4; |
|
269 |
if (ti->tileh & 0x10) |
|
270 |
z += 4; |
|
271 |
} |
|
272 |
||
273 |
{ |
|
274 |
uint16 tmp = ti->x; |
|
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
275 |
uint index; |
0 | 276 |
|
277 |
tmp = (tmp >> 2) | (tmp << 14); |
|
278 |
tmp -= ti->y; |
|
279 |
tmp = (tmp >> 3) | (tmp << 13); |
|
280 |
tmp -= ti->x; |
|
281 |
tmp = (tmp >> 1) | (tmp << 15); |
|
282 |
tmp += ti->y; |
|
283 |
||
284 |
d = _tree_layout_xy[(tmp & 0x30) >> 4]; |
|
285 |
||
286 |
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
|
287 |
|
0 | 288 |
/* different tree styles above one of the grounds */ |
289 |
if ((m2 & 0xB0) == 0xA0 && index >= 48 && index < 80) |
|
290 |
index += 164 - 48; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
291 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
292 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 293 |
s = _tree_layout_sprite[index]; |
294 |
} |
|
295 |
||
296 |
StartSpriteCombine(); |
|
297 |
||
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
|
298 |
if (!(_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) |
0 | 299 |
{ |
300 |
int i; |
|
301 |
||
302 |
/* put the trees to draw in a list */ |
|
303 |
i = (ti->map5 >> 6) + 1; |
|
304 |
do { |
|
305 |
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
|
306 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 307 |
image = (image & 0x3FFF) | 0x3224000; |
308 |
te[i].image = image; |
|
309 |
te[i].x = d[0]; |
|
310 |
te[i].y = d[1]; |
|
311 |
s++; |
|
312 |
d+=2; |
|
313 |
} while (i); |
|
314 |
||
315 |
/* draw them in a sorted way */ |
|
316 |
for(;;) { |
|
317 |
byte min = 0xFF; |
|
318 |
TreeListEnt *tep = NULL; |
|
319 |
||
320 |
i = (ti->map5 >> 6) + 1; |
|
321 |
do { |
|
322 |
if (te[--i].image!=0 && (byte)(te[i].x + te[i].y) < min) { |
|
323 |
min = te[i].x + te[i].y; |
|
324 |
tep = &te[i]; |
|
325 |
} |
|
326 |
} while (i); |
|
327 |
||
328 |
if (tep == NULL) |
|
329 |
break; |
|
330 |
||
331 |
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z); |
|
332 |
tep->image = 0; |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
EndSpriteCombine(); |
|
337 |
} |
|
338 |
||
339 |
||
340 |
static uint GetSlopeZ_Trees(TileInfo *ti) { |
|
341 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
342 |
} |
|
343 |
||
39 | 344 |
static uint GetSlopeTileh_Trees(TileInfo *ti) { |
345 |
return ti->tileh; |
|
346 |
} |
|
347 |
||
0 | 348 |
static int32 ClearTile_Trees(uint tile, byte flags) { |
349 |
int num; |
|
350 |
||
351 |
if (flags & DC_EXEC && _current_player < MAX_PLAYERS) { |
|
352 |
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
|
353 |
if (t != NULL) |
1005 | 354 |
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); |
0 | 355 |
} |
356 |
||
357 |
num = (_map5[tile] >> 6) + 1; |
|
358 |
if ( (byte)(_map3_lo[tile]-0x14) <= (0x1A-0x14)) |
|
359 |
num <<= 2; |
|
360 |
||
361 |
if (flags & DC_EXEC) |
|
362 |
DoClearSquare(tile); |
|
363 |
||
364 |
return num * _price.remove_trees; |
|
365 |
} |
|
366 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
407
diff
changeset
|
367 |
static void GetAcceptedCargo_Trees(uint tile, AcceptedCargo ac) |
0 | 368 |
{ |
369 |
/* not used */ |
|
370 |
} |
|
371 |
||
372 |
static void GetTileDesc_Trees(uint tile, TileDesc *td) |
|
373 |
{ |
|
374 |
byte b; |
|
375 |
StringID str; |
|
376 |
||
377 |
td->owner = _map_owner[tile]; |
|
378 |
||
379 |
b = _map3_lo[tile]; |
|
380 |
(str=STR_2810_CACTUS_PLANTS, b==0x1B) || |
|
381 |
(str=STR_280F_RAINFOREST, IS_BYTE_INSIDE(b, 0x14, 0x1A+1)) || |
|
382 |
(str=STR_280E_TREES, true); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
383 |
td->str = str; |
0 | 384 |
} |
385 |
||
386 |
static void AnimateTile_Trees(uint tile) |
|
387 |
{ |
|
388 |
/* not used */ |
|
389 |
} |
|
390 |
||
541 | 391 |
static SoundFx _desert_sounds[] = { |
392 |
SND_42_LOON_BIRD, |
|
393 |
SND_43_LION, |
|
394 |
SND_44_MONKEYS, |
|
395 |
SND_48_DISTANT_BIRD |
|
0 | 396 |
}; |
397 |
||
398 |
static void TileLoopTreesDesert(uint tile) |
|
399 |
{ |
|
400 |
byte b; |
|
401 |
||
402 |
if ((b=GetMapExtraBits(tile)) == 2) { |
|
403 |
uint32 r; |
|
404 |
||
405 |
if (CHANCE16I(1,200,r=Random())) { |
|
406 |
SndPlayTileFx(_desert_sounds[(r >> 16) & 3], tile); |
|
407 |
} |
|
408 |
} else if (b == 1) { |
|
409 |
if ((_map2[tile] & 0x30) != 0x20) { |
|
410 |
_map2[tile] &= 0xF; |
|
411 |
_map2[tile] |= 0xE0; |
|
412 |
MarkTileDirtyByTile(tile); |
|
413 |
} |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
static void TileLoopTreesAlps(uint tile) |
|
418 |
{ |
|
419 |
byte tmp, m2; |
|
420 |
int k; |
|
421 |
||
422 |
/* distance from snow line, in steps of 8 */ |
|
423 |
k = GetTileZ(tile) - _opt.snow_line; |
|
424 |
||
425 |
tmp = _map5[tile] & 0xF0; |
|
426 |
||
427 |
if (k < -8) { |
|
428 |
/* snow_m2_down */ |
|
429 |
if ((tmp&0x30) != 0x20) |
|
430 |
return; |
|
431 |
m2 = 0; |
|
432 |
} else if (k == -8) { |
|
433 |
/* snow_m1 */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
434 |
m2 = 0x20; |
0 | 435 |
if (tmp == m2) |
436 |
return; |
|
437 |
} else if (k < 8) { |
|
438 |
/* snow_0 */ |
|
439 |
m2 = 0x60; |
|
440 |
if (tmp == m2) |
|
441 |
return; |
|
442 |
} else if (k == 8) { |
|
443 |
/* snow_p1 */ |
|
444 |
m2 = 0xA0; |
|
445 |
if (tmp == m2) |
|
446 |
return; |
|
447 |
} else { |
|
448 |
/* snow_p2_up */ |
|
449 |
if (tmp == 0xC0) { |
|
450 |
uint32 r; |
|
451 |
if (CHANCE16I(1,200,r=Random())) { |
|
541 | 452 |
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile); |
0 | 453 |
} |
454 |
return; |
|
455 |
} else { |
|
456 |
m2 = 0xE0; |
|
457 |
} |
|
458 |
} |
|
459 |
||
460 |
_map2[tile] &= 0xF; |
|
461 |
_map2[tile] |= m2; |
|
462 |
MarkTileDirtyByTile(tile); |
|
463 |
} |
|
464 |
||
465 |
static void TileLoop_Trees(uint tile) |
|
466 |
{ |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
467 |
byte m5; |
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
468 |
uint16 m2; |
0 | 469 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
470 |
static const TileIndexDiffC _tileloop_trees_dir[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
471 |
{-1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
472 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
473 |
{ 1, -1}, |
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, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
476 |
{-1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
477 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
478 |
{ 1, 1} |
0 | 479 |
}; |
480 |
||
481 |
if (_opt.landscape == LT_DESERT) { |
|
482 |
TileLoopTreesDesert(tile); |
|
483 |
} else if (_opt.landscape == LT_HILLY) { |
|
484 |
TileLoopTreesAlps(tile); |
|
485 |
} |
|
486 |
||
487 |
TileLoopClearHelper(tile); |
|
488 |
||
489 |
/* increase counter */ |
|
490 |
{ |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
491 |
uint16 m2 = _map2[tile]; |
0 | 492 |
_map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF); |
493 |
if (m2 & 0xF) |
|
494 |
return; |
|
495 |
} |
|
496 |
||
497 |
m5 = _map5[tile]; |
|
498 |
if ((m5&7) == 3) { |
|
499 |
/* regular sized tree */ |
|
500 |
if (_opt.landscape == LT_DESERT && _map3_lo[tile]!=0x1B && GetMapExtraBits(tile)==1) { |
|
501 |
m5++; /* start destructing */ |
|
502 |
} else { |
|
503 |
switch(Random() & 0x7) { |
|
504 |
case 0: /* start destructing */ |
|
505 |
m5++; |
|
506 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
507 |
|
0 | 508 |
case 1: /* add a tree */ |
509 |
if (m5 < 0xC0) { |
|
510 |
m5 = (m5 + 0x40) & ~7; |
|
511 |
break; |
|
512 |
} |
|
513 |
/* fall through */ |
|
514 |
||
515 |
case 2: { /* add a neighbouring tree */ |
|
516 |
byte m3 = _map3_lo[tile]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
517 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
518 |
tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]); |
0 | 519 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
520 |
if (!IsTileType(tile, MP_CLEAR)) |
0 | 521 |
return; |
522 |
||
523 |
if ( (_map5[tile] & 0x1C) == 4) { |
|
524 |
_map2[tile] = 0x10; |
|
525 |
} 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
|
526 |
_map2[tile] = ((_map5[tile] & 3) << 6) | 0x20; |
0 | 527 |
} else { |
528 |
if ((_map5[tile] & 0x1F) != 3) |
|
529 |
return; |
|
530 |
_map2[tile] = 0; |
|
531 |
} |
|
532 |
||
533 |
_map3_lo[tile] = m3; |
|
534 |
_map3_hi[tile] = 0; |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1035
diff
changeset
|
535 |
SetTileType(tile, MP_TREES); |
0 | 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 */ |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1035
diff
changeset
|
552 |
SetTileType(tile, MP_CLEAR); |
0 | 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 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
572 |
void OnTick_Trees(void) |
0 | 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) && |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
582 |
IsTileType(tile, MP_CLEAR) && |
0 | 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); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
603 |
if (IsTileType(tile, MP_CLEAR) && |
0 | 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 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
642 |
void InitializeTrees(void) |
0 | 643 |
{ |
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 |
}; |