26#include "table/strings.h"
118 uint x =
TileX(tile);
119 uint y =
TileY(tile);
149 int height_diff = height - r;
152 if (
abs(height_diff) > 1) {
154 height_diff += (height_diff < 0 ? 1 : -1);
156 if (cost.Failed())
return { cost, err_tile };
157 total_cost.
AddCost(cost.GetCost());
175 int direction = (dir_up ? 1 : -1);
182 if (cost.Failed())
return { cost, 0, err_tile };
183 total_cost.
AddCost(cost.GetCost());
189 if (cost.Failed())
return { cost, 0, err_tile };
190 total_cost.
AddCost(cost.GetCost());
196 if (cost.Failed())
return { cost, 0, err_tile };
197 total_cost.
AddCost(cost.GetCost());
203 if (cost.Failed())
return { cost, 0, err_tile };
204 total_cost.
AddCost(cost.GetCost());
210 for (
int pass = 0; pass < 2; pass++) {
224 int z_min = std::min({z_N, z_W, z_S, z_E});
225 int z_max = std::max({z_N, z_W, z_S, z_E});
229 if (z_W > z_min) tileh |=
SLOPE_W;
230 if (z_S > z_min) tileh |=
SLOPE_S;
231 if (z_E > z_min) tileh |=
SLOPE_E;
232 if (z_N > z_min) tileh |=
SLOPE_N;
240 if (direction == 1 && bridge_height <= z_max) {
241 return {
CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST), 0, t };
245 if (direction == -1 && bridge_height > (z_min +
_settings_game.construction.max_bridge_height)) {
246 return {
CommandCost(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND), 0, t };
251 return {
CommandCost(STR_ERROR_EXCAVATION_WOULD_DAMAGE), 0, t };
257 bool indirectly_cleared = coa !=
nullptr && coa->
first_tile != t;
276 if (indirectly_cleared) {
277 cost = Command<Commands::LandscapeClear>::Do(tile_flags, t);
281 old_generating_world.
Restore();
283 return { cost, 0, t };
306 int height = it.second;
348 bool had_success =
false;
361 last_error = std::move(ret);
364 if (last_error.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
371 return { cost, ret.
GetCost(), error_tile };
373 Command<Commands::TerraformLand>::Do(flags, t,
SLOPE_N, curh <= h);
387 curh += (curh > h) ? -1 : 1;
391 if (limit <= 0)
break;
394 CommandCost cc_ret = had_success ? cost : last_error;
395 return { cc_ret, 0, cc_ret.
Succeeded() ? tile : error_tile };
Class for backupping variables and making sure they are restored later.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Map accessor functions for bridges.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Money GetCost() const
The costs as made up to this moment.
bool Failed() const
Did this command fail?
StringID GetErrorMessage() const
Returns the error message of a command.
Iterate a range of enum values.
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Auto
don't allow building on structures
@ NoModifyTownRating
do not change town rating
@ ClearToRocks
when clearing land, make rocks instead of bare dirt/grass
@ Execute
execute the given command
@ ForceClearTile
do not only remove the object on the tile, but also clear any water left on it
EnumBitSet< DoCommandFlag, uint16_t > DoCommandFlags
Bitset of DoCommandFlag elements.
Definition of stuff that is very close to a company, like the company struct itself.
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
DiagDirection
Enumeration for diagonal directions.
@ End
Used for iterations.
Prices _price
Prices and also the fractional part.
@ Construction
Construction costs.
@ Terraform
Price for terraforming land, e.g. rising, lowering and flattening.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
Adds a tile to the "tile_table" in a TerraformerState.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
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...
const EnumIndexArray< const TileTypeProcs *, TileType, TileType::MaxSize > _tile_type_procs
Tile callback functions for each type of tile.
Command definitions related to landscape (slopes etc.).
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
static uint TileX(TileIndex tile)
Get the X component of a tile.
LevelMode
Argument for CmdLevelLand describing what to do.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
@ Editor
In the scenario editor.
Pseudo random number generator.
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Slope
Enumeration for the slope-type.
@ SLOPE_W
the west corner of the tile is raised
@ SLOPE_E
the east corner of the tile is raised
@ SLOPE_S
the south corner of the tile is raised
@ SLOPE_N
the north corner of the tile is raised
@ SLOPE_STEEP
indicates the slope is steep
Definition of base types and functions in a cross-platform compatible way.
static constexpr StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
Class to backup a specific variable and restore it later.
void Change(const U &new_value)
Change the value of the variable.
void Restore()
Restore the variable.
Keeps track of removed objects during execution/testruns of commands.
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
uint32_t terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
static uint Size()
Get the size of the map.
static Company * GetIfValid(auto index)
Generic 'commands' that can be performed on all tiles.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static uint TileHeight(Tile tile)
Returns the height of a tile.
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ Void
Invisible tiles at the SW and SE border.
OrthoDiagonalTileArea CreateOrthoDiagonalArea(TileIndex corner1, TileIndex corner2, bool diagonal)
Create an Orthogonal/Diagonal tile area wrapper.
Type for storing the 'area' of something uses on the map.
bool IsTunnelInWay(TileIndex tile, int z)
Is there a tunnel in the way in any direction?
Map accessors for tunnels.
Functions related to (drawing on) viewports.