# AIVehicle Class Reference

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

`#include <ai_vehicle.hpp>`

Inheritance diagram for AIVehicle:

## Public Types
enum | ErrorMessages { ERR_VEHICLE_BASE = AIError::ERR_CAT_VEHICLE << AIError::ERR_CAT_BIT_SIZE, ERR_VEHICLE_TOO_MANY, ERR_VEHICLE_NOT_AVAILABLE, ERR_VEHICLE_BUILD_DISABLED, ERR_VEHICLE_WRONG_DEPOT, ERR_VEHICLE_CANNOT_SEND_TO_DEPOT, ERR_VEHICLE_CANNOT_START_STOP, ERR_VEHICLE_CANNOT_TURN, ERR_VEHICLE_CANNOT_REFIT, ERR_VEHICLE_IS_DESTROYED, ERR_VEHICLE_NOT_IN_DEPOT, ERR_VEHICLE_IN_FLIGHT, ERR_VEHCILE_NO_POWER }
| All vehicle related error messages. More...
enum | VehicleType { VT_RAIL, VT_ROAD, VT_WATER, VT_AIR, VT_INVALID = 0xFF }
| The type of a vehicle available in the game. More...
enum | VehicleState { VS_RUNNING, VS_STOPPED, VS_IN_DEPOT, VS_AT_STATION, VS_BROKEN, VS_CRASHED, VS_INVALID = 0xFF }
| The different states a vehicle can be in. More...
## Static Public Member Functions
static const char * | GetClassName ()
static bool | IsValidVehicle (VehicleID vehicle_id)
| Checks whether the given vehicle is valid and owned by you.
static int32 | GetNumWagons (VehicleID vehicle_id)
| Get the number of wagons a vehicle has.
static bool | SetName (VehicleID vehicle_id, const char *name)
| Set the name of a vehicle.
static char * | GetName (VehicleID vehicle_id)
| Get the name of a vehicle.
static TileIndex | GetLocation (VehicleID vehicle_id)
| Get the current location of a vehicle.
static EngineID | GetEngineType (VehicleID vehicle_id)
| Get the engine-type of a vehicle.
static EngineID | GetWagonEngineType (VehicleID vehicle_id, int wagon)
| Get the engine-type of a wagon.
static int32 | GetUnitNumber (VehicleID vehicle_id)
| Get the unitnumber of a vehicle.
static int32 | GetAge (VehicleID vehicle_id)
| Get the current age of a vehicle.
static int32 | GetWagonAge (VehicleID vehicle_id, int wagon)
| Get the current age of a second (or third, etc.
static int32 | GetMaxAge (VehicleID vehicle_id)
| Get the maximum age of a vehicle.
static int32 | GetAgeLeft (VehicleID vehicle_id)
| Get the age a vehicle has left (maximum - current).
static int32 | GetCurrentSpeed (VehicleID vehicle_id)
| Get the current speed of a vehicle.
static VehicleState | GetState (VehicleID vehicle_id)
| Get the current state of a vehicle.
static Money | GetRunningCost (VehicleID vehicle_id)
| Get the running cost of this vehicle.
static Money | GetProfitThisYear (VehicleID vehicle_id)
| Get the current profit of a vehicle.
static Money | GetProfitLastYear (VehicleID vehicle_id)
| Get the profit of last year of a vehicle.
static Money | GetCurrentValue (VehicleID vehicle_id)
| Get the current value of a vehicle.
static AIVehicle::VehicleType | GetVehicleType (VehicleID vehicle_id)
| Get the type of vehicle.
static AIRoad::RoadType | GetRoadType (VehicleID vehicle_id)
| Get the RoadType of the vehicle.
static bool | IsInDepot (VehicleID vehicle_id)
| Check if a vehicle is in a depot.
static bool | IsStoppedInDepot (VehicleID vehicle_id)
| Check if a vehicle is in a depot and stopped.
static VehicleID | BuildVehicle (TileIndex depot, EngineID engine_id)
| Builds a vehicle with the given engine at the given depot.
static VehicleID | CloneVehicle (TileIndex depot, VehicleID vehicle_id, bool share_orders)
| Clones a vehicle at the given depot, copying or cloning it's orders.
static bool | MoveWagon (VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon)
| Move a wagon after another wagon.
static bool | MoveWagonChain (VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon)
| Move a chain of wagons after another wagon.
static int | GetRefitCapacity (VehicleID vehicle_id, CargoID cargo)
| Gets the capacity of the given vehicle when refited to the given cargo type.
static bool | RefitVehicle (VehicleID vehicle_id, CargoID cargo)
| Refits a vehicle to the given cargo type.
static bool | SellVehicle (VehicleID vehicle_id)
| Sells the given vehicle.
static bool | SellWagon (VehicleID vehicle_id, int wagon)
| Sells the given wagon from the vehicle.
static bool | SellWagonChain (VehicleID vehicle_id, int wagon)
| Sells all wagons from the vehicle starting from a given position.
static bool | SendVehicleToDepot (VehicleID vehicle_id)
| Sends the given vehicle to a depot.
static bool | SendVehicleToDepotForServicing (VehicleID vehicle_id)
| Sends the given vehicle to a depot for servicing.
static bool | StartStopVehicle (VehicleID vehicle_id)
| Starts or stops the given vehicle depending on the current state.
static bool | SkipToVehicleOrder (VehicleID vehicle_id, AIOrder::OrderPosition order_position)
| Skips the current order of the given vehicle.
static bool | ReverseVehicle (VehicleID vehicle_id)
| Turn the given vehicle so it'll drive the other way.
static int32 | GetCapacity (VehicleID vehicle_id, CargoID cargo)
| Get the maximum amount of a specific cargo the given vehicle can transport.
static int | GetLength (VehicleID vehicle_id)
| Get the length of a the total vehicle in 1/16's of a tile.
static int32 | GetCargoLoad (VehicleID vehicle_id, CargoID cargo)
| Get the amount of a specific cargo the given vehicle transports.
static GroupID | GetGroupID (VehicleID vehicle_id)
| Get the group of a given vehicle.
static bool | IsArticulated (VehicleID vehicle_id)
| Check if the vehicle is articulated.
static bool | HasSharedOrders (VehicleID vehicle_id)
| Check if the vehicle has shared orders.
## Static Private Member Functions
static bool | _SellWagonInternal (VehicleID vehicle_id, int wagon, bool sell_attached_wagons)
| Internal function used by SellWagon(Chain).
static bool | _MoveWagonInternal (VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon)
| Internal function used by MoveWagon(Chain).

## Detailed Description

Class that handles all vehicle related functions.

Definition at line 16 of file ai_vehicle.hpp.

## Member Enumeration Documentation

enum AIVehicle::ErrorMessages

All vehicle related error messages.

Enumerator:

  ERR_VEHICLE_BASE | Base for vehicle related errors.
  ERR_VEHICLE_TOO_MANY | Too many vehicles in the game, can't build any more.
  ERR_VEHICLE_NOT_AVAILABLE | Vehicle is not available.
  ERR_VEHICLE_BUILD_DISABLED | Vehicle can't be build due to game settigns.
  ERR_VEHICLE_WRONG_DEPOT | Vehicle can't be build in the selected depot.
  ERR_VEHICLE_CANNOT_SEND_TO_DEPOT | Vehicle can't return to the depot.
  ERR_VEHICLE_CANNOT_START_STOP | Vehicle can't start / stop.
  ERR_VEHICLE_CANNOT_TURN | Vehicle can't turn.
  ERR_VEHICLE_CANNOT_REFIT | Vehicle can't be refit.
  ERR_VEHICLE_IS_DESTROYED | Vehicle is destroyed.
  ERR_VEHICLE_NOT_IN_DEPOT | Vehicle is not in a depot.
  ERR_VEHICLE_IN_FLIGHT | Vehicle is flying.
  ERR_VEHCILE_NO_POWER | Vehicle is without power.

Definition at line 23 of file ai_vehicle.hpp.

enum AIVehicle::VehicleType

The type of a vehicle available in the game.

Trams for example are road vehicles, as maglev is a rail vehicle.

Enumerator:

  VT_RAIL | Rail type vehicle.
  VT_ROAD | Road type vehicle (bus / truck).
  VT_WATER | Water type vehicle.
  VT_AIR | Air type vehicle.
  VT_INVALID | Invalid vehicle type.

Definition at line 69 of file ai_vehicle.hpp.

enum AIVehicle::VehicleState

The different states a vehicle can be in.

Enumerator:

  VS_RUNNING | The vehicle is currently running.
  VS_STOPPED | The vehicle is stopped manually.
  VS_IN_DEPOT | The vehicle is stopped in the depot.
  VS_AT_STATION | The vehicle is stopped at a station and is currently loading or unloading.
  VS_BROKEN | The vehicle has broken down and will start running again in a while.
  VS_CRASHED | The vehicle is crashed (and will never run again).
  VS_INVALID | An invalid vehicle state.

Definition at line 85 of file ai_vehicle.hpp.

## Member Function Documentation

bool AIVehicle::IsValidVehicle | ( | VehicleID | vehicle_id | ) | `[static]`

Checks whether the given vehicle is valid and owned by you.

Parameters:

  | vehicle_id | The vehicle to check.

Returns:
  True if and only if the vehicle is valid.

Definition at line 20 of file ai_vehicle.cpp.

References IsFreeWagon(), and IsValidVehicleID().

Referenced by _MoveWagonInternal(), _SellWagonInternal(), AIStationList_Vehicle::AIStationList_Vehicle(), AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(), AIWaypointList_Vehicle::AIWaypointList_Vehicle(), AIOrder::AppendConditionalOrder(), AIOrder::AppendOrder(), CloneVehicle(), AIOrder::CopyOrders(), GetAge(), GetAgeLeft(), GetCapacity(), GetCargoLoad(), GetCurrentSpeed(), GetCurrentValue(), GetEngineType(), GetGroupID(), GetLength(), GetLocation(), GetMaxAge(), GetName(), GetNumWagons(), AIOrder::GetOrderCount(), GetProfitLastYear(), GetProfitThisYear(), GetRefitCapacity(), GetRoadType(), GetRunningCost(), GetState(), GetUnitNumber(), GetVehicleType(), GetWagonAge(), GetWagonEngineType(), HasSharedOrders(), AIOrder::InsertConditionalOrder(), AIOrder::InsertOrder(), IsArticulated(), AIOrder::IsCurrentOrderPartOfOrderList(), IsInDepot(), IsStoppedInDepot(), AIOrder::IsValidVehicleOrder(), AIGroup::MoveVehicle(), RefitVehicle(), AIOrder::ResolveOrderPosition(), ReverseVehicle(), SellVehicle(), SendVehicleToDepot(), SendVehicleToDepotForServicing(), SetName(), AIOrder::ShareOrders(), StartStopVehicle(), and AIOrder::UnshareOrders().

int32 AIVehicle::GetNumWagons | ( | VehicleID | vehicle_id | ) | `[static]`

Get the number of wagons a vehicle has.

Parameters:

  | vehicle_id | The vehicle to get the number of wagons from.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The number of wagons the vehicle has.

Definition at line 27 of file ai_vehicle.cpp.

References GetNextUnit(), and IsValidVehicle().

Referenced by _MoveWagonInternal(), _SellWagonInternal(), GetWagonAge(), and GetWagonEngineType().

bool AIVehicle::SetName | ( | VehicleID | vehicle_id,
|  | const char * | name |
| ) |  |  | `[static]`

Set the name of a vehicle.

Parameters:

  | vehicle_id | The vehicle to set the name for.
  | name | The name for the vehicle.

Precondition:
  IsValidVehicle(vehicle_id).

  'name' must have at least one character.

  'name' must have at most 30 characters.

Exceptions:

  | AIError::ERR_NAME_IS_NOT_UNIQUE |

Returns:
  True if and only if the name was changed.

Definition at line 210 of file ai_vehicle.cpp.

References CMD_RENAME_VEHICLE, AIObject::DoCommand(), EnforcePrecondition, EnforcePreconditionCustomError, AIError::ERR_PRECONDITION_STRING_TOO_LONG, IsValidVehicle(), MAX_LENGTH_VEHICLE_NAME_BYTES, and StrEmpty().

char * AIVehicle::GetName | ( | VehicleID | vehicle_id | ) | `[static]`

Get the name of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the name of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The name the vehicle has.

Definition at line 259 of file ai_vehicle.cpp.

References IsValidVehicle().

TileIndex AIVehicle::GetLocation | ( | VehicleID | vehicle_id | ) | `[static]`

Get the current location of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the location of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The tile the vehicle is currently on.

Definition at line 219 of file ai_vehicle.cpp.

References Clamp(), INVALID_TILE, IsValidVehicle(), MapSizeX(), MapSizeY(), TILE_SIZE, and TileXY().

EngineID AIVehicle::GetEngineType | ( | VehicleID | vehicle_id | ) | `[static]`

Get the engine-type of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the engine-type of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The engine type the vehicle has.

Definition at line 233 of file ai_vehicle.cpp.

References IsValidVehicle().

EngineID AIVehicle::GetWagonEngineType | ( | VehicleID | vehicle_id,
|  | int | wagon |
| ) |  |  | `[static]`

Get the engine-type of a wagon.

Parameters:

  | vehicle_id | The vehicle to get the engine-type of.
  | wagon | The wagon in the vehicle to get the engine-type of.

Precondition:
  IsValidVehicle(vehicle_id).

  wagon < GetNumWagons(vehicle_id).

Returns:
  The engine type the vehicle has.

Definition at line 240 of file ai_vehicle.cpp.

References GetNextUnit(), GetNumWagons(), and IsValidVehicle().

int32 AIVehicle::GetUnitNumber | ( | VehicleID | vehicle_id | ) | `[static]`

Get the unitnumber of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the unitnumber of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The unitnumber the vehicle has.

Definition at line 252 of file ai_vehicle.cpp.

References IsValidVehicle().

int32 AIVehicle::GetAge | ( | VehicleID | vehicle_id | ) | `[static]`

Get the current age of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the age of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The current age the vehicle has.

Note:
  The age is in days.

Definition at line 271 of file ai_vehicle.cpp.

References IsValidVehicle().

int32 AIVehicle::GetWagonAge | ( | VehicleID | vehicle_id,
|  | int | wagon |
| ) |  |  | `[static]`

Get the current age of a second (or third, etc.

) engine in a train vehicle.

Parameters:

  | vehicle_id | The vehicle to get the age of.
  | wagon | The wagon in the vehicle to get the age of.

Precondition:
  IsValidVehicle(vehicle_id).

  wagon < GetNumWagons(vehicle_id).

Returns:
  The current age the vehicle has.

Note:
  The age is in days.

Definition at line 278 of file ai_vehicle.cpp.

References GetNextUnit(), GetNumWagons(), and IsValidVehicle().

int32 AIVehicle::GetMaxAge | ( | VehicleID | vehicle_id | ) | `[static]`

Get the maximum age of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the age of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The maximum age the vehicle has.

Note:
  The age is in days.

Definition at line 290 of file ai_vehicle.cpp.

References IsValidVehicle().

int32 AIVehicle::GetAgeLeft | ( | VehicleID | vehicle_id | ) | `[static]`

Get the age a vehicle has left (maximum - current).

Parameters:

  | vehicle_id | The vehicle to get the age of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The age the vehicle has left.

Note:
  The age is in days.

Definition at line 297 of file ai_vehicle.cpp.

References IsValidVehicle().

int32 AIVehicle::GetCurrentSpeed | ( | VehicleID | vehicle_id | ) | `[static]`

Get the current speed of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the age of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The current speed of the vehicle.

Note:
  The speed is in OpenTTD's internal speed unit. This is mph / 1.6, which is roughly km/h. To get km/h multiply this number by 1.00584.

Definition at line 304 of file ai_vehicle.cpp.

References IsValidVehicle().

AIVehicle::VehicleState AIVehicle::GetState | ( | VehicleID | vehicle_id | ) | `[static]`

Get the current state of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the state of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The current state of the vehicle.

Definition at line 311 of file ai_vehicle.cpp.

References IsValidVehicle(), VS_AT_STATION, VS_BROKEN, VS_CRASHED, VS_IN_DEPOT, VS_INVALID, VS_RUNNING, and VS_STOPPED.

Money AIVehicle::GetRunningCost | ( | VehicleID | vehicle_id | ) | `[static]`

Get the running cost of this vehicle.

Parameters:

  | vehicle_id | The vehicle to get the age of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The running cost of the vehicle per year.

Note:
  Cost is per year; divide by 365 to get per day.

  This is not equal to AIEngine::GetRunningCost for Trains, because wagons and second engines can add up in the calculation too.

Definition at line 326 of file ai_vehicle.cpp.

References IsValidVehicle().

Money AIVehicle::GetProfitThisYear | ( | VehicleID | vehicle_id | ) | `[static]`

Get the current profit of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the profit of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The current profit the vehicle has.

Definition at line 333 of file ai_vehicle.cpp.

References IsValidVehicle().

Money AIVehicle::GetProfitLastYear | ( | VehicleID | vehicle_id | ) | `[static]`

Get the profit of last year of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the profit of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The profit the vehicle had last year.

Definition at line 340 of file ai_vehicle.cpp.

References IsValidVehicle().

Money AIVehicle::GetCurrentValue | ( | VehicleID | vehicle_id | ) | `[static]`

Get the current value of a vehicle.

Parameters:

  | vehicle_id | The vehicle to get the value of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The value the vehicle currently has (the amount you should get when you would sell the vehicle right now).

Definition at line 347 of file ai_vehicle.cpp.

References IsValidVehicle().

AIVehicle::VehicleType AIVehicle::GetVehicleType | ( | VehicleID | vehicle_id | ) | `[static]`

Get the type of vehicle.

Parameters:

  | vehicle_id | The vehicle to get the type of.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  The vehicle type.

Definition at line 354 of file ai_vehicle.cpp.

References IsValidVehicle(), VT_AIR, VT_INVALID, VT_RAIL, VT_ROAD, and VT_WATER.

Referenced by GetRoadType(), and IsArticulated().

AIRoad::RoadType AIVehicle::GetRoadType | ( | VehicleID | vehicle_id | ) | `[static]`

Get the RoadType of the vehicle.

Parameters:

  | vehicle_id | The vehicle to get the RoadType of.

Precondition:
  IsValidVehicle(vehicle_id).

  GetVehicleType(vehicle_id) == VT_ROAD.

Returns:
  The RoadType the vehicle has.

Definition at line 367 of file ai_vehicle.cpp.

References GetVehicleType(), IsValidVehicle(), AIRoad::ROADTYPE_INVALID, and VT_ROAD.

bool AIVehicle::IsInDepot | ( | VehicleID | vehicle_id | ) | `[static]`

Check if a vehicle is in a depot.

Parameters:

  | vehicle_id | The vehicle to check.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  True if and only if the vehicle is in a depot.

Definition at line 170 of file ai_vehicle.cpp.

References IsValidVehicle().

bool AIVehicle::IsStoppedInDepot | ( | VehicleID | vehicle_id | ) | `[static]`

Check if a vehicle is in a depot and stopped.

Parameters:

  | vehicle_id | The vehicle to check.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  True if and only if the vehicle is in a depot and stopped.

Definition at line 176 of file ai_vehicle.cpp.

References IsValidVehicle().

VehicleID AIVehicle::BuildVehicle | ( | TileIndex | depot,
|  | EngineID | engine_id |
| ) |  |  | `[static]`

Builds a vehicle with the given engine at the given depot.

Parameters:

  | depot | The depot where the vehicle will be build.
  | engine_id | The engine to use for this vehicle.

Precondition:
  The tile at depot has a depot that can build the engine and is owned by you.

  IsValidEngine(engine_id).

Exceptions:

  | AIVehicle::ERR_VEHICLE_TOO_MANY |
  | AIVehicle::ERR_VEHICLE_BUILD_DISABLED |
  | AIVehicle::ERR_VEHICLE_WRONG_DEPOT |

Returns:
  The VehicleID of the new vehicle, or an invalid VehicleID when it failed. Check the return value using IsValidVehicle. In test-mode 0 is returned if it was successful; any other value indicates failure.

Note:
  In Test Mode it means you can't assign orders yet to this vehicle, as the vehicle isn't really built yet. Build it for real first before assigning orders.

Definition at line 58 of file ai_vehicle.cpp.

References AIObject::DoCommand(), EnforcePrecondition, EnforcePreconditionCustomError, ERR_VEHICLE_BUILD_DISABLED, AIGameSettings::IsDisabledVehicleType(), and AIEngine::IsValidEngine().

VehicleID AIVehicle::CloneVehicle | ( | TileIndex | depot,
|  | VehicleID | vehicle_id,
|  | bool | share_orders |
| ) |  |  | `[static]`

Clones a vehicle at the given depot, copying or cloning it's orders.

Parameters:

  | depot | The depot where the vehicle will be build.
  | vehicle_id | The vehicle to use as example for the new vehicle.
  | share_orders | Should the orders be copied or shared?

Precondition:
  The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles.

  IsValidVehicle(vehicle_id).

Exceptions:

  | AIVehicle::ERR_VEHICLE_TOO_MANY |
  | AIVehicle::ERR_VEHICLE_BUILD_DISABLED |
  | AIVehicle::ERR_VEHICLE_WRONG_DEPOT |

Returns:
  The VehicleID of the new vehicle, or an invalid VehicleID when it failed. Check the return value using IsValidVehicle. In test-mode 0 is returned if it was successful; any other value indicates failure.

Definition at line 72 of file ai_vehicle.cpp.

References CMD_CLONE_VEHICLE, AIObject::DoCommand(), EnforcePrecondition, and IsValidVehicle().

bool AIVehicle::MoveWagon | ( | VehicleID | source_vehicle_id,
|  | int | source_wagon,
|  | int | dest_vehicle_id,
|  | int | dest_wagon |
| ) |  |  | `[static]`

Move a wagon after another wagon.

Parameters:

  | source_vehicle_id | The vehicle to move a wagon away from.
  | source_wagon | The wagon in source_vehicle to move.
  | dest_vehicle_id | The vehicle to move the wagon to, or -1 to create a new vehicle.
  | dest_wagon | The wagon in dest_vehicle to place source_wagon after.

Precondition:
  IsValidVehicle(source_vehicle_id).

  source_wagon < GetNumWagons(source_vehicle_id).

  dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).

  GetVehicleType(source_vehicle_id) == VT_RAIL.

  dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VT_RAIL.

