OpenTTD GameScript API  20241118-master-gb8f3d0dd68
Public Types | Static Public Member Functions
GSOrder Class Reference

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

Inheritance diagram for GSOrder:

Public Types

enum  ErrorMessages {
  ERR_ORDER_BASE ,
  ERR_ORDER_TOO_MANY ,
  ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION ,
  ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
}
 All order related error messages. More...
 
enum  GSOrderFlags {
  OF_NONE ,
  OF_NON_STOP_INTERMEDIATE ,
  OF_NON_STOP_DESTINATION ,
  OF_UNLOAD ,
  OF_TRANSFER ,
  OF_NO_UNLOAD ,
  OF_FULL_LOAD ,
  OF_FULL_LOAD_ANY ,
  OF_NO_LOAD ,
  OF_SERVICE_IF_NEEDED ,
  OF_STOP_IN_DEPOT ,
  OF_GOTO_NEAREST_DEPOT ,
  OF_NON_STOP_FLAGS ,
  OF_UNLOAD_FLAGS ,
  OF_LOAD_FLAGS ,
  OF_DEPOT_FLAGS ,
  OF_INVALID
}
 Flags that can be used to modify the behaviour of orders. More...
 
enum  OrderCondition {
  OC_LOAD_PERCENTAGE ,
  OC_RELIABILITY ,
  OC_MAX_RELIABILITY ,
  OC_MAX_SPEED ,
  OC_AGE ,
  OC_REQUIRES_SERVICE ,
  OC_UNCONDITIONALLY ,
  OC_REMAINING_LIFETIME ,
  OC_INVALID
}
 All conditions a conditional order can depend on. More...
 
enum  CompareFunction {
  CF_EQUALS ,
  CF_NOT_EQUALS ,
  CF_LESS_THAN ,
  CF_LESS_EQUALS ,
  CF_MORE_THAN ,
  CF_MORE_EQUALS ,
  CF_IS_TRUE ,
  CF_IS_FALSE ,
  CF_INVALID
}
 Comparators for conditional orders. More...
 
enum  OrderPosition {
  ORDER_CURRENT ,
  ORDER_INVALID
}
 Index in the list of orders for a vehicle. More...
 
enum  StopLocation {
  STOPLOCATION_NEAR ,
  STOPLOCATION_MIDDLE ,
  STOPLOCATION_FAR ,
  STOPLOCATION_INVALID
}
 Where to stop trains in a station that's longer than the train. More...
 

Static Public Member Functions

static bool IsValidVehicleOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order id is valid for the given vehicle. More...
 
static bool IsGotoStationOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a goto-station order. More...
 
static bool IsGotoDepotOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a goto-depot order. More...
 
static bool IsGotoWaypointOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a goto-waypoint order. More...
 
static bool IsConditionalOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a conditional order. More...
 
static bool IsVoidOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a void order. More...
 
static bool IsRefitOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order has a valid refit cargo. More...
 
static bool IsCurrentOrderPartOfOrderList (VehicleID vehicle_id)
 Checks whether the current order is part of the orderlist. More...
 
static OrderPosition ResolveOrderPosition (VehicleID vehicle_id, OrderPosition order_position)
 Resolves the given order index to the correct index for the given vehicle. More...
 
static bool AreOrderFlagsValid (TileIndex destination, GSOrderFlags order_flags)
 Checks whether the given order flags are valid for the given destination. More...
 
static bool IsValidConditionalOrder (OrderCondition condition, CompareFunction compare)
 Checks whether the given combination of condition and compare function is valid. More...
 
static int GetOrderCount (VehicleID vehicle_id)
 Returns the number of orders for the given vehicle. More...
 
static TileIndex GetOrderDestination (VehicleID vehicle_id, OrderPosition order_position)
 Gets the destination of the given order for the given vehicle. More...
 
static GSOrderFlags GetOrderFlags (VehicleID vehicle_id, OrderPosition order_position)
 Gets the GSOrderFlags of the given order for the given vehicle. More...
 
static OrderPosition GetOrderJumpTo (VehicleID vehicle_id, OrderPosition order_position)
 Gets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle. More...
 
