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