Returns:
  Whether or not moving the wagon succeeded.

Definition at line 100 of file ai_vehicle.cpp.

References _MoveWagonInternal().

bool AIVehicle::MoveWagonChain | ( | VehicleID | source_vehicle_id,
|  | int | source_wagon,
|  | int | dest_vehicle_id,
|  | int | dest_wagon |
| ) |  |  | `[static]`

Move a chain of wagons after another wagon.

Parameters:

  | source_vehicle_id | The vehicle to move a wagon away from.
  | source_wagon | The first wagon in source_vehicle to move.
  | dest_vehicle_id | The vehicle to move the wagons to, or -1 to create a new vehicle.
  | dest_wagon | The wagon in dest_vehicle to place source_wagon and following wagons after.

Precondition:
  IsValidVehicle(source_vehicle_id).

  source_wagon < GetNumWagons(source_vehicle_id).

  dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).

  GetVehicleType(source_vehicle_id) == VT_RAIL.

  dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VT_RAIL.

Returns:
  Whether or not moving the wagons succeeded.

Definition at line 105 of file ai_vehicle.cpp.

References _MoveWagonInternal().

int AIVehicle::GetRefitCapacity | ( | VehicleID | vehicle_id,
|  | CargoID | cargo |
| ) |  |  | `[static]`

