AIOrder Class Reference

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

#include <ai_order.hpp>

Inheritance diagram for AIOrder:
AIObject SimpleCountedObject

Public Types

enum  ErrorMessages { ERR_ORDER_BASE = AIError::ERR_CAT_ORDER << AIError::ERR_CAT_BIT_SIZE, ERR_ORDER_TOO_MANY, ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION }
 

All order related error messages.

More...
enum  AIOrderFlags {
  AIOF_NONE = 0, AIOF_NON_STOP_INTERMEDIATE = 1 << 0, AIOF_NON_STOP_DESTINATION = 1 << 1, AIOF_UNLOAD = 1 << 2,
  AIOF_TRANSFER = 1 << 3, AIOF_NO_UNLOAD = 1 << 4, AIOF_FULL_LOAD = 2 << 5, AIOF_FULL_LOAD_ANY = 3 << 5,
  AIOF_NO_LOAD = 1 << 7, AIOF_SERVICE_IF_NEEDED = 1 << 2, AIOF_STOP_IN_DEPOT = 1 << 3, AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
  AIOF_NON_STOP_FLAGS = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION, AIOF_UNLOAD_FLAGS = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD, AIOF_LOAD_FLAGS = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD, AIOF_DEPOT_FLAGS = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
  AIOF_INVALID = 0xFFFF
}
 

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

More...
enum  OrderCondition {
  OC_LOAD_PERCENTAGE, OC_RELIABILITY, OC_MAX_SPEED, OC_AGE,
  OC_REQUIRES_SERVICE, OC_UNCONDITIONALLY, OC_INVALID = -1
}
 

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 = -1
}
 

Comparators for conditional orders.

More...
enum  OrderPosition { ORDER_CURRENT = 0xFF, ORDER_INVALID = -1 }
 

Different constants related to the OrderPosition.

More...
enum  StopLocation { STOPLOCATION_NEAR, STOPLOCATION_MIDDLE, STOPLOCATION_FAR, STOPLOCATION_INVALID = -1 }
 

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

More...

Static Public Member Functions

static const char * GetClassName ()
static bool IsValidVehicleOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order id is valid for the given vehicle.
static bool IsGotoStationOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a goto-station order.
static bool IsGotoDepotOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a goto-depot order.
static bool IsGotoWaypointOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a goto-waypoint order.
static bool IsConditionalOrder (VehicleID vehicle_id, OrderPosition order_position)
 Checks whether the given order is a conditional order.
static bool IsCurrentOrderPartOfOrderList (VehicleID vehicle_id)
 Checks whether the current order is part of the orderlist.
static OrderPosition ResolveOrderPosition (VehicleID vehicle_id, OrderPosition order_position)
 Resolves the given order index to the correct index for the given vehicle.
static bool AreOrderFlagsValid (TileIndex destination, AIOrderFlags order_flags)
 Checks whether the given order flags are valid for the given destination.
static bool IsValidConditionalOrder (OrderCondition condition, CompareFunction compare)
 Checks whether the given combination of condition and compare function is valid.
static int32 GetOrderCount (VehicleID vehicle_id)
 Returns the number of orders for the given vehicle.
static TileIndex GetOrderDestination (VehicleID vehicle_id, OrderPosition order_position)
 Gets the destination of the given order for the given vehicle.
static AIOrderFlags GetOrderFlags (VehicleID vehicle_id, OrderPosition order_position)
 Gets the AIOrderFlags of the given order for the given vehicle.
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.
static OrderCondition GetOrderCondition (VehicleID vehicle_id, OrderPosition order_position)
 Gets the OrderCondition of the given order for the given vehicle.
static CompareFunction GetOrderCompareFunction (VehicleID vehicle_id, OrderPosition order_position)
 Gets the CompareFunction of the given order for the given vehicle.
static int32 GetOrderCompareValue (VehicleID vehicle_id, OrderPosition order_position)
 Gets the value to compare against of the given order for the given vehicle.
