# AIRail Class Reference

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

`#include <ai_rail.hpp>`

Inheritance diagram for AIRail:

## Public Types
enum | ErrorMessages { ERR_RAIL_BASE = AIError::ERR_CAT_RAIL << AIError::ERR_CAT_BIT_SIZE, ERR_CROSSING_ON_ONEWAY_ROAD, ERR_UNSUITABLE_TRACK, ERR_NONUNIFORM_STATIONS_DISABLED }
| All rail related error messages. More...
enum | RailType { RAILTYPE_INVALID = 0xFF }
| Types of rail known to the game. More...
enum | RailTrack { RAILTRACK_NE_SW = 1 << 0, RAILTRACK_NW_SE = 1 << 1, RAILTRACK_NW_NE = 1 << 2, RAILTRACK_SW_SE = 1 << 3, RAILTRACK_NW_SW = 1 << 4, RAILTRACK_NE_SE = 1 << 5, RAILTRACK_INVALID = 0xFF }
| A bitmap with all possible rail tracks on a tile. More...
enum | SignalType { SIGNALTYPE_NORMAL = 0, SIGNALTYPE_ENTRY = 1, SIGNALTYPE_EXIT = 2, SIGNALTYPE_COMBO = 3, SIGNALTYPE_PBS = 4, SIGNALTYPE_PBS_ONEWAY = 5, SIGNALTYPE_TWOWAY = 8, SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY, SIGNALTYPE_ENTRY_TWOWAY = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY, SIGNALTYPE_EXIT_TWOWAY = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY, SIGNALTYPE_COMBO_TWOWAY = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY, SIGNALTYPE_NONE = 0xFF }
| Types of signal known to the game. More...
enum | BuildType { BT_TRACK, BT_SIGNAL, BT_DEPOT, BT_STATION, BT_WAYPOINT }
| Types of rail-related objects in the game. More...
## Static Public Member Functions
static const char * | GetClassName ()
static bool | IsRailTile (TileIndex tile)
| Checks whether the given tile is actually a tile with rail that can be used to traverse a tile.
static bool | IsLevelCrossingTile (TileIndex tile)
| Checks whether there is a road / rail crossing on a tile.
static bool | IsRailDepotTile (TileIndex tile)
| Checks whether the given tile is actually a tile with a rail depot.
static bool | IsRailStationTile (TileIndex tile)
| Checks whether the given tile is actually a tile with a rail station.
static bool | IsRailWaypointTile (TileIndex tile)
| Checks whether the given tile is actually a tile with a rail waypoint.
static bool | IsRailTypeAvailable (RailType rail_type)
| Check if a given RailType is available.
static RailType | GetCurrentRailType ()
| Get the current RailType set for all AIRail functions.
static void | SetCurrentRailType (RailType rail_type)
| Set the RailType for all further AIRail functions.
static bool | TrainCanRunOnRail (AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type)
| Check if a train build for a rail type can run on another rail type.
static bool | TrainHasPowerOnRail (AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type)
| Check if a train build for a rail type has power on another rail type.
static RailType | GetRailType (TileIndex tile)
| Get the RailType that is used on a tile.
static bool | ConvertRailType (TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to)
| Convert the tracks on all tiles within a rectangle to another RailType.
static TileIndex | GetRailDepotFrontTile (TileIndex depot)
| Gets the tile in front of a rail depot.
static RailTrack | GetRailStationDirection (TileIndex tile)
| Gets the direction of a rail station tile.
static bool | BuildRailDepot (TileIndex tile, TileIndex front)
| Builds a rail depot.
static bool | BuildRailStation (TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id)
| Build a rail station.
static bool | BuildNewGRFRailStation (TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station)
| Build a NewGRF rail station.
static bool | BuildRailWaypoint (TileIndex tile)
| Build a rail waypoint.
static bool | RemoveRailWaypointTileRectangle (TileIndex tile, TileIndex tile2, bool keep_rail)
| Remove all rail waypoint pieces within a rectangle on the map.
static bool | RemoveRailStationTileRectangle (TileIndex tile, TileIndex tile2, bool keep_rail)
| Remove all rail station platform pieces within a rectangle on the map.
static uint | GetRailTracks (TileIndex tile)
| Get all RailTracks on the given tile.
static bool | BuildRailTrack (TileIndex tile, RailTrack rail_track)
| Build rail on the given tile.
static bool | RemoveRailTrack (TileIndex tile, RailTrack rail_track)
| Remove rail on the given tile.
static bool | AreTilesConnected (TileIndex from, TileIndex tile, TileIndex to)
| Check if a tile connects two adjacent tiles.
static bool | BuildRail (TileIndex from, TileIndex tile, TileIndex to)
| Build a rail connection between two tiles.
static bool | RemoveRail (TileIndex from, TileIndex tile, TileIndex to)
| Remove a rail connection between two tiles.
static SignalType | GetSignalType (TileIndex tile, TileIndex front)
| Get the SignalType of the signal on a tile or SIGNALTYPE_NONE if there is no signal.
static bool | BuildSignal (TileIndex tile, TileIndex front, SignalType signal)
| Build a signal on a tile.
static bool | RemoveSignal (TileIndex tile, TileIndex front)
| Remove a signal.
static Money | GetBuildCost (RailType railtype, BuildType build_type)
| Get the baseprice of building a rail-related object.

