author | tron |
Sun, 23 Apr 2006 19:35:36 +0000 | |
changeset 3645 | 7f950533d510 |
parent 3636 | a36cc46e754d |
child 3657 | eb28d97d3d18 |
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" |
3144
33e42feae531
(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
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" |
|
3156
f4caf4197189
(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
ecfc674410b4
(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
6e3832ddd0f6
(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" |
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
16 |
#include "unmovable_map.h" |
0 | 17 |
|
18 |
typedef struct TerraformerHeightMod { |
|
19 |
TileIndex tile; |
|
20 |
byte height; |
|
21 |
} TerraformerHeightMod; |
|
22 |
||
23 |
typedef struct TerraformerState { |
|
24 |
int height[4]; |
|
25 |
uint32 flags; |
|
26 |
||
27 |
int direction; |
|
28 |
int modheight_count; |
|
29 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
30 |
|
0 | 31 |
int32 cost; |
32 |
||
33 |
TileIndex *tile_table; |
|
34 |
TerraformerHeightMod *modheight; |
|
35 |
||
36 |
} TerraformerState; |
|
37 |
||
38 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
39 |
{ |
|
40 |
TileIndex *t; |
|
41 |
int count; |
|
42 |
||
2639 | 43 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; |
0 | 44 |
|
45 |
t = ts->tile_table; |
|
2639 | 46 |
for (count = ts->tile_table_count; count != 0; count--, t++) { |
47 |
if (*t == tile) return 0; |
|
0 | 48 |
} |
49 |
||
50 |
return 1; |
|
51 |
} |
|
52 |
||
53 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
54 |
{ |
|
55 |
TerraformerHeightMod *mod = ts->modheight; |
|
56 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
57 |
|
2639 | 58 |
for (count = ts->modheight_count; count != 0; count--, mod++) { |
59 |
if (mod->tile == tile) return mod->height; |
|
0 | 60 |
} |
61 |
||
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
62 |
return TileHeight(tile); |
0 | 63 |
} |
64 |
||
65 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
66 |
{ |
|
67 |
int count; |
|
68 |
TileIndex *t; |
|
69 |
||
70 |
count = ts->tile_table_count; |
|
71 |
||
2639 | 72 |
if (count >= 625) return; |
0 | 73 |
|
2952 | 74 |
for (t = ts->tile_table; count != 0; count--,t++) { |
2639 | 75 |
if (*t == tile) return; |
0 | 76 |
} |
77 |
||
78 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
79 |
} |
|
80 |
||
81 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
82 |
{ |
|
1981 | 83 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
84 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
85 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 86 |
TerraformAddDirtyTile(ts, tile); |
87 |
} |
|
88 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
89 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 90 |
{ |
91 |
int r; |
|
92 |
||
863
6a1444534f62
(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 |
|
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
98 |
if (!IsTileType(tile, MP_RAILWAY)) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
99 |
int32 ret = DoCommand(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 100 |
|
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
|
101 |
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
|
102 |
_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
|
103 |
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
|
104 |
} |
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
|
105 |
|
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
|
106 |
ts->cost += ret; |
0 | 107 |
} |
108 |
||
2639 | 109 |
if (ts->tile_table_count >= 625) return -1; |
0 | 110 |
ts->tile_table[ts->tile_table_count++] = tile; |
111 |
||
112 |
return 0; |
|
113 |
} |
|
114 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
115 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 116 |
{ |
117 |
int nh; |
|
118 |
TerraformerHeightMod *mod; |
|
119 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
120 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
121 |
assert(tile < MapSize()); |
0 | 122 |
|
123 |
if (height < 0) { |
|
124 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
125 |
return false; |
|
126 |
} |
|
127 |
||
128 |
_error_message = STR_1004_TOO_HIGH; |
|
129 |
||
2639 | 130 |
if (height > 15) return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
131 |
|
0 | 132 |
nh = TerraformGetHeightOfTile(ts, tile); |
2639 | 133 |
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
|
134 |
|
1981 | 135 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
136 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
|
137 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
|
138 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
|
0 | 139 |
|
140 |
mod = ts->modheight; |
|
141 |
count = ts->modheight_count; |
|
142 |
||
2639 | 143 |
for (;;) { |
0 | 144 |
if (count == 0) { |
145 |
if (ts->modheight_count >= 576) |
|
146 |
return false; |
|
147 |
ts->modheight_count++; |
|
148 |
break; |
|
149 |
} |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
150 |
if (mod->tile == tile) break; |
0 | 151 |
mod++; |
152 |
count--; |
|
153 |
} |
|
154 |
||
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
155 |
mod->tile = tile; |
0 | 156 |
mod->height = (byte)height; |
157 |
||
158 |
ts->cost += _price.terraform; |
|
159 |
||
160 |
{ |
|
161 |
int direction = ts->direction, r; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
162 |
const TileIndexDiffC *ttm; |
0 | 163 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
164 |
static const TileIndexDiffC _terraform_tilepos[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
165 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
166 |
{-2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
167 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
168 |
{ 0, -2} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
169 |
}; |
0 | 170 |
|
2952 | 171 |
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
|
172 |
tile += ToTileIndexDiff(*ttm); |
0 | 173 |
|
174 |
r = TerraformGetHeightOfTile(ts, tile); |
|
175 |
if (r != height && r-direction != height && r+direction != height) { |
|
176 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
177 |
return false; |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
return true; |
|
183 |
} |
|
184 |
||
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
|
185 |
/** Terraform land |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
186 |
* @param tile tile to terraform |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
187 |
* @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
|
188 |
* @param p2 direction; eg up or down |
0 | 189 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
190 |
int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 191 |
{ |
192 |
TerraformerState ts; |
|
193 |
int direction; |
|
194 |
||
195 |
TerraformerHeightMod modheight_data[576]; |
|
196 |
TileIndex tile_table_data[625]; |
|
197 |
||
198 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
199 |
||
200 |
_error_message = INVALID_STRING_ID; |
|
201 |
_terraform_err_tile = 0; |
|
202 |
||
203 |
ts.direction = direction = p2 ? 1 : -1; |
|
204 |
ts.flags = flags; |
|
205 |
ts.modheight_count = ts.tile_table_count = 0; |
|
206 |
ts.cost = 0; |
|
207 |
ts.modheight = modheight_data; |
|
208 |
ts.tile_table = tile_table_data; |
|
209 |
||
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
|
210 |
/* 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
|
211 |
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
|
212 |
|
0 | 213 |
if (p1 & 1) { |
1981 | 214 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
215 |
TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
|
0 | 216 |
return CMD_ERROR; |
217 |
} |
|
218 |
||
219 |
if (p1 & 2) { |
|
1981 | 220 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
221 |
TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
|
0 | 222 |
return CMD_ERROR; |
223 |
} |
|
224 |
||
225 |
if (p1 & 4) { |
|
1981 | 226 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
227 |
TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
|
0 | 228 |
return CMD_ERROR; |
229 |
} |
|
230 |
||
231 |
if (p1 & 8) { |
|
1981 | 232 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
233 |
TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
|
0 | 234 |
return CMD_ERROR; |
235 |
} |
|
236 |
||
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
237 |
{ /* Check if tunnel or track would take damage */ |
0 | 238 |
int count; |
239 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
240 |
|
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
|
241 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
242 |
uint a, b, c, d, r, min; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
243 |
TileIndex tile = *ti; |
0 | 244 |
|
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
245 |
_terraform_err_tile = tile; |
0 | 246 |
|
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
247 |
a = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
248 |
b = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
249 |
c = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
250 |
d = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
251 |
|
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
252 |
r = GetTileh(a, b, c, d, &min); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
253 |
|
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
254 |
if (IsTileType(tile, MP_RAILWAY)) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
255 |
if (IsSteepSlope(r)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
256 |
|
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
257 |
if (IsPlainRailTile(tile)) { |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
258 |
extern const TrackBits _valid_tileh_slopes[2][15]; |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
259 |
if (GetTrackBits(tile) & ~_valid_tileh_slopes[0][r]) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
260 |
} else return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
2639 | 261 |
} |
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
262 |
|
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
263 |
if (direction == -1 && IsTunnelInWay(tile, min)) return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
264 |
|
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3267
diff
changeset
|
265 |
_terraform_err_tile = 0; |
0 | 266 |
} |
267 |
} |
|
268 |
||
269 |
if (flags & DC_EXEC) { |
|
270 |
/* Clear the landscape at the tiles */ |
|
271 |
{ |
|
272 |
int count; |
|
273 |
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
|
274 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
275 |
DoCommand(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
0 | 276 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
277 |
} |
0 | 278 |
|
279 |
/* change the height */ |
|
280 |
{ |
|
281 |
int count; |
|
282 |
TerraformerHeightMod *mod; |
|
283 |
||
284 |
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
|
285 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
82d8bcc16ce2
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
286 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
287 |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
288 |
SetTileHeight(til, mod->height); |
0 | 289 |
TerraformAddDirtyTileAround(&ts, til); |
290 |
} |
|
291 |
} |
|
292 |
||
293 |
/* finally mark the dirty tiles dirty */ |
|
294 |
{ |
|
295 |
int count; |
|
296 |
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
|
297 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 298 |
MarkTileDirtyByTile(*ti); |
299 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
300 |
} |
0 | 301 |
} |
302 |
return ts.cost; |
|
303 |
} |
|
304 |
||
305 |
||
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
|
306 |
/** Levels a selected (rectangle) area of land |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
307 |
* @param tile end tile of area-drag |
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
|
308 |
* @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
|
309 |
* @param p2 unused |
0 | 310 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
311 |
int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 312 |
{ |
313 |
int size_x, size_y; |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
314 |
int ex; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
315 |
int ey; |
0 | 316 |
int sx, sy; |
317 |
uint h, curh; |
|
318 |
int32 ret, cost, money; |
|
319 |
||
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
|
320 |
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
|
321 |
|
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
|
322 |
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
|
323 |
|
0 | 324 |
// remember level height |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
325 |
h = TileHeight(p1); |
0 | 326 |
|
327 |
// make sure sx,sy are smaller than ex,ey |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
328 |
ex = TileX(tile); |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
329 |
ey = TileY(tile); |
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
|
330 |
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
|
331 |
sy = TileY(p1); |
0 | 332 |
if (ex < sx) intswap(ex, sx); |
333 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 334 |
tile = TileXY(sx, sy); |
0 | 335 |
|
336 |
size_x = ex-sx+1; |
|
337 |
size_y = ey-sy+1; |
|
338 |
||
339 |
money = GetAvailableMoneyForCommand(); |
|
340 |
cost = 0; |
|
341 |
||
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
|
342 |
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
|
343 |
curh = TileHeight(tile2); |
0 | 344 |
while (curh != h) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
345 |
ret = DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
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
|
346 |
if (CmdFailed(ret)) break; |
0 | 347 |
cost += ret; |
348 |
||
349 |
if (flags & DC_EXEC) { |
|
350 |
if ((money -= ret) < 0) { |
|
351 |
_additional_cash_required = ret; |
|
352 |
return cost - ret; |
|
353 |
} |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
354 |
DoCommand(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 355 |
} |
356 |
||
357 |
curh += (curh > h) ? -1 : 1; |
|
358 |
} |
|
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
|
359 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 360 |
|
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 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 362 |
} |
363 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
364 |
/** 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
|
365 |
* the name is a bit confusing ;p |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
366 |
* @param tile the tile the player is purchasing |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
367 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
368 |
* @param p2 unused |
0 | 369 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
370 |
int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 371 |
{ |
372 |
int32 cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
373 |
|
0 | 374 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
375 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
376 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 377 |
|
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
378 |
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) { |
0 | 379 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
380 |
} |
0 | 381 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
382 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
383 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 384 |
|
385 |
if (flags & DC_EXEC) { |
|
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
386 |
MakeOwnedLand(tile, _current_player); |
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
387 |
MarkTileDirtyByTile(tile); |
0 | 388 |
} |
389 |
||
390 |
return cost + _price.purchase_land * 10; |
|
391 |
} |
|
392 |
||
393 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
394 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 395 |
{ |
2220 | 396 |
static const int32* clear_price_table[] = { |
397 |
&_price.clear_1, |
|
398 |
&_price.purchase_land, |
|
399 |
&_price.clear_2, |
|
400 |
&_price.clear_3, |
|
401 |
&_price.purchase_land, |
|
402 |
&_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
|
403 |
&_price.clear_2, // XXX unused? |
0 | 404 |
}; |
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
|
405 |
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
|
406 |
|
3447 | 407 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
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
|
408 |
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
|
409 |
} 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
|
410 |
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
|
411 |
} |
0 | 412 |
|
2220 | 413 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 414 |
|
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
|
415 |
return price; |
0 | 416 |
} |
417 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
418 |
/** 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
|
419 |
* the name is a bit confusing ;p |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
420 |
* @param tile the tile the player is selling |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
421 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
422 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
423 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
424 |
int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 425 |
{ |
426 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
427 |
||
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3279
diff
changeset
|
428 |
if (!IsOwnedLandTile(tile)) 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
|
429 |
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
|
430 |
|
0 | 431 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
432 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 433 |
|
434 |
if (flags & DC_EXEC) |
|
435 |
DoClearSquare(tile); |
|
436 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
437 |
return - _price.purchase_land * 2; |
0 | 438 |
} |
439 |
||
440 |
||
441 |
#include "table/clear_land.h" |
|
442 |
||
443 |
||
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
|
444 |
void DrawClearLandTile(const TileInfo *ti, byte set) |
0 | 445 |
{ |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
446 |
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19); |
0 | 447 |
} |
448 |
||
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
|
449 |
void DrawHillyLandTile(const TileInfo *ti) |
0 | 450 |
{ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
451 |
if (ti->tileh != SLOPE_FLAT) { |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
452 |
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]); |
0 | 453 |
} 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
|
454 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 455 |
} |
456 |
} |
|
457 |
||
2220 | 458 |
void DrawClearLandFence(const TileInfo *ti) |
0 | 459 |
{ |
460 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
461 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
462 |
if (ti->tileh & SLOPE_S) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
463 |
z += TILE_HEIGHT; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
464 |
if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT; |
0 | 465 |
} |
466 |
||
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
467 |
if (GetFenceSW(ti->tile) != 0) { |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
468 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 469 |
} |
470 |
||
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
471 |
if (GetFenceSE(ti->tile) != 0) { |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
472 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 473 |
} |
474 |
} |
|
475 |
||
476 |
static void DrawTile_Clear(TileInfo *ti) |
|
477 |
{ |
|
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
478 |
switch (GetClearGround(ti->tile)) { |
3447 | 479 |
case CLEAR_GRASS: |
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
480 |
DrawClearLandTile(ti, GetClearDensity(ti->tile)); |
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
|
481 |
break; |
0 | 482 |
|
3447 | 483 |
case CLEAR_ROUGH: |
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
|
484 |
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
|
485 |
break; |
0 | 486 |
|
3447 | 487 |
case CLEAR_ROCKS: |
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
|
488 |
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
|
489 |
break; |
0 | 490 |
|
3447 | 491 |
case CLEAR_FIELDS: |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
492 |
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
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
|
493 |
break; |
0 | 494 |
|
3447 | 495 |
case CLEAR_SNOW: |
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
496 |
DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
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
|
497 |
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
|
498 |
|
3447 | 499 |
case CLEAR_DESERT: |
3166
91e9fc028c95
(svn r3794) Use already available accessor functions instead of GB()
tron
parents:
3156
diff
changeset
|
500 |
DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); |
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
|
501 |
break; |
0 | 502 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
503 |
|
2220 | 504 |
DrawClearLandFence(ti); |
0 | 505 |
} |
506 |
||
2537 | 507 |
static uint GetSlopeZ_Clear(const TileInfo* ti) |
1095 | 508 |
{ |
509 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
|
510 |
} |
|
0 | 511 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
512 |
static Slope GetSlopeTileh_Clear(TileIndex tile, Slope tileh) |
39 | 513 |
{ |
3418
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
514 |
return tileh; |
39 | 515 |
} |
516 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
517 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 518 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
519 |
/* unused */ |
0 | 520 |
} |
521 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
522 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 523 |
{ |
524 |
/* unused */ |
|
525 |
} |
|
526 |
||
1293 | 527 |
void TileLoopClearHelper(TileIndex tile) |
0 | 528 |
{ |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
529 |
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
|
530 |
byte neighbour; |
1293 | 531 |
TileIndex dirty = INVALID_TILE; |
0 | 532 |
|
3447 | 533 |
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)); |
0 | 534 |
|
3447 | 535 |
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS)); |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
536 |
if (GetFenceSW(tile) == 0) { |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
537 |
if (self != neighbour) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
538 |
SetFenceSW(tile, 3); |
0 | 539 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
540 |
} |
0 | 541 |
} 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
|
542 |
if (self == 0 && neighbour == 0) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
543 |
SetFenceSW(tile, 0); |
0 | 544 |
dirty = tile; |
545 |
} |
|
546 |
} |
|
547 |
||
3447 | 548 |
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS)); |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
549 |
if (GetFenceSE(tile) == 0) { |
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
550 |
if (self != neighbour) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
551 |
SetFenceSE(tile, 3); |
0 | 552 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
553 |
} |
0 | 554 |
} 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
|
555 |
if (self == 0 && neighbour == 0) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
556 |
SetFenceSE(tile, 0); |
0 | 557 |
dirty = tile; |
558 |
} |
|
559 |
} |
|
560 |
||
2221
de4a862fa8e2
(svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents:
2220
diff
changeset
|
561 |
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty); |
0 | 562 |
} |
563 |
||
564 |
||
565 |
/* convert into snowy tiles */ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
566 |
static void TileLoopClearAlps(TileIndex tile) |
0 | 567 |
{ |
568 |
/* 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
|
569 |
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
|
570 |
|
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
571 |
if (k < -TILE_HEIGHT) { // well below the snow line |
3447 | 572 |
if (!IsClearGround(tile, CLEAR_SNOW)) return; |
573 |
if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3); |
|
0 | 574 |
} else { |
3447 | 575 |
if (!IsClearGround(tile, CLEAR_SNOW)) { |
576 |
SetClearGroundDensity(tile, CLEAR_SNOW, 0); |
|
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
|
577 |
} else { |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
578 |
uint density = min((uint)(k + TILE_HEIGHT) / TILE_HEIGHT, 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
|
579 |
|
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
|
580 |
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
|
581 |
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
|
582 |
} 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
|
583 |
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
|
584 |
} 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
|
585 |
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
|
586 |
} |
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
|
587 |
} |
0 | 588 |
} |
589 |
||
590 |
MarkTileDirtyByTile(tile); |
|
591 |
} |
|
592 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
593 |
static void TileLoopClearDesert(TileIndex tile) |
0 | 594 |
{ |
3447 | 595 |
if (IsClearGround(tile, CLEAR_DESERT)) return; |
0 | 596 |
|
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
597 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
3447 | 598 |
SetClearGroundDensity(tile, CLEAR_DESERT, 3); |
0 | 599 |
} else { |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
600 |
if (GetTropicZone(tile + TileDiffXY( 1, 0)) != TROPICZONE_DESERT && |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
601 |
GetTropicZone(tile + TileDiffXY(-1, 0)) != TROPICZONE_DESERT && |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
602 |
GetTropicZone(tile + TileDiffXY( 0, 1)) != TROPICZONE_DESERT && |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3310
diff
changeset
|
603 |
GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT) |
1981 | 604 |
return; |
3447 | 605 |
SetClearGroundDensity(tile, CLEAR_DESERT, 1); |
0 | 606 |
} |
607 |
||
608 |
MarkTileDirtyByTile(tile); |
|
609 |
} |
|
610 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
611 |
static void TileLoop_Clear(TileIndex tile) |
0 | 612 |
{ |
613 |
TileLoopClearHelper(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
614 |
|
2989 | 615 |
switch (_opt.landscape) { |
616 |
case LT_DESERT: TileLoopClearDesert(tile); break; |
|
617 |
case LT_HILLY: TileLoopClearAlps(tile); break; |
|
0 | 618 |
} |
619 |
||
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
|
620 |
switch (GetClearGround(tile)) { |
3447 | 621 |
case CLEAR_GRASS: |
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
|
622 |
if (GetClearDensity(tile) == 3) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
623 |
|
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 |
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
|
625 |
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
|
626 |
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
|
627 |
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
|
628 |
} 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
|
629 |
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
|
630 |
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
|
631 |
} |
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
|
632 |
} else { |
3447 | 633 |
SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3); |
0 | 634 |
} |
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
|
635 |
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
|
636 |
|
3447 | 637 |
case CLEAR_FIELDS: { |
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
|
638 |
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
|
639 |
|
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
|
640 |
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
|
641 |
|
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
|
642 |
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
|
643 |
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
|
644 |
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
|
645 |
} 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
|
646 |
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
|
647 |
} |
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 |
|
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
649 |
field_type = GetFieldType(tile); |
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
|
650 |
field_type = (field_type < 8) ? field_type + 1 : 0; |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2956
diff
changeset
|
651 |
SetFieldType(tile, field_type); |
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
|
652 |
break; |
0 | 653 |
} |
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
|
654 |
|
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 |
default: |
0 | 656 |
return; |
657 |
} |
|
658 |
||
659 |
MarkTileDirtyByTile(tile); |
|
660 |
} |
|
661 |
||
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
|
662 |
void GenerateClearTile(void) |
0 | 663 |
{ |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
664 |
uint i; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
665 |
TileIndex tile; |
0 | 666 |
|
667 |
/* add hills */ |
|
2635 | 668 |
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400); |
0 | 669 |
do { |
2051 | 670 |
tile = RandomTile(); |
3447 | 671 |
if (IsTileType(tile, MP_CLEAR)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3); |
0 | 672 |
} while (--i); |
673 |
||
674 |
/* add grey squares */ |
|
2635 | 675 |
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80); |
0 | 676 |
do { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
677 |
uint32 r = Random(); |
2051 | 678 |
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
|
679 |
if (IsTileType(tile, MP_CLEAR)) { |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
680 |
uint j = GB(r, 16, 4) + 5; |
2951 | 681 |
for (;;) { |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
682 |
TileIndex tile_new; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
683 |
|
3447 | 684 |
SetClearGroundDensity(tile, CLEAR_ROCKS, 3); |
0 | 685 |
do { |
686 |
if (--j == 0) goto get_out; |
|
2635 | 687 |
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
|
688 |
} while (!IsTileType(tile_new, MP_CLEAR)); |
0 | 689 |
tile = tile_new; |
690 |
} |
|
691 |
get_out:; |
|
692 |
} |
|
693 |
} while (--i); |
|
694 |
} |
|
695 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
696 |
static void ClickTile_Clear(TileIndex tile) |
0 | 697 |
{ |
698 |
/* not used */ |
|
699 |
} |
|
700 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
701 |
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode) |
0 | 702 |
{ |
703 |
return 0; |
|
704 |
} |
|
705 |
||
2220 | 706 |
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
|
707 |
STR_080D_GRASS, |
0 | 708 |
STR_080B_ROUGH_LAND, |
709 |
STR_080A_ROCKS, |
|
710 |
STR_080E_FIELDS, |
|
711 |
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
|
712 |
STR_0810_DESERT |
0 | 713 |
}; |
714 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
715 |
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
0 | 716 |
{ |
3447 | 717 |
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) { |
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
|
718 |
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
|
719 |
} 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
|
720 |
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
|
721 |
} |
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
|
722 |
td->owner = GetTileOwner(tile); |
0 | 723 |
} |
724 |
||
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
|
725 |
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 726 |
{ |
727 |
return; |
|
728 |
} |
|
729 |
||
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
|
730 |
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
|
731 |
{ |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
732 |
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT; |
0 | 733 |
} |
734 |
||
735 |
const TileTypeProcs _tile_type_clear_procs = { |
|
736 |
DrawTile_Clear, /* draw_tile_proc */ |
|
737 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
738 |
ClearTile_Clear, /* clear_tile_proc */ |
|
739 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
740 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
741 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
742 |
ClickTile_Clear, /* click_tile_proc */ |
|
743 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
744 |
TileLoop_Clear, /* tile_loop_clear */ |
|
745 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
746 |
NULL, /* get_produced_cargo_proc */ |
|
747 |
NULL, /* vehicle_enter_tile_proc */ |
|
748 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 749 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 750 |
}; |