OpenTTD GameScript API 20241220-master-g59680867c3
Public Types | Static Public Member Functions | Static Public Attributes
GSVehicle Class Reference

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

#include <script_vehicle.hpp>

Inheritance diagram for GSVehicle:

Public Types

enum  ErrorMessages {
  ERR_VEHICLE_BASE ,
  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_VEHICLE_NO_POWER ,
  ERR_VEHICLE_TOO_LONG
}
 All vehicle related error messages. More...
 
enum  VehicleType {
  VT_RAIL ,
  VT_ROAD ,
  VT_WATER ,
  VT_AIR ,
  VT_INVALID
}
 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
}
 The different states a vehicle can be in. More...
 

Static Public Member Functions

static bool IsValidVehicle (VehicleID vehicle_id)
 Checks whether the given vehicle is valid and owned by you.
 
static bool IsPrimaryVehicle (VehicleID vehicle_id)
 Checks whether this is a primary vehicle.
 
static int GetNumWagons (VehicleID vehicle_id)
 Get the number of wagons a vehicle has.
 
static bool SetName (VehicleID vehicle_id, Text *name)
 Set the name of a vehicle.
 
static string GetName (VehicleID vehicle_id)
 Get the name of a vehicle.
 
static GSCompany::CompanyID GetOwner (VehicleID vehicle_id)
 Get the owner 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 int GetUnitNumber (VehicleID vehicle_id)
 Get the unitnumber of a vehicle.
 
static int GetAge (VehicleID vehicle_id)
 Get the current age of a vehicle.
 
static int GetWagonAge (VehicleID vehicle_id, int wagon)
 Get the current age of a second (or third, etc.) engine in a train vehicle.
 
static int GetMaxAge (VehicleID vehicle_id)
 Get the maximum age of a vehicle.
 
static int GetAgeLeft (VehicleID vehicle_id)
 Get the age a vehicle has left (maximum - current).
 
static int 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 GSVehicle::VehicleType GetVehicleType (VehicleID vehicle_id)
 Get the type of vehicle.
 
static GSRoad::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 BuildVehicleWithRefit (TileIndex depot, EngineID engine_id, CargoID cargo)
 Builds a vehicle with the given engine at the given depot and refits it to the given cargo.
 
static int GetBuildWithRefitCapacity (TileIndex depot, EngineID engine_id, CargoID cargo)
 Gets the capacity of a vehicle built at the given depot with the given engine and refitted to the given cargo.
 
static VehicleID CloneVehicle (TileIndex depot, VehicleID vehicle_id, bool share_orders)
 Clones a vehicle at the given depot, copying or cloning its 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 refitted 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 ReverseVehicle (VehicleID vehicle_id)
 Turn the given vehicle so it'll drive the other way.
 
static int 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 int GetCargoLoad (VehicleID vehicle_id, CargoID cargo)
 Get the amount of a specific cargo the given vehicle is transporting.
 
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 int GetReliability (VehicleID vehicle_id)
 Get the current reliability of a vehicle.
 
static int GetMaximumOrderDistance (VehicleID vehicle_id)
 Get the maximum allowed distance between two orders for a vehicle.
 

Static Public Attributes

static const VehicleID VEHICLE_INVALID = 0xFFFFF
 Invalid VehicleID.
 

Detailed Description

Class that handles all vehicle related functions.

Member Enumeration Documentation

◆ ErrorMessages

All vehicle related error messages.

See also
ScriptErrorType
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 built due to game settings.

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_VEHICLE_NO_POWER 

Vehicle is without power.

ERR_VEHICLE_TOO_LONG 

Vehicle would get too long during construction.

◆ 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.

◆ 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.

Member Function Documentation

◆ BuildVehicle()

static VehicleID GSVehicle::BuildVehicle ( TileIndex  depot,
EngineID  engine_id 
)
static

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

Parameters
depotThe depot where the vehicle will be build.
engine_idThe engine to use for this vehicle.
Precondition
The tile at depot has a depot that can build the engine and is owned by you.
GSEngine::IsBuildable(engine_id).
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_TOO_MANY
GSVehicle::ERR_VEHICLE_BUILD_DISABLED
GSVehicle::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
Unlike the GUI, wagons are not automatically attached to trains, only to existing free wagons. This means that BuildVehicle can sometimes return an ID indicating success, but IsValidVehicle check will fail. You should use MoveWagon to attach free wagons to trains.
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.