## Detailed Description

Class that handles all rail related functions.

Definition at line 22 of file ai_rail.hpp.

## Member Enumeration Documentation

enum AIRail::BuildType

Types of rail-related objects in the game.

Enumerator:

  BT_TRACK | Build a track.
  BT_SIGNAL | Build a signal.
  BT_DEPOT | Build a depot.
  BT_STATION | Build a station.
  BT_WAYPOINT | Build a rail waypoint.

Definition at line 87 of file ai_rail.hpp.

enum AIRail::ErrorMessages

All rail related error messages.

Enumerator:

  ERR_RAIL_BASE | Base for rail building / maintaining errors.
  ERR_CROSSING_ON_ONEWAY_ROAD | One-way roads cannot have crossings.
  ERR_UNSUITABLE_TRACK | Track not suitable for signals.
  ERR_NONUNIFORM_STATIONS_DISABLED | Non-uniform stations is diabled.

Definition at line 29 of file ai_rail.hpp.

enum AIRail::RailTrack

A bitmap with all possible rail tracks on a tile.

Enumerator:

  RAILTRACK_NE_SW | Track along the x-axis (north-east to south-west).
  RAILTRACK_NW_SE | Track along the y-axis (north-west to south-east).
  RAILTRACK_NW_NE | Track in the upper corner of the tile (north).
  RAILTRACK_SW_SE | Track in the lower corner of the tile (south).
  RAILTRACK_NW_SW | Track in the left corner of the tile (west).
  RAILTRACK_NE_SE | Track in the right corner of the tile (east).
  RAILTRACK_INVALID | Flag for an invalid track.

Definition at line 54 of file ai_rail.hpp.

enum AIRail::RailType

Types of rail known to the game.

Enumerator:

  RAILTYPE_INVALID | Invalid RailType.

Definition at line 46 of file ai_rail.hpp.

enum AIRail::SignalType

Types of signal known to the game.

Enumerator:

  SIGNALTYPE_NORMAL | Normal signal.
  SIGNALTYPE_ENTRY | Entry presignal.
  SIGNALTYPE_EXIT | Exit signal.
  SIGNALTYPE_COMBO | Combo signal.
  SIGNALTYPE_PBS | Normal PBS signal.
  SIGNALTYPE_PBS_ONEWAY | No-entry PBS signal.
  SIGNALTYPE_TWOWAY | Bit mask for twoway signal.
  SIGNALTYPE_NORMAL_TWOWAY | Normal twoway signal.
  SIGNALTYPE_ENTRY_TWOWAY | Entry twoway signal.
  SIGNALTYPE_EXIT_TWOWAY | Exit twoway signal.
  SIGNALTYPE_COMBO_TWOWAY | Combo twoway signal.
  SIGNALTYPE_NONE | No signal.

Definition at line 68 of file ai_rail.hpp.

## Member Function Documentation

bool AIRail::AreTilesConnected | ( | TileIndex | from,
|  | TileIndex | tile,
|  | TileIndex | to |
| ) |  |  | `[static]`