static StopLocation GetStopLocation (VehicleID vehicle_id, OrderPosition order_position)
 Gets the stoplocation of the given order for the given train.
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.
static bool SetOrderCondition (VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
 Sets the OrderCondition of the given order for the given vehicle.
static bool SetOrderCompareFunction (VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
 Sets the CompareFunction of the given order for the given vehicle.
static bool SetOrderCompareValue (VehicleID vehicle_id, OrderPosition order_position, int32 value)
 Sets the value to compare against of the given order for the given vehicle.
static bool SetStopLocation (VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
 Sets the stoplocation of the given order for the given train.
static bool AppendOrder (VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags)
 Appends an order to the end of the vehicle's order list.
static bool AppendConditionalOrder (VehicleID vehicle_id, OrderPosition jump_to)
 Appends a conditional order to the end of the vehicle's order list.
static bool InsertOrder (VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags)
 Inserts an order before the given order_position into the vehicle's order list.
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.
static bool RemoveOrder (VehicleID vehicle_id, OrderPosition order_position)
 Removes an order from the vehicle's order list.
static bool _SetOrderFlags ()
 Internal function to help SetOrderFlags.
static bool SetOrderFlags (VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags)
 Changes the order flags of the given order.
static bool MoveOrder (VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target)
 Move an order inside the orderlist.
static bool SkipToOrder (VehicleID vehicle_id, OrderPosition next_order)
 Make a vehicle execute next_order instead of its current order.
static bool CopyOrders (VehicleID vehicle_id, VehicleID main_vehicle_id)
 Copies the orders from another vehicle.
static bool ShareOrders (VehicleID vehicle_id, VehicleID main_vehicle_id)
 Shares the orders between two vehicles.
static bool UnshareOrders (VehicleID vehicle_id)
 Removes the given vehicle from a shared orders list.

Detailed Description

Class that handles all order related functions.

Definition at line 21 of file ai_order.hpp.


Member Enumeration Documentation

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

Enumerator:
AIOF_NONE 

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

AIOF_NON_STOP_INTERMEDIATE 

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

Only for trains and road vehicles.

AIOF_NON_STOP_DESTINATION 

Do not stop at the destionation station.

Only for trains and road vehicles.

AIOF_UNLOAD 

Always unload the vehicle; only for stations.

Cannot be set when AIOF_TRANSFER or AIOF_NO_UNLOAD is set.

AIOF_TRANSFER 

Transfer instead of deliver the goods; only for stations.

Cannot be set when AIOF_UNLOAD or AIOF_NO_UNLOAD is set.

AIOF_NO_UNLOAD 

Never unload the vehicle; only for stations.

Cannot be set when AIOF_UNLOAD, AIOF_TRANSFER or AIOF_NO_LOAD is set.

AIOF_FULL_LOAD 

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

Cannot be set when AIOF_NO_LOAD is set.

AIOF_FULL_LOAD_ANY 

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

Cannot be set when AIOF_NO_LOAD is set.

AIOF_NO_LOAD 

Do not load any cargo; only for stations.

Cannot be set when AIOF_NO_UNLOAD, AIOF_FULL_LOAD or AIOF_FULL_LOAD_ANY is set.

AIOF_SERVICE_IF_NEEDED 

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

AIOF_STOP_IN_DEPOT 

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

AIOF_GOTO_NEAREST_DEPOT 

Go to nearest depot.

AIOF_NON_STOP_FLAGS 

All flags related to non-stop settings.

AIOF_UNLOAD_FLAGS 

All flags related to unloading.

AIOF_LOAD_FLAGS 

All flags related to loading.

AIOF_DEPOT_FLAGS 

All flags related to depots.

AIOF_INVALID 

For marking invalid order flags.

Definition at line 42 of file ai_order.hpp.

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.

Definition at line 102 of file ai_order.hpp.

All order related error messages.

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 to far away from the previous order.

Definition at line 28 of file ai_order.hpp.

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_SPEED 

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

OC_AGE 

Skip based on the age, value is in years.

OC_REQUIRES_SERVICE 

Skip when the vehicle requires service, no value.

OC_UNCONDITIONALLY 

Always skip, no compare function, no value.

OC_INVALID 

An invalid condition, do not use.

Definition at line 88 of file ai_order.hpp.

Different constants related to the OrderPosition.

Enumerator:
ORDER_CURRENT 

Constant that gets resolved to the current order.

ORDER_INVALID 

An invalid order.

Definition at line 116 of file ai_order.hpp.

Where to stop trains in a station that's longer then 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.

Definition at line 122 of file ai_order.hpp.


Member Function Documentation

bool AIOrder::AppendConditionalOrder ( VehicleID  vehicle_id,
OrderPosition  jump_to 
) [static]

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

Parameters:
vehicle_id The vehicle to append the order to.
jump_to The OrderPosition to jump to if the condition is true.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
IsValidVehicleOrder(vehicle_id, jump_to).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
AIOrder::ERR_ORDER_TOO_MANY 
Returns:
True if and only if the order was appended.

Definition at line 355 of file ai_order.cpp.

References EnforcePrecondition, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), InsertConditionalOrder(), AIVehicle::IsValidVehicle(), and IsValidVehicleOrder().

bool AIOrder::AppendOrder ( VehicleID  vehicle_id,
TileIndex  destination,
AIOrderFlags  order_flags 
) [static]

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

Parameters:
vehicle_id The vehicle to append the order to.
destination The destination of the order.
order_flags The flags given to the order.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
AreOrderFlagsValid(destination, order_flags).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
AIOrder::ERR_ORDER_TOO_MANY 
AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION 
Returns:
True if and only if the order was appended.

Definition at line 347 of file ai_order.cpp.

References AreOrderFlagsValid(), EnforcePrecondition, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), InsertOrder(), and AIVehicle::IsValidVehicle().

bool AIOrder::AreOrderFlagsValid ( TileIndex  destination,
AIOrderFlags  order_flags 
) [static]

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

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

Definition at line 121 of file ai_order.cpp.

References AIOF_DEPOT_FLAGS, AIOF_FULL_LOAD_ANY, AIOF_GOTO_NEAREST_DEPOT, AIOF_LOAD_FLAGS, AIOF_NO_LOAD, AIOF_NO_UNLOAD, AIOF_NON_STOP_FLAGS, AIOF_SERVICE_IF_NEEDED, AIOF_STOP_IN_DEPOT, AIOF_TRANSFER, AIOF_UNLOAD, AIOF_UNLOAD_FLAGS, and GetOrderTypeByTile().

Referenced by _SetOrderFlags(), AppendOrder(), and InsertOrder().

bool AIOrder::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_id The vehicle to copy the orders to.
main_vehicle_id The vehicle to copy the orders from.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
AIVehicle::IsValidVehicle(main_vehicle_id).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
AIOrder::ERR_ORDER_TOO_MANY 
Returns:
True if and only if the copying succeeded.

Definition at line 538 of file ai_order.cpp.

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

AIOrder::CompareFunction AIOrder::GetOrderCompareFunction ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

Parameters:
vehicle_id The vehicle to get the compare function for.
order_position The 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.

Definition at line 268 of file ai_order.cpp.

References CF_INVALID, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetConditionComparator(), IsConditionalOrder(), IsValidVehicleOrder(), and ORDER_CURRENT.

int32 AIOrder::GetOrderCompareValue ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

Parameters:
vehicle_id The vehicle to get the value for.
order_position The 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.

Definition at line 277 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetConditionValue(), Order::GetConditionVariable(), IsConditionalOrder(), IsValidVehicleOrder(), OCV_MAX_SPEED, and ORDER_CURRENT.

AIOrder::OrderCondition AIOrder::GetOrderCondition ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

Parameters:
vehicle_id The vehicle to get the condition type for.
order_position The 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.

Definition at line 259 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetConditionVariable(), IsConditionalOrder(), IsValidVehicleOrder(), OC_INVALID, and ORDER_CURRENT.

Referenced by SetOrderCompareValue().

int32 AIOrder::GetOrderCount ( VehicleID  vehicle_id  )  [static]

Returns the number of orders for the given vehicle.

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

Definition at line 163 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), and AIVehicle::IsValidVehicle().

