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