# terraform_cmd.cpp File Reference

Commands related to terraforming. More...

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "command_func.h"`
`#include "tunnel_map.h"`
`#include "bridge_map.h"`
`#include "variables.h"`
`#include "functions.h"`
`#include "economy_func.h"`
`#include "settings_type.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures

struct | TerraformerHeightMod
struct | TerraformerState

## Functions

static int | TerraformGetHeightOfTile (const TerraformerState *ts, TileIndex tile)
| Gets the TileHeight (height of north corner) of a tile as of current terraforming progress.
static void | TerraformSetHeightOfTile (TerraformerState *ts, TileIndex tile, int height)
| Stores the TileHeight (height of north corner) of a tile in a TerraformerState.
static void | TerraformAddDirtyTile (TerraformerState *ts, TileIndex tile)
| Adds a tile to the "tile_table" in a TerraformerState.
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.
static CommandCost | TerraformTileHeight (TerraformerState *ts, TileIndex tile, int height)
| Terraform the north corner of a tile to a specific height.
CommandCost | CmdTerraformLand (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Terraform land.
CommandCost | CmdLevelLand (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Levels a selected (rectangle) area of land.

## Variables

static const int | TERRAFORMER_MODHEIGHT_SIZE = 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 1)
static const int | TERRAFORMER_TILE_TABLE_SIZE = 1 + 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 3)
TileIndex | _terraform_err_tile
| first tile we couldn't terraform

## Detailed Description

Commands related to terraforming.

Definition in file terraform_cmd.cpp.

## Function Documentation

CommandCost CmdLevelLand | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Levels a selected (rectangle) area of land.

Parameters:

  | tile | end tile of area-drag
  | flags | for this command type
  | p1 | start tile of area drag
  | p2 | height difference; eg raise (+1), lower (-1) or level (0)

Returns:
  error or cost of terraforming

Definition at line 357 of file terraform_cmd.cpp.

References _terraform_err_tile, CommandCost::AddCost(), BEGIN_TILE_LOOP, CMD_ERROR, CMD_TERRAFORM_LAND, CmdFailed(), DC_EXEC, DoCommand(), END_TILE_LOOP, GetAvailableMoneyForCommand(), CommandCost::GetCost(), INVALID_TILE, MapSize(), MAX_TILE_HEIGHT, return_cmd_error, SLOPE_N, Swap(), TileHeight(), TileX(), TileXY(), and TileY().

CommandCost CmdTerraformLand | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Terraform land.

Parameters:

  | tile | tile to terraform
  | flags | for this command type
  | p1 | corners to terraform (SLOPE_xxx)
  | p2 | direction; eg up (non-zero) or down (zero)

Returns:
  error or cost of terraforming

Definition at line 231 of file terraform_cmd.cpp.

References _terraform_err_tile, _tile_type_procs, CommandCost::AddCost(), CmdFailed(), DC_AUTO, DC_EXEC, GetBridgeHeight(), GetSouthernBridgeEnd(), GetTileType(), INVALID_TILE, IsBridgeAbove(), IsTileType(), IsTunnelInWay(), MapSize(), MarkTileDirtyByTile(), max(), MayHaveBridgeAbove(), min(), MP_VOID, return_cmd_error, SetTileHeight(), SLOPE_E, SLOPE_FLAT, SLOPE_N, SLOPE_S, SLOPE_STEEP, SLOPE_W, TileTypeProcs::terraform_tile_proc, TerraformGetHeightOfTile(), TerraformTileHeight(), TILE_HEIGHT, TileDiffXY(), and TileHeight().

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:

  | ts | TerraformerState.
  | tile | Tile.

Returns:
  TileHeight.

Definition at line 60 of file terraform_cmd.cpp.

References TileHeight().

Referenced by CmdTerraformLand(), and TerraformTileHeight().

static void TerraformSetHeightOfTile | ( | TerraformerState * | ts,
|  | TileIndex | tile,
|  | int | height |
| ) |  |  | `[static]`

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

Parameters:

  | ts | TerraformerState.
  | tile | Tile.
  | height | New TileHeight.

Definition at line 79 of file terraform_cmd.cpp.

Referenced by TerraformTileHeight().

static CommandCost TerraformTileHeight | ( | TerraformerState * | ts,
|  | TileIndex | tile,
|  | int | height |
| ) |  |  | `[static]`

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

Parameters:

  | ts | TerraformerState.
  | tile | Tile.
  | height | Aimed height.
  | return | Error code or cost.

Definition at line 147 of file terraform_cmd.cpp.

References _settings_game, _terraform_err_tile, abs(), CommandCost::AddCost(), CMD_ERROR, CmdFailed(), GameSettings::construction, Delta(), endof, ConstructionSettings::freeform_edges, MapMaxX(), MapMaxY(), MapSize(), MapSizeX(), MapSizeY(), MAX_TILE_HEIGHT, return_cmd_error, TerraformAddDirtyTileAround(), TerraformGetHeightOfTile(), TerraformSetHeightOfTile(), TileX(), TileXY(), TileY(), and ToTileIndexDiff().

Referenced by CmdTerraformLand().