Referenced by IsCurrentOrderPartOfOrderList().

TileIndex AIOrder::GetOrderDestination ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

Parameters:
vehicle_id The vehicle to get the destination for.
order_position The 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.

Definition at line 168 of file ai_order.cpp.

References Station::airport_tile, Station::bus_stops, Station::dock_tile, SpecializedStation< Waypoint, true >::Get(), SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetDepotActionType(), Order::GetDestination(), Order::GetType(), INVALID_TILE, IsHangar(), IsValidVehicleOrder(), ODATFB_NEAREST_DEPOT, ResolveOrder(), AirportSpec::size_x, AirportSpec::size_y, TileArea::tile, TILE_AREA_LOOP, TILE_LOOP, Waypoint::TileBelongsToRailStation(), Station::TileBelongsToRailStation(), BaseStation::train_station, Station::truck_stops, BaseVehicle::type, VEH_AIRCRAFT, BaseStation::xy, and RoadStop::xy.

Referenced by _SetOrderFlags().

AIOrder::AIOrderFlags AIOrder::GetOrderFlags ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

Parameters:
vehicle_id The vehicle to get the destination for.
order_position The 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 AIOrderFlags of the order.

Definition at line 223 of file ai_order.cpp.

References AIOF_GOTO_NEAREST_DEPOT, AIOF_INVALID, AIOF_NONE, AIOF_SERVICE_IF_NEEDED, AIOF_STOP_IN_DEPOT, Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetLoadType(), Order::GetNonStopType(), Order::GetType(), Order::GetUnloadType(), IsValidVehicleOrder(), ODATFB_HALT, ODATFB_NEAREST_DEPOT, ODTFB_SERVICE, and ResolveOrder().