Gets the capacity of the given vehicle when refited to the given cargo type.

Parameters:

  | vehicle_id | The vehicle to refit.
  | cargo | The cargo to refit to.

Precondition:
  IsValidVehicle(vehicle_id).

  AICargo::IsValidCargo(cargo).

  You must own the vehicle.

  The vehicle must be stopped in the depot.

Returns:
  The capacity the vehicle will have when refited.

Definition at line 110 of file ai_vehicle.cpp.

References CmdSucceeded(), DC_QUERY_COST, AIObject::DoCommand(), AICargo::IsValidCargo(), and IsValidVehicle().

bool AIVehicle::RefitVehicle | ( | VehicleID | vehicle_id,
|  | CargoID | cargo |
| ) |  |  | `[static]`

Refits a vehicle to the given cargo type.

Parameters:

  | vehicle_id | The vehicle to refit.
  | cargo | The cargo to refit to.

Precondition:
  IsValidVehicle(vehicle_id).

  AICargo::IsValidCargo(cargo).

  You must own the vehicle.

  The vehicle must be stopped in the depot.

Exceptions:

  | AIVehicle::ERR_VEHICLE_CANNOT_REFIT |
  | AIVehicle::ERR_VEHICLE_IS_DESTROYED |
  | AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT |

Returns:
  True if and only if the refit succeeded.

