OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
23 #include "table/strings.h"
115 uint x =
TileX(tile);
116 uint y =
TileY(tile);
135 total_cost.
AddCost(_price[PR_TERRAFORM]);
147 for (
const auto &ttm : _terraform_tilepos) {
157 int height_diff = height - r;
160 if (
abs(height_diff) > 1) {
162 height_diff += (height_diff < 0 ? 1 : -1);
164 if (cost.Failed())
return { cost, err_tile };
184 int direction = (dir_up ? 1 : -1);
191 if (cost.Failed())
return { cost, 0, err_tile };
198 if (cost.Failed())
return { cost, 0, err_tile };
205 if (cost.Failed())
return { cost, 0, err_tile };
212 if (cost.Failed())
return { cost, 0, err_tile };
219 for (
int pass = 0; pass < 2; pass++) {
233 int z_min = std::min({z_N, z_W, z_S, z_E});
234 int z_max = std::max({z_N, z_W, z_S, z_E});
238 if (z_W > z_min) tileh |=
SLOPE_W;
239 if (z_S > z_min) tileh |=
SLOPE_S;
240 if (z_E > z_min) tileh |=
SLOPE_E;
241 if (z_N > z_min) tileh |=
SLOPE_N;
249 if (direction == 1 && bridge_height <= z_max) {
250 return {
CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST), 0, t };
255 return {
CommandCost(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND), 0, t };
260 return {
CommandCost(STR_ERROR_EXCAVATION_WOULD_DAMAGE), 0, t };
266 bool indirectly_cleared = coa !=
nullptr && coa->
first_tile != t;
270 if (_game_mode == GM_EDITOR) old_generating_world.
Change(
true);
277 if (indirectly_cleared) {
282 old_generating_world.
Restore();
284 return { cost, 0, t };
286 if (pass == 1) total_cost.
AddCost(cost);
307 int height = it.second;
349 bool had_success =
false;
367 if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
374 return { cost, ret.
GetCost(), error_tile };
390 curh += (curh > h) ? -1 : 1;
394 if (limit <= 0)
break;
397 CommandCost cc_ret = had_success ? cost : last_error;
398 return { cc_ret, 0, cc_ret.
Succeeded() ? tile : error_tile };
@ SLOPE_E
the east corner of the tile is raised
void Change(const U &new_value)
Change the value of the variable.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
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.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
@ LM_LEVEL
Level the land.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
Adds a tile to the "tile_table" in a TerraformerState.
@ SLOPE_W
the west corner of the tile is raised
@ DC_EXEC
execute the given command
StringID GetErrorMessage() const
Returns the error message of a command.
DoCommandFlag
List of flags for a command.
@ SLOPE_S
the south corner of the tile is raised
bool Succeeded() const
Did this command succeed?
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
LevelMode
Argument for CmdLevelLand describing what to do.
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
Common return value for all commands.
uint8_t map_height_limit
the maximum allowed heightlevel
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?
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
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.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
@ SLOPE_N
the north corner of the tile is raised
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
@ LM_LOWER
Lower the land.
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
A pair-construct of a TileIndexDiff.
static debug_inline uint SizeX()
Get the size of the map along the X.
bool _generating_world
Whether we are generating the map or not.
@ LM_RAISE
Raise the land.
CompanyID _current_company
Company currently doing an action.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ DC_FORCE_CLEAR_TILE
do not only remove the object on the tile, but also clear any water left on it
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.
@ SLOPE_STEEP
indicates the slope is steep
void Restore()
Restore the variable.
Slope
Enumeration for the slope-type.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
static debug_inline uint Size()
Get the size of the map.
uint32_t terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
@ DC_AUTO
don't allow building on structures
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
uint8_t max_bridge_height
maximum height of bridges
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
ConstructionSettings construction
construction of things in-game
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Keeps track of removed objects during execution/testruns of commands.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static uint SizeY()
Get the size of the map along the Y.
@ EXPENSES_CONSTRUCTION
Construction costs.