Check if a tile connects two adjacent tiles.

Parameters:

  | from | The first tile to connect.
  | tile | The tile that is checked.
  | to | The second tile to connect.

Precondition:
  from != to.
  AIMap::DistanceManhattan(from, tile) == 1.
  AIMap::DistanceManhattan(to, tile) == 1.

Returns:
  True if 'tile' connects 'from' and 'to'.

Definition at line 239 of file ai_rail.cpp.

References AIMap::DistanceManhattan(), GetRailTracks(), IsRailTile(), MapSizeX(), RAILTRACK_NE_SE, RAILTRACK_NE_SW, RAILTRACK_NW_NE, RAILTRACK_NW_SE, RAILTRACK_NW_SW, RAILTRACK_SW_SE, and Swap().

bool AIRail::BuildNewGRFRailStation | ( | TileIndex | tile,
|  | RailTrack | direction,
|  | uint | num_platforms,
|  | uint | platform_length,
|  | StationID | station_id,
|  | CargoID | cargo_id,
|  | IndustryType | source_industry,
|  | IndustryType | goal_industry,
|  | int | distance,
|  | bool | source_station |
| ) |  |  | `[static]`

Build a NewGRF rail station.

This calls callback 18 to let a NewGRF provide the station class / id to build, so we don't end up with only the default stations on the map.

Parameters:

  | tile | Place to build the station.
  | direction | The direction to build the station.
  | num_platforms | The number of platforms to build.
  | platform_length | The length of each platform.
  | station_id | The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT.
  | cargo_id | The CargoID of the cargo that will be transported from / to this station.
  | source_industry | The IndustryType of the industry you'll transport goods from.
  | goal_industry | The IndustryType of the industry you'll transport goods to.
  | distance | The manhattan distance you'll transport the cargo over.
  | source_station | True if this is the source station, false otherwise.

Precondition:
  IsRailTypeAvailable(GetCurrentRailType()).
  AIMap::IsValidTile(tile).
  direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW.
  num_platforms > 0 && num_platforms <= 255.
  platform_length > 0 && platform_length <= 255.
  station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id).

Exceptions:

  | AIError::ERR_OWNED_BY_ANOTHER_COMPANY |
  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_FLAT_LAND_REQUIRED |
  | AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION |
  | AIStation::ERR_STATION_TOO_MANY_STATIONS |
  | AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN |

Returns:
  Whether the station has been/can be build or not.

Definition at line 153 of file ai_rail.cpp.

References AICE_STATION_GET_STATION_ID, CALLBACK_FAILED, CMD_BUILD_RAIL_STATION, AIObject::DoCommand(), EnforcePrecondition, GetAiPurchaseCallbackResult(), GetCurrentRailType(), GetCustomStationSpecByGrf(), IsRailTypeAvailable(), AIStation::IsValidStation(), IsValidTile(), min(), RAILTRACK_NE_SW, RAILTRACK_NW_SE, StationSpec::sclass, AIBaseStation::STATION_JOIN_ADJACENT, and AIBaseStation::STATION_NEW.

bool AIRail::BuildRail | ( | TileIndex | from,
|  | TileIndex | tile,
|  | TileIndex | to |
| ) |  |  | `[static]`

Build a rail connection between two tiles.

Parameters:

  | from | The tile just before the tile to build on.
  | tile | The first tile to build on.
  | to | The tile just after the last tile to build on.

Precondition:
  from != to.
  AIMap::DistanceManhattan(from, tile) == 1.
  AIMap::DistanceManhattan(to, tile) >= 1.
  (abs(abs(AIMap::GetTileX(to) - AIMap::GetTileX(tile)) - abs(AIMap::GetTileY(to) - AIMap::GetTileY(tile))) <= 1) || (AIMap::GetTileX(from) == AIMap::GetTileX(tile) && AIMap::GetTileX(tile) == AIMap::GetTileX(to)) || (AIMap::GetTileY(from) == AIMap::GetTileY(tile) && AIMap::GetTileY(tile) == AIMap::GetTileY(to)).
  IsRailTypeAvailable(GetCurrentRailType()).

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_LAND_SLOPED_WRONG |
  | AIRail::ERR_CROSSING_ON_ONEWAY_ROAD |
  | AIRoad::ERR_ROAD_WORKS_IN_PROGRESS |
  | AIError::ERR_ALREADY_BUILT |

