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