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