# AIMap Class Reference

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

`#include <ai_map.hpp>`

Inheritance diagram for AIMap:

## Static Public Member Functions
static const char * | GetClassName ()
static bool | IsValidTile (TileIndex tile)
| Checks whether the given tile is valid.
static TileIndex | GetMapSize ()
| Gets the number of tiles in the map.
static uint32 | GetMapSizeX ()
| Gets the amount of tiles along the SW and NE border.
static uint32 | GetMapSizeY ()
| Gets the amount of tiles along the SE and NW border.
static int32 | GetTileX (TileIndex tile)
| Gets the place along the SW/NE border (X-value).
static int32 | GetTileY (TileIndex tile)
| Gets the place along the SE/NW border (Y-value).
static TileIndex | GetTileIndex (uint32 x, uint32 y)
| Gets the TileIndex given a x,y-coordinate.
static int32 | DistanceManhattan (TileIndex tile_from, TileIndex tile_to)
| Calculates the Manhattan distance; the difference of the X and Y added together.
static int32 | DistanceMax (TileIndex tile_from, TileIndex tile_to)
| Calculates the distance between two tiles via 1D calculation.
static int32 | DistanceSquare (TileIndex tile_from, TileIndex tile_to)
| The squared distance between the two tiles.
static int32 | DistanceFromEdge (TileIndex tile)
| Calculates the shortest distance to the edge.
## Static Public Attributes
static const int | TILE_INVALID = (int)INVALID_TILE
| Invalid TileIndex.

## Detailed Description

Class that handles all map related functions.

Definition at line 21 of file ai_map.hpp.

## Member Function Documentation

int32 AIMap::DistanceFromEdge | ( | TileIndex | tile | ) | `[static]`

Calculates the shortest distance to the edge.

Parameters:

  | tile | From where the distance has to be calculated.

Precondition:
  IsValidTile(tile).

Returns:
  The distances to the closest edge.

Definition at line 70 of file ai_map.cpp.

References IsValidTile().

int32 AIMap::DistanceManhattan | ( | TileIndex | tile_from,
|  | TileIndex | tile_to |
| ) |  |  | `[static]`

Calculates the Manhattan distance; the difference of the X and Y added together.

Parameters:

  | tile_from | The start tile.
  | tile_to | The destination tile.

Precondition:
  IsValidTile(tile_from).
  IsValidTile(tile_to).

Returns:
  The Manhattan distance between the tiles.

Definition at line 52 of file ai_map.cpp.

References IsValidTile().

Referenced by AIRail::AreTilesConnected(), AIRail::BuildSignal(), AIRail::GetSignalType(), and AIRail::RemoveSignal().

int32 AIMap::DistanceMax | ( | TileIndex | tile_from,
|  | TileIndex | tile_to |
| ) |  |  | `[static]`

Calculates the distance between two tiles via 1D calculation.

This means the distance between X or the distance between Y, depending on which one is bigger.

Parameters:

  | tile_from | The start tile.
  | tile_to | The destination tile.

Precondition:
  IsValidTile(tile_from).
  IsValidTile(tile_to).

Returns:
  The maximum distance between the tiles.

Definition at line 58 of file ai_map.cpp.

References IsValidTile().

int32 AIMap::DistanceSquare | ( | TileIndex | tile_from,
|  | TileIndex | tile_to |
| ) |  |  | `[static]`

The squared distance between the two tiles.

This is the distance is the length of the shortest straight line between both points.

Parameters:

  | tile_from | The start tile.
  | tile_to | The destination tile.

Precondition:
  IsValidTile(tile_from).
  IsValidTile(tile_to).

Returns:
  The squared distance between the tiles.

Definition at line 64 of file ai_map.cpp.

References IsValidTile().

TileIndex AIMap::GetMapSize | ( |  | ) | `[static]`

Gets the number of tiles in the map.

Returns:
  The size of the map in tiles.

Postcondition:
  Return value is always positive.

Definition at line 20 of file ai_map.cpp.

References MapSize().

uint32 AIMap::GetMapSizeX | ( |  | ) | `[static]`

Gets the amount of tiles along the SW and NE border.

Returns:
  The length along the SW and NE borders.

Postcondition:
  Return value is always positive.

Definition at line 25 of file ai_map.cpp.

References MapSizeX().

uint32 AIMap::GetMapSizeY | ( |  | ) | `[static]`

Gets the amount of tiles along the SE and NW border.

Returns:
  The length along the SE and NW borders.

Postcondition:
  Return value is always positive.

Definition at line 30 of file ai_map.cpp.

References MapSizeY().

TileIndex AIMap::GetTileIndex | ( | uint32 | x,
|  | uint32 | y |
| ) |  |  | `[static]`

Gets the TileIndex given a x,y-coordinate.

Parameters:

  | x | The X coordinate.
  | y | The Y coordinate.

Precondition:
  x < GetMapSizeX().
  y < GetMapSizeY().

Returns:
  The TileIndex for the given (x,y) coordinate.

Definition at line 47 of file ai_map.cpp.

References TileXY().

Referenced by AITile::IsBuildableRectangle().

int32 AIMap::GetTileX | ( | TileIndex | tile | ) | `[static]`

Gets the place along the SW/NE border (X-value).

Parameters:

  | tile | The tile to get the X-value of.

Precondition:
  IsValidTile(tile).

Returns:
  The X-value.

Postcondition:
  Return value is always lower than GetMapSizeX().

Definition at line 35 of file ai_map.cpp.

References IsValidTile(), and TileX().

Referenced by AITile::IsBuildableRectangle().

int32 AIMap::GetTileY | ( | TileIndex | tile | ) | `[static]`

Gets the place along the SE/NW border (Y-value).

Parameters:

  | tile | The tile to get the Y-value of.

Precondition:
  IsValidTile(tile).

Returns:
  The Y-value.

Postcondition:
  Return value is always lower than GetMapSizeY().

Definition at line 41 of file ai_map.cpp.

References IsValidTile(), and TileY().

Referenced by AITile::IsBuildableRectangle().

bool AIMap::IsValidTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is valid.

Parameters:

  | tile | The tile to check.

Returns:
  True is the tile it within the boundaries of the map.

Definition at line 15 of file ai_map.cpp.

Referenced by AIVehicleList_Depot::AIVehicleList_Depot(), AIIndustryType::BuildIndustry(), DistanceFromEdge(), DistanceManhattan(), DistanceMax(), DistanceSquare(), GetTileX(), GetTileY(), and AIRoad::HasRoadType().

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

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