◆ BuildVehicleWithRefit()

static VehicleID GSVehicle::BuildVehicleWithRefit ( TileIndex  depot,
EngineID  engine_id,
CargoID  cargo 
)
static

Builds a vehicle with the given engine at the given depot and refits it to the given cargo.

Parameters
depotThe depot where the vehicle will be build.
engine_idThe engine to use for this vehicle.
cargoThe cargo to refit to.
Precondition
The tile at depot has a depot that can build the engine and is owned by you.
GSEngine::IsBuildable(engine_id).
GSCargo::IsValidCargo(cargo).
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_TOO_MANY
GSVehicle::ERR_VEHICLE_BUILD_DISABLED
GSVehicle::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.

◆ CloneVehicle()

static VehicleID GSVehicle::CloneVehicle ( TileIndex  depot,
VehicleID  vehicle_id,
bool  share_orders 
)
static

Clones a vehicle at the given depot, copying or cloning its orders.

Parameters
depotThe depot where the vehicle will be build.
vehicle_idThe vehicle to use as example for the new vehicle.
share_ordersShould the orders be copied or shared?
Precondition
The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles.
IsPrimaryVehicle(vehicle_id).
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_TOO_MANY
GSVehicle::ERR_VEHICLE_BUILD_DISABLED
GSVehicle::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.

◆ GetAge()

static int GSVehicle::GetAge ( VehicleID  vehicle_id)
static

Get the current age of a vehicle.

Parameters
vehicle_idThe vehicle to get the age of.
Precondition
IsValidVehicle(vehicle_id).
Returns
The current age of the vehicle in calendar-days.
See also
GSCalendarTime

◆ GetAgeLeft()

static int GSVehicle::GetAgeLeft ( VehicleID  vehicle_id)
static

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

Parameters
vehicle_idThe vehicle to get the age of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The remaining age of the vehicle in calendar-days.
See also
GSCalendarTime

◆ GetBuildWithRefitCapacity()

static int GSVehicle::GetBuildWithRefitCapacity ( TileIndex  depot,
EngineID  engine_id,
CargoID  cargo 
)
static

Gets the capacity of a vehicle built at the given depot with the given engine and refitted to the given cargo.

Parameters
depotThe depot where the vehicle will be build.
engine_idThe engine to use for this vehicle.
cargoThe cargo to refit to.
Precondition
The tile at depot has a depot that can build the engine and is owned by you.
GSEngine::IsBuildable(engine_id).
GSCargo::IsValidCargo(cargo).
Returns
The capacity the vehicle will have when refited.

◆ GetCapacity()

static int GSVehicle::GetCapacity ( VehicleID  vehicle_id,
CargoID  cargo 
)
static

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

Parameters
vehicle_idThe vehicle to get the capacity of.
cargoThe cargo to get the capacity for.
Precondition
IsValidVehicle(vehicle_id).
GSCargo::IsValidCargo(cargo).
Returns
The maximum amount of the given cargo the vehicle can transport.

◆ GetCargoLoad()

static int GSVehicle::GetCargoLoad ( VehicleID  vehicle_id,
CargoID  cargo 
)
static

Get the amount of a specific cargo the given vehicle is transporting.

Parameters
vehicle_idThe vehicle to get the load amount of.
cargoThe cargo to get the loaded amount for.
Precondition
IsValidVehicle(vehicle_id).
GSCargo::IsValidCargo(cargo).
Returns
The amount of the given cargo the vehicle is currently transporting.

◆ GetCurrentSpeed()

static int GSVehicle::GetCurrentSpeed ( VehicleID  vehicle_id)
static

Get the current speed of a vehicle.

Parameters
vehicle_idThe vehicle to get the speed of.
Precondition
IsPrimaryVehicle(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.

◆ GetCurrentValue()

static Money GSVehicle::GetCurrentValue ( VehicleID  vehicle_id)
static

Get the current value of a vehicle.

Parameters
vehicle_idThe 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).

◆ GetEngineType()

static EngineID GSVehicle::GetEngineType ( VehicleID  vehicle_id)
static

Get the engine-type of a vehicle.

Parameters
vehicle_idThe vehicle to get the engine-type of.
Precondition
IsValidVehicle(vehicle_id).
Returns
The engine type the vehicle has.

◆ GetGroupID()