Referenced by _SetOrderFlags().

AIOrder::OrderPosition AIOrder::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_id The vehicle to get the OrderPosition for.
order_position The 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.

Definition at line 250 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetConditionSkipToOrder(), IsConditionalOrder(), IsValidVehicleOrder(), ORDER_CURRENT, and ORDER_INVALID.

AIOrder::StopLocation AIOrder::GetStopLocation ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

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

Definition at line 288 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetStopLocation(), AIVehicle::GetVehicleType(), IsGotoStationOrder(), IsValidVehicleOrder(), STOPLOCATION_INVALID, and AIVehicle::VT_RAIL.

bool AIOrder::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_id The vehicle to add the order to.
order_position The order to place the new order before.
jump_to The OrderPosition to jump to if the condition is true.
Precondition:
IsValidVehicleOrder(vehicle_id, order_position).
IsValidVehicleOrder(vehicle_id, jump_to).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
AIOrder::ERR_ORDER_TOO_MANY 
Returns:
True if and only if the order was inserted.

Definition at line 416 of file ai_order.cpp.

References CMD_INSERT_ORDER, AIObject::DoCommand(), EnforcePrecondition, AIVehicle::IsValidVehicle(), IsValidVehicleOrder(), Order::MakeConditional(), ORDER_CURRENT, Order::Pack(), and ResolveOrderPosition().

Referenced by AppendConditionalOrder().

bool AIOrder::InsertOrder ( VehicleID  vehicle_id,
OrderPosition  order_position,
TileIndex  destination,
AIOrder::AIOrderFlags  order_flags 
) [static]
bool AIOrder::IsConditionalOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

Checks whether the given order is a conditional order.

Parameters:
vehicle_id The vehicle to check.
order_position The 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.

Definition at line 93 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetType(), IsValidVehicleOrder(), and ORDER_CURRENT.

Referenced by GetOrderCompareFunction(), GetOrderCompareValue(), GetOrderCondition(), GetOrderJumpTo(), SetOrderCompareFunction(), SetOrderCompareValue(), SetOrderCondition(), and SetOrderJumpTo().

bool AIOrder::IsCurrentOrderPartOfOrderList ( VehicleID  vehicle_id  )  [static]

Checks whether the current order is part of the orderlist.

