20 #include "table/strings.h" 117 uint x =
TileX(tile);
118 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;
192 int direction = (p2 != 0 ? 1 : -1);
199 if (cost.
Failed())
return cost;
206 if (cost.
Failed())
return cost;
213 if (cost.
Failed())
return cost;
220 if (cost.
Failed())
return cost;
227 for (
int pass = 0; pass < 2; pass++) {
243 int z_min =
min(
min(z_N, z_W),
min(z_S, z_E));
244 int z_max =
max(
max(z_N, z_W),
max(z_S, z_E));
248 if (z_W > z_min) tileh |=
SLOPE_W;
249 if (z_S > z_min) tileh |=
SLOPE_S;
250 if (z_E > z_min) tileh |=
SLOPE_E;
251 if (z_N > z_min) tileh |=
SLOPE_N;
259 if (direction == 1 && bridge_height <= z_max) {
279 bool indirectly_cleared = coa !=
nullptr && coa->
first_tile != tile;
290 if (indirectly_cleared) {
300 if (pass == 1) total_cost.
AddCost(cost);
322 int height = it->second;
369 bool had_success =
false;
385 if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
392 _additional_cash_required = ret.
GetCost();
410 curh += (curh > h) ? -1 : 1;
414 if (limit <= 0)
break;
418 return had_success ? cost : last_error;
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
don't allow building on structures
the north corner of the tile is raised
do not change town rating
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
uint8 max_heightlevel
maximum allowed heightlevel
static uint MapSizeX()
Get the size of the map along the X.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static uint MapSizeY()
Get the size of the map along the Y.
do not only remove the object on the tile, but also clear any water left on it
the west corner of the tile is raised
Money GetAvailableMoneyForCommand()
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
Adds a tile to the "tile_table" in a TerraformerState.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
static uint TileX(TileIndex tile)
Get the X component of a tile.
the east corner of the tile is raised
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Functions related to world/map generation.
Money GetCost() const
The costs as made up to this moment.
Common return value for all commands.
static T max(const T a, const T b)
Returns the maximum of two values.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Functions related to (drawing on) viewports.
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
bool freeform_edges
allow terraforming the tiles at the map edges
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
indicates the slope is steep
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Iterator to iterate over a diagonal area of the map.
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
StringID GetErrorMessage() const
Returns the error message of a command.
DoCommandFlag
List of flags for a command.
Keeps track of removed objects during execution/testruns of commands.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Map accessor functions for bridges.
Base class for tile iterators.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
static T min(const T a, const T b)
Returns the minimum of two values.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
bool Failed() const
Did this command fail?
bool IsTunnelInWay(TileIndex tile, int z)
Is there a tunnel in the way in any direction?
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
A pair-construct of a TileIndexDiff.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
execute the given command
LevelMode
Argument for CmdLevelLand describing what to do.
Functions related to companies.
static uint MapSize()
Get the size of the map.
bool _generating_world
Whether we are generating the map or not.
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...
Invisible tiles at the SW and SE border.
uint32 TileIndex
The index/ID of a Tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Slope
Enumeration for the slope-type.
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
#define endof(x)
Get the end element of an fixed size array.
byte max_bridge_height
maximum height of bridges
Functions related to commands.
Iterator to iterate over a tile area (rectangle) of the map.
CompanyID _current_company
Company currently doing an action.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
ConstructionSettings construction
construction of things in-game
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Map accessors for tunnels.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
the south corner of the tile is raised
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.