author | tron |
Wed, 08 Mar 2006 15:28:38 +0000 | |
changeset 3166 | 747e74d236f0 |
parent 3156 | 028b6756b279 |
child 3267 | 591027d10884 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
4 |
#include "openttd.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
2989
diff
changeset
|
5 |
#include "clear_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
6 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
7 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
507
diff
changeset
|
8 |
#include "map.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
9 |
#include "player.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
|
10 |
#include "tile.h" |
0 | 11 |
#include "viewport.h" |
12 |
#include "command.h" |
|
3156
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3144
diff
changeset
|
13 |
#include "tunnel_map.h" |
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
14 |
#include "variables.h" |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
15 |
#include "table/sprites.h" |
0 | 16 |
|
17 |
typedef struct TerraformerHeightMod { |
|
18 |
TileIndex tile; |
|
19 |
byte height; |
|
20 |
} TerraformerHeightMod; |
|
21 |
||
22 |
typedef struct TerraformerState { |
|
23 |
int height[4]; |
|
24 |
uint32 flags; |
|
25 |
||
26 |
int direction; |
|
27 |
int modheight_count; |
|
28 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
29 |
|
0 | 30 |
int32 cost; |
31 |
||
32 |
TileIndex *tile_table; |
|
33 |
TerraformerHeightMod *modheight; |
|
34 |
||
35 |
} TerraformerState; |
|
36 |
||
37 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
38 |
{ |
|
39 |
TileIndex *t; |
|
40 |
int count; |
|
41 |
||
2639 | 42 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 43 |
|
44 |
t = ts->tile_table; |
|
2639 | 45 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
46 |
if (*t == tile) return 0; |
|
0 | 47 |
} |
48 |
||
49 |
return 1; |
|
50 |
} |
|
51 |
||
52 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
53 |
{ |
|
54 |
TerraformerHeightMod *mod = ts->modheight; |
|
55 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
56 |
|
2639 | 57 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
58 |
if (mod->tile == tile) return mod->height; |
|
0 | 59 |
} |
60 |
||
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
61 |
return TileHeight(tile); |
0 | 62 |
} |
63 |
||
64 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
65 |
{ |
|
66 |
int count; |
|
67 |
TileIndex *t; |
|
68 |
||
69 |
count = ts->tile_table_count; |
|
70 |
||
2639 | 71 |
if (count >= 625) return; |
0 | 72 |
|
2952 | 73 |
for (t = ts->tile_table; count != 0; count--,t++) { |
2639 | 74 |
if (*t == tile) return; |
0 | 75 |
} |
76 |
||
77 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
78 |
} |
|
79 |
||
80 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
81 |
{ |
|
1981 | 82 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
83 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
84 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 85 |
TerraformAddDirtyTile(ts, tile); |
86 |
} |
|
87 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
88 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 89 |
{ |
90 |
int r; |
|
2686
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
91 |
bool skip_clear = false; |
0 | 92 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
93 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
94 |
|
0 | 95 |
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0) |
96 |
return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
97 |
|
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
98 |
if (IsTileType(tile, MP_RAILWAY)) { |
0 | 99 |
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20}; |
100 |
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb}; |
|
345
883efb18bc56
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
101 |
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4}; |
0 | 102 |
|
103 |
// Nothing could be built at the steep slope - this avoids a bug |
|
104 |
// when you have a single diagonal track in one corner on a |
|
345
883efb18bc56
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
105 |
// basement and then you raise/lower the other corner. |
883efb18bc56
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
106 |
int tileh = GetTileSlope(tile, NULL) & 0xF; |
883efb18bc56
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
107 |
if (tileh == _railway_dangslopes[mode] || |
883efb18bc56
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
108 |
tileh == _railway_dangslopes2[mode]) { |
883efb18bc56
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
109 |
_terraform_err_tile = tile; |
0 | 110 |
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; |
111 |
return -1; |
|
112 |
} |
|
113 |
||
114 |
// If we have a single diagonal track there, the other side of |
|
115 |
// tile can be terraformed. |
|
2705
a0aed2277d0c
(svn r3249) Fix for issue introduced in r3228. The original code was good for raising, then for lowering, now for both.
peter1138
parents:
2686
diff
changeset
|
116 |
if ((_m[tile].m5 & ~0x40) == _railway_modes[mode]) { |
a0aed2277d0c
(svn r3249) Fix for issue introduced in r3228. The original code was good for raising, then for lowering, now for both.
peter1138
parents:
2686
diff
changeset
|
117 |
if (ts->direction == 1) return 0; |
a0aed2277d0c
(svn r3249) Fix for issue introduced in r3228. The original code was good for raising, then for lowering, now for both.
peter1138
parents:
2686
diff
changeset
|
118 |
skip_clear = true; |
a0aed2277d0c
(svn r3249) Fix for issue introduced in r3228. The original code was good for raising, then for lowering, now for both.
peter1138
parents:
2686
diff
changeset
|
119 |
} |
0 | 120 |
} |
121 |
||
2686
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
122 |
if (!skip_clear) { |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
123 |
int32 ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 124 |
|
2686
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
125 |
if (CmdFailed(ret)) { |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
126 |
_terraform_err_tile = tile; |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
127 |
return -1; |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
128 |
} |
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
129 |
|
a3e667057607
(svn r3228) - Fix: [ 1327011 ] Fix: don't lower land on tunnel, even with diag tracks on it (based on patch by glx)
peter1138
parents:
2639
diff
changeset
|
130 |
ts->cost += ret; |
0 | 131 |
} |
132 |
||
2639 | 133 |
if (ts->tile_table_count >= 625) return -1; |
0 | 134 |
ts->tile_table[ts->tile_table_count++] = tile; |
135 |
||
136 |
return 0; |
|
137 |
} |
|
138 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
139 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 140 |
{ |
141 |
int nh; |
|
142 |
TerraformerHeightMod *mod; |
|
143 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
144 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
145 |
assert(tile < MapSize()); |
0 | 146 |
|
147 |
if (height < 0) { |
|
148 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
149 |
return false; |
|
150 |
} |
|
151 |
||
152 |
_error_message = STR_1004_TOO_HIGH; |
|
153 |
||
2639 | 154 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
155 |
|
0 | 156 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 157 |
if (nh < 0 || height == nh) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
158 |
|
1981 | 159 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
160 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
|
161 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
|
162 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
|
0 | 163 |
|
164 |
mod = ts->modheight; |
|
165 |
count = ts->modheight_count; |
|
166 |
||
2639 | 167 |
for (;;) { |
0 | 168 |
if (count == 0) { |
169 |
if (ts->modheight_count >= 576) |
|
170 |
return false; |
|
171 |
ts->modheight_count++; |
|
172 |
break; |
|
173 |
} |
|
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
174 |
if (mod->tile == tile) break; |
0 | 175 |
mod++; |
176 |
count--; |
|
177 |
} |
|
178 |
||
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
179 |
mod->tile = tile; |
0 | 180 |
mod->height = (byte)height; |
181 |
||
182 |
ts->cost += _price.terraform; |
|
183 |
||
184 |
{ |
|
185 |
int direction = ts->direction, r; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
186 |
const TileIndexDiffC *ttm; |
0 | 187 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
188 |
static const TileIndexDiffC _terraform_tilepos[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
189 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
190 |
{-2, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
191 |
{ 1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
192 |
{ 0, -2} |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
193 |
}; |
0 | 194 |
|
2952 | 195 |
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
196 |
tile += ToTileIndexDiff(*ttm); |
0 | 197 |
|
198 |
r = TerraformGetHeightOfTile(ts, tile); |
|
199 |
if (r != height && r-direction != height && r+direction != height) { |
|
200 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
201 |
return false; |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
return true; |
|
207 |
} |
|
208 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
209 |
/** Terraform land |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
210 |
* @param x,y coordinates to terraform |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
211 |
* @param p1 corners to terraform. |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
212 |
* @param p2 direction; eg up or down |
0 | 213 |
*/ |
214 |
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
215 |
{ |
|
216 |
TerraformerState ts; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
217 |
TileIndex tile; |
0 | 218 |
int direction; |
219 |
||
220 |
TerraformerHeightMod modheight_data[576]; |
|
221 |
TileIndex tile_table_data[625]; |
|
222 |
||
223 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
224 |
||
225 |
_error_message = INVALID_STRING_ID; |
|
226 |
_terraform_err_tile = 0; |
|
227 |
||
228 |
ts.direction = direction = p2 ? 1 : -1; |
|
229 |
ts.flags = flags; |
|
230 |
ts.modheight_count = ts.tile_table_count = 0; |
|
231 |
ts.cost = 0; |
|
232 |
ts.modheight = modheight_data; |
|
233 |
ts.tile_table = tile_table_data; |
|
234 |
||
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
235 |
tile = TileVirtXY(x, y); |
0 | 236 |
|
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
237 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2705
diff
changeset
|
238 |
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
239 |
|
0 | 240 |
if (p1 & 1) { |
1981 | 241 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
242 |
TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
|
0 | 243 |
return CMD_ERROR; |
244 |
} |
|
245 |
||
246 |
if (p1 & 2) { |
|
1981 | 247 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
248 |
TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
|
0 | 249 |
return CMD_ERROR; |
250 |
} |
|
251 |
||
252 |
if (p1 & 4) { |
|
1981 | 253 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
254 |
TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
|
0 | 255 |
return CMD_ERROR; |
256 |
} |
|
257 |
||
258 |
if (p1 & 8) { |
|
1981 | 259 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
260 |
TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
|
0 | 261 |
return CMD_ERROR; |
262 |
} |
|
263 |
||
264 |
if (direction == -1) { |
|
265 |
/* Check if tunnel would take damage */ |
|
266 |
int count; |
|
267 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
268 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
269 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 270 |
uint z, t; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
271 |
TileIndex tile = *ti; |
0 | 272 |
|
1981 | 273 |
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
274 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
|
0 | 275 |
if (t <= z) z = t; |
1981 | 276 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
0 | 277 |
if (t <= z) z = t; |
1981 | 278 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
0 | 279 |
if (t <= z) z = t; |
280 |
||
3156
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3144
diff
changeset
|
281 |
if (IsTunnelInWay(tile, z * 8)) { |
0 | 282 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
2639 | 283 |
} |
0 | 284 |
} |
285 |
} |
|
286 |
||
287 |
if (flags & DC_EXEC) { |
|
288 |
/* Clear the landscape at the tiles */ |
|
289 |
{ |
|
290 |
int count; |
|
291 |
TileIndex *ti = ts.tile_table; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
292 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 293 |
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
294 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
295 |
} |
0 | 296 |
|
297 |
/* change the height */ |
|
298 |
{ |
|
299 |
int count; |
|
300 |
TerraformerHeightMod *mod; |
|
301 |
||
302 |
mod = ts.modheight; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
303 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
f4462d4e8e62
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
304 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
305 |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
306 |
SetTileHeight(til, mod->height); |
0 | 307 |
TerraformAddDirtyTileAround(&ts, til); |
308 |
} |
|
309 |
} |
|
310 |
||
311 |
/* finally mark the dirty tiles dirty */ |
|
312 |
{ |
|
313 |
int count; |
|
314 |
TileIndex *ti = ts.tile_table; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1571
diff
changeset
|
315 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 316 |
MarkTileDirtyByTile(*ti); |
317 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
318 |
} |
0 | 319 |
} |
320 |
return ts.cost; |
|
321 |
} |
|
322 |
||
323 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
324 |
/** Levels a selected (rectangle) area of land |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
325 |
* @param x,y end tile of area-drag |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
326 |
* @param p1 start tile of area drag |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
327 |
* @param p2 unused |
0 | 328 |
*/ |
329 |
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
330 |
{ |
|
331 |
int size_x, size_y; |
|
332 |
int sx, sy; |
|
333 |
uint h, curh; |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
334 |
TileIndex tile; |
0 | 335 |
int32 ret, cost, money; |
336 |
||
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2705
diff
changeset
|
337 |
if (p1 >= MapSize()) return CMD_ERROR; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
338 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
339 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
340 |
|
0 | 341 |
// remember level height |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
342 |
h = TileHeight(p1); |
0 | 343 |
|
344 |
ex >>= 4; ey >>= 4; |
|
345 |
||
346 |
// 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:
909
diff
changeset
|
347 |
sx = TileX(p1); |
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:
909
diff
changeset
|
348 |
sy = TileY(p1); |
0 | 349 |
if (ex < sx) intswap(ex, sx); |
350 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 351 |
tile = TileXY(sx, sy); |
0 | 352 |
|
353 |
size_x = ex-sx+1; |
|
354 |
size_y = ey-sy+1; |
|
355 |
||
356 |
money = GetAvailableMoneyForCommand(); |
|
357 |
cost = 0; |
|
358 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
359 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
360 |
curh = TileHeight(tile2); |
0 | 361 |
while (curh != h) { |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
362 |
ret = DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
363 |
if (CmdFailed(ret)) break; |
0 | 364 |
cost += ret; |
365 |
||
366 |
if (flags & DC_EXEC) { |
|
367 |
if ((money -= ret) < 0) { |
|
368 |
_additional_cash_required = ret; |
|
369 |
return cost - ret; |
|
370 |
} |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
371 |
DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 372 |
} |
373 |
||
374 |
curh += (curh > h) ? -1 : 1; |
|
375 |
} |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
376 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 377 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
378 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 379 |
} |
380 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
381 |
/** Purchase a land area. Actually you only purchase one tile, so |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
382 |
* the name is a bit confusing ;p |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
383 |
* @param x,y the tile the player is purchasing |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
384 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
385 |
* @param p2 unused |
0 | 386 |
*/ |
387 |
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
388 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
389 |
TileIndex tile; |
0 | 390 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
391 |
|
0 | 392 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
393 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
394 |
tile = TileVirtXY(x, y); |
0 | 395 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
396 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 397 |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
398 |
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 && |
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
|
399 |
IsTileOwner(tile, _current_player)) |
0 | 400 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
401 |
||
402 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
403 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 404 |
|
405 |
if (flags & DC_EXEC) { |
|
406 |
ModifyTile(tile, |
|
407 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
408 |
3 /* map5 */ |
|
409 |
); |
|
410 |
} |
|
411 |
||
412 |
return cost + _price.purchase_land * 10; |
|
413 |
} |
|
414 |
||
415 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
416 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 417 |
{ |
2220 | 418 |
static const int32* clear_price_table[] = { |
419 |
&_price.clear_1, |
|
420 |
&_price.purchase_land, |
|
421 |
&_price.clear_2, |
|
422 |
&_price.clear_3, |
|
423 |
&_price.purchase_land, |
|
424 |
&_price.purchase_land, |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
425 |
&_price.clear_2, // XXX unused? |
0 | 426 |
}; |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
427 |
int32 price; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
428 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
429 |
if (IsClearGround(tile, CL_GRASS) && GetClearDensity(tile) == 0) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
430 |
price = 0; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
431 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
432 |
price = *clear_price_table[GetClearGround(tile)]; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
433 |
} |
0 | 434 |
|
2220 | 435 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 436 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
437 |
return price; |
0 | 438 |
} |
439 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
440 |
/** Sell a land area. Actually you only sell one tile, so |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
441 |
* the name is a bit confusing ;p |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
442 |
* @param x,y the tile the player is selling |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
443 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
444 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
445 |
*/ |
0 | 446 |
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
447 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
448 |
TileIndex tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
449 |
|
0 | 450 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
451 |
||
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
452 |
tile = TileVirtXY(x, y); |
0 | 453 |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1986
diff
changeset
|
454 |
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR; |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
455 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1796
diff
changeset
|
456 |
|
0 | 457 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
458 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 459 |
|
460 |
if (flags & DC_EXEC) |
|
461 |
DoClearSquare(tile); |
|
462 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
463 |
return - _price.purchase_land * 2; |
0 | 464 |
} |
465 |
||
466 |
||
467 |
#include "table/clear_land.h" |
|
468 |
||
469 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
470 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 471 |
{ |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
472 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 473 |
} |
474 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
475 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 476 |
{ |
477 |
if (ti->tileh != 0) { |
|
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
478 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 479 |
} else { |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2051
diff
changeset
|
480 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 481 |
} |
482 |
} |
|
483 |
||
2220 | 484 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 485 |
{ |
486 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
487 |
|
0 | 488 |
if (ti->tileh & 2) { |
489 |
z += 8; |
|
2639 | 490 |
if (ti->tileh == 0x17) z += 8; |
0 | 491 |
} |
492 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
493 |
if (GetFenceSW(ti->tile) != 0) { |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
494 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 495 |
} |
496 |
||
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
497 |
if (GetFenceSE(ti->tile) != 0) { |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
498 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 499 |
} |
500 |
} |
|
501 |
||
502 |
static void DrawTile_Clear(TileInfo *ti) |
|
503 |
{ |
|
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
504 |
switch (GetClearGround(ti->tile)) { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
505 |
case CL_GRASS: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
506 |
DrawClearLandTile(ti, GetClearDensity(ti->tile)); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
507 |
break; |
0 | 508 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
509 |
case CL_ROUGH: |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
510 |
DrawHillyLandTile(ti); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
511 |
break; |
0 | 512 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
513 |
case CL_ROCKS: |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
514 |
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh]); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
515 |
break; |
0 | 516 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
517 |
case CL_FIELDS: |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
518 |
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
519 |
break; |
0 | 520 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
521 |
case CL_SNOW: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
522 |
DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
523 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
524 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
525 |
case CL_DESERT: |
3166
747e74d236f0
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
526 |
DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
527 |
break; |
0 | 528 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
529 |
|
2220 | 530 |
DrawClearLandFence(ti); |
0 | 531 |
} |
532 |
||
2537 | 533 |
static uint GetSlopeZ_Clear(const TileInfo* ti) |
1095 | 534 |
{ |
535 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
|
536 |
} |
|
0 | 537 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
538 |
static uint GetSlopeTileh_Clear(const TileInfo *ti) |
39 | 539 |
{ |
540 |
return ti->tileh; |
|
541 |
} |
|
542 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
543 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 544 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
545 |
/* unused */ |
0 | 546 |
} |
547 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
548 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 549 |
{ |
550 |
/* unused */ |
|
551 |
} |
|
552 |
||
1293 | 553 |
void TileLoopClearHelper(TileIndex tile) |
0 | 554 |
{ |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
555 |
byte self; |
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
556 |
byte neighbour; |
1293 | 557 |
TileIndex dirty = INVALID_TILE; |
0 | 558 |
|
2956 | 559 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CL_FIELDS)); |
0 | 560 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
561 |
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CL_FIELDS)); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
562 |
if (GetFenceSW(tile) == 0) { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
563 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
564 |
SetFenceSW(tile, 3); |
0 | 565 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
566 |
} |
0 | 567 |
} else { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
568 |
if (self == 0 && neighbour == 0) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
569 |
SetFenceSW(tile, 0); |
0 | 570 |
dirty = tile; |
571 |
} |
|
572 |
} |
|
573 |
||
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
574 |
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CL_FIELDS)); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
575 |
if (GetFenceSE(tile) == 0) { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
576 |
if (self != neighbour) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
577 |
SetFenceSE(tile, 3); |
0 | 578 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
579 |
} |
0 | 580 |
} else { |
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
581 |
if (self == 0 && neighbour == 0) { |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
582 |
SetFenceSE(tile, 0); |
0 | 583 |
dirty = tile; |
584 |
} |
|
585 |
} |
|
586 |
||
2221
a25240840b32
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
587 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 588 |
} |
589 |
||
590 |
||
591 |
/* convert into snowy tiles */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
592 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 593 |
{ |
594 |
/* distance from snow line, in steps of 8 */ |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
595 |
int k = GetTileZ(tile) - _opt.snow_line; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
596 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
597 |
if (k < -8) { // well below the snow line |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
598 |
if (!IsClearGround(tile, CL_SNOW)) return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
599 |
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CL_GRASS, 3); |
0 | 600 |
} else { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
601 |
if (!IsClearGround(tile, CL_SNOW)) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
602 |
SetClearGroundDensity(tile, CL_SNOW, 0); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
603 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
604 |
uint density = min((uint)(k + 8) / 8, 3); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
605 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
606 |
if (GetClearDensity(tile) < density) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
607 |
AddClearDensity(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
608 |
} else if (GetClearDensity(tile) > density) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
609 |
AddClearDensity(tile, -1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
610 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
611 |
return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
612 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
613 |
} |
0 | 614 |
} |
615 |
||
616 |
MarkTileDirtyByTile(tile); |
|
617 |
} |
|
618 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
619 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 620 |
{ |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
621 |
if (IsClearGround(tile, CL_DESERT)) return; |
0 | 622 |
|
623 |
if (GetMapExtraBits(tile) == 1) { |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
624 |
SetClearGroundDensity(tile, CL_DESERT, 3); |
0 | 625 |
} else { |
1981 | 626 |
if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 && |
627 |
GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 && |
|
628 |
GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 && |
|
629 |
GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1) |
|
630 |
return; |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
631 |
SetClearGroundDensity(tile, CL_DESERT, 1); |
0 | 632 |
} |
633 |
||
634 |
MarkTileDirtyByTile(tile); |
|
635 |
} |
|
636 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
637 |
static void TileLoop_Clear(TileIndex tile) |
0 | 638 |
{ |
639 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
640 |
|
2989 | 641 |
switch (_opt.landscape) { |
642 |
case LT_DESERT: TileLoopClearDesert(tile); break; |
|
643 |
case LT_HILLY: TileLoopClearAlps(tile); break; |
|
0 | 644 |
} |
645 |
||
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
646 |
switch (GetClearGround(tile)) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
647 |
case CL_GRASS: |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
648 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
649 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
650 |
if (_game_mode != GM_EDITOR) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
651 |
if (GetClearCounter(tile) < 7) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
652 |
AddClearCounter(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
653 |
return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
654 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
655 |
SetClearCounter(tile, 0); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
656 |
AddClearDensity(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
657 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
658 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
659 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CL_GRASS : CL_ROUGH, 3); |
0 | 660 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
661 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
662 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
663 |
case CL_FIELDS: { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
664 |
uint field_type; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
665 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
666 |
if (_game_mode == GM_EDITOR) return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
667 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
668 |
if (GetClearCounter(tile) < 7) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
669 |
AddClearCounter(tile, 1); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
670 |
return; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
671 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
672 |
SetClearCounter(tile, 0); |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
673 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
674 |
|
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
675 |
field_type = GetFieldType(tile); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
676 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
677 |
SetFieldType(tile, field_type); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
678 |
break; |
0 | 679 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
680 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
681 |
default: |
0 | 682 |
return; |
683 |
} |
|
684 |
||
685 |
MarkTileDirtyByTile(tile); |
|
686 |
} |
|
687 |
||
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
|
688 |
void GenerateClearTile(void) |
0 | 689 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
690 |
uint i; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
691 |
TileIndex tile; |
0 | 692 |
|
693 |
/* add hills */ |
|
2635 | 694 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
0 | 695 |
do { |
2051 | 696 |
tile = RandomTile(); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
697 |
if (IsTileType(tile, MP_CLEAR)) SetClearGroundDensity(tile, CL_ROUGH, 3); |
0 | 698 |
} while (--i); |
699 |
||
700 |
/* add grey squares */ |
|
2635 | 701 |
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
0 | 702 |
do { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
703 |
uint32 r = Random(); |
2051 | 704 |
tile = RandomTileSeed(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:
926
diff
changeset
|
705 |
if (IsTileType(tile, MP_CLEAR)) { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
706 |
uint j = GB(r, 16, 4) + 5; |
2951 | 707 |
for (;;) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
708 |
TileIndex tile_new; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
709 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
710 |
SetClearGroundDensity(tile, CL_ROCKS, 3); |
0 | 711 |
do { |
712 |
if (--j == 0) goto get_out; |
|
2635 | 713 |
tile_new = tile + TileOffsByDir(GB(Random(), 0, 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:
926
diff
changeset
|
714 |
} while (!IsTileType(tile_new, MP_CLEAR)); |
0 | 715 |
tile = tile_new; |
716 |
} |
|
717 |
get_out:; |
|
718 |
} |
|
719 |
} while (--i); |
|
720 |
} |
|
721 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
722 |
static void ClickTile_Clear(TileIndex tile) |
0 | 723 |
{ |
724 |
/* not used */ |
|
725 |
} |
|
726 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
727 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 728 |
{ |
729 |
return 0; |
|
730 |
} |
|
731 |
||
2220 | 732 |
static const StringID _clear_land_str[] = { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
733 |
STR_080D_GRASS, |
0 | 734 |
STR_080B_ROUGH_LAND, |
735 |
STR_080A_ROCKS, |
|
736 |
STR_080E_FIELDS, |
|
737 |
STR_080F_SNOW_COVERED_LAND, |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
738 |
STR_0810_DESERT |
0 | 739 |
}; |
740 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
741 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 742 |
{ |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
743 |
if (IsClearGround(tile, CL_GRASS) && GetClearDensity(tile) == 0) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
744 |
td->str = STR_080C_BARE_LAND; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
745 |
} else { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
746 |
td->str = _clear_land_str[GetClearGround(tile)]; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
747 |
} |
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
|
748 |
td->owner = GetTileOwner(tile); |
0 | 749 |
} |
750 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
751 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 752 |
{ |
753 |
return; |
|
754 |
} |
|
755 |
||
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
|
756 |
void InitializeClearLand(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
757 |
{ |
0 | 758 |
_opt.snow_line = _patches.snow_line_height * 8; |
759 |
} |
|
760 |
||
761 |
const TileTypeProcs _tile_type_clear_procs = { |
|
762 |
DrawTile_Clear, /* draw_tile_proc */ |
|
763 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
764 |
ClearTile_Clear, /* clear_tile_proc */ |
|
765 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
766 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
767 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
768 |
ClickTile_Clear, /* click_tile_proc */ |
|
769 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
770 |
TileLoop_Clear, /* tile_loop_clear */ |
|
771 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
772 |
NULL, /* get_produced_cargo_proc */ |
|
773 |
NULL, /* vehicle_enter_tile_proc */ |
|
774 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 775 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 776 |
}; |