author | tron |
Thu, 21 Jul 2005 18:44:27 +0000 | |
changeset 2153 | ecfc674410b4 |
parent 2150 | f710b959b1c4 |
child 2154 | f86c59e73a16 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1878
diff
changeset
|
2 |
#include "openttd.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
473
diff
changeset
|
3 |
#include "table/strings.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
|
4 |
#include "map.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
|
5 |
#include "tile.h" |
0 | 6 |
#include "viewport.h" |
7 |
#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
|
8 |
#include "variables.h" |
0 | 9 |
|
10 |
typedef struct TerraformerHeightMod { |
|
11 |
TileIndex tile; |
|
12 |
byte height; |
|
13 |
} TerraformerHeightMod; |
|
14 |
||
15 |
typedef struct TerraformerState { |
|
16 |
int height[4]; |
|
17 |
uint32 flags; |
|
18 |
||
19 |
int direction; |
|
20 |
int modheight_count; |
|
21 |
int tile_table_count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
22 |
|
0 | 23 |
int32 cost; |
24 |
||
25 |
TileIndex *tile_table; |
|
26 |
TerraformerHeightMod *modheight; |
|
27 |
||
28 |
} TerraformerState; |
|
29 |
||
30 |
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) |
|
31 |
{ |
|
32 |
TileIndex *t; |
|
33 |
int count; |
|
34 |
||
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
|
35 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) |
0 | 36 |
return -1; |
37 |
||
38 |
t = ts->tile_table; |
|
39 |
for(count = ts->tile_table_count; count != 0; count--,t++) { |
|
40 |
if (*t == tile) |
|
41 |
return 0; |
|
42 |
} |
|
43 |
||
44 |
return 1; |
|
45 |
} |
|
46 |
||
47 |
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) |
|
48 |
{ |
|
49 |
TerraformerHeightMod *mod = ts->modheight; |
|
50 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
51 |
|
0 | 52 |
for(count = ts->modheight_count; count != 0; count--, mod++) { |
53 |
if (mod->tile == tile) |
|
54 |
return mod->height; |
|
55 |
} |
|
56 |
||
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
57 |
return TileHeight(tile); |
0 | 58 |
} |
59 |
||
60 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
61 |
{ |
|
62 |
int count; |
|
63 |
TileIndex *t; |
|
64 |
||
65 |
count = ts->tile_table_count; |
|
66 |
||
67 |
if (count >= 625) |
|
68 |
return; |
|
69 |
||
70 |
for(t = ts->tile_table; count != 0; count--,t++) { |
|
71 |
if (*t == tile) |
|
72 |
return; |
|
73 |
} |
|
74 |
||
75 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
76 |
} |
|
77 |
||
78 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
79 |
{ |
|
1981 | 80 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
81 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
82 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
0 | 83 |
TerraformAddDirtyTile(ts, tile); |
84 |
} |
|
85 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
86 |
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
0 | 87 |
{ |
88 |
int r; |
|
89 |
int32 ret; |
|
90 |
||
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
91 |
assert(tile < MapSize()); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
92 |
|
0 | 93 |
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0) |
94 |
return r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
95 |
|
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
96 |
if (IsTileType(tile, MP_RAILWAY)) { |
0 | 97 |
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20}; |
98 |
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb}; |
|
345
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
99 |
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4}; |
0 | 100 |
|
101 |
// Nothing could be built at the steep slope - this avoids a bug |
|
102 |
// when you have a single diagonal track in one corner on a |
|
345
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
103 |
// basement and then you raise/lower the other corner. |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
104 |
int tileh = GetTileSlope(tile, NULL) & 0xF; |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
105 |
if (tileh == _railway_dangslopes[mode] || |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
106 |
tileh == _railway_dangslopes2[mode]) { |
ba68d5714caf
(svn r526) -Fix: [1035303] bug about lowering tracks built on slopes
tron
parents:
193
diff
changeset
|
107 |
_terraform_err_tile = tile; |
0 | 108 |
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; |
109 |
return -1; |
|
110 |
} |
|
111 |
||
112 |
// If we have a single diagonal track there, the other side of |
|
113 |
// tile can be terraformed. |
|
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
|
114 |
if ((_m[tile].m5&~0x40) == _railway_modes[mode]) |
0 | 115 |
return 0; |
116 |
} |
|
117 |
||
118 |
ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
119 |
||
120 |
if (ret == CMD_ERROR) { |
|
121 |
_terraform_err_tile = tile; |
|
122 |
return -1; |
|
123 |
} |
|
124 |
||
125 |
ts->cost += ret; |
|
126 |
||
127 |
if (ts->tile_table_count >= 625) |
|
128 |
return -1; |
|
129 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
130 |
||
131 |
return 0; |
|
132 |
} |
|
133 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
134 |
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
0 | 135 |
{ |
136 |
int nh; |
|
137 |
TerraformerHeightMod *mod; |
|
138 |
int count; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
139 |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
140 |
assert(tile < MapSize()); |
0 | 141 |
|
142 |
if (height < 0) { |
|
143 |
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL; |
|
144 |
return false; |
|
145 |
} |
|
146 |
||
147 |
_error_message = STR_1004_TOO_HIGH; |
|
148 |
||
149 |
if (height > 0xF) |
|
150 |
return false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
151 |
|
0 | 152 |
nh = TerraformGetHeightOfTile(ts, tile); |
153 |
if (nh < 0 || height == nh) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
154 |
return false; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
155 |
|
1981 | 156 |
if (TerraformProc(ts, tile, 0) < 0) return false; |
157 |
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
|
158 |
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
|
159 |
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
|
0 | 160 |
|
161 |
mod = ts->modheight; |
|
162 |
count = ts->modheight_count; |
|
163 |
||
164 |
for(;;) { |
|
165 |
if (count == 0) { |
|
166 |
if (ts->modheight_count >= 576) |
|
167 |
return false; |
|
168 |
ts->modheight_count++; |
|
169 |
break; |
|
170 |
} |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
171 |
if (mod->tile == tile) break; |
0 | 172 |
mod++; |
173 |
count--; |
|
174 |
} |
|
175 |
||
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1981
diff
changeset
|
176 |
mod->tile = tile; |
0 | 177 |
mod->height = (byte)height; |
178 |
||
179 |
ts->cost += _price.terraform; |
|
180 |
||
181 |
{ |
|
182 |
int direction = ts->direction, r; |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
183 |
const TileIndexDiffC *ttm; |
0 | 184 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
185 |
static const TileIndexDiffC _terraform_tilepos[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
186 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
187 |
{-2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
188 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
189 |
{ 0, -2} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
190 |
}; |
0 | 191 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
192 |
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
|
193 |
tile += ToTileIndexDiff(*ttm); |
0 | 194 |
|
195 |
r = TerraformGetHeightOfTile(ts, tile); |
|
196 |
if (r != height && r-direction != height && r+direction != height) { |
|
197 |
if (!TerraformTileHeight(ts, tile, r+direction)) |
|
198 |
return false; |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
return true; |
|
204 |
} |
|
205 |
||
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
|
206 |
/** 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
|
207 |
* @param x,y coordinates to terraform |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
208 |
* @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
|
209 |
* @param p2 direction; eg up or down |
0 | 210 |
*/ |
211 |
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
212 |
{ |
|
213 |
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
|
214 |
TileIndex tile; |
0 | 215 |
int direction; |
216 |
||
217 |
TerraformerHeightMod modheight_data[576]; |
|
218 |
TileIndex tile_table_data[625]; |
|
219 |
||
220 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
221 |
||
222 |
_error_message = INVALID_STRING_ID; |
|
223 |
_terraform_err_tile = 0; |
|
224 |
||
225 |
ts.direction = direction = p2 ? 1 : -1; |
|
226 |
ts.flags = flags; |
|
227 |
ts.modheight_count = ts.tile_table_count = 0; |
|
228 |
ts.cost = 0; |
|
229 |
ts.modheight = modheight_data; |
|
230 |
ts.tile_table = tile_table_data; |
|
231 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
232 |
tile = TileVirtXY(x, y); |
0 | 233 |
|
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
|
234 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
1981 | 235 |
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
|
236 |
|
0 | 237 |
if (p1 & 1) { |
1981 | 238 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
239 |
TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
|
0 | 240 |
return CMD_ERROR; |
241 |
} |
|
242 |
||
243 |
if (p1 & 2) { |
|
1981 | 244 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
245 |
TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
|
0 | 246 |
return CMD_ERROR; |
247 |
} |
|
248 |
||
249 |
if (p1 & 4) { |
|
1981 | 250 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
251 |
TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
|
0 | 252 |
return CMD_ERROR; |
253 |
} |
|
254 |
||
255 |
if (p1 & 8) { |
|
1981 | 256 |
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
257 |
TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
|
0 | 258 |
return CMD_ERROR; |
259 |
} |
|
260 |
||
261 |
if (direction == -1) { |
|
262 |
/* Check if tunnel would take damage */ |
|
263 |
int count; |
|
264 |
TileIndex *ti = ts.tile_table; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
265 |
|
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
|
266 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 267 |
uint z, t; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
268 |
TileIndex tile = *ti; |
0 | 269 |
|
1981 | 270 |
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
271 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
|
0 | 272 |
if (t <= z) z = t; |
1981 | 273 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
0 | 274 |
if (t <= z) z = t; |
1981 | 275 |
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
0 | 276 |
if (t <= z) z = t; |
277 |
||
278 |
if (!CheckTunnelInWay(tile, z*8)) |
|
279 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
if (flags & DC_EXEC) { |
|
284 |
/* Clear the landscape at the tiles */ |
|
285 |
{ |
|
286 |
int count; |
|
287 |
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
|
288 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 289 |
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
290 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
291 |
} |
0 | 292 |
|
293 |
/* change the height */ |
|
294 |
{ |
|
295 |
int count; |
|
296 |
TerraformerHeightMod *mod; |
|
297 |
||
298 |
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
|
299 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
1979
82d8bcc16ce2
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
300 |
TileIndex til = mod->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
301 |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
302 |
SetTileHeight(til, mod->height); |
0 | 303 |
TerraformAddDirtyTileAround(&ts, til); |
304 |
} |
|
305 |
} |
|
306 |
||
307 |
/* finally mark the dirty tiles dirty */ |
|
308 |
{ |
|
309 |
int count; |
|
310 |
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
|
311 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
0 | 312 |
MarkTileDirtyByTile(*ti); |
313 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
314 |
} |
0 | 315 |
} |
316 |
return ts.cost; |
|
317 |
} |
|
318 |
||
319 |
||
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
|
320 |
/** 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
|
321 |
* @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
|
322 |
* @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
|
323 |
* @param p2 unused |
0 | 324 |
*/ |
325 |
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
326 |
{ |
|
327 |
int size_x, size_y; |
|
328 |
int sx, sy; |
|
329 |
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
|
330 |
TileIndex tile; |
0 | 331 |
int32 ret, cost, money; |
332 |
||
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
|
333 |
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
|
334 |
|
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
|
335 |
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
|
336 |
|
0 | 337 |
// remember level height |
1044
63e0601a43cc
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1035
diff
changeset
|
338 |
h = TileHeight(p1); |
0 | 339 |
|
340 |
ex >>= 4; ey >>= 4; |
|
341 |
||
342 |
// 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
|
343 |
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
|
344 |
sy = TileY(p1); |
0 | 345 |
if (ex < sx) intswap(ex, sx); |
346 |
if (ey < sy) intswap(ey, sy); |
|
1981 | 347 |
tile = TileXY(sx, sy); |
0 | 348 |
|
349 |
size_x = ex-sx+1; |
|
350 |
size_y = ey-sy+1; |
|
351 |
||
352 |
money = GetAvailableMoneyForCommand(); |
|
353 |
cost = 0; |
|
354 |
||
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
355 |
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
|
356 |
curh = TileHeight(tile2); |
0 | 357 |
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
|
358 |
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
|
359 |
if (CmdFailed(ret)) break; |
0 | 360 |
cost += ret; |
361 |
||
362 |
if (flags & DC_EXEC) { |
|
363 |
if ((money -= ret) < 0) { |
|
364 |
_additional_cash_required = ret; |
|
365 |
return cost - ret; |
|
366 |
} |
|
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
|
367 |
DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
0 | 368 |
} |
369 |
||
370 |
curh += (curh > h) ? -1 : 1; |
|
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 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
0 | 373 |
|
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
|
374 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 375 |
} |
376 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
377 |
/** 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
|
378 |
* the name is a bit confusing ;p |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
379 |
* @param x,y the tile the player is purchasing |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
380 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
381 |
* @param p2 unused |
0 | 382 |
*/ |
383 |
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
384 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
385 |
TileIndex tile; |
0 | 386 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
387 |
|
0 | 388 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
389 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
390 |
tile = TileVirtXY(x, y); |
0 | 391 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
392 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 393 |
|
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
|
394 |
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
|
395 |
IsTileOwner(tile, _current_player)) |
0 | 396 |
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
397 |
||
398 |
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
|
399 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 400 |
|
401 |
if (flags & DC_EXEC) { |
|
402 |
ModifyTile(tile, |
|
403 |
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
404 |
3 /* map5 */ |
|
405 |
); |
|
406 |
} |
|
407 |
||
408 |
return cost + _price.purchase_land * 10; |
|
409 |
} |
|
410 |
||
411 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
412 |
static int32 ClearTile_Clear(TileIndex tile, byte flags) |
1095 | 413 |
{ |
0 | 414 |
static const int32 * _clear_price_table[] = { |
415 |
NULL, |
|
416 |
&_price.clear_1, &_price.clear_1,&_price.clear_1, |
|
417 |
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
|
418 |
&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2, |
|
419 |
&_price.clear_3,&_price.clear_3,&_price.clear_3,&_price.clear_3, |
|
420 |
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
|
421 |
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
|
422 |
&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2, |
|
423 |
}; |
|
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
|
424 |
const int32 *price = _clear_price_table[_m[tile].m5 & 0x1F]; |
0 | 425 |
|
426 |
if (flags & DC_EXEC) |
|
427 |
DoClearSquare(tile); |
|
428 |
||
429 |
if (price == NULL) |
|
430 |
return 0; |
|
431 |
return *price; |
|
432 |
} |
|
433 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
434 |
/** 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
|
435 |
* the name is a bit confusing ;p |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
436 |
* @param x,y the tile the player is selling |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
437 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
438 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
439 |
*/ |
0 | 440 |
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
441 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
442 |
TileIndex tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
443 |
|
0 | 444 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
445 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
446 |
tile = TileVirtXY(x, y); |
0 | 447 |
|
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
|
448 |
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
|
449 |
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
|
450 |
|
0 | 451 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
452 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 453 |
|
454 |
if (flags & DC_EXEC) |
|
455 |
DoClearSquare(tile); |
|
456 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1775
diff
changeset
|
457 |
return - _price.purchase_land * 2; |
0 | 458 |
} |
459 |
||
460 |
||
461 |
#include "table/clear_land.h" |
|
462 |
||
463 |
||
464 |
void DrawClearLandTile(TileInfo *ti, byte set) |
|
465 |
{ |
|
466 |
DrawGroundSprite(0xF54 + _tileh_to_sprite[ti->tileh] + set * 19); |
|
467 |
} |
|
468 |
||
469 |
void DrawHillyLandTile(TileInfo *ti) |
|
470 |
{ |
|
471 |
if (ti->tileh != 0) { |
|
472 |
DrawGroundSprite(0xFA0 + _tileh_to_sprite[ti->tileh]); |
|
473 |
} 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
|
474 |
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]); |
0 | 475 |
} |
476 |
} |
|
477 |
||
478 |
void DrawClearLandFence(TileInfo *ti, byte img) |
|
479 |
{ |
|
480 |
byte z = ti->z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
481 |
|
0 | 482 |
if (ti->tileh & 2) { |
483 |
z += 8; |
|
484 |
if (ti->tileh == 0x17) |
|
485 |
z += 8; |
|
486 |
} |
|
487 |
||
488 |
if (img & 0x38) { |
|
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
|
489 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(img, 3, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); |
0 | 490 |
} |
491 |
||
492 |
if (img & 0x7) { |
|
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
|
493 |
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(img, 0, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); |
0 | 494 |
} |
495 |
} |
|
496 |
||
497 |
static void DrawTile_Clear(TileInfo *ti) |
|
498 |
{ |
|
499 |
||
500 |
switch((ti->map5 & (7<<2)) >> 2) { |
|
501 |
case 0: |
|
502 |
DrawClearLandTile(ti, (ti->map5 & 3)); |
|
503 |
break; |
|
504 |
||
505 |
case 1: |
|
506 |
DrawHillyLandTile(ti); |
|
507 |
break; |
|
508 |
||
509 |
case 2: |
|
510 |
DrawGroundSprite(0xFB7 + _tileh_to_sprite[ti->tileh]); |
|
511 |
break; |
|
512 |
||
513 |
case 3: |
|
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
|
514 |
DrawGroundSprite( _clear_land_sprites_1[_m[ti->tile].m3&0xF] + _tileh_to_sprite[ti->tileh]); |
0 | 515 |
break; |
516 |
||
517 |
case 4: |
|
518 |
DrawGroundSprite( _clear_land_sprites_2[ti->map5&3] + _tileh_to_sprite[ti->tileh]); |
|
519 |
break; |
|
520 |
||
521 |
case 5: |
|
522 |
DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]); |
|
523 |
break; |
|
524 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
525 |
|
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
|
526 |
DrawClearLandFence(ti, _m[ti->tile].m4 >> 2); |
0 | 527 |
} |
528 |
||
1095 | 529 |
static uint GetSlopeZ_Clear(TileInfo *ti) |
530 |
{ |
|
531 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
|
532 |
} |
|
0 | 533 |
|
1095 | 534 |
static uint GetSlopeTileh_Clear(TileInfo *ti) |
39 | 535 |
{ |
536 |
return ti->tileh; |
|
537 |
} |
|
538 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
539 |
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac) |
0 | 540 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
541 |
/* unused */ |
0 | 542 |
} |
543 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
544 |
static void AnimateTile_Clear(TileIndex tile) |
0 | 545 |
{ |
546 |
/* unused */ |
|
547 |
} |
|
548 |
||
1293 | 549 |
void TileLoopClearHelper(TileIndex tile) |
0 | 550 |
{ |
1293 | 551 |
byte img_1; |
552 |
byte img_2; |
|
1571
9afc220894dd
(svn r2075) -Fix: added missing breaks in switches
truelight
parents:
1298
diff
changeset
|
553 |
static const byte img_by_map5[] = { 0, 0, 0, 2, 1, 1, 0, 0 }; |
1293 | 554 |
TileIndex dirty = INVALID_TILE; |
0 | 555 |
|
1293 | 556 |
switch (GetTileType(tile)) { |
557 |
case MP_CLEAR: |
|
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
|
558 |
img_1 = img_by_map5[(_m[tile].m5 & 0x1C) >> 2]; |
1293 | 559 |
break; |
560 |
||
561 |
case MP_TREES: |
|
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
|
562 |
if ((_m[tile].m2 & 0x30) == 0x20) |
1293 | 563 |
img_1 = 1; |
564 |
else |
|
565 |
img_1 = 0; |
|
1298 | 566 |
break; |
1293 | 567 |
|
568 |
default: |
|
569 |
img_1 = 0; |
|
570 |
break; |
|
0 | 571 |
} |
572 |
||
1293 | 573 |
switch (GetTileType(TILE_ADDXY(tile, 1, 0))) { |
574 |
case MP_CLEAR: |
|
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
|
575 |
img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 1, 0)].m5 & 0x1C) >> 2]; |
1293 | 576 |
break; |
577 |
||
578 |
case MP_TREES: |
|
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
|
579 |
if ((_m[TILE_ADDXY(tile, 1, 0)].m2 & 0x30) == 0x20) |
1293 | 580 |
img_2 = 1; |
581 |
else |
|
582 |
img_2 = 0; |
|
583 |
break; |
|
584 |
||
585 |
default: |
|
586 |
img_2 = 0; |
|
587 |
break; |
|
0 | 588 |
} |
589 |
||
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
|
590 |
if ((_m[tile].m4 & 0xE0) == 0) { |
1293 | 591 |
if ((img_1 & 2) != (img_2 & 2)) { |
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
|
592 |
_m[tile].m4 |= 3 << 5; |
0 | 593 |
dirty = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
594 |
} |
0 | 595 |
} else { |
596 |
if (img_1 == 1 && img_2 == 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
|
597 |
_m[tile].m4 &= ~(3 << 5); |
0 | 598 |
dirty = tile; |
599 |
} |
|
600 |
} |
|
601 |
||
1293 | 602 |
switch (GetTileType(TILE_ADDXY(tile, 0, 1))) { |
603 |
case MP_CLEAR: |
|
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
|
604 |
img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 0, 1)].m5 & 0x1C) >> 2]; |
1293 | 605 |
break; |
606 |
||
607 |
case MP_TREES: |
|
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
|
608 |
if ((_m[TILE_ADDXY(tile, 0, 1)].m2 & 0x30) == 0x20) |
1293 | 609 |
img_2 = 1; |
610 |
else |
|
611 |
img_2 = 0; |
|
612 |
break; |
|
613 |
||
614 |
default: |
|
615 |
img_2 = 0; |
|
616 |
break; |
|
0 | 617 |
} |
618 |
||
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
|
619 |
if ((_m[tile].m4 & 0x1C) == 0) { |
1293 | 620 |
if ((img_1 & 2) != (img_2 & 2)) { |
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
|
621 |
_m[tile].m4 |= 3 << 2; |
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 { |
625 |
if (img_1 == 1 && img_2 == 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
|
626 |
_m[tile].m4 &= ~(3 << 2); |
0 | 627 |
dirty = tile; |
628 |
} |
|
629 |
} |
|
630 |
||
1293 | 631 |
if (dirty != INVALID_TILE) |
0 | 632 |
MarkTileDirtyByTile(dirty); |
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 */ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1130
diff
changeset
|
775 |
i = ScaleByMapSize((Random() & 0x3FF) + 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 */ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1130
diff
changeset
|
782 |
i = ScaleByMapSize((Random() & 0x7F) + 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; |
|
900 | 794 |
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
|
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 |
||
813 |
static const StringID _clear_land_str[4+8-1] = { |
|
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 |
{ |
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
|
829 |
int i = (_m[tile].m5>>2) & 7; |
0 | 830 |
if (i == 0) |
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
|
831 |
i = (_m[tile].m5 & 3) + 8; |
0 | 832 |
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
|
833 |
td->owner = GetTileOwner(tile); |
0 | 834 |
} |
835 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1901
diff
changeset
|
836 |
static void ChangeTileOwner_Clear(TileIndex tile, byte old_player, byte new_player) |
0 | 837 |
{ |
838 |
return; |
|
839 |
} |
|
840 |
||
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
|
841 |
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
|
842 |
{ |
0 | 843 |
_opt.snow_line = _patches.snow_line_height * 8; |
844 |
} |
|
845 |
||
846 |
const TileTypeProcs _tile_type_clear_procs = { |
|
847 |
DrawTile_Clear, /* draw_tile_proc */ |
|
848 |
GetSlopeZ_Clear, /* get_slope_z_proc */ |
|
849 |
ClearTile_Clear, /* clear_tile_proc */ |
|
850 |
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */ |
|
851 |
GetTileDesc_Clear, /* get_tile_desc_proc */ |
|
852 |
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */ |
|
853 |
ClickTile_Clear, /* click_tile_proc */ |
|
854 |
AnimateTile_Clear, /* animate_tile_proc */ |
|
855 |
TileLoop_Clear, /* tile_loop_clear */ |
|
856 |
ChangeTileOwner_Clear, /* change_tile_owner_clear */ |
|
857 |
NULL, /* get_produced_cargo_proc */ |
|
858 |
NULL, /* vehicle_enter_tile_proc */ |
|
859 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 860 |
GetSlopeTileh_Clear, /* get_slope_tileh_proc */ |
0 | 861 |
}; |