static OrderCondition GetOrderCondition (VehicleID vehicle_id, OrderPosition order_position)
 Gets the OrderCondition of the given order for the given vehicle. More...
 
static CompareFunction GetOrderCompareFunction (VehicleID vehicle_id, OrderPosition order_position)
 Gets the CompareFunction of the given order for the given vehicle. More...
 
static int GetOrderCompareValue (VehicleID vehicle_id, OrderPosition order_position)
 Gets the value to compare against of the given order for the given vehicle. More...
 
static StopLocation GetStopLocation (VehicleID vehicle_id, OrderPosition order_position)
 Gets the stoplocation of the given order for the given train. More...
 
static CargoID GetOrderRefit (VehicleID vehicle_id, OrderPosition order_position)
 Gets the refit cargo type of the given order for the given vehicle. More...
 
static bool SetOrderJumpTo (VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
 Sets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle. More...
 
static bool SetOrderCondition (VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
 Sets the OrderCondition of the given order for the given vehicle. More...
 
static bool SetOrderCompareFunction (VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
 Sets the CompareFunction of the given order for the given vehicle. More...
 
static bool SetOrderCompareValue (VehicleID vehicle_id, OrderPosition order_position, int value)
 Sets the value to compare against of the given order for the given vehicle. More...
 
static bool SetStopLocation (VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
 Sets the stoplocation of the given order for the given train. More...
 
static bool SetOrderRefit (VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo)
 Sets the refit cargo type of the given order for the given vehicle. More...
 
static bool AppendOrder (VehicleID vehicle_id, TileIndex destination, GSOrderFlags order_flags)
 Appends an order to the end of the vehicle's order list. More...
 
static bool AppendConditionalOrder (VehicleID vehicle_id, OrderPosition jump_to)
 Appends a conditional order to the end of the vehicle's order list. More...
 
static bool InsertOrder (VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, GSOrderFlags order_flags)
 Inserts an order before the given order_position into the vehicle's order list. More...
 
static bool InsertConditionalOrder (VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
 Appends a conditional order before the given order_position into the vehicle's order list. More...
 
static bool RemoveOrder (VehicleID vehicle_id, OrderPosition order_position)
 Removes an order from the vehicle's order list. More...
 
static bool SetOrderFlags (VehicleID vehicle_id, OrderPosition order_position, GSOrderFlags order_flags)
 Changes the order flags of the given order. More...
 
static bool MoveOrder (VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target)
 Move an order inside the orderlist. More...
 
static bool SkipToOrder (VehicleID vehicle_id, OrderPosition next_order)
 Make a vehicle execute next_order instead of its current order. More...
 
static bool CopyOrders (VehicleID vehicle_id, VehicleID main_vehicle_id)
 Copies the orders from another vehicle. More...
 
static bool ShareOrders (VehicleID vehicle_id, VehicleID main_vehicle_id)
 Shares the orders between two vehicles. More...
 
static bool UnshareOrders (VehicleID vehicle_id)
 Removes the given vehicle from a shared orders list. More...
 
static int GetOrderDistance (GSVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile)
 Get the distance between two points for a vehicle type. More...
 

Detailed Description

Class that handles all order related functions.

Member Enumeration Documentation

◆ CompareFunction

Comparators for conditional orders.

Enumerator
CF_EQUALS 

Skip if both values are equal.

CF_NOT_EQUALS 

Skip if both values are not equal.

CF_LESS_THAN 

Skip if the value is less than the limit.

CF_LESS_EQUALS 

Skip if the value is less or equal to the limit.

CF_MORE_THAN 

Skip if the value is more than the limit.

CF_MORE_EQUALS 

Skip if the value is more or equal to the limit.

CF_IS_TRUE 

Skip if the variable is true.

CF_IS_FALSE 

Skip if the variable is false.

CF_INVALID 

Invalid compare function, do not use.

◆ ErrorMessages

All order related error messages.

See also
ScriptErrorType
Enumerator
ERR_ORDER_BASE 

Base for all order related errors.

ERR_ORDER_TOO_MANY 

No more space for orders.

ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION 

Destination of new order is too far away from the previous order.

ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE 

Aircraft has not enough range to copy/share orders.

◆ GSOrderFlags

Flags that can be used to modify the behaviour of orders.

Enumerator
OF_NONE 

Just go to the station/depot, stop unload if possible and load if needed.

OF_NON_STOP_INTERMEDIATE 

Do not stop at the stations that are passed when going to the destination.

Only for trains and road vehicles.

OF_NON_STOP_DESTINATION 

Do not stop at the destination station.

Only for trains and road vehicles.

OF_UNLOAD 

Always unload the vehicle; only for stations.

Cannot be set when OF_TRANSFER or OF_NO_UNLOAD is set.

OF_TRANSFER 

Transfer instead of deliver the goods; only for stations.

Cannot be set when OF_UNLOAD or OF_NO_UNLOAD is set.

OF_NO_UNLOAD 

Never unload the vehicle; only for stations.

Cannot be set when OF_UNLOAD, OF_TRANSFER or OF_NO_LOAD is set.

OF_FULL_LOAD 

Wt till the vehicle is fully loaded; only for stations.

Cannot be set when OF_NO_LOAD is set.

OF_FULL_LOAD_ANY 

Wt till at least one cargo of the vehicle is fully loaded; only for stations.

Cannot be set when OF_NO_LOAD is set.

OF_NO_LOAD 

Do not load any cargo; only for stations.

Cannot be set when OF_NO_UNLOAD, OF_FULL_LOAD or OF_FULL_LOAD_ANY is set.

OF_SERVICE_IF_NEEDED 

Service the vehicle when needed, otherwise skip this order; only for depots.

OF_STOP_IN_DEPOT 

Stop in the depot instead of only go there for servicing; only for depots.

OF_GOTO_NEAREST_DEPOT 

Go to nearest depot.

OF_NON_STOP_FLAGS 

All flags related to non-stop settings.

OF_UNLOAD_FLAGS 

All flags related to unloading.

OF_LOAD_FLAGS 

All flags related to loading.

OF_DEPOT_FLAGS 

All flags related to depots.

OF_INVALID 

For marking invalid order flags.

◆ OrderCondition

All conditions a conditional order can depend on.

Enumerator
OC_LOAD_PERCENTAGE 

Skip based on the amount of load, value is in tons.

OC_RELIABILITY 

Skip based on the reliability, value is percent (0..100).

OC_MAX_RELIABILITY 

Skip based on the maximum reliability. Value in percent.

OC_MAX_SPEED 

Skip based on the maximum speed, value is in OpenTTD's internal speed unit, see GSEngine::GetMaxSpeed.

OC_AGE 

Skip based on the age, value is in calender-years.

See also
GSCalendarTime
OC_REQUIRES_SERVICE 

Skip when the vehicle requires service, no value.

OC_UNCONDITIONALLY 

Always skip, no compare function, no value.

OC_REMAINING_LIFETIME 

Skip based on the remaining lifetime in calendar-years.

See also
GSCalendarTime
OC_INVALID 

An invalid condition, do not use.

◆ OrderPosition

Index in the list of orders for a vehicle.

The first order has index 0, the second order index 1, etc. The current order can be queried by using ORDER_CURRENT. Do not use ORDER_INVALID yourself, it's used as return value by for example ResolveOrderPosition.

Note
Automatic orders are hidden from scripts, so OrderPosition 0 will always be the first manual order.
Enumerator
ORDER_CURRENT 

Constant that gets resolved to the current order.

ORDER_INVALID 

An invalid order.

◆ StopLocation

Where to stop trains in a station that's longer than the train.

Enumerator
STOPLOCATION_NEAR 

Stop the train as soon as it's completely in the station.

STOPLOCATION_MIDDLE 

Stop the train in the middle of the station.

STOPLOCATION_FAR 

Stop the train at the far end of the station.

STOPLOCATION_INVALID 

An invalid stop location.

Member Function Documentation

◆ AppendConditionalOrder()

static bool GSOrder::AppendConditionalOrder ( VehicleID  vehicle_id,
OrderPosition  jump_to 
)
static

Appends a conditional order to the end of the vehicle's order list.

Parameters
vehicle_idThe vehicle to append the order to.
jump_toThe OrderPosition to jump to if the condition is true.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
IsValidVehicleOrder(vehicle_id, jump_to).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSOrder::ERR_ORDER_TOO_MANY
Returns
True if and only if the order was appended.

◆ AppendOrder()

static bool GSOrder::AppendOrder ( VehicleID  vehicle_id,
TileIndex  destination,
GSOrderFlags  order_flags 
)
static

Appends an order to the end of the vehicle's order list.

Parameters
vehicle_idThe vehicle to append the order to.
destinationThe destination of the order.
order_flagsThe flags given to the order.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
AreOrderFlagsValid(destination, order_flags).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSOrder::ERR_ORDER_TOO_MANY
GSOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
Returns
True if and only if the order was appended.

◆ AreOrderFlagsValid()

static bool GSOrder::AreOrderFlagsValid ( TileIndex  destination,
GSOrderFlags  order_flags 
)
static

Checks whether the given order flags are valid for the given destination.

Parameters
destinationThe destination of the order.
order_flagsThe flags given to the order.
Returns
True if and only if the order_flags are valid for the given location.

◆ CopyOrders()

static bool GSOrder::CopyOrders ( VehicleID  vehicle_id,
VehicleID  main_vehicle_id 
)
static

Copies the orders from another vehicle.

The orders of the main vehicle are going to be the orders of the changed vehicle.

Parameters
vehicle_idThe vehicle to copy the orders to.
main_vehicle_idThe vehicle to copy the orders from.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
GSVehicle::IsPrimaryVehicle(main_vehicle_id).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSOrder::ERR_ORDER_TOO_MANY
GSOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
Returns
True if and only if the copying succeeded.

◆ GetOrderCompareFunction()

static CompareFunction GSOrder::GetOrderCompareFunction ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the CompareFunction of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the compare function for.
order_positionThe order to get the compare function for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
Returns
The CompareFunction of the order.

◆ GetOrderCompareValue()

static int GSOrder::GetOrderCompareValue ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the value to compare against of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the value for.
order_positionThe order to get the value for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
Returns
The value to compare against of the order.

◆ GetOrderCondition()

static OrderCondition GSOrder::GetOrderCondition ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the OrderCondition of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the condition type for.
order_positionThe order to get the condition type for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
Returns
The OrderCondition of the order.

◆ GetOrderCount()

static int GSOrder::GetOrderCount ( VehicleID  vehicle_id)
static

Returns the number of orders for the given vehicle.

Parameters
vehicle_idThe vehicle to get the order count of.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
Returns
The number of orders for the given vehicle or a negative value when the vehicle does not exist.

◆ GetOrderDestination()

static TileIndex GSOrder::GetOrderDestination ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the destination of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the destination for.
order_positionThe order to get the destination for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position).
Note
Giving ORDER_CURRENT as order_position will give the order that is currently being executed by the vehicle. This is not necessarily the current order as given by ResolveOrderPosition (the current index in the order list) as manual or autoservicing depot orders do not show up in the orderlist, but they can be the current order of a vehicle.
Returns
The destination tile of the order.

◆ GetOrderDistance()

static int GSOrder::GetOrderDistance ( GSVehicle::VehicleType  vehicle_type,
TileIndex  origin_tile,
TileIndex  dest_tile 
)
static

Get the distance between two points for a vehicle type.

Use this function to compute the distance between two tiles wrt. a vehicle type. These vehicle-type specific distances are independent from other map distances, you may use the result of this function to compare it with the result of GSEngine::GetMaximumOrderDistance or GSVehicle::GetMaximumOrderDistance.

Parameters
vehicle_typeThe vehicle type to get the distance for.
origin_tileOrigin, can be any tile or a tile of a specific station.
dest_tileDestination, can be any tile or a tile of a specific station.
Returns
The distance between the origin and the destination for a vehicle of the given vehicle type.
Note
The unit of the order distances is unspecified and should not be compared with map distances
See also
GSEngine::GetMaximumOrderDistance and GSVehicle::GetMaximumOrderDistance

◆ GetOrderFlags()

static GSOrderFlags GSOrder::GetOrderFlags ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the GSOrderFlags of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the destination for.
order_positionThe order to get the destination for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position == ORDER_CURRENT || (!IsConditionalOrder(vehicle_id, order_position) && !IsVoidOrder(vehicle_id, order_position)).
Note
Giving ORDER_CURRENT as order_position will give the order that is currently being executed by the vehicle. This is not necessarily the current order as given by ResolveOrderPosition (the current index in the order list) as manual or autoservicing depot orders do not show up in the orderlist, but they can be the current order of a vehicle.
Returns
The GSOrderFlags of the order.

◆ GetOrderJumpTo()

static OrderPosition GSOrder::GetOrderJumpTo ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the OrderPosition for.
order_positionThe order to get the OrderPosition for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
Returns
The target of the conditional jump.

◆ GetOrderRefit()

static CargoID GSOrder::GetOrderRefit ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the refit cargo type of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to get the refit cargo for.
order_positionThe order to get the refit cargo for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position == ORDER_CURRENT || IsGotoStationOrder(vehicle_id, order_position) || IsGotoDepotOrder(vehicle_id, order_position).
Note
Giving ORDER_CURRENT as order_position will give the order that is currently being executed by the vehicle. This is not necessarily the current order as given by ResolveOrderPosition (the current index in the order list) as manual or autoservicing depot orders do not show up in the orderlist, but they can be the current order of a vehicle.
Returns
The refit cargo of the order or CT_NO_REFIT if no refit is set.

◆ GetStopLocation()

static StopLocation GSOrder::GetStopLocation ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Gets the stoplocation of the given order for the given train.

Parameters
vehicle_idThe vehicle to get the value for.
order_positionThe order to get the value for.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
GSVehicle::GetVehicleType(vehicle_id) == GSVehicle::VT_RAIL.
IsGotoStationOrder(vehicle_id, order_position).
Returns
The relative position where the train will stop inside a station.

◆ InsertConditionalOrder()

static bool GSOrder::InsertConditionalOrder ( VehicleID  vehicle_id,
OrderPosition  order_position,
OrderPosition  jump_to 
)
static

Appends a conditional order before the given order_position into the vehicle's order list.

Parameters
vehicle_idThe vehicle to add the order to.
order_positionThe order to place the new order before.
jump_toThe OrderPosition to jump to if the condition is true.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
IsValidVehicleOrder(vehicle_id, order_position).
IsValidVehicleOrder(vehicle_id, jump_to).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSOrder::ERR_ORDER_TOO_MANY
Returns
True if and only if the order was inserted.

◆ InsertOrder()

static bool GSOrder::InsertOrder ( VehicleID  vehicle_id,
OrderPosition  order_position,
TileIndex  destination,
GSOrderFlags  order_flags 
)
static

Inserts an order before the given order_position into the vehicle's order list.

Parameters
vehicle_idThe vehicle to add the order to.
order_positionThe order to place the new order before.
destinationThe destination of the order.
order_flagsThe flags given to the order.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id)
IsValidVehicleOrder(vehicle_id, order_position).
AreOrderFlagsValid(destination, order_flags).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSOrder::ERR_ORDER_TOO_MANY
GSOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
Returns
True if and only if the order was inserted.

◆ IsConditionalOrder()

static bool GSOrder::IsConditionalOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order is a conditional order.

Parameters
vehicle_idThe vehicle to check.
order_positionThe order index to check.
Precondition
order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
Returns
True if and only if the order is a conditional order.

◆ IsCurrentOrderPartOfOrderList()

static bool GSOrder::IsCurrentOrderPartOfOrderList ( VehicleID  vehicle_id)
static

Checks whether the current order is part of the orderlist.

Parameters
vehicle_idThe vehicle to check.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
Returns
True if and only if the current order is part of the order list.
Note
If the order is a non-'non-stop' order, and the vehicle is currently (un)loading at a station that is not the final destination, this function will still return true.

◆ IsGotoDepotOrder()

static bool GSOrder::IsGotoDepotOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order is a goto-depot order.

Parameters
vehicle_idThe vehicle to check.
order_positionThe order index to check.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
Returns
True if and only if the order is a goto-depot order.

◆ IsGotoStationOrder()

static bool GSOrder::IsGotoStationOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order is a goto-station order.

Parameters
vehicle_idThe vehicle to check.
order_positionThe order index to check.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
Returns
True if and only if the order is a goto-station order.

◆ IsGotoWaypointOrder()

static bool GSOrder::IsGotoWaypointOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order is a goto-waypoint order.

Parameters
vehicle_idThe vehicle to check.
order_positionThe order index to check.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
Returns
True if and only if the order is a goto-waypoint order.

◆ IsRefitOrder()

static bool GSOrder::IsRefitOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order has a valid refit cargo.

Parameters
vehicle_idThe vehicle to check.
order_positionThe order index to check.
Precondition
order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
Returns
True if and only if the order is has a valid refit cargo.

◆ IsValidConditionalOrder()

static bool GSOrder::IsValidConditionalOrder ( OrderCondition  condition,
CompareFunction  compare 
)
static

Checks whether the given combination of condition and compare function is valid.

Parameters
conditionThe condition to check.
compareThe compare function to check.
Returns
True if and only if the combination of condition and compare function is valid.

◆ IsValidVehicleOrder()

static bool GSOrder::IsValidVehicleOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order id is valid for the given vehicle.

Parameters
vehicle_idThe vehicle to check the order index for.
order_positionThe order index to check.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
Returns
True if and only if the order_position is valid for the given vehicle.

◆ IsVoidOrder()

static bool GSOrder::IsVoidOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Checks whether the given order is a void order.

A void order is an order that used to be a goto station, depot or waypoint order but its destination got removed. In OpenTTD these orders as shown as "(Invalid Order)" in the order list of a vehicle.

Parameters
vehicle_idThe vehicle to check.
order_positionThe order index to check.
Precondition
order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
Returns
True if and only if the order is a void order.

◆ MoveOrder()

static bool GSOrder::MoveOrder ( VehicleID  vehicle_id,
OrderPosition  order_position_move,
OrderPosition  order_position_target 
)
static

Move an order inside the orderlist.

Parameters
vehicle_idThe vehicle to move the orders.
order_position_moveThe order to move.
order_position_targetThe target order
Precondition
IsValidVehicleOrder(vehicle_id, order_position_move).
IsValidVehicleOrder(vehicle_id, order_position_target).
order_position_move != order_position_target.
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
Returns
True if and only if the order was moved.
Note
If the order is moved to a lower place (e.g. from 7 to 2) the target order is moved upwards (e.g. 3). If the order is moved to a higher place (e.g. from 7 to 9) the target will be moved downwards (e.g. 8).

◆ RemoveOrder()

static bool GSOrder::RemoveOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Removes an order from the vehicle's order list.

Parameters
vehicle_idThe vehicle to remove the order from.
order_positionThe order to remove from the order list.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
Returns
True if and only if the order was removed.

◆ ResolveOrderPosition()

static OrderPosition GSOrder::ResolveOrderPosition ( VehicleID  vehicle_id,
OrderPosition  order_position 
)
static

Resolves the given order index to the correct index for the given vehicle.

If the order index was ORDER_CURRENT it will be resolved to the index of the current order (as shown in the order list). If the order with the given index does not exist it will return ORDER_INVALID.

Parameters
vehicle_idThe vehicle to check the order index for.
order_positionThe order index to resolve.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
Returns
The resolved order index.

◆ SetOrderCompareFunction()

static bool GSOrder::SetOrderCompareFunction ( VehicleID  vehicle_id,
OrderPosition  order_position,
CompareFunction  compare 
)
static

Sets the CompareFunction of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to set the compare function for.
order_positionThe order to set the compare function for.
compareThe new compare function of the order.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
compare >= CF_EQUALS && compare <= CF_IS_FALSE.
GSCompanyMode::IsValid().
Returns
Whether the order has been/can be changed.

◆ SetOrderCompareValue()

static bool GSOrder::SetOrderCompareValue ( VehicleID  vehicle_id,
OrderPosition  order_position,
int  value 
)
static

Sets the value to compare against of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to set the value for.
order_positionThe order to set the value for.
valueThe value to compare against.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
value >= 0 && value < 2048.
GSCompanyMode::IsValid().
Returns
Whether the order has been/can be changed.

◆ SetOrderCondition()

static bool GSOrder::SetOrderCondition ( VehicleID  vehicle_id,
OrderPosition  order_position,
OrderCondition  condition 
)
static

Sets the OrderCondition of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to set the condition type for.
order_positionThe order to set the condition type for.
conditionThe condition to compare on.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY.
GSCompanyMode::IsValid().
Returns
Whether the order has been/can be changed.

◆ SetOrderFlags()

static bool GSOrder::SetOrderFlags ( VehicleID  vehicle_id,
OrderPosition  order_position,
GSOrderFlags  order_flags 
)
static

Changes the order flags of the given order.

Parameters
vehicle_idThe vehicle to change the order of.
order_positionThe order to change.
order_flagsThe new flags given to the order.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
(order_flags & OF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & OF_GOTO_NEAREST_DEPOT).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
Returns
True if and only if the order was changed.

◆ SetOrderJumpTo()

static bool GSOrder::SetOrderJumpTo ( VehicleID  vehicle_id,
OrderPosition  order_position,
OrderPosition  jump_to 
)
static

Sets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to set the OrderPosition for.
order_positionThe order to set the OrderPosition for.
jump_toThe order to jump to if the check succeeds.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
IsValidVehicleOrder(vehicle_id, jump_to).
order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
GSCompanyMode::IsValid().
Returns
Whether the order has been/can be changed.

◆ SetOrderRefit()

static bool GSOrder::SetOrderRefit ( VehicleID  vehicle_id,
OrderPosition  order_position,
CargoID  refit_cargo 
)
static

Sets the refit cargo type of the given order for the given vehicle.

Parameters
vehicle_idThe vehicle to set the refit cargo for.
order_positionThe order to set the refit cargo for.
refit_cargoThe cargo to refit to. The refit can be cleared by passing CT_NO_REFIT.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT).
GSCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT
GSCompanyMode::IsValid().
Returns
Whether the order has been/can be changed.

◆ SetStopLocation()

static bool GSOrder::SetStopLocation ( VehicleID  vehicle_id,
OrderPosition  order_position,
StopLocation  stop_location 
)
static

Sets the stoplocation of the given order for the given train.

Parameters
vehicle_idThe vehicle to get the value for.
order_positionThe order to get the value for.
stop_locationThe relative position where a train will stop inside a station.
Precondition
IsValidVehicleOrder(vehicle_id, order_position).
GSVehicle::GetVehicleType(vehicle_id) == GSVehicle::VT_RAIL.
IsGotoStationOrder(vehicle_id, order_position).
stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR
GSCompanyMode::IsValid().
Returns
Whether the order has been/can be changed.

◆ ShareOrders()

static bool GSOrder::ShareOrders ( VehicleID  vehicle_id,
VehicleID  main_vehicle_id 
)
static

Shares the orders between two vehicles.

The orders of the main vehicle are going to be the orders of the changed vehicle.

Parameters
vehicle_idThe vehicle to add to the shared order list.
main_vehicle_idThe vehicle to share the orders with.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
GSVehicle::IsPrimaryVehicle(main_vehicle_id).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
Returns
True if and only if the sharing succeeded.

◆ SkipToOrder()

static bool GSOrder::SkipToOrder ( VehicleID  vehicle_id,
OrderPosition  next_order 
)
static

Make a vehicle execute next_order instead of its current order.

Parameters
vehicle_idThe vehicle that should skip some orders.
next_orderThe order the vehicle should skip to.
Precondition
IsValidVehicleOrder(vehicle_id, next_order).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
Returns
True if and only the current order was changed.

◆ UnshareOrders()

static bool GSOrder::UnshareOrders ( VehicleID  vehicle_id)
static

Removes the given vehicle from a shared orders list.

After unsharing orders, the orders list of the vehicle is empty.

Parameters
vehicle_idThe vehicle to remove from the shared order list.
Precondition
GSVehicle::IsPrimaryVehicle(vehicle_id).
GSCompanyMode::IsValid().
Returns
True if and only if the unsharing succeeded.