Definition at line 119 of file ai_vehicle.cpp.

References AIObject::DoCommand(), EnforcePrecondition, AICargo::IsValidCargo(), and IsValidVehicle().

bool AIVehicle::SellVehicle | ( | VehicleID | vehicle_id | ) | `[static]`

Sells the given vehicle.

Parameters:

  | vehicle_id | The vehicle to sell.

Precondition:
  IsValidVehicle(vehicle_id).

  You must own the vehicle.

  The vehicle must be stopped in the depot.

Exceptions:

  | AIVehicle::ERR_VEHICLE_IS_DESTROYED |
  | AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT |

Returns:
  True if and only if the vehicle has been sold.

Definition at line 127 of file ai_vehicle.cpp.

References AIObject::DoCommand(), EnforcePrecondition, and IsValidVehicle().

bool AIVehicle::SellWagon | ( | VehicleID | vehicle_id,
|  | int | wagon |
| ) |  |  | `[static]`

Sells the given wagon from the vehicle.

Parameters:

  | vehicle_id | The vehicle to sell a wagon from.
  | wagon | The wagon to sell.

Precondition:
  IsValidVehicle(vehicle_id).

  wagon < GetNumWagons(vehicle_id).

  You must own the vehicle.

  The vehicle must be stopped in the depot.

