Go to the documentation of this file.
23 #include "table/strings.h"
118 uint x =
TileX(tile);
119 uint y =
TileY(tile);
138 total_cost.
AddCost(_price[PR_TERRAFORM]);
152 for (ttm = _terraform_tilepos; ttm !=
endof(_terraform_tilepos); ttm++) {
155 if (tile >=
MapSize())
continue;
162 int height_diff = height - r;
165 if (
abs(height_diff) > 1) {
167 height_diff += (height_diff < 0 ? 1 : -1);
169 if (cost.Failed())
return { cost, err_tile };
189 int direction = (dir_up ? 1 : -1);
196 if (cost.Failed())
return { cost, 0, err_tile };
203 if (cost.Failed())
return { cost, 0, err_tile };
210 if (cost.Failed())
return { cost, 0, err_tile };
217 if (cost.Failed())
return { cost, 0, err_tile };
224 for (
int pass = 0; pass < 2; pass++) {
240 int z_min = std::min({z_N, z_W, z_S, z_E});
241 int z_max = std::max({z_N, z_W, z_S, z_E});
245 if (z_W > z_min) tileh |=
SLOPE_W;
246 if (z_S > z_min) tileh |=
SLOPE_S;
247 if (z_E > z_min) tileh |=
SLOPE_E;
248 if (z_N > z_min) tileh |=
SLOPE_N;
256 if (direction == 1 && bridge_height <= z_max) {
257 return {
CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST), 0, t };
262 return {
CommandCost(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND), 0, t };
267 return {
CommandCost(STR_ERROR_EXCAVATION_WOULD_DAMAGE), 0, t };
273 bool indirectly_cleared = coa !=
nullptr && coa->
first_tile != t;
277 if (_game_mode == GM_EDITOR) old_generating_world.
Change(
true);
284 if (indirectly_cleared) {
289 old_generating_world.
Restore();
291 return { cost, 0, t };
293 if (pass == 1) total_cost.
AddCost(cost);
315 int height = it->second;
357 bool had_success =
false;
375 if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
383 return { cost, ret.
GetCost(), error_tile };
399 curh += (curh > h) ? -1 : 1;
403 if (limit <= 0)
break;
407 CommandCost cc_ret = had_success ? cost : last_error;
408 return { cc_ret, 0, cc_ret.
Succeeded() ? tile : error_tile };
void Change(const U &new_value)
Change the value of the variable.
Iterator to iterate over a diagonal area of the map.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Class to backup a specific variable and restore it later.
@ LM_LOWER
Lower the land.
uint8 map_height_limit
the maximum allowed heightlevel
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
Adds a tile to the "tile_table" in a TerraformerState.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
@ SLOPE_S
the south corner of the tile is raised
@ DC_EXEC
execute the given command
StringID GetErrorMessage() const
Returns the error message of a command.
@ SLOPE_E
the east corner of the tile is raised
DoCommandFlag
List of flags for a command.
bool Succeeded() const
Did this command succeed?
static uint TileX(TileIndex tile)
Get the X component of a tile.
static uint MapSizeX()
Get the size of the map along the X.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Slope
Enumeration for the slope-type.
Iterator to iterate over a tile area (rectangle) of the map.
static uint MapSize()
Get the size of the map.
@ EXPENSES_CONSTRUCTION
Construction costs.
Common return value for all commands.
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Base class for tile iterators.
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
bool Failed() const
Did this command fail?
bool IsTunnelInWay(TileIndex tile, int z)
Is there a tunnel in the way in any direction?
byte max_bridge_height
maximum height of bridges
GameSettings _settings_game
Game settings of a running game or the scenario editor.
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...
bool freeform_edges
allow terraforming the tiles at the map edges
Money GetCost() const
The costs as made up to this moment.
Money GetAvailableMoneyForCommand()
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
static uint MapSizeY()
Get the size of the map along the Y.
@ LM_LEVEL
Level the land.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
@ SLOPE_W
the west corner of the tile is raised
A pair-construct of a TileIndexDiff.
bool _generating_world
Whether we are generating the map or not.
CompanyID _current_company
Company currently doing an action.
@ DC_FORCE_CLEAR_TILE
do not only remove the object on the tile, but also clear any water left on it
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
@ MP_VOID
Invisible tiles at the SW and SE border.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
void Restore()
Restore the variable.
@ SLOPE_N
the north corner of the tile is raised
#define endof(x)
Get the end element of an fixed size array.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
@ DC_AUTO
don't allow building on structures
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
LevelMode
Argument for CmdLevelLand describing what to do.
ConstructionSettings construction
construction of things in-game
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
@ LM_RAISE
Raise the land.
Keeps track of removed objects during execution/testruns of commands.
@ SLOPE_STEEP
indicates the slope is steep
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile