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