Exceptions:

  | AIVehicle::ERR_VEHICLE_IS_DESTROYED |
  | AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT |

Returns:
  True if and only if the wagon has been sold.

Definition at line 146 of file ai_vehicle.cpp.

References _SellWagonInternal().

bool AIVehicle::SellWagonChain | ( | VehicleID | vehicle_id,
|  | int | wagon |
| ) |  |  | `[static]`

Sells all wagons from the vehicle starting from a given position.

Parameters:

  | vehicle_id | The vehicle to sell a wagon from.
  | wagon | The wagon to sell.

Precondition:
  IsValidVehicle(vehicle_id).

  wagon < GetNumWagons(vehicle_id).

  You must own the vehicle.

  The vehicle must be stopped in the depot.

Exceptions:

  | AIVehicle::ERR_VEHICLE_IS_DESTROYED |
  | AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT |

Returns:
  True if and only if the wagons have been sold.

Definition at line 151 of file ai_vehicle.cpp.

References _SellWagonInternal().

bool AIVehicle::SendVehicleToDepot | ( | VehicleID | vehicle_id | ) | `[static]`

Sends the given vehicle to a depot.

If the vehicle has already been sent to a depot it continues with its normal orders instead.

Parameters:

  | vehicle_id | The vehicle to send to a depot.