static GroupID GSVehicle::GetGroupID ( VehicleID  vehicle_id)
static

Get the group of a given vehicle.

Parameters
vehicle_idThe vehicle to get the group from.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The group of the given vehicle.

◆ GetLength()

static int GSVehicle::GetLength ( VehicleID  vehicle_id)
static

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

Parameters
vehicle_idThe 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.

◆ GetLocation()

static TileIndex GSVehicle::GetLocation ( VehicleID  vehicle_id)
static

Get the current location of a vehicle.

Parameters
vehicle_idThe vehicle to get the location of.
Precondition
IsValidVehicle(vehicle_id).
Returns
The tile the vehicle is currently on.

◆ GetMaxAge()

static int GSVehicle::GetMaxAge ( VehicleID  vehicle_id)
static

Get the maximum age of a vehicle.

Parameters
vehicle_idThe vehicle to get the age of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The maximum age for the vehicle in calendar-days.
See also
GSCalendarTime

◆ GetMaximumOrderDistance()

static int GSVehicle::GetMaximumOrderDistance ( VehicleID  vehicle_id)
static

Get the maximum allowed distance between two orders for a vehicle.

The distance returned is a vehicle-type specific distance independent from other map distances, you may use the result of this function to compare it with the result of GSOrder::GetOrderDistance.

Parameters
vehicle_idThe vehicle to get the distance for.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The maximum distance between two orders for this vehicle or 0 if the distance is unlimited.
Note
The unit of the order distances is unspecified and should not be compared with map distances
See also
GSOrder::GetOrderDistance

◆ GetName()

static string GSVehicle::GetName ( VehicleID  vehicle_id)
static

Get the name of a vehicle.

Parameters
vehicle_idThe vehicle to get the name of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The name the vehicle has.

◆ GetNumWagons()

static int GSVehicle::GetNumWagons ( VehicleID  vehicle_id)
static

Get the number of wagons a vehicle has.

Parameters
vehicle_idThe vehicle to get the number of wagons from.
Precondition
IsValidVehicle(vehicle_id).
Returns
The number of wagons the vehicle has.

◆ GetOwner()

static GSCompany::CompanyID GSVehicle::GetOwner ( VehicleID  vehicle_id)
static

Get the owner of a vehicle.

Parameters
vehicle_idThe vehicle to get the owner of.
Precondition
IsValidVehicle(vehicle_id).
Returns
The owner the vehicle has.

◆ GetProfitLastYear()

static Money GSVehicle::GetProfitLastYear ( VehicleID  vehicle_id)
static

Get the profit of last year of a vehicle.

Parameters
vehicle_idThe vehicle to get the profit of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The profit the vehicle made in the previous economy-year.
See also
GSEconomyTime

◆ GetProfitThisYear()

static Money GSVehicle::GetProfitThisYear ( VehicleID  vehicle_id)
static

Get the current profit of a vehicle.

Parameters
vehicle_idThe vehicle to get the profit of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The profit the vehicle has made this economy-year so far.
See also
GSEconomyTime

◆ GetRefitCapacity()

static int GSVehicle::GetRefitCapacity ( VehicleID  vehicle_id,
CargoID  cargo 
)
static

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

Parameters
vehicle_idThe vehicle to refit.
cargoThe cargo to refit to.
Precondition
IsValidVehicle(vehicle_id).
GSCargo::IsValidCargo(cargo).
You must own the vehicle.
The vehicle must be stopped in the depot.
Returns
The capacity the vehicle will have when refited.

◆ GetReliability()

static int GSVehicle::GetReliability ( VehicleID  vehicle_id)
static

Get the current reliability of a vehicle.

Parameters
vehicle_idThe vehicle to check.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The current reliability (0-100%).

◆ GetRoadType()

static GSRoad::RoadType GSVehicle::GetRoadType ( VehicleID  vehicle_id)
static

Get the RoadType of the vehicle.

Parameters
vehicle_idThe vehicle to get the RoadType of.
Precondition
IsValidVehicle(vehicle_id).
GetVehicleType(vehicle_id) == VT_ROAD.
Returns
The RoadType the vehicle has.

◆ GetRunningCost()

static Money GSVehicle::GetRunningCost ( VehicleID  vehicle_id)
static

Get the running cost of this vehicle.

Parameters
vehicle_idThe vehicle to get the running cost of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The running cost of the vehicle per economy-year.
Note
This is not equal to GSEngine::GetRunningCost for Trains, because wagons and second engines can add up in the calculation too.
See also
GSEconomyTime

