OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
21 #include "table/strings.h"
118 uint x =
TileX(tile);
119 uint y =
TileY(tile);
139 total_cost.
AddCost(_price[PR_TERRAFORM]);
153 for (ttm = _terraform_tilepos; ttm !=
endof(_terraform_tilepos); ttm++) {
156 if (tile >=
MapSize())
continue;
163 int height_diff = height - r;
166 if (
abs(height_diff) > 1) {
168 height_diff += (height_diff < 0 ? 1 : -1);
170 if (cost.
Failed())
return cost;
193 int direction = (p2 != 0 ? 1 : -1);
200 if (cost.
Failed())
return cost;
207 if (cost.
Failed())
return cost;
214 if (cost.
Failed())
return cost;
221 if (cost.
Failed())
return cost;
228 for (
int pass = 0; pass < 2; pass++) {
244 int z_min = std::min({z_N, z_W, z_S, z_E});
245 int z_max = std::max({z_N, z_W, z_S, z_E});
249 if (z_W > z_min) tileh |=
SLOPE_W;
250 if (z_S > z_min) tileh |=
SLOPE_S;
251 if (z_E > z_min) tileh |=
SLOPE_E;
252 if (z_N > z_min) tileh |=
SLOPE_N;
260 if (direction == 1 && bridge_height <= z_max) {
280 bool indirectly_cleared = coa !=
nullptr && coa->
first_tile != t;
284 if (_game_mode == GM_EDITOR) old_generating_world.
Change(
true);
291 if (indirectly_cleared) {
296 old_generating_world.
Restore();
301 if (pass == 1) total_cost.
AddCost(cost);
323 int height = it->second;
370 bool had_success =
false;
386 if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
393 _additional_cash_required = ret.
GetCost();
411 curh += (curh > h) ? -1 : 1;
415 if (limit <= 0)
break;
419 return had_success ? cost : last_error;
void Change(const U &new_value)
Change the value of the variable.
uint32 TileIndex
The index/ID of a Tile.
Iterator to iterate over a diagonal area of the map.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
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.
uint8 map_height_limit
the maximum allowed heightlevel
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
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.
@ DC_EXEC
execute the given command
StringID GetErrorMessage() const
Returns the error message of a command.
DoCommandFlag
List of flags for a command.
@ LM_LEVEL
Level the land.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static uint MapSizeX()
Get the size of the map along the X.
LevelMode
Argument for CmdLevelLand describing what to do.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
Iterator to iterate over a tile area (rectangle) of the map.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
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.
@ CMD_TERRAFORM_LAND
terraform 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...
@ SLOPE_STEEP
indicates the slope is steep
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.
Slope
Enumeration for the slope-type.
static uint MapSizeY()
Get the size of the map along the Y.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
@ LM_RAISE
Raise the land.
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.
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.
@ SLOPE_N
the north corner of the tile is raised
@ 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.
#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
@ SLOPE_S
the south corner of the tile is raised
@ 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.
@ SLOPE_W
the west corner of the tile is raised
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
ConstructionSettings construction
construction of things in-game
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Keeps track of removed objects during execution/testruns of commands.
@ LM_LOWER
Lower the land.
@ SLOPE_E
the east corner of the tile is raised
@ CMD_LANDSCAPE_CLEAR
demolish a tile
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