Precondition:
  IsValidVehicle(vehicle_id).

Exceptions:

  | AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT |

Returns:
  True if the current order was changed.

Definition at line 156 of file ai_vehicle.cpp.

References AIObject::DoCommand(), EnforcePrecondition, and IsValidVehicle().

bool AIVehicle::SendVehicleToDepotForServicing | ( | VehicleID | vehicle_id | ) | `[static]`

Sends the given vehicle to a depot for servicing.

If the vehicle has already been sent to a depot it continues with its normal orders instead.

Parameters:

  | vehicle_id | The vehicle to send to a depot for servicing.

Precondition:
  IsValidVehicle(vehicle_id).

Exceptions:

  | AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT |

Returns:
  True if the current order was changed.

Definition at line 163 of file ai_vehicle.cpp.

References DEPOT_SERVICE, AIObject::DoCommand(), EnforcePrecondition, and IsValidVehicle().

bool AIVehicle::StartStopVehicle | ( | VehicleID | vehicle_id | ) | `[static]`

Starts or stops the given vehicle depending on the current state.

Parameters:

  | vehicle_id | The vehicle to start/stop.

Precondition:
  IsValidVehicle(vehicle_id).

Exceptions:

  | AIVehicle::ERR_VEHICLE_CANNOT_START_STOP |
  | (For | aircraft only): AIVehicle::ERR_VEHICLE_IN_FLIGHT
  | (For | trains only): AIVehicle::ERR_VEHICLE_NO_POWER

