OpenTTD AI API  20240424-master-g9121770582
Static Public Member Functions | Static Public Attributes
AIMap Class Reference

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

Inheritance diagram for AIMap:

Static Public Member Functions

static bool IsValidTile (TileIndex tile)
 Checks whether the given tile is valid. More...
 
static SQInteger GetMapSize ()
 Gets the number of tiles in the map. More...
 
static SQInteger GetMapSizeX ()
 Gets the amount of tiles along the SW and NE border. More...
 
static SQInteger GetMapSizeY ()
 Gets the amount of tiles along the SE and NW border. More...
 
static SQInteger GetTileX (TileIndex tile)
 Gets the place along the SW/NE border (X-value). More...
 
static SQInteger GetTileY (TileIndex tile)
 Gets the place along the SE/NW border (Y-value). More...
 
static TileIndex GetTileIndex (SQInteger x, SQInteger y)
 Gets the TileIndex given a x,y-coordinate. More...
 
static SQInteger DistanceManhattan (TileIndex tile_from, TileIndex tile_to)
 Calculates the Manhattan distance; the difference of the X and Y added together. More...
 
static SQInteger DistanceMax (TileIndex tile_from, TileIndex tile_to)
 Calculates the distance between two tiles via 1D calculation. More...
 
static SQInteger DistanceSquare (TileIndex tile_from, TileIndex tile_to)
 The squared distance between the two tiles. More...
 
static SQInteger DistanceFromEdge (TileIndex tile)
 Calculates the shortest distance to the edge. More...
 

Static Public Attributes

static const int TILE_INVALID = INVALID_TILE.base()
 Invalid TileIndex.
 

Detailed Description

Class that handles all map related functions.

Member Function Documentation

◆ DistanceFromEdge()

static SQInteger AIMap::DistanceFromEdge ( TileIndex  tile)
static

Calculates the shortest distance to the edge.

Parameters
tileFrom where the distance has to be calculated.
Precondition
IsValidTile(tile).
Returns
The distances to the closest edge.

◆ DistanceManhattan()

static SQInteger AIMap::DistanceManhattan ( TileIndex  tile_from,
TileIndex  tile_to 
)
static

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

Parameters
tile_fromThe start tile.
tile_toThe destination tile.
Precondition
IsValidTile(tile_from).
IsValidTile(tile_to).
Returns
The Manhattan distance between the tiles.

◆ DistanceMax()

static SQInteger 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_fromThe start tile.
tile_toThe destination tile.
Precondition
IsValidTile(tile_from).
IsValidTile(tile_to).
Returns
The maximum distance between the tiles.

◆ DistanceSquare()

static SQInteger 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_fromThe start tile.
tile_toThe destination tile.
Precondition
IsValidTile(tile_from).
IsValidTile(tile_to).
Returns
The squared distance between the tiles.

◆ GetMapSize()

static SQInteger 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.

◆ GetMapSizeX()

static SQInteger 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.

◆ GetMapSizeY()

static SQInteger 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.

◆ GetTileIndex()

static TileIndex AIMap::GetTileIndex ( SQInteger  x,
SQInteger  y 
)
static

Gets the TileIndex given a x,y-coordinate.

Parameters
xThe X coordinate.
yThe Y coordinate.
Returns
The TileIndex for the given (x,y) coordinate.
Postcondition
When 0 <= x && x < GetMapSizeX() && 0 <= y && y < GetMapSizeY(), then a valid tile index is returned. Otherwise it may be invalid, but could be used to calculated neighbouring tiles, e.g. tile + AIMap.GetTileIndex(-1, -1) gets the tile index of the tile to the north. But be aware that even when tile is a valid tile, the result might not be a valid tile.

◆ GetTileX()

static SQInteger AIMap::GetTileX ( TileIndex  tile)
static

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

Parameters
tileThe tile to get the X-value of.
Precondition
IsValidTile(tile).
Returns
The X-value.
Postcondition
Return value is always lower than GetMapSizeX().

◆ GetTileY()

static SQInteger AIMap::GetTileY ( TileIndex  tile)
static

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

Parameters
tileThe tile to get the Y-value of.
Precondition
IsValidTile(tile).
Returns
The Y-value.
Postcondition
Return value is always lower than GetMapSizeY().

◆ IsValidTile()

static bool AIMap::IsValidTile ( TileIndex  tile)
static

Checks whether the given tile is valid.

Parameters
tileThe tile to check.
Returns
True is the tile it within the boundaries of the map.