author | glx |
Sun, 15 Jun 2008 22:56:43 +0000 | |
branch | noai |
changeset 10973 | 8577bc56132c |
parent 10645 | 8cbdb511a674 |
permissions | -rw-r--r-- |
9723 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file terraform_cmd.cpp Commands related to terraforming. */ |
|
4 |
||
5 |
#include "stdafx.h" |
|
6 |
#include "openttd.h" |
|
7 |
#include "strings_type.h" |
|
8 |
#include "command_func.h" |
|
9 |
#include "tile_map.h" |
|
10 |
#include "tunnel_map.h" |
|
11 |
#include "bridge_map.h" |
|
12 |
#include "variables.h" |
|
13 |
#include "functions.h" |
|
14 |
#include "economy_func.h" |
|
15 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
16 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
17 |
|
9723 | 18 |
/* |
19 |
* In one terraforming command all four corners of a initial tile can be raised/lowered (though this is not available to the player). |
|
20 |
* The maximal amount of height modifications is archieved when raising a complete flat land from sea level to MAX_TILE_HEIGHT or vice versa. |
|
21 |
* This affects all corners with a manhatten distance smaller than MAX_TILE_HEIGHT to one of the initial 4 corners. |
|
22 |
* Their maximal amount is computed to 4 * \sum_{i=1}^{h_max} i = 2 * h_max * (h_max + 1). |
|
23 |
*/ |
|
24 |
static const int TERRAFORMER_MODHEIGHT_SIZE = 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 1); |
|
25 |
||
26 |
/* |
|
27 |
* The maximal amount of affected tiles (i.e. the tiles that incident with one of the corners above, is computed similiar to |
|
28 |
* 1 + 4 * \sum_{i=1}^{h_max} (i+1) = 1 + 2 * h_max + (h_max + 3). |
|
29 |
*/ |
|
30 |
static const int TERRAFORMER_TILE_TABLE_SIZE = 1 + 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 3); |
|
31 |
||
32 |
struct TerraformerHeightMod { |
|
33 |
TileIndex tile; ///< Referenced tile. |
|
34 |
byte height; ///< New TileHeight (height of north corner) of the tile. |
|
35 |
}; |
|
36 |
||
37 |
struct TerraformerState { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
38 |
int modheight_count; ///< amount of entries in "modheight". |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
39 |
int tile_table_count; ///< amount of entries in "tile_table". |
9723 | 40 |
|
41 |
/** |
|
42 |
* Dirty tiles, i.e.\ at least one corner changed. |
|
43 |
* |
|
44 |
* This array contains the tiles which are or will be marked as dirty. |
|
45 |
* |
|
46 |
* @ingroup dirty |
|
47 |
*/ |
|
48 |
TileIndex tile_table[TERRAFORMER_TILE_TABLE_SIZE]; |
|
49 |
TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE]; ///< Height modifications. |
|
50 |
}; |
|
51 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
52 |
TileIndex _terraform_err_tile; ///< first tile we couldn't terraform |
9723 | 53 |
|
54 |
/** |
|
55 |
* Gets the TileHeight (height of north corner) of a tile as of current terraforming progress. |
|
56 |
* |
|
57 |
* @param ts TerraformerState. |
|
58 |
* @param tile Tile. |
|
59 |
* @return TileHeight. |
|
60 |
*/ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
61 |
static int TerraformGetHeightOfTile(const TerraformerState *ts, TileIndex tile) |
9723 | 62 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
63 |
const TerraformerHeightMod *mod = ts->modheight; |
9723 | 64 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
65 |
for (int count = ts->modheight_count; count != 0; count--, mod++) { |
9723 | 66 |
if (mod->tile == tile) return mod->height; |
67 |
} |
|
68 |
||
69 |
/* TileHeight unchanged so far, read value from map. */ |
|
70 |
return TileHeight(tile); |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Stores the TileHeight (height of north corner) of a tile in a TerraformerState. |
|
75 |
* |
|
76 |
* @param ts TerraformerState. |
|
77 |
* @param tile Tile. |
|
78 |
* @param height New TileHeight. |
|
79 |
*/ |
|
80 |
static void TerraformSetHeightOfTile(TerraformerState *ts, TileIndex tile, int height) |
|
81 |
{ |
|
82 |
/* Find tile in the "modheight" table. |
|
83 |
* Note: In a normal user-terraform command the tile will not be found in the "modheight" table. |
|
84 |
* But during house- or industry-construction multiple corners can be terraformed at once. */ |
|
85 |
TerraformerHeightMod *mod = ts->modheight; |
|
86 |
int count = ts->modheight_count; |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
87 |
|
9723 | 88 |
while ((count > 0) && (mod->tile != tile)) { |
89 |
mod++; |
|
90 |
count--; |
|
91 |
} |
|
92 |
||
93 |
/* New entry? */ |
|
94 |
if (count == 0) { |
|
95 |
assert(ts->modheight_count < TERRAFORMER_MODHEIGHT_SIZE); |
|
96 |
ts->modheight_count++; |
|
97 |
} |
|
98 |
||
99 |
/* Finally store the new value */ |
|
100 |
mod->tile = tile; |
|
101 |
mod->height = (byte)height; |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Adds a tile to the "tile_table" in a TerraformerState. |
|
106 |
* |
|
107 |
* @param ts TerraformerState. |
|
108 |
* @param tile Tile. |
|
109 |
* @ingroup dirty |
|
110 |
*/ |
|
111 |
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) |
|
112 |
{ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
113 |
int count = ts->tile_table_count; |
9723 | 114 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
115 |
for (TileIndex *t = ts->tile_table; count != 0; count--, t++) { |
9723 | 116 |
if (*t == tile) return; |
117 |
} |
|
118 |
||
119 |
assert(ts->tile_table_count < TERRAFORMER_TILE_TABLE_SIZE); |
|
120 |
||
121 |
ts->tile_table[ts->tile_table_count++] = tile; |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a TerraformerState. |
|
126 |
* |
|
127 |
* @param ts TerraformerState. |
|
128 |
* @param tile Tile. |
|
129 |
* @ingroup dirty |
|
130 |
*/ |
|
131 |
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
|
132 |
{ |
|
133 |
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
|
134 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
|
135 |
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
|
136 |
TerraformAddDirtyTile(ts, tile); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Terraform the north corner of a tile to a specific height. |
|
141 |
* |
|
142 |
* @param ts TerraformerState. |
|
143 |
* @param tile Tile. |
|
144 |
* @param height Aimed height. |
|
145 |
* @param return Error code or cost. |
|
146 |
*/ |
|
147 |
static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height) |
|
148 |
{ |
|
149 |
assert(tile < MapSize()); |
|
150 |
||
151 |
/* Check range of destination height */ |
|
152 |
if (height < 0) return_cmd_error(STR_1003_ALREADY_AT_SEA_LEVEL); |
|
153 |
if (height > MAX_TILE_HEIGHT) return_cmd_error(STR_1004_TOO_HIGH); |
|
154 |
||
155 |
/* |
|
156 |
* Check if the terraforming has any effect. |
|
157 |
* This can only be true, if multiple corners of the start-tile are terraformed (i.e. the terraforming is done by towns/industries etc.). |
|
158 |
* In this case the terraforming should fail. (Don't know why.) |
|
159 |
*/ |
|
160 |
if (height == TerraformGetHeightOfTile(ts, tile)) return CMD_ERROR; |
|
161 |
||
162 |
/* Check "too close to edge of map" */ |
|
163 |
uint x = TileX(tile); |
|
164 |
uint y = TileY(tile); |
|
165 |
if ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1)) { |
|
166 |
/* |
|
167 |
* Determine a sensible error tile |
|
168 |
* Note: If x and y are both zero this will disable the error tile. (Tile 0 cannot be highlighted :( ) |
|
169 |
*/ |
|
170 |
if ((x == 1) && (y != 0)) x = 0; |
|
171 |
if ((y == 1) && (x != 0)) y = 0; |
|
172 |
_terraform_err_tile = TileXY(x, y); |
|
173 |
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); |
|
174 |
} |
|
175 |
||
176 |
/* Mark incident tiles, that are involved in the terraforming */ |
|
177 |
TerraformAddDirtyTileAround(ts, tile); |
|
178 |
||
179 |
/* Store the height modification */ |
|
180 |
TerraformSetHeightOfTile(ts, tile, height); |
|
181 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
182 |
CommandCost total_cost(EXPENSES_CONSTRUCTION); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
183 |
|
9723 | 184 |
/* Increment cost */ |
185 |
total_cost.AddCost(_price.terraform); |
|
186 |
||
187 |
/* Recurse to neighboured corners if height difference is larger than 1 */ |
|
188 |
{ |
|
189 |
const TileIndexDiffC *ttm; |
|
190 |
||
191 |
static const TileIndexDiffC _terraform_tilepos[] = { |
|
192 |
{ 1, 0}, // move to tile in SE |
|
193 |
{-2, 0}, // undo last move, and move to tile in NW |
|
194 |
{ 1, 1}, // undo last move, and move to tile in SW |
|
195 |
{ 0, -2} // undo last move, and move to tile in NE |
|
196 |
}; |
|
197 |
||
198 |
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { |
|
199 |
tile += ToTileIndexDiff(*ttm); |
|
200 |
||
201 |
/* Get TileHeight of neighboured tile as of current terraform progress */ |
|
202 |
int r = TerraformGetHeightOfTile(ts, tile); |
|
203 |
int height_diff = height - r; |
|
204 |
||
205 |
/* Is the height difference to the neighboured corner greater than 1? */ |
|
206 |
if (abs(height_diff) > 1) { |
|
207 |
/* Terraform the neighboured corner. The resulting height difference should be 1. */ |
|
208 |
height_diff += (height_diff < 0 ? 1 : -1); |
|
209 |
CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff); |
|
210 |
if (CmdFailed(cost)) return cost; |
|
211 |
total_cost.AddCost(cost); |
|
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
return total_cost; |
|
217 |
} |
|
218 |
||
219 |
/** Terraform land |
|
220 |
* @param tile tile to terraform |
|
221 |
* @param flags for this command type |
|
222 |
* @param p1 corners to terraform (SLOPE_xxx) |
|
223 |
* @param p2 direction; eg up (non-zero) or down (zero) |
|
224 |
* @return error or cost of terraforming |
|
225 |
*/ |
|
226 |
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
|
227 |
{ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
228 |
/* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
229 |
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
230 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
231 |
_terraform_err_tile = INVALID_TILE; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
232 |
|
9723 | 233 |
CommandCost total_cost(EXPENSES_CONSTRUCTION); |
234 |
int direction = (p2 != 0 ? 1 : -1); |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
235 |
TerraformerState ts; |
9723 | 236 |
|
237 |
ts.modheight_count = ts.tile_table_count = 0; |
|
238 |
||
239 |
/* Compute the costs and the terraforming result in a model of the landscape */ |
|
240 |
if ((p1 & SLOPE_W) != 0) { |
|
241 |
TileIndex t = tile + TileDiffXY(1, 0); |
|
242 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
|
243 |
if (CmdFailed(cost)) return cost; |
|
244 |
total_cost.AddCost(cost); |
|
245 |
} |
|
246 |
||
247 |
if ((p1 & SLOPE_S) != 0) { |
|
248 |
TileIndex t = tile + TileDiffXY(1, 1); |
|
249 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
|
250 |
if (CmdFailed(cost)) return cost; |
|
251 |
total_cost.AddCost(cost); |
|
252 |
} |
|
253 |
||
254 |
if ((p1 & SLOPE_E) != 0) { |
|
255 |
TileIndex t = tile + TileDiffXY(0, 1); |
|
256 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
|
257 |
if (CmdFailed(cost)) return cost; |
|
258 |
total_cost.AddCost(cost); |
|
259 |
} |
|
260 |
||
261 |
if ((p1 & SLOPE_N) != 0) { |
|
262 |
TileIndex t = tile + TileDiffXY(0, 0); |
|
263 |
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); |
|
264 |
if (CmdFailed(cost)) return cost; |
|
265 |
total_cost.AddCost(cost); |
|
266 |
} |
|
267 |
||
268 |
/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface */ |
|
269 |
{ |
|
270 |
TileIndex *ti = ts.tile_table; |
|
271 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
272 |
for (int count = ts.tile_table_count; count != 0; count--, ti++) { |
9723 | 273 |
TileIndex tile = *ti; |
274 |
||
275 |
/* Find new heights of tile corners */ |
|
276 |
uint z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
|
277 |
uint z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
|
278 |
uint z_S = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
|
279 |
uint z_E = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
|
280 |
||
281 |
/* Find min and max height of tile */ |
|
282 |
uint z_min = min(min(z_N, z_W), min(z_S, z_E)); |
|
283 |
uint z_max = max(max(z_N, z_W), max(z_S, z_E)); |
|
284 |
||
285 |
/* Compute tile slope */ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
286 |
Slope tileh = (z_max > z_min + 1 ? SLOPE_STEEP : SLOPE_FLAT); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
287 |
if (z_W > z_min) tileh |= SLOPE_W; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
288 |
if (z_S > z_min) tileh |= SLOPE_S; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
289 |
if (z_E > z_min) tileh |= SLOPE_E; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
290 |
if (z_N > z_min) tileh |= SLOPE_N; |
9723 | 291 |
|
292 |
/* Check if bridge would take damage */ |
|
293 |
if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && |
|
294 |
GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) { |
|
295 |
_terraform_err_tile = tile; // highlight the tile under the bridge |
|
296 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
|
297 |
} |
|
298 |
/* Check if tunnel would take damage */ |
|
299 |
if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) { |
|
300 |
_terraform_err_tile = tile; // highlight the tile above the tunnel |
|
301 |
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
|
302 |
} |
|
303 |
/* Check tiletype-specific things, and add extra-cost */ |
|
10645 | 304 |
const bool curr_gen = _generating_world; |
305 |
if (_game_mode == GM_EDITOR) _generating_world = true; // used to create green terraformed land |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
306 |
CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags | DC_AUTO, z_min * TILE_HEIGHT, tileh); |
10645 | 307 |
_generating_world = curr_gen; |
9723 | 308 |
if (CmdFailed(cost)) { |
309 |
_terraform_err_tile = tile; |
|
310 |
return cost; |
|
311 |
} |
|
312 |
total_cost.AddCost(cost); |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
if (flags & DC_EXEC) { |
|
317 |
/* change the height */ |
|
318 |
{ |
|
319 |
int count; |
|
320 |
TerraformerHeightMod *mod; |
|
321 |
||
322 |
mod = ts.modheight; |
|
323 |
for (count = ts.modheight_count; count != 0; count--, mod++) { |
|
324 |
TileIndex til = mod->tile; |
|
325 |
||
326 |
SetTileHeight(til, mod->height); |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
/* finally mark the dirty tiles dirty */ |
|
331 |
{ |
|
332 |
int count; |
|
333 |
TileIndex *ti = ts.tile_table; |
|
334 |
for (count = ts.tile_table_count; count != 0; count--, ti++) { |
|
335 |
MarkTileDirtyByTile(*ti); |
|
336 |
} |
|
337 |
} |
|
338 |
} |
|
339 |
return total_cost; |
|
340 |
} |
|
341 |
||
342 |
||
343 |
/** Levels a selected (rectangle) area of land |
|
344 |
* @param tile end tile of area-drag |
|
345 |
* @param flags for this command type |
|
346 |
* @param p1 start tile of area drag |
|
347 |
* @param p2 height difference; eg raise (+1), lower (-1) or level (0) |
|
348 |
* @return error or cost of terraforming |
|
349 |
*/ |
|
350 |
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
|
351 |
{ |
|
352 |
if (p1 >= MapSize()) return CMD_ERROR; |
|
353 |
||
354 |
/* remember level height */ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
355 |
uint oldh = TileHeight(p1); |
9723 | 356 |
|
357 |
/* compute new height */ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
358 |
uint h = oldh + p2; |
9723 | 359 |
|
360 |
/* Check range of destination height */ |
|
361 |
if (h > MAX_TILE_HEIGHT) return_cmd_error((oldh == 0) ? STR_1003_ALREADY_AT_SEA_LEVEL : STR_1004_TOO_HIGH); |
|
362 |
||
363 |
/* make sure sx,sy are smaller than ex,ey */ |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
364 |
int ex = TileX(tile); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
365 |
int ey = TileY(tile); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
366 |
int sx = TileX(p1); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
367 |
int sy = TileY(p1); |
9723 | 368 |
if (ex < sx) Swap(ex, sx); |
369 |
if (ey < sy) Swap(ey, sy); |
|
370 |
tile = TileXY(sx, sy); |
|
371 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
372 |
int size_x = ex - sx + 1; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
373 |
int size_y = ey - sy + 1; |
9723 | 374 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
375 |
Money money = GetAvailableMoneyForCommand(); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
376 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
9723 | 377 |
|
378 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
379 |
uint curh = TileHeight(tile2); |
9723 | 380 |
while (curh != h) { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
381 |
CommandCost ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); |
9723 | 382 |
if (CmdFailed(ret)) break; |
383 |
||
384 |
if (flags & DC_EXEC) { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
385 |
money -= ret.GetCost(); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9724
diff
changeset
|
386 |
if (money < 0) { |
9723 | 387 |
_additional_cash_required = ret.GetCost(); |
388 |
return cost; |
|
389 |
} |
|
390 |
DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
|
391 |
} |
|
392 |
||
393 |
cost.AddCost(ret); |
|
394 |
curh += (curh > h) ? -1 : 1; |
|
395 |
} |
|
396 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
|
397 |
||
398 |
return (cost.GetCost() == 0) ? CMD_ERROR : cost; |
|
399 |
} |