Returns:
  True if and only if the vehicle has been started or stopped.

Definition at line 182 of file ai_vehicle.cpp.

References CMD_START_STOP_VEHICLE, AIObject::DoCommand(), EnforcePrecondition, and IsValidVehicle().

bool AIVehicle::SkipToVehicleOrder | ( | VehicleID | vehicle_id,
|  | AIOrder::OrderPosition | order_position |
| ) |  |  | `[static]`

Skips the current order of the given vehicle.

Parameters:

  | vehicle_id | The vehicle to skip the order for.
  | order_position | The selected order to which we want to skip.

Precondition:
  IsValidVehicleOrder(vehicle_id, order_position).

Returns:
  True if and only if the order has been skipped.

Definition at line 189 of file ai_vehicle.cpp.

References CMD_SKIP_TO_ORDER, AIObject::DoCommand(), EnforcePrecondition, AIOrder::IsValidVehicleOrder(), and AIOrder::ResolveOrderPosition().

bool AIVehicle::ReverseVehicle | ( | VehicleID | vehicle_id | ) | `[static]`

Turn the given vehicle so it'll drive the other way.

Parameters:

  | vehicle_id | The vehicle to turn.

Precondition:
  IsValidVehicle(vehicle_id).

  GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.

Returns:
  True if and only if the vehicle has started to turn.