Parameters:
vehicle_id The vehicle to check.
Precondition:
AIVehicle::IsValidVehicle(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.

Definition at line 102 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Order::GetDepotOrderType(), GetOrderCount(), Order::GetType(), AIVehicle::IsValidVehicle(), and ODTFB_PART_OF_ORDERS.

bool AIOrder::IsGotoDepotOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

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

Definition at line 77 of file ai_order.cpp.

References Order::GetType(), IsValidVehicleOrder(), and ResolveOrder().

bool AIOrder::IsGotoStationOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

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

Definition at line 69 of file ai_order.cpp.

References Order::GetType(), IsValidVehicleOrder(), and ResolveOrder().

Referenced by GetStopLocation(), and SetStopLocation().

bool AIOrder::IsGotoWaypointOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

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

Definition at line 85 of file ai_order.cpp.

References Order::GetType(), IsValidVehicleOrder(), and ResolveOrder().

bool AIOrder::IsValidConditionalOrder ( OrderCondition  condition,
CompareFunction  compare 
) [static]

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

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

Definition at line 144 of file ai_order.cpp.

References CF_EQUALS, CF_IS_FALSE, CF_IS_TRUE, CF_MORE_EQUALS, OC_AGE, OC_LOAD_PERCENTAGE, OC_MAX_SPEED, OC_RELIABILITY, OC_REQUIRES_SERVICE, and OC_UNCONDITIONALLY.

bool AIOrder::IsValidVehicleOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

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

Parameters:
vehicle_id The vehicle to check the order index for.
order_position The order index to check.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
Returns:
True if and only if the order_position is valid for the given vehicle.

Definition at line 47 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), AIVehicle::IsValidVehicle(), and ORDER_CURRENT.

Referenced by _SetOrderFlags(), AppendConditionalOrder(), GetOrderCompareFunction(), GetOrderCompareValue(), GetOrderCondition(), GetOrderDestination(), GetOrderFlags(), GetOrderJumpTo(), GetStopLocation(), InsertConditionalOrder(), IsConditionalOrder(), IsGotoDepotOrder(), IsGotoStationOrder(), IsGotoWaypointOrder(), MoveOrder(), RemoveOrder(), SetOrderCompareFunction(), SetOrderCompareValue(), SetOrderCondition(), SetOrderJumpTo(), SetStopLocation(), and SkipToOrder().

bool AIOrder::MoveOrder ( VehicleID  vehicle_id,
OrderPosition  order_position_move,
OrderPosition  order_position_target 
) [static]

Move an order inside the orderlist.

Parameters:
vehicle_id The vehicle to move the orders.
order_position_move The order to move.
order_position_target The target order
Precondition:
IsValidVehicleOrder(vehicle_id, order_position_move).
IsValidVehicleOrder(vehicle_id, order_position_target).
Exceptions:
AIError::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).

Definition at line 527 of file ai_order.cpp.

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

bool AIOrder::RemoveOrder ( VehicleID  vehicle_id,
OrderPosition  order_position 
) [static]

Removes an order from the vehicle's order list.

Parameters:
vehicle_id The vehicle to remove the order from.
order_position The order to remove from the order list.
Precondition:
IsValidVehicleOrder(vehicle_id, order_position).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
Returns:
True if and only if the order was removed.

Definition at line 430 of file ai_order.cpp.

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

AIOrder::OrderPosition AIOrder::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_id The vehicle to check the order index for.
order_position The order index to resolve.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
Returns:
The resolved order index.

Definition at line 112 of file ai_order.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), AIVehicle::IsValidVehicle(), ORDER_CURRENT, and ORDER_INVALID.

Referenced by _SetOrderFlags(), InsertConditionalOrder(), InsertOrder(), MoveOrder(), RemoveOrder(), ResolveOrder(), and SkipToOrder().

bool AIOrder::SetOrderCompareFunction ( VehicleID  vehicle_id,
OrderPosition  order_position,
CompareFunction  compare 
) [static]

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

Parameters:
vehicle_id The vehicle to set the compare function for.
order_position The order to set the compare function for.
compare The 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.
Returns:
Whether the order has been/can be changed.

Definition at line 316 of file ai_order.cpp.

