OpenTTD

terraform_cmd.cpp
Go to the documentation of this file.
1 /* $Id: terraform_cmd.cpp 27381 2015-08-10 20:24:13Z michi_cc $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "tunnel_map.h"
15 #include "bridge_map.h"
16 #include "viewport_func.h"
17 #include "genworld.h"
18 #include "object_base.h"
19 #include "company_base.h"
20 #include "company_func.h"
21
22 #include "table/strings.h"
23
24 #include <map>
25 #include <set>
26
27 #include "safeguards.h"
28
30 typedef std::set<TileIndex> TileIndexSet;
32 typedef std::map<TileIndex, int> TileIndexToHeightMap;
33
35 struct TerraformerState {
36 TileIndexSet dirty_tiles;
37 TileIndexToHeightMap tile_to_new_height;
38 };
39
40 TileIndex _terraform_err_tile;
41
49 static int TerraformGetHeightOfTile(const TerraformerState *ts, TileIndex tile)
50 {
51 TileIndexToHeightMap::const_iterator it = ts->tile_to_new_height.find(tile);
52 return it != ts->tile_to_new_height.end() ? it->second : TileHeight(tile);
53 }
54
62 static void TerraformSetHeightOfTile(TerraformerState *ts, TileIndex tile, int height)
63 {
64 ts->tile_to_new_height[tile] = height;
65 }
66
74 static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
75 {
76 ts->dirty_tiles.insert(tile);
77 }
78
86 static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
87 {
88 /* Make sure all tiles passed to TerraformAddDirtyTile are within [0, MapSize()] */
89 if (TileY(tile) >= 1) TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
90 if (TileY(tile) >= 1 && TileX(tile) >= 1) TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
91 if (TileX(tile) >= 1) TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0));
92 TerraformAddDirtyTile(ts, tile);
93 }
94
103 static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
104 {
105 assert(tile < MapSize());
106
107 /* Check range of destination height */
108 if (height < 0) return_cmd_error(STR_ERROR_ALREADY_AT_SEA_LEVEL);
109 if (height > _settings_game.construction.max_heightlevel) return_cmd_error(STR_ERROR_TOO_HIGH);
110
111 /*
112 * Check if the terraforming has any effect.
113 * This can only be true, if multiple corners of the start-tile are terraformed (i.e. the terraforming is done by towns/industries etc.).
114 * In this case the terraforming should fail. (Don't know why.)
115 */
116 if (height == TerraformGetHeightOfTile(ts, tile)) return CMD_ERROR;
117
118 /* Check "too close to edge of map". Only possible when freeform-edges is off. */
119 uint x = TileX(tile);
120 uint y = TileY(tile);
121 if (!_settings_game.construction.freeform_edges && ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1))) {
122 /*
123 * Determine a sensible error tile
124 */
125 if (x == 1) x = 0;
126 if (y == 1) y = 0;
127 _terraform_err_tile = TileXY(x, y);
128 return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
129 }
130
131 /* Mark incident tiles that are involved in the terraforming. */
132 TerraformAddDirtyTileAround(ts, tile);
133
134 /* Store the height modification */
135 TerraformSetHeightOfTile(ts, tile, height);
136
137 CommandCost total_cost(EXPENSES_CONSTRUCTION);
138
139 /* Increment cost */
140 total_cost.AddCost(_price[PR_TERRAFORM]);
141
142 /* Recurse to neighboured corners if height difference is larger than 1 */
143 {
144 const TileIndexDiffC *ttm;
145
146 TileIndex orig_tile = tile;
147 static const TileIndexDiffC _terraform_tilepos[] = {
148 { 1, 0}, // move to tile in SE
149 {-2, 0}, // undo last move, and move to tile in NW
150 { 1, 1}, // undo last move, and move to tile in SW
151 { 0, -2} // undo last move, and move to tile in NE
152 };
153
154 for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
155 tile += ToTileIndexDiff(*ttm);
156
157 if (tile >= MapSize()) continue;
158 /* Make sure we don't wrap around the map */
159 if (Delta(TileX(orig_tile), TileX(tile)) == MapSizeX() - 1) continue;
160 if (Delta(TileY(orig_tile), TileY(tile)) == MapSizeY() - 1) continue;
161
162 /* Get TileHeight of neighboured tile as of current terraform progress */
163 int r = TerraformGetHeightOfTile(ts, tile);
164 int height_diff = height - r;
165
166 /* Is the height difference to the neighboured corner greater than 1? */
167 if (abs(height_diff) > 1) {
168 /* Terraform the neighboured corner. The resulting height difference should be 1. */
169 height_diff += (height_diff < 0 ? 1 : -1);
170 CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff);
171 if (cost.Failed()) return cost;
172 total_cost.AddCost(cost);
173 }
174 }
175 }
176
177 return total_cost;
178 }
179
189 CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
190 {
191 _terraform_err_tile = INVALID_TILE;
192
193 CommandCost total_cost(EXPENSES_CONSTRUCTION);
194 int direction = (p2 != 0 ? 1 : -1);
195 TerraformerState ts;
196
197 /* Compute the costs and the terraforming result in a model of the landscape */
198 if ((p1 & SLOPE_W) != 0 && tile + TileDiffXY(1, 0) < MapSize()) {
199 TileIndex t = tile + TileDiffXY(1, 0);
200 CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
201 if (cost.Failed()) return cost;
202 total_cost.AddCost(cost);
203 }
204
205 if ((p1 & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < MapSize()) {
206 TileIndex t = tile + TileDiffXY(1, 1);
207 CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
208 if (cost.Failed()) return cost;
209 total_cost.AddCost(cost);
210 }
211
212 if ((p1 & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < MapSize()) {
213 TileIndex t = tile + TileDiffXY(0, 1);
214 CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
215 if (cost.Failed()) return cost;
216 total_cost.AddCost(cost);
217 }
218
219 if ((p1 & SLOPE_N) != 0) {
220 TileIndex t = tile + TileDiffXY(0, 0);
221 CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
222 if (cost.Failed()) return cost;
223 total_cost.AddCost(cost);
224 }
225
226 /* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface
227 * Pass == 0: Collect tileareas which are caused to be auto-cleared.
228 * Pass == 1: Collect the actual cost. */
229 for (int pass = 0; pass < 2; pass++) {
230 for (TileIndexSet::const_iterator it = ts.dirty_tiles.begin(); it != ts.dirty_tiles.end(); it++) {
231 TileIndex tile = *it;
232
233 assert(tile < MapSize());
234 /* MP_VOID tiles can be terraformed but as tunnels and bridges
235 * cannot go under / over these tiles they don't need checking. */
236 if (IsTileType(tile, MP_VOID)) continue;
237
238 /* Find new heights of tile corners */
239 int z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
240 int z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
241 int z_S = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
242 int z_E = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
243
244 /* Find min and max height of tile */
245 int z_min = min(min(z_N, z_W), min(z_S, z_E));
246 int z_max = max(max(z_N, z_W), max(z_S, z_E));
247
248 /* Compute tile slope */
249 Slope tileh = (z_max > z_min + 1 ? SLOPE_STEEP : SLOPE_FLAT);
250 if (z_W > z_min) tileh |= SLOPE_W;
251 if (z_S > z_min) tileh |= SLOPE_S;
252 if (z_E > z_min) tileh |= SLOPE_E;
253 if (z_N > z_min) tileh |= SLOPE_N;
254
255 if (pass == 0) {
256 /* Check if bridge would take damage */
257 if (IsBridgeAbove(tile)) {
258 int bridge_height = GetBridgeHeight(GetSouthernBridgeEnd(tile));
259
260 /* Check if bridge would take damage. */
261 if (direction == 1 && bridge_height <= z_max) {
262 _terraform_err_tile = tile; // highlight the tile under the bridge
263 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
264 }
265
266 /* Is the bridge above not too high afterwards? */
267 if (direction == -1 && bridge_height > (z_min + _settings_game.construction.max_bridge_height)) {
268 _terraform_err_tile = tile;
269 return_cmd_error(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND);
270 }
271 }
272 /* Check if tunnel would take damage */
273 if (direction == -1 && IsTunnelInWay(tile, z_min)) {
274 _terraform_err_tile = tile; // highlight the tile above the tunnel
275 return_cmd_error(STR_ERROR_EXCAVATION_WOULD_DAMAGE);
276 }
277 }
278
279 /* Is the tile already cleared? */
280 const ClearedObjectArea *coa = FindClearedObject(tile);
281 bool indirectly_cleared = coa != NULL && coa->first_tile != tile;
282
283 /* Check tiletype-specific things, and add extra-cost */
284 const bool curr_gen = _generating_world;
285 if (_game_mode == GM_EDITOR) _generating_world = true; // used to create green terraformed land
286 DoCommandFlag tile_flags = flags | DC_AUTO | DC_FORCE_CLEAR_TILE;
287 if (pass == 0) {
288 tile_flags &= ~DC_EXEC;
289 tile_flags |= DC_NO_MODIFY_TOWN_RATING;
290 }
291 CommandCost cost;
292 if (indirectly_cleared) {
293 cost = DoCommand(tile, 0, 0, tile_flags, CMD_LANDSCAPE_CLEAR);
294 } else {
295 cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, tile_flags, z_min, tileh);
296 }
297 _generating_world = curr_gen;
298 if (cost.Failed()) {
299 _terraform_err_tile = tile;
300 return cost;
301 }
302 if (pass == 1) total_cost.AddCost(cost);
303 }
304 }
305
306 Company *c = Company::GetIfValid(_current_company);
307 if (c != NULL && GB(c->terraform_limit, 16, 16) < ts.tile_to_new_height.size()) {
308 return_cmd_error(STR_ERROR_TERRAFORM_LIMIT_REACHED);
309 }
310
311 if (flags & DC_EXEC) {
312 /* change the height */
313 for (TileIndexToHeightMap::const_iterator it = ts.tile_to_new_height.begin();
314 it != ts.tile_to_new_height.end(); it++) {
315 TileIndex tile = it->first;
316 int height = it->second;
317
318 SetTileHeight(tile, (uint)height);
319 }
320
321 /* Finally mark the dirty tiles dirty */
322 for (TileIndexSet::const_iterator it = ts.dirty_tiles.begin(); it != ts.dirty_tiles.end(); it++) {
323 MarkTileDirtyByTile(*it);
324
325 int height = TerraformGetHeightOfTile(&ts, *it);
326
327 /* Now, if we alter the height of the map edge, we need to take care
328 * about repainting the affected areas outside map as well.
329 * Remember:
330 * Outside map, we assume that our landscape descends to
331 * height zero as fast as possible.
332 * Those simulated tiles (they don't exist as datastructure,
333 * only as concept in code) need to be repainted properly,
334 * otherwise we will get ugly glitches.
335 *
336 * Furthermore, note that we have to take care about the possibility,
337 * that landscape was higher before the change,
338 * so also tiles a bit outside need to be repainted.
339 */
340 int x = TileX(*it);
341 int y = TileY(*it);
342 if (x == 0) {
343 if (y == 0) {
344 /* Height of the northern corner is altered. */
345 for (int cx = 0; cx >= -height - 1; cx--) {
346 for (int cy = 0; cy >= -height - 1; cy--) {
347 /* This means, tiles in the sector north of that
348 * corner need to be repainted.
349 */
350 if (cx + cy >= -height - 2) {
351 /* But only tiles that actually might have changed. */
352 MarkTileDirtyByTileOutsideMap(cx, cy);
353 }
354 }
355 }
356 } else if (y < (int)MapMaxY()) {
357 for (int cx = 0; cx >= -height - 1; cx--) {
358 MarkTileDirtyByTileOutsideMap(cx, y);
359 }
360 } else {
361 for (int cx = 0; cx >= -height - 1; cx--) {
362 for (int cy = (int)MapMaxY(); cy <= (int)MapMaxY() + height + 1; cy++) {
363 if (cx + ((int)MapMaxY() - cy) >= -height - 2) {
364 MarkTileDirtyByTileOutsideMap(cx, cy);
365 }
366 }
367 }
368 }
369 } else if (x < (int)MapMaxX()) {
370 if (y == 0) {
371 for (int cy = 0; cy >= -height - 1; cy--) {
372 MarkTileDirtyByTileOutsideMap(x, cy);
373 }
374 } else if (y < (int)MapMaxY()) {
375 /* Nothing to be done here, we are inside the map. */
376 } else {
377 for (int cy = (int)MapMaxY(); cy <= (int)MapMaxY() + height + 1; cy++) {
378 MarkTileDirtyByTileOutsideMap(x, cy);
379 }
380 }
381 } else {
382 if (y == 0) {
383 for (int cx = (int)MapMaxX(); cx <= (int)MapMaxX() + height + 1; cx++) {
384 for (int cy = 0; cy >= -height - 1; cy--) {
385 if (((int)MapMaxX() - cx) + cy >= -height - 2) {
386 MarkTileDirtyByTileOutsideMap(cx, cy);
387 }
388 }
389 }
390 } else if (y < (int)MapMaxY()) {
391 for (int cx = (int)MapMaxX(); cx <= (int)MapMaxX() + height + 1; cx++) {
392 MarkTileDirtyByTileOutsideMap(cx, y);
393 }
394 } else {
395 for (int cx = (int)MapMaxX(); cx <= (int)MapMaxX() + height + 1; cx++) {
396 for (int cy = (int)MapMaxY(); cy <= (int)MapMaxY() + height + 1; cy++) {
397 if (((int)MapMaxX() - cx) + ((int)MapMaxY() - cy) >= -height - 2) {
398 MarkTileDirtyByTileOutsideMap(cx, cy);
399 }
400 }
401 }
402 }
403 }
404 }
405
406 if (c != NULL) c->terraform_limit -= (uint32)ts.tile_to_new_height.size() << 16;
407 }
408 return total_cost;
409 }
410
411
423 CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
424 {
425 if (p1 >= MapSize()) return CMD_ERROR;
426
427 _terraform_err_tile = INVALID_TILE;
428
429 /* remember level height */
430 uint oldh = TileHeight(p1);
431
432 /* compute new height */
433 uint h = oldh;
434 LevelMode lm = (LevelMode)GB(p2, 1, 2);
435 switch (lm) {
436 case LM_LEVEL: break;
437 case LM_RAISE: h++; break;
438 case LM_LOWER: h--; break;
439 default: return CMD_ERROR;
440 }
441
442 /* Check range of destination height */
443 if (h > _settings_game.construction.max_heightlevel) return_cmd_error((oldh == 0) ? STR_ERROR_ALREADY_AT_SEA_LEVEL : STR_ERROR_TOO_HIGH);
444
445 Money money = GetAvailableMoneyForCommand();
446 CommandCost cost(EXPENSES_CONSTRUCTION);
447 CommandCost last_error(lm == LM_LEVEL ? STR_ERROR_ALREADY_LEVELLED : INVALID_STRING_ID);
448 bool had_success = false;
449
450 const Company *c = Company::GetIfValid(_current_company);
451 int limit = (c == NULL ? INT32_MAX : GB(c->terraform_limit, 16, 16));
452 if (limit == 0) return_cmd_error(STR_ERROR_TERRAFORM_LIMIT_REACHED);
453
454 TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(tile, p1);
455 for (; *iter != INVALID_TILE; ++(*iter)) {
456 TileIndex t = *iter;
457 uint curh = TileHeight(t);
458 while (curh != h) {
459 CommandCost ret = DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
460 if (ret.Failed()) {
461 last_error = ret;
462
463 /* Did we reach the limit? */
464 if (ret.GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
465 break;
466 }
467
468 if (flags & DC_EXEC) {
469 money -= ret.GetCost();
470 if (money < 0) {
471 _additional_cash_required = ret.GetCost();
472 delete iter;
473 return cost;
474 }
475 DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
476 } else {
477 /* When we're at the terraform limit we better bail (unneeded) testing as well.
478 * This will probably cause the terraforming cost to be underestimated, but only
479 * when it's near the terraforming limit. Even then, the estimation is
480 * completely off due to it basically counting terraforming double, so it being
481 * cut off earlier might even give a better estimate in some cases. */
482 if (--limit <= 0) {
483 had_success = true;
484 break;
485 }
486 }
487
488 cost.AddCost(ret);
489 curh += (curh > h) ? -1 : 1;
490 had_success = true;
491 }
492
493 if (limit <= 0) break;
494 }
495
496 delete iter;
497 return had_success ? cost : last_error;
498 }
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:89
DC_AUTO
don&#39;t allow building on structures
Definition: command_type.h:343
SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:55
DC_NO_MODIFY_TOWN_RATING
do not change town rating
Definition: command_type.h:352
ClearedObjectArea::first_tile
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition: object_base.h:90
ConstructionSettings::max_heightlevel
uint8 max_heightlevel
maximum allowed heightlevel
Definition: settings_type.h:300
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:74
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:84
DC_FORCE_CLEAR_TILE
do not only remove the object on the tile, but also clear any water left on it
Definition: command_type.h:353
SLOPE_W
the west corner of the tile is raised
Definition: slope_type.h:52
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:514
TerraformSetHeightOfTile
static void TerraformSetHeightOfTile(TerraformerState *ts, TileIndex tile, int height)
Stores the TileHeight (height of north corner) of a tile in a TerraformerState.
Definition: terraform_cmd.cpp:62
TerraformAddDirtyTile
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
Adds a tile to the "tile_table" in a TerraformerState.
Definition: terraform_cmd.cpp:74
CMD_TERRAFORM_LAND
terraform a tile
Definition: command_type.h:188
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
TerraformGetHeightOfTile
static int TerraformGetHeightOfTile(const TerraformerState *ts, TileIndex tile)
Gets the TileHeight (height of north corner) of a tile as of current terraforming progress...
Definition: terraform_cmd.cpp:49
LM_LOWER
Lower the land.
Definition: map_type.h:84
TileIndexSet
std::set< TileIndex > TileIndexSet
Set of tiles.
Definition: terraform_cmd.cpp:30
LM_LEVEL
Level the land.
Definition: map_type.h:83
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
TerraformerState::dirty_tiles
TileIndexSet dirty_tiles
The tiles that need to be redrawn.
Definition: terraform_cmd.cpp:36
CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:182
SLOPE_E
the east corner of the tile is raised
Definition: slope_type.h:54
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height (&#39;z&#39;) of a bridge.
Definition: bridge_map.cpp:72
genworld.h
Functions related to world/map generation.
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:84
CommandCost
Common return value for all commands.
Definition: command_type.h:25
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
LM_RAISE
Raise the land.
Definition: map_type.h:85
SLOPE_FLAT
a flat tile
Definition: slope_type.h:51
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:64
viewport_func.h
Functions related to (drawing on) viewports.
MarkTileDirtyByTileOutsideMap
void MarkTileDirtyByTileOutsideMap(int x, int y)
Mark a (virtual) tile outside the map dirty for repaint.
Definition: viewport.cpp:1920
TileIndexToHeightMap
std::map< TileIndex, int > TileIndexToHeightMap
Mapping of tiles to their height.
Definition: terraform_cmd.cpp:32
SetTileHeight
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
Definition: tile_map.h:49
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:312
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
object_base.h
Base for all objects.
SLOPE_STEEP
indicates the slope is steep
Definition: slope_type.h:56
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
DiagonalTileIterator
Iterator to iterate over a diagonal area of the map.
Definition: tilearea_type.h:188
CompanyProperties::terraform_limit
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
Definition: company_base.h:86
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:436
CmdTerraformLand
CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Terraform land.
Definition: terraform_cmd.cpp:189
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:142
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition: object_base.h:89
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
safeguards.h
A number of safeguards to prevent using unsafe methods.
TerraformTileHeight
static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
Terraform the north corner of a tile to a specific height.
Definition: terraform_cmd.cpp:103
bridge_map.h
Map accessor functions for bridges.
TileIterator
Base class for tile iterators.
Definition: tilearea_type.h:99
TerraformerState
State of the terraforming.
Definition: terraform_cmd.cpp:35
TileTypeProcs::terraform_tile_proc
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
Definition: tile_cmd.h:158
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:51
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:453
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:161
IsTunnelInWay
bool IsTunnelInWay(TileIndex tile, int z)
Is there a tunnel in the way in any direction?
Definition: tunnel_map.cpp:70
TerraformerState::tile_to_new_height
TileIndexToHeightMap tile_to_new_height
The tiles for which the height has changed.
Definition: terraform_cmd.cpp:37
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1904
Company
Definition: company_base.h:110
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:58
EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:151
ToTileIndexDiff
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
Definition: map_func.h:232
DC_EXEC
execute the given command
Definition: command_type.h:342
LevelMode
LevelMode
Argument for CmdLevelLand describing what to do.
Definition: map_type.h:82
company_func.h
Functions related to companies.
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:94
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
TerraformAddDirtyTileAround
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a Terraf...
Definition: terraform_cmd.cpp:86
MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:50
_current_company
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:83
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:34
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
_tile_type_procs
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
Definition: landscape.cpp:61
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:113
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:427
ConstructionSettings::max_bridge_height
byte max_bridge_height
maximum height of bridges
Definition: settings_type.h:304
command_func.h
Functions related to commands.
OrthogonalTileIterator
Iterator to iterate over a tile area (rectangle) of the map.
Definition: tilearea_type.h:138
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:31
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:545
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:181
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
tunnel_map.h
Map accessors for tunnels.
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:104
Delta
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
Definition: math_func.hpp:232
SLOPE_S
the south corner of the tile is raised
Definition: slope_type.h:53
CmdLevelLand
CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Levels a selected (rectangle) area of land.
Definition: terraform_cmd.cpp:423
_terraform_err_tile
TileIndex _terraform_err_tile
first tile we couldn&#39;t terraform
Definition: terraform_cmd.cpp:40
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:165