Note:
  Vehicles cannot always be reversed. For example busses and trucks need to be running and not be inside a depot.

Definition at line 198 of file ai_vehicle.cpp.

References CMD_REVERSE_TRAIN_DIRECTION, CMD_TURN_ROADVEH, AIObject::DoCommand(), EnforcePrecondition, and IsValidVehicle().

int32 AIVehicle::GetCapacity | ( | VehicleID | vehicle_id,
|  | CargoID | cargo |
| ) |  |  | `[static]`

Get the maximum amount of a specific cargo the given vehicle can transport.

Parameters:

  | vehicle_id | The vehicle to get the capacity of.
  | cargo | The cargo to get the capacity for.

Precondition:
  IsValidVehicle(vehicle_id).

  AICargo::IsValidCargo(cargo).

Returns:
  The maximum amount of the given cargo the vehicle can transport.

Definition at line 375 of file ai_vehicle.cpp.

References AICargo::IsValidCargo(), and IsValidVehicle().

int AIVehicle::GetLength | ( | VehicleID | vehicle_id | ) | `[static]`

Get the length of a the total vehicle in 1/16's of a tile.

Parameters:

  | vehicle_id | The vehicle to get the length of.

Precondition:
  IsValidVehicle(vehicle_id).

  GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.

Returns:
  The length of the engine.

Definition at line 40 of file ai_vehicle.cpp.

References IsValidVehicle().

int32 AIVehicle::GetCargoLoad | ( | VehicleID | vehicle_id,
|  | CargoID | cargo |
| ) |  |  | `[static]`

Get the amount of a specific cargo the given vehicle transports.

Parameters:

  | vehicle_id | The vehicle to get the load amount of.
  | cargo | The cargo to get the load amount for.

Precondition:
  IsValidVehicle(vehicle_id).

  AICargo::IsValidCargo(cargo).

Returns:
  The amount of the given cargo the vehicle currently transports.

Definition at line 388 of file ai_vehicle.cpp.

References AICargo::IsValidCargo(), and IsValidVehicle().

GroupID AIVehicle::GetGroupID | ( | VehicleID | vehicle_id | ) | `[static]`

Get the group of a given vehicle.

Parameters:

  | vehicle_id | The vehicle to get the group from.

Returns:
  The group of the given vehicle.

Definition at line 401 of file ai_vehicle.cpp.

References AIGroup::GROUP_INVALID, and IsValidVehicle().

bool AIVehicle::IsArticulated | ( | VehicleID | vehicle_id | ) | `[static]`

Check if the vehicle is articulated.

Parameters:

  | vehicle_id | The vehicle to check.

Precondition:
  IsValidVehicle(vehicle_id).

  GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.

Returns:
  True if the vehicle is articulated.

Definition at line 408 of file ai_vehicle.cpp.

References EngineHasArticPart(), GetVehicleType(), IsValidVehicle(), VT_RAIL, and VT_ROAD.

bool AIVehicle::HasSharedOrders | ( | VehicleID | vehicle_id | ) | `[static]`

Check if the vehicle has shared orders.

Parameters:

  | vehicle_id | The vehicle to check.

Precondition:
  IsValidVehicle(vehicle_id).

Returns:
  True if the vehicle has shared orders.

Definition at line 421 of file ai_vehicle.cpp.

References IsValidVehicle().

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

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