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