Note:
  Construction will fail if an obstacle is found between the start and end tiles.

Returns:
  Whether the rail has been/can be build or not.

Definition at line 322 of file ai_rail.cpp.

References abs(), CMD_BUILD_RAILROAD_TRACK, DistanceManhattan(), AIObject::DoCommand(), EnforcePrecondition, GetCurrentRailType(), IsRailTypeAvailable(), IsValidTile(), SimulateDrag(), TileX(), and TileY().

bool AIRail::BuildRailDepot | ( | TileIndex | tile,
|  | TileIndex | front |
| ) |  |  | `[static]`

Builds a rail depot.

Parameters:

  | tile | Place to build the depot.
  | front | The tile exactly in front of the depot.

Precondition:
  AIMap::IsValidTile(tile).
  AIMap::IsValidTile(front).
  'tile' is not equal to 'front', but in a straight line of it.
  IsRailTypeAvailable(GetCurrentRailType()).

Exceptions:

  | AIError::ERR_FLAT_LAND_REQUIRED |
  | AIError::ERR_AREA_NOT_CLEAR |

Returns:
  Whether the rail depot has been/can be build or not.

Definition at line 125 of file ai_rail.cpp.

References CMD_BUILD_TRAIN_DEPOT, AIObject::DoCommand(), EnforcePrecondition, GetCurrentRailType(), AIObject::GetRailType(), IsRailTypeAvailable(), IsValidTile(), TileX(), and TileY().

bool AIRail::BuildRailStation | ( | TileIndex | tile,
|  | RailTrack | direction,
|  | uint | num_platforms,
|  | uint | platform_length,
|  | StationID | station_id |
| ) |  |  | `[static]`

Build a rail station.

Parameters:

  | tile | Place to build the station.
  | direction | The direction to build the station.
  | num_platforms | The number of platforms to build.
  | platform_length | The length of each platform.
  | station_id | The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT.

Precondition:
  IsRailTypeAvailable(GetCurrentRailType()).
  AIMap::IsValidTile(tile).
  direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW.
  num_platforms > 0 && num_platforms <= 255.
  platform_length > 0 && platform_length <= 255.
  station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id).

Exceptions:

  | AIError::ERR_OWNED_BY_ANOTHER_COMPANY |
  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_FLAT_LAND_REQUIRED |
  | AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION |
  | AIStation::ERR_STATION_TOO_MANY_STATIONS |
  | AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN |

Returns:
  Whether the station has been/can be build or not.

Definition at line 138 of file ai_rail.cpp.

References CMD_BUILD_RAIL_STATION, AIObject::DoCommand(), EnforcePrecondition, GetCurrentRailType(), IsRailTypeAvailable(), AIStation::IsValidStation(), IsValidTile(), RAILTRACK_NE_SW, RAILTRACK_NW_SE, AIBaseStation::STATION_JOIN_ADJACENT, and AIBaseStation::STATION_NEW.

bool AIRail::BuildRailTrack | ( | TileIndex | tile,
|  | RailTrack | rail_track |
| ) |  |  | `[static]`

Build rail on the given tile.

Parameters:

  | tile | The tile to build on.
  | rail_track | The RailTrack to build.

Precondition:
  AIMap::IsValidTile(tile).
  IsRailTypeAvailable(GetCurrentRailType()).

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_LAND_SLOPED_WRONG |
  | AIRoad::ERR_ROAD_WORKS_IN_PROGRESS |
  | AIRail::ERR_CROSSING_ON_ONEWAY_ROAD |
  | AIError::ERR_ALREADY_BUILT |

Returns:
  Whether the rail has been/can be build or not.

Note:
  You can only build a single track with this function so do not use the values from RailTrack as bitmask.

Definition at line 218 of file ai_rail.cpp.

References CMD_BUILD_RAILROAD_TRACK, AIObject::DoCommand(), EnforcePrecondition, FindFirstTrack(), GetCurrentRailType(), IsRailTypeAvailable(), IsValidTile(), KillFirstBit(), and TRACK_BIT_ALL.

