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