References CF_EQUALS, CF_IS_FALSE, CMD_MODIFY_ORDER, AIObject::DoCommand(), EnforcePrecondition, IsConditionalOrder(), IsValidVehicleOrder(), MOF_COND_COMPARATOR, and ORDER_CURRENT.

bool AIOrder::SetOrderCompareValue ( VehicleID  vehicle_id,
OrderPosition  order_position,
int32  value 
) [static]

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

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

Definition at line 325 of file ai_order.cpp.

References CMD_MODIFY_ORDER, AIObject::DoCommand(), EnforcePrecondition, GetOrderCondition(), IsConditionalOrder(), IsValidVehicleOrder(), MOF_COND_VALUE, OC_MAX_SPEED, and ORDER_CURRENT.

bool AIOrder::SetOrderCondition ( VehicleID  vehicle_id,
OrderPosition  order_position,
OrderCondition  condition 
) [static]

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

Parameters:
vehicle_id The vehicle to set the condition type for.
order_position The order to set the condition type for.
condition The 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.
Returns:
Whether the order has been/can be changed.

Definition at line 307 of file ai_order.cpp.

References CMD_MODIFY_ORDER, AIObject::DoCommand(), EnforcePrecondition, IsConditionalOrder(), IsValidVehicleOrder(), MOF_COND_VARIABLE, OC_LOAD_PERCENTAGE, OC_UNCONDITIONALLY, and ORDER_CURRENT.

bool AIOrder::SetOrderFlags ( VehicleID  vehicle_id,
OrderPosition  order_position,
AIOrder::AIOrderFlags  order_flags 
) [static]

Changes the order flags of the given order.

Parameters:
vehicle_id The vehicle to change the order of.
order_position The order to change.
order_flags The new flags given to the order.
Precondition:
IsValidVehicleOrder(vehicle_id, order_position).
AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
Returns:
True if and only if the order was changed.

Definition at line 516 of file ai_order.cpp.

References _SetOrderFlags(), and AIObject::SetCallbackVariable().

bool AIOrder::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_id The vehicle to set the OrderPosition for.
order_position The order to set the OrderPosition for.
jump_to The 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).
Returns:
Whether the order has been/can be changed.

Definition at line 298 of file ai_order.cpp.

References CMD_MODIFY_ORDER, AIObject::DoCommand(), EnforcePrecondition, IsConditionalOrder(), IsValidVehicleOrder(), MOF_COND_DESTINATION, and ORDER_CURRENT.

bool AIOrder::SetStopLocation ( VehicleID  vehicle_id,
OrderPosition  order_position,
StopLocation  stop_location 
) [static]

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

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

Definition at line 335 of file ai_order.cpp.

References CMD_MODIFY_ORDER, AIObject::DoCommand(), EnforcePrecondition, AIVehicle::GetVehicleType(), IsGotoStationOrder(), IsValidVehicleOrder(), MOF_STOP_LOCATION, STOPLOCATION_FAR, STOPLOCATION_NEAR, and AIVehicle::VT_RAIL.

bool AIOrder::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_id The vehicle to add to the shared order list.
main_vehicle_id The vehicle to share the orders with.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
AIVehicle::IsValidVehicle(main_vehicle_id).
Exceptions:
AIError::ERR_OWNED_BY_ANOTHER_COMPANY 
Returns:
True if and only if the sharing succeeded.

Definition at line 546 of file ai_order.cpp.

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

bool AIOrder::SkipToOrder ( VehicleID  vehicle_id,
OrderPosition  next_order 
) [static]

Make a vehicle execute next_order instead of its current order.

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

Definition at line 439 of file ai_order.cpp.

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

bool AIOrder::UnshareOrders ( VehicleID  vehicle_id  )  [static]

Removes the given vehicle from a shared orders list.

Parameters:
vehicle_id The vehicle to remove from the shared order list.
Precondition:
AIVehicle::IsValidVehicle(vehicle_id).
Returns:
True if and only if the unsharing succeeded.

Definition at line 554 of file ai_order.cpp.

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


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

Generated on Fri Apr 30 21:56:01 2010 for OpenTTD by  doxygen 1.6.1