bool AIRail::BuildRailWaypoint | ( | TileIndex | tile | ) | `[static]`

Build a rail waypoint.

Parameters:

  | tile | Place to build the waypoint.

Precondition:
  AIMap::IsValidTile(tile).
  IsRailTile(tile).
  GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE.
  IsRailTypeAvailable(GetCurrentRailType()).

Exceptions:

  | AIError::ERR_FLAT_LAND_REQUIRED |

Returns:
  Whether the rail waypoint has been/can be build or not.

Definition at line 182 of file ai_rail.cpp.

References AXIS_X, AXIS_Y, CMD_BUILD_RAIL_WAYPOINT, AIObject::DoCommand(), EnforcePrecondition, GetCurrentRailType(), GetRailTracks(), IsRailTile(), IsRailTypeAvailable(), IsValidTile(), RAILTRACK_NE_SW, RAILTRACK_NW_SE, and STAT_CLASS_WAYP.

bool AIRail::BuildSignal | ( | TileIndex | tile,
|  | TileIndex | front,
|  | SignalType | signal |
| ) |  |  | `[static]`

Build a signal on a tile.

Parameters:

  | tile | The tile to build on.
  | front | The tile in front of the signal.
  | signal | The SignalType to build.

Precondition:
  AIMap::DistanceManhattan(tile, front) == 1.
  IsRailTile(tile) && !IsRailStationTile(tile) && !IsRailWaypointTile(tile).

Exceptions:

  | AIRail::ERR_UNSUITABLE_TRACK |

Returns:
  Whether the signal has been/can be build or not.

Definition at line 412 of file ai_rail.cpp.

References CMD_BUILD_SIGNALS, AIMap::DistanceManhattan(), AIObject::DoCommand(), EnforcePrecondition, GetRailTracks(), INVALID_TRACK, IsPlainRailTile(), IsValidSignalType(), NUM_TRACK_DIRECTIONS, AIRailSignalData::signal_cycles, SIGNALTYPE_PBS, SIGNALTYPE_PBS_ONEWAY, SIGNALTYPE_TWOWAY, TileX(), TileY(), AIRailSignalData::track, and TrackToTrackBits().

bool AIRail::ConvertRailType | ( | TileIndex | start_tile,
|  | TileIndex | end_tile,
|  | AIRail::RailType | convert_to |
| ) |  |  | `[static]`

Convert the tracks on all tiles within a rectangle to another RailType.

Parameters:

  | start_tile | One corner of the rectangle.
  | end_tile | The opposite corner of the rectangle.
  | convert_to | The RailType you want to convert the rails to.

Precondition:
  AIMap::IsValidTile(start_tile).
  AIMap::IsValidTile(end_tile).
  IsRailTypeAvailable(convert_to).

Exceptions:

  | AIRail::ERR_UNSUITABLE_TRACK |

Returns:
  Whether at least some rail has been converted succesfully.

Definition at line 102 of file ai_rail.cpp.

References CMD_CONVERT_RAIL, AIObject::DoCommand(), EnforcePrecondition, IsRailTypeAvailable(), and IsValidTile().

Money AIRail::GetBuildCost | ( | RailType | railtype,
|  | BuildType | build_type |
| ) |  |  | `[static]`

Get the baseprice of building a rail-related object.

Parameters:

  | railtype | the railtype that is build (on)
  | build_type | the type of object to build

Precondition:
  IsRailTypeAvailable(railtype)

Returns:
  The baseprice of building the given object.

Definition at line 459 of file ai_rail.cpp.

References BT_DEPOT, BT_SIGNAL, BT_STATION, BT_TRACK, BT_WAYPOINT, GetPrice(), IsRailTypeAvailable(), and RailBuildCost().

AIRail::RailType AIRail::GetCurrentRailType | ( |  | ) | `[static]`

Get the current RailType set for all AIRail functions.

Returns:
  The RailType currently set.

Definition at line 67 of file ai_rail.cpp.

References AIObject::GetRailType().

Referenced by AIBridge::BuildBridge(), BuildNewGRFRailStation(), BuildRail(), BuildRailDepot(), BuildRailStation(), BuildRailTrack(), BuildRailWaypoint(), AITunnel::BuildTunnel(), RemoveRail(), RemoveRailTrack(), and SimulateDrag().

