author | tron |
Fri, 24 Jun 2005 12:38:35 +0000 | |
changeset 1977 | 4392ae3d8e31 |
parent 1902 | 5d653da1abb7 |
child 1981 | de031d2aed47 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1784
diff
changeset
|
2 |
#include "openttd.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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
38 |
static void PlaceTree(TileIndex tile, uint32 r, byte m5_or) |
0 | 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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
69 |
static void DoPlaceMoreTrees(TileIndex tile) |
0 | 70 |
{ |
71 |
int i = 1000; |
|
72 |
int x,y; |
|
73 |
int dist; |
|
74 |
||
75 |
do { |
|
76 |
uint32 r = Random(); |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
77 |
TileIndex cur_tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
78 |
|
0 | 79 |
x = (r & 0x1F) - 16; |
80 |
y = ((r>>8) & 0x1F) - 16; |
|
81 |
||
82 |
dist = myabs(x) + myabs(y); |
|
83 |
||
828
bb08003e61b5
(svn r1299) -Fix: [ 1092473 ] In SE, when trees are placed randomly, they are no
truelight
parents:
817
diff
changeset
|
84 |
cur_tile = TILE_MASK(tile + TILE_XY(x,y)); |
0 | 85 |
|
828
bb08003e61b5
(svn r1299) -Fix: [ 1092473 ] In SE, when trees are placed randomly, they are no
truelight
parents:
817
diff
changeset
|
86 |
/* 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
|
87 |
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
|
88 |
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
|
89 |
(_map5[cur_tile] & 0x1F) != 0x0F && (_map5[cur_tile] & 0x1C) != 8) { |
0 | 90 |
PlaceTree(cur_tile, r, dist <= 6 ? 0xC0 : 0); |
91 |
} |
|
92 |
} while (--i); |
|
93 |
} |
|
94 |
||
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
|
95 |
static void PlaceMoreTrees(void) |
0 | 96 |
{ |
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
97 |
int i = ScaleByMapSize((Random() & 0x1F) + 25); |
0 | 98 |
do { |
99 |
DoPlaceMoreTrees(TILE_MASK(Random())); |
|
100 |
} while (--i); |
|
101 |
} |
|
102 |
||
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
|
103 |
void PlaceTreesRandomly(void) |
0 | 104 |
{ |
105 |
int i; |
|
106 |
uint32 r; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
107 |
TileIndex tile; |
0 | 108 |
|
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
109 |
i = ScaleByMapSize(1000); |
0 | 110 |
do { |
111 |
r = Random(); |
|
112 |
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
|
113 |
/* 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
|
114 |
if (IsTileType(tile, MP_CLEAR) && (_map5[tile] & 0x1F) != 0x0F && (_map5[tile] & 0x1C) != 8) { |
0 | 115 |
PlaceTree(tile, r, 0); |
116 |
} |
|
117 |
} while (--i); |
|
118 |
||
119 |
/* place extra trees at rainforest area */ |
|
120 |
if (_opt.landscape == LT_DESERT) { |
|
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
121 |
i = ScaleByMapSize(15000); |
0 | 122 |
|
123 |
do { |
|
124 |
r = Random(); |
|
125 |
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
|
126 |
if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) { |
0 | 127 |
PlaceTree(tile, r, 0); |
128 |
} |
|
129 |
} while (--i); |
|
130 |
} |
|
131 |
} |
|
132 |
||
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
|
133 |
void GenerateTrees(void) |
0 | 134 |
{ |
135 |
int i; |
|
136 |
||
137 |
if (_opt.landscape != LT_CANDY) { |
|
138 |
PlaceMoreTrees(); |
|
139 |
} |
|
140 |
||
141 |
i = _opt.landscape == LT_HILLY ? 15 : 6; |
|
142 |
do { |
|
143 |
PlaceTreesRandomly(); |
|
144 |
} while (--i); |
|
145 |
} |
|
146 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
147 |
/** Plant a tree. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
148 |
* @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
|
149 |
* @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
|
150 |
* @param p2 end tile of area-drag |
0 | 151 |
*/ |
152 |
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
153 |
{ |
|
154 |
int32 cost; |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
155 |
int sx; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
156 |
int sy; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
157 |
int x; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
158 |
int y; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
159 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
160 |
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
|
161 |
/* 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
|
162 |
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
|
163 |
|
0 | 164 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
165 |
||
166 |
// 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
|
167 |
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
|
168 |
sy = TileY(p2) * 16; |
0 | 169 |
if (ex < sx) intswap(ex, sx); |
170 |
if (ey < sy) intswap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
171 |
|
0 | 172 |
cost = 0; // total cost |
173 |
||
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
TileInfo ti; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
177 |
|
0 | 178 |
FindLandscapeHeight(&ti, x, y); |
179 |
if (!EnsureNoVehicle(ti.tile)) |
|
180 |
continue; |
|
181 |
||
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
182 |
switch (ti.type) { |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
183 |
case MP_TREES: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
184 |
// no more space for trees? |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
185 |
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
|
186 |
_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
|
187 |
continue; |
0 | 188 |
} |
189 |
||
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
190 |
if (flags & DC_EXEC) { |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
191 |
_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
|
192 |
MarkTileDirtyByTile(ti.tile); |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
193 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
194 |
// 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
|
195 |
cost += _price.build_trees * 2; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
196 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
197 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
198 |
case MP_CLEAR: |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
199 |
if (!IsTileOwner(ti.tile, OWNER_NONE)) { |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
200 |
_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
|
201 |
continue; |
0 | 202 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
203 |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
204 |
// 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
|
205 |
if ((ti.map5 & 0x1F) == 0xF) |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
206 |
cost += _price.clear_3; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
207 |
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
|
208 |
cost += _price.clear_2; |
0 | 209 |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
210 |
if (flags & DC_EXEC) { |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
211 |
int treetype; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
212 |
int m2; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
213 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
if (t != NULL) |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
217 |
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
|
218 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
219 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
220 |
switch (ti.map5 & 0x1C) { |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
221 |
case 0x04: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
222 |
m2 = 16; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
223 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
224 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
225 |
case 0x10: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
226 |
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
|
227 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
228 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
229 |
default: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
230 |
m2 = 0; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
231 |
break; |
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 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
234 |
treetype = p1; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
235 |
if (treetype == -1) { |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
236 |
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
|
237 |
if (treetype == -1) treetype = 27; |
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 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
240 |
ModifyTile(ti.tile, |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
241 |
MP_SETTYPE(MP_TREES) | |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
242 |
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
|
243 |
m2, /* map2 */ |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
244 |
treetype, /* map3lo */ |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
245 |
_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
|
246 |
); |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
247 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
248 |
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
|
249 |
SetMapExtraBits(ti.tile, 2); |
0 | 250 |
} |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
251 |
cost += _price.build_trees; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
252 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
253 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
254 |
default: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
255 |
_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
|
256 |
break; |
0 | 257 |
} |
258 |
} |
|
259 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
260 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
261 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 262 |
} |
263 |
||
264 |
typedef struct TreeListEnt { |
|
265 |
uint32 image; |
|
266 |
byte x,y; |
|
267 |
} TreeListEnt; |
|
268 |
||
269 |
static void DrawTile_Trees(TileInfo *ti) |
|
270 |
{ |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
271 |
uint16 m2; |
0 | 272 |
const uint32 *s; |
273 |
const byte *d; |
|
274 |
byte z; |
|
275 |
TreeListEnt te[4]; |
|
276 |
||
277 |
m2 = _map2[ti->tile]; |
|
278 |
||
279 |
if ( (m2&0x30) == 0) { |
|
280 |
DrawClearLandTile(ti, 3); |
|
281 |
} else if ((m2&0x30) == 0x20) { |
|
282 |
DrawGroundSprite(_tree_sprites_1[m2 >> 6] + _tileh_to_sprite[ti->tileh]); |
|
283 |
} else { |
|
284 |
DrawHillyLandTile(ti); |
|
285 |
} |
|
286 |
||
287 |
DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2); |
|
288 |
||
289 |
z = ti->z; |
|
290 |
if (ti->tileh != 0) { |
|
291 |
z += 4; |
|
292 |
if (ti->tileh & 0x10) |
|
293 |
z += 4; |
|
294 |
} |
|
295 |
||
296 |
{ |
|
297 |
uint16 tmp = ti->x; |
|
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
298 |
uint index; |
0 | 299 |
|
300 |
tmp = (tmp >> 2) | (tmp << 14); |
|
301 |
tmp -= ti->y; |
|
302 |
tmp = (tmp >> 3) | (tmp << 13); |
|
303 |
tmp -= ti->x; |
|
304 |
tmp = (tmp >> 1) | (tmp << 15); |
|
305 |
tmp += ti->y; |
|
306 |
||
307 |
d = _tree_layout_xy[(tmp & 0x30) >> 4]; |
|
308 |
||
309 |
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
|
310 |
|
0 | 311 |
/* different tree styles above one of the grounds */ |
312 |
if ((m2 & 0xB0) == 0xA0 && index >= 48 && index < 80) |
|
313 |
index += 164 - 48; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
314 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
315 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 316 |
s = _tree_layout_sprite[index]; |
317 |
} |
|
318 |
||
319 |
StartSpriteCombine(); |
|
320 |
||
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
|
321 |
if (!(_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) |
0 | 322 |
{ |
323 |
int i; |
|
324 |
||
325 |
/* put the trees to draw in a list */ |
|
326 |
i = (ti->map5 >> 6) + 1; |
|
327 |
do { |
|
328 |
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
|
329 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 330 |
image = (image & 0x3FFF) | 0x3224000; |
331 |
te[i].image = image; |
|
332 |
te[i].x = d[0]; |
|
333 |
te[i].y = d[1]; |
|
334 |
s++; |
|
335 |
d+=2; |
|
336 |
} while (i); |
|
337 |
||
338 |
/* draw them in a sorted way */ |
|
339 |
for(;;) { |
|
340 |
byte min = 0xFF; |
|
341 |
TreeListEnt *tep = NULL; |
|
342 |
||
343 |
i = (ti->map5 >> 6) + 1; |
|
344 |
do { |
|
345 |
if (te[--i].image!=0 && (byte)(te[i].x + te[i].y) < min) { |
|
346 |
min = te[i].x + te[i].y; |
|
347 |
tep = &te[i]; |
|
348 |
} |
|
349 |
} while (i); |
|
350 |
||
351 |
if (tep == NULL) |
|
352 |
break; |
|
353 |
||
354 |
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z); |
|
355 |
tep->image = 0; |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
EndSpriteCombine(); |
|
360 |
} |
|
361 |
||
362 |
||
363 |
static uint GetSlopeZ_Trees(TileInfo *ti) { |
|
364 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
365 |
} |
|
366 |
||
39 | 367 |
static uint GetSlopeTileh_Trees(TileInfo *ti) { |
368 |
return ti->tileh; |
|
369 |
} |
|
370 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
371 |
static int32 ClearTile_Trees(TileIndex tile, byte flags) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
372 |
{ |
0 | 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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
391 |
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac) |
0 | 392 |
{ |
393 |
/* not used */ |
|
394 |
} |
|
395 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
396 |
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td) |
0 | 397 |
{ |
398 |
byte b; |
|
399 |
StringID str; |
|
400 |
||
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
401 |
td->owner = GetTileOwner(tile); |
0 | 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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
410 |
static void AnimateTile_Trees(TileIndex tile) |
0 | 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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
422 |
static void TileLoopTreesDesert(TileIndex tile) |
0 | 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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
441 |
static void TileLoopTreesAlps(TileIndex tile) |
0 | 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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
489 |
static void TileLoop_Trees(TileIndex tile) |
0 | 490 |
{ |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
491 |
byte m5; |
4f9377b7fd2b
(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
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
494 |
static const TileIndexDiffC _tileloop_trees_dir[] = { |
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 |
{ 0, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
497 |
{ 1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
498 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
499 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
500 |
{-1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
501 |
{ 0, 1}, |
81bc9ef93f50
(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
4f9377b7fd2b
(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
81bc9ef93f50
(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
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
|
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
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
|
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
c28c6be74291
(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
c28c6be74291
(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
bf5a77cbed91
(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
bf5a77cbed91
(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 |
} |
|
1902 | 585 |
SetTileOwner(tile, OWNER_NONE); |
0 | 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
e8d26c7dc42f
(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; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
599 |
TileIndex tile; |
0 | 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
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
|
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
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
|
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
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
|
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 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
651 |
static void ClickTile_Trees(TileIndex tile) |
0 | 652 |
{ |
653 |
/* not used */ |
|
654 |
} |
|
655 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
656 |
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode) |
0 | 657 |
{ |
658 |
return 0; |
|
659 |
} |
|
660 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
661 |
static void ChangeTileOwner_Trees(TileIndex tile, byte old_player, byte new_player) |
0 | 662 |
{ |
663 |
/* not used */ |
|
664 |
} |
|
665 |
||
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
|
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 |
}; |