OpenTTD Source  20241108-master-g80f628063a
terraform_cmd.cpp File Reference

Commands related to terraforming. More...

#include "stdafx.h"
#include "command_func.h"
#include "tunnel_map.h"
#include "bridge_map.h"
#include "viewport_func.h"
#include "genworld.h"
#include "object_base.h"
#include "company_base.h"
#include "company_func.h"
#include "core/backup_type.hpp"
#include "terraform_cmd.h"
#include "landscape_cmd.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  TerraformerState
 State of the terraforming. More...
 

Typedefs

typedef std::set< TileIndexTileIndexSet
 Set of tiles.
 
typedef std::map< TileIndex, int > TileIndexToHeightMap
 Mapping of tiles to their height.
 

Functions

static int TerraformGetHeightOfTile (const TerraformerState *ts, TileIndex tile)
 Gets the TileHeight (height of north corner) of a tile as of current terraforming progress. More...
 
static void TerraformSetHeightOfTile (TerraformerState *ts, TileIndex tile, int height)
 Stores the TileHeight (height of north corner) of a tile in a TerraformerState. More...
 
static void TerraformAddDirtyTile (TerraformerState *ts, TileIndex tile)
 Adds a tile to the "tile_table" in a TerraformerState. More...
 
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 TerraformerState. More...
 
static std::tuple< CommandCost, TileIndexTerraformTileHeight (TerraformerState *ts, TileIndex tile, int height)
 Terraform the north corner of a tile to a specific height. More...
 
std::tuple< CommandCost, Money, TileIndexCmdTerraformLand (DoCommandFlag flags, TileIndex tile, Slope slope, bool dir_up)
 Terraform land. More...
 
std::tuple< CommandCost, Money, TileIndexCmdLevelLand (DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal, LevelMode lm)
 Levels a selected (rectangle) area of land. More...
 

Detailed Description

Commands related to terraforming.

Definition in file terraform_cmd.cpp.

Function Documentation

◆ CmdLevelLand()

std::tuple<CommandCost, Money, TileIndex> CmdLevelLand ( DoCommandFlag  flags,
TileIndex  tile,
TileIndex  start_tile,
bool  diagonal,
LevelMode  lm 
)

Levels a selected (rectangle) area of land.

Parameters
flagsfor this command type
tileend tile of area-drag
start_tilestart tile of area drag
diagonalWhether to use the Orthogonal (false) or Diagonal (true) iterator.
LevelModeMode of leveling LevelMode.
Returns
the cost of this operation or an error

Definition at line 315 of file terraform_cmd.cpp.

References _current_company, _settings_game, CommandCost::AddCost(), CMD_ERROR, GameSettings::construction, TileIterator::Create(), DC_EXEC, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GB(), GetAvailableMoneyForCommand(), CommandCost::GetCost(), CommandCost::GetErrorMessage(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), INVALID_STRING_ID, INVALID_TILE, LM_LEVEL, LM_LOWER, LM_RAISE, ConstructionSettings::map_height_limit, Map::Size(), SLOPE_N, CommandCost::Succeeded(), CompanyProperties::terraform_limit, and TileHeight().

◆ CmdTerraformLand()

std::tuple<CommandCost, Money, TileIndex> CmdTerraformLand ( DoCommandFlag  flags,
TileIndex  tile,
Slope  slope,
bool  dir_up 
)

Terraform land.

Parameters
flagsfor this command type
tiletile to terraform
slopecorners to terraform (SLOPE_xxx)
dir_updirection; eg up (true) or down (false)
Returns
the cost of this operation or an error

Definition at line 169 of file terraform_cmd.cpp.

References _generating_world, _settings_game, CommandCost::AddCost(), GameSettings::construction, TerraformerState::dirty_tiles, EXPENSES_CONSTRUCTION, FindClearedObject(), ClearedObjectArea::first_tile, GetBridgeHeight(), GetSouthernBridgeEnd(), IsBridgeAbove(), IsTileType(), IsTunnelInWay(), ConstructionSettings::max_bridge_height, MP_VOID, Map::Size(), SLOPE_E, SLOPE_FLAT, SLOPE_N, SLOPE_S, SLOPE_STEEP, SLOPE_W, TerraformGetHeightOfTile(), TerraformTileHeight(), TileDiffXY(), and TileHeight().

◆ TerraformGetHeightOfTile()

static int TerraformGetHeightOfTile ( const TerraformerState ts,
TileIndex  tile 
)
static

Gets the TileHeight (height of north corner) of a tile as of current terraforming progress.

Parameters
tsTerraformerState.
tileTile.
Returns
TileHeight.

Definition at line 45 of file terraform_cmd.cpp.

References TerraformerState::tile_to_new_height, and TileHeight().

Referenced by CmdTerraformLand(), and TerraformTileHeight().

◆ TerraformSetHeightOfTile()

static void TerraformSetHeightOfTile ( TerraformerState ts,
TileIndex  tile,
int  height 
)
static

Stores the TileHeight (height of north corner) of a tile in a TerraformerState.

Parameters
tsTerraformerState.
tileTile.
heightNew TileHeight.

Definition at line 58 of file terraform_cmd.cpp.

References TerraformerState::tile_to_new_height.

◆ TerraformTileHeight()

static std::tuple<CommandCost, TileIndex> TerraformTileHeight ( TerraformerState ts,
TileIndex  tile,
int  height 
)
static

Terraform the north corner of a tile to a specific height.

Parameters
tsTerraformerState.
tileTile.
heightAimed height.
Returns
Error code or cost.

Definition at line 99 of file terraform_cmd.cpp.

References _settings_game, CMD_ERROR, GameSettings::construction, INVALID_TILE, ConstructionSettings::map_height_limit, Map::Size(), and TerraformGetHeightOfTile().

Referenced by CmdTerraformLand().