◆ GetState()

static VehicleState GSVehicle::GetState ( VehicleID  vehicle_id)
static

Get the current state of a vehicle.

Parameters
vehicle_idThe vehicle to get the state of.
Precondition
IsValidVehicle(vehicle_id).
Returns
The current state of the vehicle.

◆ GetUnitNumber()

static int GSVehicle::GetUnitNumber ( VehicleID  vehicle_id)
static

Get the unitnumber of a vehicle.

Parameters
vehicle_idThe vehicle to get the unitnumber of.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
The unitnumber the vehicle has.

◆ GetVehicleType()

static GSVehicle::VehicleType GSVehicle::GetVehicleType ( VehicleID  vehicle_id)
static

Get the type of vehicle.

Parameters
vehicle_idThe vehicle to get the type of.
Precondition
IsValidVehicle(vehicle_id).
Returns
The vehicle type.

◆ GetWagonAge()

static int GSVehicle::GetWagonAge ( VehicleID  vehicle_id,
int  wagon 
)
static

Get the current age of a second (or third, etc.) engine in a train vehicle.

Parameters
vehicle_idThe vehicle to get the age of.
wagonThe wagon in the vehicle to get the age of.
Precondition
IsValidVehicle(vehicle_id).
wagon < GetNumWagons(vehicle_id).
Returns
The current age of the vehicle in calendar-days.
See also
GSCalendarTime

◆ GetWagonEngineType()

static EngineID GSVehicle::GetWagonEngineType ( VehicleID  vehicle_id,
int  wagon 
)
static

Get the engine-type of a wagon.

Parameters
vehicle_idThe vehicle to get the engine-type of.
wagonThe 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.

◆ HasSharedOrders()

static bool GSVehicle::HasSharedOrders ( VehicleID  vehicle_id)
static

Check if the vehicle has shared orders.

Parameters
vehicle_idThe vehicle to check.
Precondition
IsPrimaryVehicle(vehicle_id).
Returns
True if the vehicle has shared orders.

◆ IsArticulated()

static bool GSVehicle::IsArticulated ( VehicleID  vehicle_id)
static

Check if the vehicle is articulated.

Parameters
vehicle_idThe vehicle to check.
Precondition
IsValidVehicle(vehicle_id).
GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
Returns
True if the vehicle is articulated.

◆ IsInDepot()

static bool GSVehicle::IsInDepot ( VehicleID  vehicle_id)
static

Check if a vehicle is in a depot.

Parameters
vehicle_idThe vehicle to check.
Precondition
IsValidVehicle(vehicle_id).
Returns
True if and only if the vehicle is in a depot.

◆ IsPrimaryVehicle()

static bool GSVehicle::IsPrimaryVehicle ( VehicleID  vehicle_id)
static

Checks whether this is a primary vehicle.

Parameters
vehicle_idThe vehicle to check.
Precondition
IsValidVehicle(vehicle_id).
Returns
True if the vehicle is a primary vehicle.
Note
Returns false when the leading part of the vehicle is a wagon.

◆ IsStoppedInDepot()

static bool GSVehicle::IsStoppedInDepot ( VehicleID  vehicle_id)
static

Check if a vehicle is in a depot and stopped.

Parameters
vehicle_idThe vehicle to check.
Precondition
IsValidVehicle(vehicle_id).
Returns
True if and only if the vehicle is in a depot and stopped.

◆ IsValidVehicle()

static bool GSVehicle::IsValidVehicle ( VehicleID  vehicle_id)
static

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

Parameters
vehicle_idThe vehicle to check.
Returns
True if and only if the vehicle is valid.
Note
Also returns true when the leading part of the vehicle is a wagon. Use IsPrimaryVehicle() to check for a valid vehicle with a leading engine.

◆ MoveWagon()

static bool GSVehicle::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_idThe vehicle to move a wagon away from.
source_wagonThe wagon in source_vehicle to move.
dest_vehicle_idThe vehicle to move the wagon to, or -1 to create a new vehicle.
dest_wagonThe 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.
GSCompanyMode::IsValid().
Returns
Whether or not moving the wagon succeeded.

◆ MoveWagonChain()

