# AITile Class Reference

Class that handles all tile related functions. More...

`#include <ai_tile.hpp>`

Inheritance diagram for AITile:

## Public Types
enum | ErrorMessages { ERR_TILE_BASE = AIError::ERR_CAT_TILE << AIError::ERR_CAT_BIT_SIZE, ERR_TILE_TOO_HIGH, ERR_TILE_TOO_LOW }
| Error messages related to modifying tiles. More...
enum | Slope { SLOPE_FLAT = 0x00, SLOPE_W = 0x01, SLOPE_S = 0x02, SLOPE_E = 0x04, SLOPE_N = 0x08, SLOPE_STEEP = 0x10, SLOPE_NW = SLOPE_N | SLOPE_W, SLOPE_SW = SLOPE_S | SLOPE_W, SLOPE_SE = SLOPE_S | SLOPE_E, SLOPE_NE = SLOPE_N | SLOPE_E, SLOPE_EW = SLOPE_E | SLOPE_W, SLOPE_NS = SLOPE_N | SLOPE_S, SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, SLOPE_NWS = SLOPE_N | SLOPE_W | SLOPE_S, SLOPE_WSE = SLOPE_W | SLOPE_S | SLOPE_E, SLOPE_SEN = SLOPE_S | SLOPE_E | SLOPE_N, SLOPE_ENW = SLOPE_E | SLOPE_N | SLOPE_W, SLOPE_STEEP_W = SLOPE_STEEP | SLOPE_NWS, SLOPE_STEEP_S = SLOPE_STEEP | SLOPE_WSE, SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN, SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW, SLOPE_INVALID = 0xFF }
| Enumeration for the slope-type (from slopes.h). More...
enum | TransportType { TRANSPORT_RAIL = 0, TRANSPORT_ROAD = 1, TRANSPORT_WATER = 2, TRANSPORT_AIR = 3, TRANSPORT_INVALID = -1 }
| The different transport types a tile can have. More...
## Static Public Member Functions
static const char * | GetClassName ()
static bool | IsBuildable (TileIndex tile)
| Check if this tile is buildable, i.e.
static bool | IsBuildableRectangle (TileIndex tile, uint width, uint height)
| Check if this tile is buildable in a rectangle around a tile, with the entry in the list as top-left.
static bool | IsWaterTile (TileIndex tile)
| Checks whether the given tile is actually a water tile.
static bool | IsCoastTile (TileIndex tile)
| Checks whether the given tile is actually a coast tile.
static bool | IsStationTile (TileIndex tile)
| Checks whether the given tile is a station tile of any station.
static bool | IsSteepSlope (Slope slope)
| Check if a tile has a steep slope.
static bool | IsHalftileSlope (Slope slope)
| Check if a tile has a halftile slope.
static bool | HasTreeOnTile (TileIndex tile)
| Check if the tile has any tree on it.
static bool | IsFarmTile (TileIndex tile)
| Check if the tile is a farmland tile.
static bool | IsRockTile (TileIndex tile)
| Check if the tile is a rock tile.
static bool | IsRoughTile (TileIndex tile)
| Check if the tile is a rough tile.
static bool | IsSnowTile (TileIndex tile)
| Check if the tile is a snow tile.
static bool | IsDesertTile (TileIndex tile)
| Check if the tile is a desert tile.
static Slope | GetSlope (TileIndex tile)
| Get the slope of a tile.
static Slope | GetComplementSlope (Slope slope)
| Get the complement of the slope.
static int32 | GetHeight (TileIndex tile)
| Get the height of the tile.
static AICompany::CompanyID | GetOwner (TileIndex tile)
| Get the owner of the tile.
static bool | HasTransportType (TileIndex tile, TransportType transport_type)
| Checks whether the given tile contains parts suitable for the given TransportType.
static int32 | GetCargoAcceptance (TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
| Check how much cargo this tile accepts.
static int32 | GetCargoProduction (TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
| Checks how many tiles in the radius produces this cargo.
static int32 | GetDistanceManhattanToTile (TileIndex tile_from, TileIndex tile_to)
| Get the manhattan distance from the tile to the tile.
static int32 | GetDistanceSquareToTile (TileIndex tile_from, TileIndex tile_to)
| Get the square distance from the tile to the tile.
static bool | RaiseTile (TileIndex tile, int32 slope)
| Raise the given corners of the tile.
static bool | LowerTile (TileIndex tile, int32 slope)
| Lower the given corners of the tile.
static bool | LevelTiles (TileIndex start_tile, TileIndex end_tile)
| Level all tiles in the rectangle between start_tile and end_tile so they are at the same height.
static bool | DemolishTile (TileIndex tile)
| Destroy everything on the given tile.
static bool | PlantTree (TileIndex tile)
| Create a random tree on a tile.
static bool | PlantTreeRectangle (TileIndex tile, uint width, uint height)
| Create a random tree on a rectangle of tiles.
static bool | IsWithinTownInfluence (TileIndex tile, TownID town_id)
| Find out if this tile is within the rating influence of a town.
static TownID | GetClosestTown (TileIndex tile)
| Find the town that is closest to a tile.

## Detailed Description

Class that handles all tile related functions.

Definition at line 15 of file ai_tile.hpp.

## Member Enumeration Documentation

enum AITile::ErrorMessages

Error messages related to modifying tiles.

Enumerator:

  ERR_TILE_BASE | Base for tile related errors.
  ERR_TILE_TOO_HIGH | Tile can't be raised any higher.
  ERR_TILE_TOO_LOW | Tile can't be lowered any lower.

Definition at line 22 of file ai_tile.hpp.

enum AITile::Slope

Enumeration for the slope-type (from slopes.h).

This enumeration use the chars N, E, S, W corresponding the direction North, East, South and West. The top corner of a tile is the north-part of the tile.

Enumerator:

  SLOPE_FLAT | A flat tile.
  SLOPE_W | The west corner of the tile is raised.
  SLOPE_S | The south corner of the tile is raised.
  SLOPE_E | The east corner of the tile is raised.
  SLOPE_N | The north corner of the tile is raised.
  SLOPE_STEEP | Indicates the slope is steep.
  SLOPE_NW | North and west corner are raised.
  SLOPE_SW | South and west corner are raised.
  SLOPE_SE | South and east corner are raised.
  SLOPE_NE | North and east corner are raised.
  SLOPE_EW | East and west corner are raised.
  SLOPE_NS | North and south corner are raised.
  SLOPE_ELEVATED | All corner are raised, similar to SLOPE_FLAT.
  SLOPE_NWS | North, west and south corner are raised.
  SLOPE_WSE | West, south and east corner are raised.
  SLOPE_SEN | South, east and north corner are raised.
  SLOPE_ENW | East, north and west corner are raised.
  SLOPE_STEEP_W | A steep slope falling to east (from west).
  SLOPE_STEEP_S | A steep slope falling to north (from south).
  SLOPE_STEEP_E | A steep slope falling to west (from east).
  SLOPE_STEEP_N | A steep slope falling to south (from north).
  SLOPE_INVALID | An invalid slope.

Definition at line 41 of file ai_tile.hpp.

enum AITile::TransportType

The different transport types a tile can have.

Enumerator:

  TRANSPORT_RAIL | Tile with rail.
  TRANSPORT_ROAD | Tile with road.
  TRANSPORT_WATER | Tile with navigable waterways.
  TRANSPORT_AIR | Tile with airport.
  TRANSPORT_INVALID | Tile without any transport type.

Definition at line 71 of file ai_tile.hpp.

## Member Function Documentation

bool AITile::IsBuildable | ( | TileIndex | tile | ) | `[static]`

Check if this tile is buildable, i.e.

no things on it that needs demolishing.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if it is buildable, false if not.

Note:
  For trams you also might want to check for AIRoad::IsRoad(), as you can build tram-rails on road-tiles.

  For rail you also might want to check for AIRoad::IsRoad(), as in some cases you can build rails on road-tiles.

Definition at line 15 of file ai_tile.cpp.

References CountBits(), GetTileType(), IsValidTile(), MP_CLEAR, MP_ROAD, MP_TREES, MP_WATER, OWNER_TOWN, ROADTYPE_ROAD, and ROADTYPES_ROAD.

Referenced by IsBuildableRectangle().

bool AITile::IsBuildableRectangle | ( | TileIndex | tile,
|  | uint | width,
|  | uint | height |
| ) |  |  | `[static]`

Check if this tile is buildable in a rectangle around a tile, with the entry in the list as top-left.

Parameters:

  | tile | The tile to check on.
  | width | The width of the rectangle.
  | height | The height of the rectangle.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if it is buildable, false if not.

Definition at line 36 of file ai_tile.cpp.

References AIMap::GetTileIndex(), AIMap::GetTileX(), AIMap::GetTileY(), and IsBuildable().

bool AITile::IsWaterTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is actually a water tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is a water tile.

Definition at line 52 of file ai_tile.cpp.

References IsTileType(), IsValidTile(), and MP_WATER.

bool AITile::IsCoastTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is actually a coast tile.

Parameters:

  | tile | The tile to check.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is a coast tile.

Note:
  Building on coast tiles in general is more expensive.

Definition at line 59 of file ai_tile.cpp.

References IsTileType(), IsValidTile(), and MP_WATER.

bool AITile::IsStationTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is a station tile of any station.

Parameters:

  | tile | The tile to check.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is a station tile.

Definition at line 66 of file ai_tile.cpp.

References IsTileType(), IsValidTile(), and MP_STATION.

Referenced by AIAirport::GetAirportType().

bool AITile::IsSteepSlope | ( | Slope | slope | ) | `[static]`

Check if a tile has a steep slope.

Parameters:

  | slope | The slope to check on.

Precondition:
  slope != SLOPE_INVALID.

Returns:
  True if the slope is a steep slope.

Definition at line 73 of file ai_tile.cpp.

References IsSteepSlope(), and SLOPE_INVALID.

Referenced by GetComplementSlope().

bool AITile::IsHalftileSlope | ( | Slope | slope | ) | `[static]`

Check if a tile has a halftile slope.

Parameters:

  | slope | The slope to check on.

Precondition:
  slope != SLOPE_INVALID.

Returns:
  True if the slope is a halftile slope.

Definition at line 80 of file ai_tile.cpp.

References IsHalftileSlope(), and SLOPE_INVALID.

Referenced by GetComplementSlope().

bool AITile::HasTreeOnTile | ( | TileIndex | tile | ) | `[static]`

Check if the tile has any tree on it.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if there is a tree on the tile.

Definition at line 87 of file ai_tile.cpp.

References IsTileType(), and MP_TREES.

bool AITile::IsFarmTile | ( | TileIndex | tile | ) | `[static]`

Check if the tile is a farmland tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is farmland.

Definition at line 92 of file ai_tile.cpp.

References CLEAR_FIELDS, IsClearGround(), IsTileType(), and MP_CLEAR.

bool AITile::IsRockTile | ( | TileIndex | tile | ) | `[static]`

Check if the tile is a rock tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is rock tile.

Definition at line 97 of file ai_tile.cpp.

References CLEAR_ROCKS, IsClearGround(), IsTileType(), and MP_CLEAR.

bool AITile::IsRoughTile | ( | TileIndex | tile | ) | `[static]`

Check if the tile is a rough tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is rough tile.

Definition at line 102 of file ai_tile.cpp.

References CLEAR_ROUGH, IsClearGround(), IsTileType(), and MP_CLEAR.

bool AITile::IsSnowTile | ( | TileIndex | tile | ) | `[static]`

Check if the tile is a snow tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is snow tile.

Definition at line 107 of file ai_tile.cpp.

References CLEAR_SNOW, IsClearGround(), IsTileType(), and MP_CLEAR.

bool AITile::IsDesertTile | ( | TileIndex | tile | ) | `[static]`

Check if the tile is a desert tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile is desert tile.

Definition at line 112 of file ai_tile.cpp.

References CLEAR_DESERT, IsClearGround(), IsTileType(), and MP_CLEAR.

AITile::Slope AITile::GetSlope | ( | TileIndex | tile | ) | `[static]`

Get the slope of a tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  0 means flat, others indicate internal state of slope.

Definition at line 117 of file ai_tile.cpp.

References GetTileSlope(), IsValidTile(), and SLOPE_INVALID.

Referenced by AIRoad::CanBuildConnectedRoadPartsHere().

AITile::Slope AITile::GetComplementSlope | ( | Slope | slope | ) | `[static]`

Get the complement of the slope.

Parameters:

  | slope | The slope to get the complement of.

Precondition:
  slope != SLOPE_INVALID.

  !IsSteepSlope(slope).

  !IsHalftileSlope(slope).

Returns:
  The complement of a slope. This means that all corners that weren't raised, are raised, and visa versa.

Definition at line 124 of file ai_tile.cpp.

References ComplementSlope(), IsHalftileSlope(), IsSteepSlope(), and SLOPE_INVALID.

int32 AITile::GetHeight | ( | TileIndex | tile | ) | `[static]`

Get the height of the tile.

Parameters:

  | tile | The tile to check on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  The height of the tile, ranging from 0 to 15.

Definition at line 133 of file ai_tile.cpp.

References IsValidTile(), and TileHeight().

AICompany::CompanyID AITile::GetOwner | ( | TileIndex | tile | ) | `[static]`

Get the owner of the tile.

Parameters:

  | tile | The tile to get the owner from.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  The CompanyID of the owner of the tile, or COMPANY_INVALID if there is no owner (grass/industry/water tiles, etc.).

Definition at line 140 of file ai_tile.cpp.

References AICompany::COMPANY_INVALID, GetTileOwner(), IsTileType(), IsValidTile(), MP_HOUSE, MP_INDUSTRY, and AICompany::ResolveCompanyID().

bool AITile::HasTransportType | ( | TileIndex | tile,
|  | TransportType | transport_type |
| ) |  |  | `[static]`

Checks whether the given tile contains parts suitable for the given TransportType.

Parameters:

  | tile | The tile to check.
  | transport_type | The TransportType to check against.

Precondition:
  AIMap::IsValidTile(tile).

Note:
  Returns false on tiles with roadworks and on road tiles with only a single piece of road as these tiles cannot be used to transport anything on. It furthermore returns true on some coast tile for TRANSPORT_WATER because ships can navigate over them.

Returns:
  True if and only if the tile has the given TransportType.

Definition at line 149 of file ai_tile.cpp.

References GetTileTrackStatus(), IsValidTile(), TRACKDIR_BIT_NONE, and TrackStatusToTrackdirBits().

Referenced by AIRail::GetRailType().

int32 AITile::GetCargoAcceptance | ( | TileIndex | tile,
|  | CargoID | cargo_type,
|  | uint | width,
|  | uint | height,
|  | uint | radius |
| ) |  |  | `[static]`

Check how much cargo this tile accepts.

It creates a radius around the tile, and adds up all acceptance of this cargo.

Parameters:

  | tile | The tile to check on.
  | cargo_type | The cargo to check the acceptance of.
  | width | The width of the station.
  | height | The height of the station.
  | radius | The radius of the station.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  Value below 8 means no acceptance; the more the better.

Definition at line 156 of file ai_tile.cpp.

References _settings_game, CA_UNMODIFIED, GetAcceptanceAroundTiles(), IsValidTile(), StationSettings::modified_catchment, and GameSettings::station.

int32 AITile::GetCargoProduction | ( | TileIndex | tile,
|  | CargoID | cargo_type,
|  | uint | width,
|  | uint | height,
|  | uint | radius |
| ) |  |  | `[static]`

Checks how many tiles in the radius produces this cargo.

It creates a radius around the tile, and adds up all tiles that produce this cargo.

Parameters:

  | tile | The tile to check on.
  | cargo_type | The cargo to check the production of.
  | width | The width of the station.
  | height | The height of the station.
  | radius | The radius of the station.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  The tiles that produce this cargo within radius of the tile.

Note:
  Town(houses) are not included in the value.

Definition at line 165 of file ai_tile.cpp.

References _settings_game, CA_UNMODIFIED, GetProductionAroundTiles(), IsValidTile(), StationSettings::modified_catchment, and GameSettings::station.

int32 AITile::GetDistanceManhattanToTile | ( | TileIndex | tile_from,
|  | TileIndex | tile_to |
| ) |  |  | `[static]`

Get the manhattan distance from the tile to the tile.

Parameters:

  | tile_from | The tile to get the distance to.
  | tile_to | The tile to get the distance to.

Returns:
  The distance between the two tiles.

Definition at line 174 of file ai_tile.cpp.

References AIMap::DistanceManhattan().

int32 AITile::GetDistanceSquareToTile | ( | TileIndex | tile_from,
|  | TileIndex | tile_to |
| ) |  |  | `[static]`

Get the square distance from the tile to the tile.

Parameters:

  | tile_from | The tile to get the distance to.
  | tile_to | The tile to get the distance to.

Returns:
  The distance between the two tiles.

Definition at line 179 of file ai_tile.cpp.

References AIMap::DistanceSquare().

bool AITile::RaiseTile | ( | TileIndex | tile,
|  | int32 | slope |
| ) |  |  | `[static]`

Raise the given corners of the tile.

The corners can be combined, for example: SLOPE_N | SLOPE_W (= SLOPE_NW)

Parameters:

  | tile | The tile to raise.
  | slope | Corners to raise (SLOPE_xxx).

Precondition:
  tile < AIMap::GetMapSize().

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_TOO_CLOSE_TO_EDGE |
  | AITile::ERR_TILE_TOO_HIGH |

Returns:
  0 means failed, 1 means success.

Definition at line 184 of file ai_tile.cpp.

References CMD_TERRAFORM_LAND, AIObject::DoCommand(), EnforcePrecondition, and MapSize().

bool AITile::LowerTile | ( | TileIndex | tile,
|  | int32 | slope |
| ) |  |  | `[static]`

Lower the given corners of the tile.

The corners can be combined, for example: SLOPE_N | SLOPE_W (= SLOPE_NW)

Parameters:

  | tile | The tile to lower.
  | slope | Corners to lower (SLOPE_xxx).

Precondition:
  tile < AIMap::GetMapSize().

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_TOO_CLOSE_TO_EDGE |
  | AITile::ERR_TILE_TOO_LOW |

Returns:
  0 means failed, 1 means success.

Definition at line 191 of file ai_tile.cpp.

References CMD_TERRAFORM_LAND, AIObject::DoCommand(), EnforcePrecondition, and MapSize().

bool AITile::LevelTiles | ( | TileIndex | start_tile,
|  | TileIndex | end_tile |
| ) |  |  | `[static]`

Level all tiles in the rectangle between start_tile and end_tile so they are at the same height.

All tiles will be raised or lowered until they are at height AITile::GetHeight(start_tile).

Parameters:

  | start_tile | One corner of the rectangle to level.
  | end_tile | The opposite corner of the rectangle.

Precondition:
  start_tile < AIMap::GetMapSize().

  end_tile < AIMap::GetMapSize().

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_TOO_CLOSE_TO_EDGE |

Returns:
  True if and only if the area was completely leveled.

Note:
  Even if leveling some part fails, some other part may have been succesfully leveled already.

  This function may return true in AITestMode, although it fails in AIExecMode.

Definition at line 198 of file ai_tile.cpp.

References CMD_LEVEL_LAND, AIObject::DoCommand(), EnforcePrecondition, and MapSize().

bool AITile::DemolishTile | ( | TileIndex | tile | ) | `[static]`

Destroy everything on the given tile.

Parameters:

  | tile | The tile to demolish.

Precondition:
  AIMap::IsValidTile(tile).

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |

Returns:
  True if and only if the tile was demolished.

Definition at line 206 of file ai_tile.cpp.

References CMD_LANDSCAPE_CLEAR, AIObject::DoCommand(), EnforcePrecondition, and IsValidTile().

bool AITile::PlantTree | ( | TileIndex | tile | ) | `[static]`

Create a random tree on a tile.

Parameters:

  | tile | The tile to build a tree on.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if a tree was added on the tile.

Definition at line 213 of file ai_tile.cpp.

References CMD_PLANT_TREE, AIObject::DoCommand(), EnforcePrecondition, and IsValidTile().

bool AITile::PlantTreeRectangle | ( | TileIndex | tile,
|  | uint | width,
|  | uint | height |
| ) |  |  | `[static]`

Create a random tree on a rectangle of tiles.

Parameters:

  | tile | The top left tile of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.

Precondition:
  AIMap::IsValidTile(tile).

  width >= 1 && width <= 20.

  height >= 1 && height <= 20.

Returns:
  True if and only if a tree was added on any of the tiles in the rectangle.

Definition at line 220 of file ai_tile.cpp.

References CMD_PLANT_TREE, AIObject::DoCommand(), EnforcePrecondition, IsValidTile(), and TileDiffXY().

bool AITile::IsWithinTownInfluence | ( | TileIndex | tile,
|  | TownID | town_id |
| ) |  |  | `[static]`

Find out if this tile is within the rating influence of a town.

Stations on this tile influence the rating of the town.

Parameters:

  | tile | The tile to check.
  | town_id | The town to check.

Returns:
  True if the tile is within the rating influence of the town.

Definition at line 230 of file ai_tile.cpp.

References AITown::IsWithinTownInfluence().

TownID AITile::GetClosestTown | ( | TileIndex | tile | ) | `[static]`

Find the town that is closest to a tile.

Stations you build at this tile will belong to this town.

Parameters:

  | tile | The tile to check.

Returns:
  The TownID of the town closest to the tile.

Definition at line 235 of file ai_tile.cpp.

References IsValidTile().

The documentation for this class was generated from the following files:

- src/ai/api/ai_tile.hpp
- src/ai/api/ai_tile.cpp