TileIndex AIRail::GetRailDepotFrontTile | ( | TileIndex | depot | ) | `[static]`

Gets the tile in front of a rail depot.

Parameters:

  | depot | The rail depot tile.

Precondition:
  IsRailDepotTile(depot).

Returns:
  The tile in front of the depot.

Definition at line 111 of file ai_rail.cpp.

References GetRailDepotDirection(), INVALID_TILE, IsRailDepotTile(), and TileOffsByDiagDir().

AIRail::RailTrack AIRail::GetRailStationDirection | ( | TileIndex | tile | ) | `[static]`

Gets the direction of a rail station tile.

Parameters:

  | tile | The rail station tile.

Precondition:
  IsRailStationTile(tile).

Returns:
  The direction of the station (either RAILTRACK_NE_SW or RAILTRACK_NW_SE).

Definition at line 118 of file ai_rail.cpp.

References GetRailStationTrackBits(), IsRailStationTile(), and RAILTRACK_INVALID.

uint AIRail::GetRailTracks | ( | TileIndex | tile | ) | `[static]`

Get all RailTracks on the given tile.

Note:
  A depot has no railtracks.

Parameters:

  | tile | The tile to check.

Precondition:
  IsRailTile(tile).

Returns:
  A bitmask of RailTrack with all RailTracks on the tile.

Definition at line 208 of file ai_rail.cpp.

References GetRailStationTrack(), GetTrackBits(), IsLevelCrossingTile(), IsRailDepotTile(), IsRailStationTile(), IsRailTile(), IsRailWaypointTile(), RAILTRACK_INVALID, TRACK_BIT_NONE, and TrackToTrackBits().

Referenced by AreTilesConnected(), BuildRailWaypoint(), BuildSignal(), GetSignalType(), RemoveRailTrack(), and RemoveSignal().

AIRail::RailType AIRail::GetRailType | ( | TileIndex | tile | ) | `[static]`

Get the RailType that is used on a tile.

Parameters:

  | tile | The tile to check.

Precondition:
  AITile::HasTransportType(tile, AITile.TRANSPORT_RAIL).

Returns:
  The RailType that is used on a tile.

Definition at line 95 of file ai_rail.cpp.

References AIObject::GetRailType(), AITile::HasTransportType(), RAILTYPE_INVALID, and AITile::TRANSPORT_RAIL.

AIRail::SignalType AIRail::GetSignalType | ( | TileIndex | tile,
|  | TileIndex | front |
| ) |  |  | `[static]`

Get the SignalType of the signal on a tile or SIGNALTYPE_NONE if there is no signal.

Precondition:
  AIMap::DistanceManhattan(tile, front) == 1.

Parameters:

  | tile | The tile that might have a signal.
  | front | The tile in front of 'tile'.

Returns:
  The SignalType of the signal on 'tile' with it's front to 'front'.

Definition at line 382 of file ai_rail.cpp.

References AIMap::DistanceManhattan(), GetRailTracks(), HasSignalOnTrack(), HasSignalOnTrackdir(), HasSignals(), IsTileType(), MP_RAILWAY, NUM_TRACK_DIRECTIONS, ReverseTrackdir(), SIGNALTYPE_NONE, SIGNALTYPE_TWOWAY, TileX(), TileY(), AIRailSignalData::track, and TrackToTrackBits().

Referenced by RemoveSignal().

bool AIRail::IsLevelCrossingTile | ( | TileIndex | tile | ) | `[static]`

Checks whether there is a road / rail crossing on a tile.

Parameters:

  | tile | The tile to check.

Returns:
  True if and only if there is a road / rail crossing.

Definition at line 32 of file ai_rail.cpp.

References IsValidTile().

Referenced by GetRailTracks(), IsRailTile(), and RemoveRailTrack().

bool AIRail::IsRailDepotTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is actually a tile with a rail depot.

Parameters:

  | tile | The tile to check.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile has a rail depot.

Definition at line 39 of file ai_rail.cpp.

References IsValidTile().

Referenced by GetRailDepotFrontTile(), and GetRailTracks().

bool AIRail::IsRailStationTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is actually a tile with a rail station.