static bool GSVehicle::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_idThe vehicle to move a wagon away from.
source_wagonThe first wagon in source_vehicle to move.
dest_vehicle_idThe vehicle to move the wagons to, or -1 to create a new vehicle.
dest_wagonThe 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.
GSCompanyMode::IsValid().
Returns
Whether or not moving the wagons succeeded.

◆ RefitVehicle()

static bool GSVehicle::RefitVehicle ( VehicleID  vehicle_id,
CargoID  cargo 
)
static

Refits a vehicle to the given cargo type.

Parameters
vehicle_idThe vehicle to refit.
cargoThe cargo to refit to.
Precondition
IsValidVehicle(vehicle_id).
GSCargo::IsValidCargo(cargo).
You must own the vehicle.
The vehicle must be stopped in the depot.
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_CANNOT_REFIT
GSVehicle::ERR_VEHICLE_IS_DESTROYED
GSVehicle::ERR_VEHICLE_NOT_IN_DEPOT
Returns
True if and only if the refit succeeded.

◆ ReverseVehicle()

static bool GSVehicle::ReverseVehicle ( VehicleID  vehicle_id)
static

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

Parameters
vehicle_idThe vehicle to turn.
Precondition
IsPrimaryVehicle(vehicle_id).
GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
GSCompanyMode::IsValid().
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.

◆ SellVehicle()

static bool GSVehicle::SellVehicle ( VehicleID  vehicle_id)
static

Sells the given vehicle.

Parameters
vehicle_idThe vehicle to sell.
Precondition
IsValidVehicle(vehicle_id).
You must own the vehicle.
The vehicle must be stopped in the depot.
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_IS_DESTROYED
GSVehicle::ERR_VEHICLE_NOT_IN_DEPOT
Returns
True if and only if the vehicle has been sold.

◆ SellWagon()

static bool GSVehicle::SellWagon ( VehicleID  vehicle_id,
int  wagon 
)
static

Sells the given wagon from the vehicle.

Parameters
vehicle_idThe vehicle to sell a wagon from.
wagonThe wagon to sell.
Precondition
IsValidVehicle(vehicle_id).
wagon < GetNumWagons(vehicle_id).
You must own the vehicle.
The vehicle must be stopped in the depot.
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_IS_DESTROYED
GSVehicle::ERR_VEHICLE_NOT_IN_DEPOT
Returns
True if and only if the wagon has been sold.

◆ SellWagonChain()

static bool GSVehicle::SellWagonChain ( VehicleID  vehicle_id,
int  wagon 
)
static

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

Parameters
vehicle_idThe vehicle to sell a wagon from.
wagonThe wagon to sell.
Precondition
IsValidVehicle(vehicle_id).
wagon < GetNumWagons(vehicle_id).
You must own the vehicle.
The vehicle must be stopped in the depot.
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_IS_DESTROYED
GSVehicle::ERR_VEHICLE_NOT_IN_DEPOT
Returns
True if and only if the wagons have been sold.

◆ SendVehicleToDepot()

static bool GSVehicle::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_idThe vehicle to send to a depot.
Precondition
IsPrimaryVehicle(vehicle_id).
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
Returns
True if the current order was changed.

◆ SendVehicleToDepotForServicing()

static bool GSVehicle::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_idThe vehicle to send to a depot for servicing.
Precondition
IsPrimaryVehicle(vehicle_id).
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
Returns
True if the current order was changed.

◆ SetName()

static bool GSVehicle::SetName ( VehicleID  vehicle_id,
Text *  name 
)
static

Set the name of a vehicle.

Parameters
vehicle_idThe vehicle to set the name for.
nameThe name for the vehicle (can be either a raw string, or a GSText object).
Precondition
IsPrimaryVehicle(vehicle_id).
name != null && len(name) != 0.
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_NAME_IS_NOT_UNIQUE
Returns
True if and only if the name was changed.

◆ StartStopVehicle()

static bool GSVehicle::StartStopVehicle ( VehicleID  vehicle_id)
static

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

Parameters
vehicle_idThe vehicle to start/stop.
Precondition
IsPrimaryVehicle(vehicle_id).
GSCompanyMode::IsValid().
Exceptions
GSVehicle::ERR_VEHICLE_CANNOT_START_STOP
(Foraircraft only): GSVehicle::ERR_VEHICLE_IN_FLIGHT
(Fortrains only): GSVehicle::ERR_VEHICLE_NO_POWER
Returns
True if and only if the vehicle has been started or stopped.