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