22 #include "table/strings.h" 119 uint x =
TileX(tile);
120 uint y =
TileY(tile);
140 total_cost.
AddCost(_price[PR_TERRAFORM]);
154 for (ttm = _terraform_tilepos; ttm !=
endof(_terraform_tilepos); ttm++) {
157 if (tile >=
MapSize())
continue;
164 int height_diff = height - r;
167 if (
abs(height_diff) > 1) {
169 height_diff += (height_diff < 0 ? 1 : -1);
171 if (cost.
Failed())
return cost;
194 int direction = (p2 != 0 ? 1 : -1);
201 if (cost.
Failed())
return cost;
208 if (cost.
Failed())
return cost;
215 if (cost.
Failed())
return cost;
222 if (cost.
Failed())
return cost;
229 for (
int pass = 0; pass < 2; pass++) {
245 int z_min =
min(
min(z_N, z_W),
min(z_S, z_E));
246 int z_max =
max(
max(z_N, z_W),
max(z_S, z_E));
250 if (z_W > z_min) tileh |=
SLOPE_W;
251 if (z_S > z_min) tileh |=
SLOPE_S;
252 if (z_E > z_min) tileh |=
SLOPE_E;
253 if (z_N > z_min) tileh |=
SLOPE_N;
261 if (direction == 1 && bridge_height <= z_max) {
281 bool indirectly_cleared = coa != NULL && coa->
first_tile != tile;
292 if (indirectly_cleared) {
302 if (pass == 1) total_cost.
AddCost(cost);
316 int height = it->second;
345 for (
int cx = 0; cx >= -height - 1; cx--) {
346 for (
int cy = 0; cy >= -height - 1; cy--) {
350 if (cx + cy >= -height - 2) {
356 }
else if (y < (
int)
MapMaxY()) {
357 for (
int cx = 0; cx >= -height - 1; cx--) {
361 for (
int cx = 0; cx >= -height - 1; cx--) {
362 for (
int cy = (
int)
MapMaxY(); cy <= (int)
MapMaxY() + height + 1; cy++) {
363 if (cx + ((
int)
MapMaxY() - cy) >= -height - 2) {
369 }
else if (x < (
int)
MapMaxX()) {
371 for (
int cy = 0; cy >= -height - 1; cy--) {
374 }
else if (y < (
int)
MapMaxY()) {
377 for (
int cy = (
int)
MapMaxY(); cy <= (int)
MapMaxY() + height + 1; cy++) {
383 for (
int cx = (
int)
MapMaxX(); cx <= (int)
MapMaxX() + height + 1; cx++) {
384 for (
int cy = 0; cy >= -height - 1; cy--) {
385 if (((
int)
MapMaxX() - cx) + cy >= -height - 2) {
390 }
else if (y < (
int)
MapMaxY()) {
391 for (
int cx = (
int)
MapMaxX(); cx <= (int)
MapMaxX() + height + 1; cx++) {
395 for (
int cx = (
int)
MapMaxX(); cx <= (int)
MapMaxX() + height + 1; cx++) {
396 for (
int cy = (
int)
MapMaxY(); cy <= (int)
MapMaxY() + height + 1; cy++) {
397 if (((
int)
MapMaxX() - cx) + ((
int)
MapMaxY() - cy) >= -height - 2) {
448 bool had_success =
false;
464 if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
471 _additional_cash_required = ret.
GetCost();
489 curh += (curh > h) ? -1 : 1;
493 if (limit <= 0)
break;
497 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.
void MarkTileDirtyByTileOutsideMap(int x, int y)
Mark a (virtual) tile outside the map dirty for repaint.
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 give 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.
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.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
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.
CompanyByte _current_company
Company currently doing an action.
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.
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.