Parameters:

  | tile | The tile to check.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile has a rail station.

Definition at line 46 of file ai_rail.cpp.

References IsValidTile().

Referenced by GetRailStationDirection(), and GetRailTracks().

bool AIRail::IsRailTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is actually a tile with rail that can be used to traverse a tile.

This excludes rail depots but includes stations and waypoints.

Parameters:

  | tile | The tile to check.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile has rail.

Definition at line 24 of file ai_rail.cpp.

References HasStationTileRail(), IsLevelCrossingTile(), IsRailDepot(), IsTileType(), IsValidTile(), and MP_RAILWAY.

Referenced by AreTilesConnected(), BuildRailWaypoint(), and GetRailTracks().

bool AIRail::IsRailTypeAvailable | ( | RailType | rail_type | ) | `[static]`

Check if a given RailType is available.

Parameters:

  | rail_type | The RailType to check for.

Returns:
  True if this RailType can be used.

Definition at line 60 of file ai_rail.cpp.

References HasRailtypeAvail(), RAILTYPE_BEGIN, and RAILTYPE_END.

Referenced by AIBridge::BuildBridge(), BuildNewGRFRailStation(), BuildRail(), BuildRailDepot(), BuildRailStation(), BuildRailTrack(), BuildRailWaypoint(), AITunnel::BuildTunnel(), AIEngine::CanRunOnRail(), ConvertRailType(), GetBuildCost(), AIEngine::HasPowerOnRail(), RemoveRail(), SetCurrentRailType(), TrainCanRunOnRail(), and TrainHasPowerOnRail().

bool AIRail::IsRailWaypointTile | ( | TileIndex | tile | ) | `[static]`

Checks whether the given tile is actually a tile with a rail waypoint.

Parameters:

  | tile | The tile to check.

Precondition:
  AIMap::IsValidTile(tile).

Returns:
  True if and only if the tile has a rail waypoint.

Definition at line 53 of file ai_rail.cpp.

References IsValidTile().

Referenced by GetRailTracks(), and AIWaypoint::GetWaypointID().

bool AIRail::RemoveRail | ( | TileIndex | from,
|  | TileIndex | tile,
|  | TileIndex | to |
| ) |  |  | `[static]`

Remove a rail connection between two tiles.

Parameters:

  | from | The tile just before the tile to remove rail from.
  | tile | The first tile to remove rail from.
  | to | The tile just after the last tile to remove rail from.

Precondition:
  from != to.
  AIMap::DistanceManhattan(from, tile) == 1.
  AIMap::DistanceManhattan(to, tile) >= 1.
  (abs(abs(AIMap::GetTileX(to) - AIMap::GetTileX(tile)) - abs(AIMap::GetTileY(to) - AIMap::GetTileY(tile))) <= 1) || (AIMap::GetTileX(from) == AIMap::GetTileX(tile) && AIMap::GetTileX(tile) == AIMap::GetTileX(to)) || (AIMap::GetTileY(from) == AIMap::GetTileY(tile) && AIMap::GetTileY(tile) == AIMap::GetTileY(to)).

Returns:
  Whether the rail has been/can be removed or not.

Definition at line 339 of file ai_rail.cpp.

References abs(), CMD_REMOVE_RAILROAD_TRACK, DistanceManhattan(), AIObject::DoCommand(), EnforcePrecondition, GetCurrentRailType(), AIObject::GetRailType(), IsRailTypeAvailable(), IsValidTile(), SetCurrentRailType(), SimulateDrag(), TileX(), and TileY().

bool AIRail::RemoveRailStationTileRectangle | ( | TileIndex | tile,
|  | TileIndex | tile2,
|  | bool | keep_rail |
| ) |  |  | `[static]`

Remove all rail station platform pieces within a rectangle on the map.

Parameters:

  | tile | One corner of the rectangle to clear.
  | tile2 | The oppposite corner.
  | keep_rail | Whether to keep the rail after removal.

Precondition:
  IsValidTile(tile).
  IsValidTile(tile2).

Returns:
  Whether at least one tile has been/can be cleared or not.

Definition at line 200 of file ai_rail.cpp.

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

bool AIRail::RemoveRailTrack | ( | TileIndex | tile,
|  | RailTrack | rail_track |
| ) |  |  | `[static]`

