23 #include "table/strings.h"
115 uint x =
TileX(tile);
116 uint y =
TileY(tile);
135 total_cost.
AddCost(_price[PR_TERRAFORM]);
146 int height_diff = height - r;
149 if (
abs(height_diff) > 1) {
151 height_diff += (height_diff < 0 ? 1 : -1);
153 if (cost.Failed())
return { cost, err_tile };
172 int direction = (dir_up ? 1 : -1);
179 if (cost.Failed())
return { cost, 0, err_tile };
186 if (cost.Failed())
return { cost, 0, err_tile };
193 if (cost.Failed())
return { cost, 0, err_tile };
200 if (cost.Failed())
return { cost, 0, err_tile };
207 for (
int pass = 0; pass < 2; pass++) {
221 int z_min = std::min({z_N, z_W, z_S, z_E});
222 int z_max = std::max({z_N, z_W, z_S, z_E});
226 if (z_W > z_min) tileh |=
SLOPE_W;
227 if (z_S > z_min) tileh |=
SLOPE_S;
228 if (z_E > z_min) tileh |=
SLOPE_E;
229 if (z_N > z_min) tileh |=
SLOPE_N;
237 if (direction == 1 && bridge_height <= z_max) {
238 return {
CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST), 0, t };
243 return {
CommandCost(STR_ERROR_BRIDGE_TOO_HIGH_AFTER_LOWER_LAND), 0, t };
248 return {
CommandCost(STR_ERROR_EXCAVATION_WOULD_DAMAGE), 0, t };
254 bool indirectly_cleared = coa !=
nullptr && coa->
first_tile != t;
258 if (_game_mode == GM_EDITOR) old_generating_world.
Change(
true);
265 if (indirectly_cleared) {
270 old_generating_world.
Restore();
272 return { cost, 0, t };
274 if (pass == 1) total_cost.
AddCost(cost);
295 int height = it.second;
337 bool had_success =
false;
355 if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
362 return { cost, ret.
GetCost(), error_tile };
378 curh += (curh > h) ? -1 : 1;
382 if (limit <= 0)
break;
385 CommandCost cc_ret = had_success ? cost : last_error;
386 return { cc_ret, 0, cc_ret.
Succeeded() ? tile : error_tile };
Class for backupping variables and making sure they are restored later.
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.
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
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.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
DoCommandFlag
List of flags for a command.
@ DC_AUTO
don't allow building on structures
@ DC_FORCE_CLEAR_TILE
do not only remove the object on the tile, but also clear any water left on it
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
@ DC_EXEC
execute the given command
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.
@ DIAGDIR_END
Used for iterations.
@ DIAGDIR_BEGIN
Used for iterations.
@ EXPENSES_CONSTRUCTION
Construction costs.
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 TileTypeProcs *const _tile_type_procs[16]
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.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
LevelMode
Argument for CmdLevelLand describing what to do.
@ LM_LEVEL
Level the land.
@ LM_LOWER
Lower the land.
@ LM_RAISE
Raise the land.
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.
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 const 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).
uint8_t max_bridge_height
maximum height of bridges
bool freeform_edges
allow terraforming the tiles at the map edges
uint8_t map_height_limit
the maximum allowed heightlevel
ConstructionSettings construction
construction of things in-game
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static debug_inline uint Size()
Get the size of the map.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
TerraformTileProc * terraform_tile_proc
Called when a terraforming operation is about to take place.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_VOID
Invisible tiles at the SW and SE border.
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.