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