Remove rail on the given tile.

Parameters:

  | tile | The tile to remove rail from.
  | rail_track | The RailTrack to remove.

Precondition:
  AIMap::IsValidTile(tile).
  (GetRailTracks(tile) & rail_track) != 0.

Returns:
  Whether the rail has been/can be removed or not.

Note:
  You can only remove a single track with this function so do not use the values from RailTrack as bitmask.

Definition at line 229 of file ai_rail.cpp.

References CMD_REMOVE_RAILROAD_TRACK, AIObject::DoCommand(), EnforcePrecondition, FindFirstTrack(), GetCurrentRailType(), GetRailTracks(), IsLevelCrossingTile(), IsPlainRailTile(), IsValidTile(), and KillFirstBit().

bool AIRail::RemoveRailWaypointTileRectangle | ( | TileIndex | tile,
|  | TileIndex | tile2,
|  | bool | keep_rail |
| ) |  |  | `[static]`

Remove all rail waypoint pieces within a rectangle on the map.

Parameters:

  | tile | One corner of the rectangle to clear.
  | tile2 | The oppposite corner.
  | keep_rail | Whether to keep the rail after removal.

Precondition:
  IsValidTile(tile).
  IsValidTile(tile2).

Returns:
  Whether at least one tile has been/can be cleared or not.

Definition at line 192 of file ai_rail.cpp.

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

bool AIRail::RemoveSignal | ( | TileIndex | tile,
|  | TileIndex | front |
| ) |  |  | `[static]`

Remove a signal.

Parameters:

  | tile | The tile to remove the signal from.
  | front | The tile in front of the signal.

Precondition:
  AIMap::DistanceManhattan(tile, front) == 1.
  GetSignalType(tile, front) != SIGNALTYPE_NONE.

Returns:
  Whether the signal has been/can be removed or not.

Definition at line 441 of file ai_rail.cpp.

References CMD_REMOVE_SIGNALS, AIMap::DistanceManhattan(), AIObject::DoCommand(), EnforcePrecondition, GetRailTracks(), GetSignalType(), INVALID_TRACK, NUM_TRACK_DIRECTIONS, SIGNALTYPE_NONE, TileX(), TileY(), AIRailSignalData::track, and TrackToTrackBits().

void AIRail::SetCurrentRailType | ( | RailType | rail_type | ) | `[static]`

Set the RailType for all further AIRail functions.

Parameters:

  | rail_type | The RailType to set.

Definition at line 72 of file ai_rail.cpp.

References IsRailTypeAvailable(), and AIObject::SetRailType().

Referenced by RemoveRail().

bool AIRail::TrainCanRunOnRail | ( | AIRail::RailType | engine_rail_type,
|  | AIRail::RailType | track_rail_type |
| ) |  |  | `[static]`

Check if a train build for a rail type can run on another rail type.

Parameters:

  | engine_rail_type | The rail type the train is build for.
  | track_rail_type | The type you want to check.

Precondition:
  AIRail::IsRailTypeAvailable(engine_rail_type).
  AIRail::IsRailTypeAvailable(track_rail_type).

Returns:
  Whether a train build for 'engine_rail_type' can run on 'track_rail_type'.

Note:
  Even if a train can run on a RailType that doesn't mean that it'll be able to power the train. Use TrainHasPowerOnRail for that.

Definition at line 79 of file ai_rail.cpp.

References IsCompatibleRail(), and IsRailTypeAvailable().

bool AIRail::TrainHasPowerOnRail | ( | AIRail::RailType | engine_rail_type,
|  | AIRail::RailType | track_rail_type |
| ) |  |  | `[static]`

Check if a train build for a rail type has power on another rail type.

Parameters:

  | engine_rail_type | The rail type the train is build for.
  | track_rail_type | The type you want to check.

Precondition:
  AIRail::IsRailTypeAvailable(engine_rail_type).
  AIRail::IsRailTypeAvailable(track_rail_type).

Returns:
  Whether a train build for 'engine_rail_type' has power on 'track_rail_type'.

Definition at line 87 of file ai_rail.cpp.

References HasPowerOnRail(), and IsRailTypeAvailable().

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

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