author | tron |
Wed, 01 Feb 2006 15:31:21 +0000 | |
changeset 2955 | 24de69e236d2 |
parent 2952 | 58522ed8f0f1 |
child 2956 | 3e9a354875c5 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
4 |
#include "openttd.h" |
2955
24de69e236d2
(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
|
5 |
#include "clear.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
6 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
7 |
#include "functions.h" |
679
04ca2cd69420
(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
f86c59e73a16
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2153
diff
changeset
|
9 |
#include "player.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
10 |
#include "tile.h" |
0 | 11 |
#include "viewport.h" |
12 |
#include "command.h" |
|
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
13 |
#include "variables.h" |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
14 |
#include "table/sprites.h" |
0 | 15 |
|
16 |
typedef struct TerraformerHeightMod { |
|
17 |
TileIndex tile; |
|
18 |
byte height; |
|
19 |
} TerraformerHeightMod; |
|
20 |
||
21 |
typedef struct TerraformerState { |
|
22 |
int height[4]; |
|
23 |
uint32 flags; |
|
24 |
||
25 |
int direction; |
|
26 |
int modheight_count; |
|
27 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
28 |
|
0 | 29 |
int32 cost; |
30 |
||
31 |
TileIndex *tile_table; |
|
32 |
TerraformerHeightMod *modheight; |
|
33 |
||
34 |
} TerraformerState; |
|
35 |
||
36 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
37 |
{ |
|
38 |
TileIndex *t; |
|
39 |
int count; |
|
40 |
||
2639 | 41 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 42 |
|
43 |
t = ts->tile_table; |
|
2639 | 44 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
45 |
if (*t == tile) return 0; |
|
0 | 46 |
} |
47 |
||
48 |
return 1; |
|
49 |
} |
|
50 |
||
51 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
52 |
{ |
|
53 |
TerraformerHeightMod *mod = ts->modheight; |
|
54 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
55 |
|
2639 | 56 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
57 |
if (mod->tile == tile) return mod->height; |
|
0 | 58 |
} |
59 |
||
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
60 |
return TileHeight(tile); |
0 | 61 |
} |
62 |
||
63 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
64 |
{ |
|
65 |
int count; |
|
66 |
TileIndex *t; |
|
67 |
||
68 |
count = ts->tile_table_count; |
|
69 |
||
2639 | 70 |
if (count >= 625) return; |
0 | 71 |
|
2952 | 72 |
for (t = ts->tile_table; count != 0; count--,t++) { |
2639 | 73 |
if (*t == tile) return; |
0 | 74 |
} |
75 |
||
76 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
77 |
} |
|
78 |
||
79 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
80 |
{ |
|
1981 | 81 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
82 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
83 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 84 |
TerraformAddDirtyTile(ts, tile); |
85 |
} |
|
86 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
87 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 88 |
{ |
89 |
int r; |
|
2686
609f3b4d2fd4
(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
|
90 |
bool skip_clear = false; |
0 | 91 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
92 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
93 |
|
0 | 94 |
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0) |
95 |
return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
96 |
|
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
97 |
if (IsTileType(tile, MP_RAILWAY)) { |
0 | 98 |
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20}; |
99 |
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb}; |
|
345
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
100 |
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4}; |
0 | 101 |
|
102 |
// Nothing could be built at the steep slope - this avoids a bug |
|
103 |
// when you have a single diagonal track in one corner on a |
|
345
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
104 |
// basement and then you raise/lower the other corner. |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
105 |
int tileh = GetTileSlope(tile, NULL) & 0xF; |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
106 |
if (tileh == _railway_dangslopes[mode] || |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
107 |
tileh == _railway_dangslopes2[mode]) { |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
108 |
_terraform_err_tile = tile; |
0 | 109 |
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; |
110 |
return -1; |
|
111 |
} |
|
112 |
||
113 |
// If we have a single diagonal track there, the other side of |
|
114 |
// tile can be terraformed. |
|
2705
494b6b5e7a08
(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
|
115 |
if ((_m[tile].m5 & ~0x40) == _railway_modes[mode]) { |
494b6b5e7a08
(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 (ts->direction == 1) return 0; |
494b6b5e7a08
(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 |
skip_clear = true; |
494b6b5e7a08
(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 |
} |
0 | 119 |
} |
120 |
||
2686
609f3b4d2fd4
(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
|
121 |
if (!skip_clear) { |
609f3b4d2fd4
(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 |
int32 ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 123 |
|
2686
609f3b4d2fd4
(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
|
124 |
if (CmdFailed(ret)) { |
609f3b4d2fd4
(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 |
_terraform_err_tile = tile; |
609f3b4d2fd4
(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 |
return -1; |
609f3b4d2fd4
(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 |
} |
609f3b4d2fd4
(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 |
|
609f3b4d2fd4
(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 |
ts->cost += ret; |
0 | 130 |
} |
131 |
||
2639 | 132 |
if (ts->tile_table_count >= 625) return -1; |
0 | 133 |
ts->tile_table[ts->tile_table_count++] = tile; |
134 |
||
135 |
return 0; |
|
136 |
} |
|
137 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
138 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 139 |
{ |
140 |
int nh; |
|
141 |
TerraformerHeightMod *mod; |
|
142 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
143 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
144 |
assert(tile < MapSize()); |
0 | 145 |
|
146 |
if (height < 0) { |
|
147 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
148 |
return false; |
|
149 |
} |
|
150 |
||
151 |
_error_message = STR_1004_TOO_HIGH; |
|
152 |
||
2639 | 153 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
154 |
|
0 | 155 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 156 |
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
|
157 |
|
1981 | 158 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
159 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
|
160 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
|
161 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
|
0 | 162 |
|
163 |
mod = ts->modheight; |
|
164 |
count = ts->modheight_count; |
|
165 |
||
2639 | 166 |
for (;;) { |
0 | 167 |
if (count == 0) { |
168 |
if (ts->modheight_count >= 576) |
|
169 |
return false; |
|
170 |
ts->modheight_count++; |
|
171 |
break; |
|
172 |
} |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
173 |
if (mod->tile == tile) break; |
0 | 174 |
mod++; |
175 |
count--; |
|
176 |
} |
|
177 |
||
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
178 |
mod->tile = tile; |
0 | 179 |
mod->height = (byte)height; |
180 |
||
181 |
ts->cost += _price.terraform; |
|
182 |
||
183 |
{ |
|
184 |
int direction = ts->direction, r; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
185 |
const TileIndexDiffC *ttm; |
0 | 186 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
187 |
static const TileIndexDiffC _terraform_tilepos[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
188 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
189 |
{-2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
190 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
191 |
{ 0, -2} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
192 |
}; |
0 | 193 |
|
2952 | 194 |
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
195 |
tile += ToTileIndexDiff(*ttm); |
0 | 196 |
|
197 |
r = TerraformGetHeightOfTile(ts, tile); |
|
198 |
if (r != height && r-direction != height && r+direction != height) { |
|
199 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
200 |
return false; |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
return true; |
|
206 |
} |
|
207 |
||
1775
548dc04d50e2
(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
|
208 |
/** Terraform land |
548dc04d50e2
(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 |
* @param x,y coordinates to terraform |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
210 |
* @param p1 corners to terraform. |
1775
548dc04d50e2
(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
|
211 |
* @param p2 direction; eg up or down |
0 | 212 |
*/ |
213 |
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
214 |
{ |
|
215 |
TerraformerState ts; |
|
1775
548dc04d50e2
(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
|
216 |
TileIndex tile; |
0 | 217 |
int direction; |
218 |
||
219 |
TerraformerHeightMod modheight_data[576]; |
|
220 |
TileIndex tile_table_data[625]; |
|
221 |
||
222 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
223 |
||
224 |
_error_message = INVALID_STRING_ID; |
|
225 |
_terraform_err_tile = 0; |
|
226 |
||
227 |
ts.direction = direction = p2 ? 1 : -1; |
|
228 |
ts.flags = flags; |
|
229 |
ts.modheight_count = ts.tile_table_count = 0; |
|
230 |
ts.cost = 0; |
|
231 |
ts.modheight = modheight_data; |
|
232 |
ts.tile_table = tile_table_data; |
|
233 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
234 |
tile = TileVirtXY(x, y); |
0 | 235 |
|
1878
980fabc7d8a5
(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
|
236 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
2934
3f29a7212713
(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
|
237 |
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; |
1878
980fabc7d8a5
(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
|
238 |
|
0 | 239 |
if (p1 & 1) { |
1981 | 240 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
241 |
TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
|
0 | 242 |
return CMD_ERROR; |
243 |
} |
|
244 |
||
245 |
if (p1 & 2) { |
|
1981 | 246 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
247 |
TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
|
0 | 248 |
return CMD_ERROR; |
249 |
} |
|
250 |
||
251 |
if (p1 & 4) { |
|
1981 | 252 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
253 |
TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
|
0 | 254 |
return CMD_ERROR; |
255 |
} |
|
256 |
||
257 |
if (p1 & 8) { |
|
1981 | 258 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
259 |
TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
|
0 | 260 |
return CMD_ERROR; |
261 |
} |
|
262 |
||
263 |
if (direction == -1) { |
|
264 |
/* Check if tunnel would take damage */ |
|
265 |
int count; |
|
266 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
267 |
|
1775
548dc04d50e2
(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
|
268 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 269 |
uint z, t; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
270 |
TileIndex tile = *ti; |
0 | 271 |
|
1981 | 272 |
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
273 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
|
0 | 274 |
if (t <= z) z = t; |
1981 | 275 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
0 | 276 |
if (t <= z) z = t; |
1981 | 277 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
0 | 278 |
if (t <= z) z = t; |
279 |
||
2639 | 280 |
if (!CheckTunnelInWay(tile, z * 8)) { |
0 | 281 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
2639 | 282 |
} |
0 | 283 |
} |
284 |
} |
|
285 |
||
286 |
if (flags & DC_EXEC) { |
|
287 |
/* Clear the landscape at the tiles */ |
|
288 |
{ |
|
289 |
int count; |
|
290 |
TileIndex *ti = ts.tile_table; |
|
1775
548dc04d50e2
(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
|
291 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 292 |
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
293 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
294 |
} |
0 | 295 |
|
296 |
/* change the height */ |
|
297 |
{ |
|
298 |
int count; |
|
299 |
TerraformerHeightMod *mod; |
|
300 |
||
301 |
mod = ts.modheight; |
|
1775
548dc04d50e2
(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
|
302 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
82d8bcc16ce2
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
303 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
304 |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
305 |
SetTileHeight(til, mod->height); |
0 | 306 |
TerraformAddDirtyTileAround(&ts, til); |
307 |
} |
|
308 |
} |
|
309 |
||
310 |
/* finally mark the dirty tiles dirty */ |
|
311 |
{ |
|
312 |
int count; |
|
313 |
TileIndex *ti = ts.tile_table; |
|
1775
548dc04d50e2
(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
|
314 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 315 |
MarkTileDirtyByTile(*ti); |
316 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
317 |
} |
0 | 318 |
} |
319 |
return ts.cost; |
|
320 |
} |
|
321 |
||
322 |
||
1796
614d996f6be7
(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
|
323 |
/** Levels a selected (rectangle) area of land |
614d996f6be7
(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 |
* @param x,y end tile of area-drag |
614d996f6be7
(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 p1 start tile of area drag |
614d996f6be7
(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 p2 unused |
0 | 327 |
*/ |
328 |
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
329 |
{ |
|
330 |
int size_x, size_y; |
|
331 |
int sx, sy; |
|
332 |
uint h, curh; |
|
1796
614d996f6be7
(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
|
333 |
TileIndex tile; |
0 | 334 |
int32 ret, cost, money; |
335 |
||
2934
3f29a7212713
(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
|
336 |
if (p1 >= MapSize()) return CMD_ERROR; |
1796
614d996f6be7
(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
|
337 |
|
889
64d2f7d5f02b
(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
|
338 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(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 |
|
0 | 340 |
// remember level height |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
341 |
h = TileHeight(p1); |
0 | 342 |
|
343 |
ex >>= 4; ey >>= 4; |
|
344 |
||
345 |
// make sure sx,sy are smaller than ex,ey |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
346 |
sx = TileX(p1); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
347 |
sy = TileY(p1); |
0 | 348 |
if (ex < sx) intswap(ex, sx); |
349 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 350 |
tile = TileXY(sx, sy); |
0 | 351 |
|
352 |
size_x = ex-sx+1; |
|
353 |
size_y = ey-sy+1; |
|
354 |
||
355 |
money = GetAvailableMoneyForCommand(); |
|
356 |
cost = 0; |
|
357 |
||
1796
614d996f6be7
(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
|
358 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
359 |
curh = TileHeight(tile2); |
0 | 360 |
while (curh != h) { |
1796
614d996f6be7
(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
|
361 |
ret = DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
614d996f6be7
(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 |
if (CmdFailed(ret)) break; |
0 | 363 |
cost += ret; |
364 |
||
365 |
if (flags & DC_EXEC) { |
|
366 |
if ((money -= ret) < 0) { |
|
367 |
_additional_cash_required = ret; |
|
368 |
return cost - ret; |
|
369 |
} |
|
1796
614d996f6be7
(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
|
370 |
DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 371 |
} |
372 |
||
373 |
curh += (curh > h) ? -1 : 1; |
|
374 |
} |
|
1796
614d996f6be7
(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
|
375 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 376 |
|
1796
614d996f6be7
(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
|
377 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 378 |
} |
379 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
380 |
/** Purchase a land area. Actually you only purchase one tile, so |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
381 |
* the name is a bit confusing ;p |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
382 |
* @param x,y the tile the player is purchasing |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
383 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
384 |
* @param p2 unused |
0 | 385 |
*/ |
386 |
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
387 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
388 |
TileIndex tile; |
0 | 389 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
390 |
|
0 | 391 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
392 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
393 |
tile = TileVirtXY(x, y); |
0 | 394 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
395 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 396 |
|
2049
538e73c53f54
(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
|
397 |
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 && |
1901
03bf9bf99319
(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
|
398 |
IsTileOwner(tile, _current_player)) |
0 | 399 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
400 |
||
401 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
402 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 403 |
|
404 |
if (flags & DC_EXEC) { |
|
405 |
ModifyTile(tile, |
|
406 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
407 |
3 /* map5 */ |
|
408 |
); |
|
409 |
} |
|
410 |
||
411 |
return cost + _price.purchase_land * 10; |
|
412 |
} |
|
413 |
||
414 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
415 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 416 |
{ |
2220 | 417 |
static const int32* clear_price_table[] = { |
418 |
&_price.clear_1, |
|
419 |
&_price.purchase_land, |
|
420 |
&_price.clear_2, |
|
421 |
&_price.clear_3, |
|
422 |
&_price.purchase_land, |
|
423 |
&_price.purchase_land, |
|
2955
24de69e236d2
(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
|
424 |
&_price.clear_2, // XXX unused? |
0 | 425 |
}; |
2955
24de69e236d2
(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
|
426 |
int32 price; |
24de69e236d2
(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 |
|
24de69e236d2
(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 |
if (IsClearGround(tile, CL_GRASS) && GetClearDensity(tile) == 0) { |
24de69e236d2
(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 |
price = 0; |
24de69e236d2
(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 |
} else { |
24de69e236d2
(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 |
price = *clear_price_table[GetClearGround(tile)]; |
24de69e236d2
(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 |
} |
0 | 433 |
|
2220 | 434 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 435 |
|
2955
24de69e236d2
(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
|
436 |
return price; |
0 | 437 |
} |
438 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
439 |
/** Sell a land area. Actually you only sell one tile, so |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
440 |
* the name is a bit confusing ;p |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
441 |
* @param x,y the tile the player is selling |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
442 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
443 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
444 |
*/ |
0 | 445 |
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
446 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
447 |
TileIndex tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
448 |
|
0 | 449 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
450 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
451 |
tile = TileVirtXY(x, y); |
0 | 452 |
|
2049
538e73c53f54
(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
|
453 |
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR; |
1878
980fabc7d8a5
(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
|
454 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
980fabc7d8a5
(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 |
|
0 | 456 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
457 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 458 |
|
459 |
if (flags & DC_EXEC) |
|
460 |
DoClearSquare(tile); |
|
461 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
462 |
return - _price.purchase_land * 2; |
0 | 463 |
} |
464 |
||
465 |
||
466 |
#include "table/clear_land.h" |
|
467 |
||
468 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
469 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 470 |
{ |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
471 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 472 |
} |
473 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
474 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 475 |
{ |
476 |
if (ti->tileh != 0) { |
|
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
477 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 478 |
} else { |
2140
a04d0142ad65
(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
|
479 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 480 |
} |
481 |
} |
|
482 |
||
2220 | 483 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 484 |
{ |
2220 | 485 |
byte m4 = _m[ti->tile].m4; |
0 | 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 |
||
2220 | 493 |
if (GB(m4, 5, 3) != 0) { |
494 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 5, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
|
0 | 495 |
} |
496 |
||
2220 | 497 |
if (GB(m4, 2, 3) != 0) { |
498 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 2, 3) - 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 |
{ |
|
2220 | 504 |
switch (GB(ti->map5, 2, 3)) { |
2955
24de69e236d2
(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: |
24de69e236d2
(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
|
506 |
DrawClearLandTile(ti, GB(ti->map5, 0, 2)); |
24de69e236d2
(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
24de69e236d2
(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: |
24de69e236d2
(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); |
24de69e236d2
(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
24de69e236d2
(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: |
24de69e236d2
(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]); |
24de69e236d2
(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
24de69e236d2
(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: |
24de69e236d2
(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
|
518 |
DrawGroundSprite(_clear_land_sprites_1[GB(_m[ti->tile].m3, 0, 4)] + _tileh_to_sprite[ti->tileh]); |
24de69e236d2
(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
24de69e236d2
(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: |
24de69e236d2
(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
|
522 |
DrawGroundSprite(_clear_land_sprites_2[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]); |
24de69e236d2
(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; |
24de69e236d2
(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 |
|
24de69e236d2
(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: |
24de69e236d2
(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
|
526 |
DrawGroundSprite(_clear_land_sprites_3[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]); |
24de69e236d2
(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
7d5df545bd5d
(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
37bbebf94434
(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
37bbebf94434
(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
de4a862fa8e2
(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; |
de4a862fa8e2
(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 |
|
2955
24de69e236d2
(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
|
559 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CL_FIELDS)); |
0 | 560 |
|
2955
24de69e236d2
(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)); |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
562 |
if (GB(_m[tile].m4, 5, 3) == 0) { |
de4a862fa8e2
(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) { |
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
564 |
SB(_m[tile].m4, 5, 3, 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
de4a862fa8e2
(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) { |
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
569 |
SB(_m[tile].m4, 5, 3, 0); |
0 | 570 |
dirty = tile; |
571 |
} |
|
572 |
} |
|
573 |
||
2955
24de69e236d2
(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)); |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
575 |
if (GB(_m[tile].m4, 2, 3) == 0) { |
de4a862fa8e2
(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) { |
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
577 |
SB(_m[tile].m4, 2, 3, 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
de4a862fa8e2
(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) { |
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
582 |
SB(_m[tile].m4, 2, 3, 0); |
0 | 583 |
dirty = tile; |
584 |
} |
|
585 |
} |
|
586 |
||
2221
de4a862fa8e2
(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
37bbebf94434
(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
24de69e236d2
(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
24de69e236d2
(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 |
24de69e236d2
(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; |
24de69e236d2
(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
24de69e236d2
(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)) { |
24de69e236d2
(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); |
24de69e236d2
(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 { |
24de69e236d2
(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); |
24de69e236d2
(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 |
|
24de69e236d2
(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) { |
24de69e236d2
(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); |
24de69e236d2
(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) { |
24de69e236d2
(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); |
24de69e236d2
(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 { |
24de69e236d2
(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; |
24de69e236d2
(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 |
} |
24de69e236d2
(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
37bbebf94434
(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
24de69e236d2
(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
24de69e236d2
(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
24de69e236d2
(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
37bbebf94434
(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 |
|
0 | 641 |
if (_opt.landscape == LT_DESERT) { |
642 |
TileLoopClearDesert(tile); |
|
643 |
} else if (_opt.landscape == LT_HILLY) { |
|
644 |
TileLoopClearAlps(tile); |
|
645 |
} |
|
646 |
||
2955
24de69e236d2
(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 |
switch (GetClearGround(tile)) { |
24de69e236d2
(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 |
case CL_GRASS: |
24de69e236d2
(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
|
649 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
650 |
|
2955
24de69e236d2
(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 (_game_mode != GM_EDITOR) { |
24de69e236d2
(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 |
if (GetClearCounter(tile) < 7) { |
24de69e236d2
(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 |
AddClearCounter(tile, 1); |
24de69e236d2
(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 |
return; |
24de69e236d2
(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 |
} else { |
24de69e236d2
(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 |
SetClearCounter(tile, 0); |
24de69e236d2
(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 |
AddClearDensity(tile, 1); |
24de69e236d2
(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 |
} |
24de69e236d2
(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 |
} else { |
24de69e236d2
(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
|
660 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CL_GRASS : CL_ROUGH, 3); |
0 | 661 |
} |
2955
24de69e236d2
(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 |
break; |
24de69e236d2
(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 |
|
24de69e236d2
(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 |
case CL_FIELDS: { |
24de69e236d2
(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 |
uint field_type; |
24de69e236d2
(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 |
|
24de69e236d2
(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 |
if (_game_mode == GM_EDITOR) return; |
24de69e236d2
(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 |
|
24de69e236d2
(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 |
if (GetClearCounter(tile) < 7) { |
24de69e236d2
(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 |
AddClearCounter(tile, 1); |
24de69e236d2
(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 |
return; |
24de69e236d2
(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 |
} else { |
24de69e236d2
(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 |
SetClearCounter(tile, 0); |
24de69e236d2
(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 |
} |
24de69e236d2
(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
|
675 |
|
24de69e236d2
(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 = GB(_m[tile].m3, 0, 4); |
24de69e236d2
(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
|
677 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
24de69e236d2
(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 |
SB(_m[tile].m3, 0, 4, field_type); |
24de69e236d2
(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
|
679 |
break; |
0 | 680 |
} |
2955
24de69e236d2
(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 |
|
24de69e236d2
(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
|
682 |
default: |
0 | 683 |
return; |
684 |
} |
|
685 |
||
686 |
MarkTileDirtyByTile(tile); |
|
687 |
} |
|
688 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
689 |
void GenerateClearTile(void) |
0 | 690 |
{ |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
691 |
uint i; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
692 |
TileIndex tile; |
0 | 693 |
|
694 |
/* add hills */ |
|
2635 | 695 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
0 | 696 |
do { |
2051 | 697 |
tile = RandomTile(); |
2955
24de69e236d2
(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
|
698 |
if (IsTileType(tile, MP_CLEAR)) SetClearGroundDensity(tile, CL_ROUGH, 3); |
0 | 699 |
} while (--i); |
700 |
||
701 |
/* add grey squares */ |
|
2635 | 702 |
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
0 | 703 |
do { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
704 |
uint32 r = Random(); |
2051 | 705 |
tile = RandomTileSeed(r); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
706 |
if (IsTileType(tile, MP_CLEAR)) { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
707 |
uint j = GB(r, 16, 4) + 5; |
2951 | 708 |
for (;;) { |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
709 |
TileIndex tile_new; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
710 |
|
2955
24de69e236d2
(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
|
711 |
SetClearGroundDensity(tile, CL_ROCKS, 3); |
0 | 712 |
do { |
713 |
if (--j == 0) goto get_out; |
|
2635 | 714 |
tile_new = tile + TileOffsByDir(GB(Random(), 0, 2)); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
926
diff
changeset
|
715 |
} while (!IsTileType(tile_new, MP_CLEAR)); |
0 | 716 |
tile = tile_new; |
717 |
} |
|
718 |
get_out:; |
|
719 |
} |
|
720 |
} while (--i); |
|
721 |
} |
|
722 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
723 |
static void ClickTile_Clear(TileIndex tile) |
0 | 724 |
{ |
725 |
/* not used */ |
|
726 |
} |
|
727 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
728 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 729 |
{ |
730 |
return 0; |
|
731 |
} |
|
732 |
||
2220 | 733 |
static const StringID _clear_land_str[] = { |
2955
24de69e236d2
(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
|
734 |
STR_080D_GRASS, |
0 | 735 |
STR_080B_ROUGH_LAND, |
736 |
STR_080A_ROCKS, |
|
737 |
STR_080E_FIELDS, |
|
738 |
STR_080F_SNOW_COVERED_LAND, |
|
2955
24de69e236d2
(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
|
739 |
STR_0810_DESERT |
0 | 740 |
}; |
741 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
742 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 743 |
{ |
2955
24de69e236d2
(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 |
if (IsClearGround(tile, CL_GRASS) && GetClearDensity(tile) == 0) { |
24de69e236d2
(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 |
td->str = STR_080C_BARE_LAND; |
24de69e236d2
(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 |
} else { |
24de69e236d2
(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 |
td->str = _clear_land_str[GetClearGround(tile)]; |
24de69e236d2
(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
|
748 |
} |
1901
03bf9bf99319
(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
|
749 |
td->owner = GetTileOwner(tile); |
0 | 750 |
} |
751 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2221
diff
changeset
|
752 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 753 |
{ |
754 |
return; |
|
755 |
} |
|
756 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
757 |
void InitializeClearLand(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
758 |
{ |
0 | 759 |
_opt.snow_line = _patches.snow_line_height * 8; |
760 |
} |
|
761 |
||
762 |
const TileTypeProcs _tile_type_clear_procs = { |
|
763 |
DrawTile_Clear, /* draw_tile_proc */ |
|
764 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
765 |
ClearTile_Clear, /* clear_tile_proc */ |
|
766 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
767 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
768 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
769 |
ClickTile_Clear, /* click_tile_proc */ |
|
770 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
771 |
TileLoop_Clear, /* tile_loop_clear */ |
|
772 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
773 |
NULL, /* get_produced_cargo_proc */ |
|
774 |
NULL, /* vehicle_enter_tile_proc */ |
|
775 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 776 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 777 |
}; |