OpenTTD: src/order_cmd.cpp File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions | Variables
order_cmd.cpp File Reference

Handling of orders. More...

`#include "stdafx.h"`
`#include "debug.h"`
`#include "cmd_helper.h"`
`#include "command_func.h"`
`#include "company_func.h"`
`#include "news_func.h"`
`#include "strings_func.h"`
`#include "timetable.h"`
`#include "vehicle_func.h"`
`#include "depot_base.h"`
`#include "core/pool_func.hpp"`
`#include "core/random_func.hpp"`
`#include "aircraft.h"`
`#include "roadveh.h"`
`#include "station_base.h"`
`#include "waypoint_base.h"`
`#include "company_base.h"`
`#include "order_backup.h"`
`#include "cheat_type.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
| assert_compile (sizeof(DestinationID) >=sizeof(DepotID))
void | InvalidateVehicleOrder (const Vehicle *v, int data)
| Updates the widgets of a vehicle which contains the order-data.
static bool | OrderGoesToStation (const Vehicle *v, const Order *o)
| Checks whether the order goes to a station or not, i.e.
static void | DeleteOrderWarnings (const Vehicle *v)
| Delete all news items regarding defective orders about a vehicle This could kill still valid warnings (for example about void order when just another order gets added), but assume the company will notice the problems, when (s)he's changing the orders.
uint | GetOrderDistance (const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
| Get the distance between two orders of a vehicle.
CommandCost | CmdInsertOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Add an order to the orderlist of a vehicle.
void | InsertOrder (Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
| Insert a new order but skip the validation.
static CommandCost | DecloneOrder (Vehicle *dst, DoCommandFlag flags)
| Declone an order-list.
CommandCost | CmdDeleteOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Delete an order from the orderlist of a vehicle.
static void | CancelLoadingDueToDeletedOrder (Vehicle *v)
| Cancel the current loading order of the vehicle as the order was deleted.
void | DeleteOrder (Vehicle *v, VehicleOrderID sel_ord)
| Delete an order but skip the parameter validation.
CommandCost | CmdSkipToOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Goto order of order-list.
CommandCost | CmdMoveOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Move an order inside the orderlist.
CommandCost | CmdModifyOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Modify an order in the orderlist of a vehicle.
static bool | CheckAircraftOrderDistance (const Aircraft *v_new, const Vehicle *v_order, const Order *first)
| Check if an aircraft has enough range for an order list.
CommandCost | CmdCloneOrder (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Clone/share/copy an order-list of another vehicle.
CommandCost | CmdOrderRefit (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Add/remove refit orders from an order.
void | CheckOrders (const Vehicle *v)
| Check the orders of a vehicle, to see if there are invalid orders and stuff.
void | RemoveOrderFromAllVehicles (OrderType type, DestinationID destination)
| Removes an order from all vehicles.
void | DeleteVehicleOrders (Vehicle *v, bool keep_orderlist, bool reset_order_indices)
| Delete all orders from a vehicle.
uint16 | GetServiceIntervalClamped (uint interval, bool ispercent)
| Clamp the service interval to the correct min/max.
static bool | CheckForValidOrders (const Vehicle *v)
| Check if a vehicle has any valid orders.
static bool | OrderConditionCompare (OrderConditionComparator occ, int variable, int value)
| Compare the variable and value based on the given comparator.
VehicleOrderID | ProcessConditionalOrder (const Order *order, const Vehicle *v)
| Process a conditional order and determine the next order.
bool | UpdateOrderDest (Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
| Update the vehicle's destination tile from an order.
bool | ProcessOrders (Vehicle *v)
| Handle the orders of a vehicle and determine the next place to go to if needed.

## Variables
OrderPool | _order_pool ("Order")
OrderListPool | _orderlist_pool ("OrderList")

## Detailed Description

Handling of orders.

Definition in file order_cmd.cpp.

## Function Documentation

static void CancelLoadingDueToDeletedOrder | ( | Vehicle * | v | ) |
| static

Cancel the current loading order of the vehicle as the order was deleted.

Parameters

  v | the vehicle

Definition at line 1063 of file order_cmd.cpp.

References Vehicle::current_order, Order::GetLoadType(), Order::IsType(), OLF_LOAD_IF_POSSIBLE, OLFB_FULL_LOAD, ONSF_STOP_EVERYWHERE, Order::SetLoadType(), and Order::SetNonStopType().

Referenced by DeleteOrder(), and DeleteVehicleOrders().

static bool CheckAircraftOrderDistance | ( | const Aircraft * | v_new,
|  | const Vehicle * | v_order,
|  | const Order * | first
| ) |  |
| static

Check if an aircraft has enough range for an order list.

Parameters

  v_new | Aircraft to check.
  v_order | Vehicle currently holding the order list.
  first | First order in the source order list.

Returns
  True if the aircraft has enough range for the orders, false otherwise.

Definition at line 1524 of file order_cmd.cpp.

References AircraftCache::cached_max_range, AircraftCache::cached_max_range_sqr, GetOrderDistance(), and Order::next.

Referenced by CmdCloneOrder().

static bool CheckForValidOrders | ( | const Vehicle * | v | ) |
| static

Check if a vehicle has any valid orders.

Returns
  false if there are no valid orders

Note
  Conditional orders are not considered valid destination orders

Definition at line 1964 of file order_cmd.cpp.

References Order::GetType().

Referenced by ProcessOrders().

void CheckOrders | ( | const Vehicle * | v | ) |

Check the orders of a vehicle, to see if there are invalid orders and stuff.

Definition at line 1759 of file order_cmd.cpp.

References _cheats, _local_company, _settings_client, _settings_game, AddVehicleAdviceNewsItem(), Station::airport, CanVehicleUseStation(), Vehicle::day_counter, OrderList::DebugCheckSanity(), Vehicle::engine_type, Order::Equals(), Vehicle::FirstShared(), AirportFTAClass::flags, SpecializedStation< Station, false >::Get(), Order::GetDestination(), OrderList::GetFirstOrder(), Airport::GetFTA(), Vehicle::GetLastOrder(), Vehicle::GetNumOrders(), ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_STRING_ID, Order::IsType(), Vehicle::list, Cheats::no_jetcrash, GUISettings::order_review_system, Vehicle::orders, Vehicle::owner, VehicleSettings::plane_crashes, SetDParam(), AirportFTAClass::SHORT_STRIP, BaseVehicle::type, Cheat::value, VEH_AIRCRAFT, GameSettings::vehicle, Vehicle::vehstatus, VS_CRASHED, and VS_STOPPED.

Referenced by Ship::OnNewDay(), Aircraft::OnNewDay(), RoadVehicle::OnNewDay(), and Train::OnNewDay().

CommandCost CmdCloneOrder | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Clone/share/copy an order-list of another vehicle.

Parameters

  tile | unused
  flags | operation to perform
  p1 | various bitstuffed elements p1 = (bit 0-19) - destination vehicle to clone orders to p1 = (bit 30-31) - action to perform
  p2 | source vehicle to clone orders from, if any (none for CO_UNSHARE)
  text | unused

Returns
  the cost of this operation or an error

Definition at line 1557 of file order_cmd.cpp.

References Vehicle::AddToShared(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::CanAllocateItem(), CanVehicleUseStation(), CheckAircraftOrderDistance(), CheckOwnership(), CMD_ERROR, DC_EXEC, DecloneOrder(), DeleteVehicleOrders(), CommandCost::Failed(), Vehicle::FirstShared(), SpecializedVehicle< RoadVehicle, Type >::From(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), GB(), SpecializedStation< Station, false >::Get(), Order::GetDestination(), OrderList::GetFirstOrder(), Vehicle::GetFirstOrder(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), GetWindowClassForVehicleType(), InvalidateVehicleOrder(), InvalidateWindowClassesData(), RoadVehicle::IsBus(), Vehicle::IsPrimaryVehicle(), OrderList::IsShared(), Vehicle::list, OrderGoesToStation(), Vehicle::orders, Vehicle::owner, return_cmd_error, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VIWD_MODIFY_ORDERS, and VIWD_REMOVE_ALL_ORDERS.

CommandCost CmdDeleteOrder | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Delete an order from the orderlist of a vehicle.

Parameters

  tile | unused
  flags | operation to perform
  p1 | the ID of the vehicle
  p2 | the order to delete (max 255)
  text | unused

Returns
  the cost of this operation or an error

Definition at line 1038 of file order_cmd.cpp.

References CheckOwnership(), CMD_ERROR, DC_EXEC, DecloneOrder(), DeleteOrder(), CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::IsPrimaryVehicle(), and Vehicle::owner.

CommandCost CmdInsertOrder | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Add an order to the orderlist of a vehicle.

Parameters

  tile | unused
  flags | operation to perform
  p1 | various bitstuffed elements p1 = (bit 0 - 19) - ID of the vehicle p1 = (bit 24 - 31) - the selected order (if any). If the last order is given, the order will be inserted before that one the maximum vehicle order id is 254.
  p2 | packed order to insert
  text | unused

Returns
  the cost of this operation or an error

Definition at line 728 of file order_cmd.cpp.

References _settings_game, Station::airport, Order::AssignOrder(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::CanAllocateItem(), CanVehicleUseStation(), CheckOwnership(), CMD_ERROR, DC_EXEC, FACIL_DOCK, FACIL_TRAIN, BaseStation::facilities, CommandCost::Failed(), Vehicle::FirstShared(), GB(), Order::GetConditionComparator(), Order::GetConditionSkipToOrder(), Order::GetConditionValue(), Order::GetConditionVariable(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), SpecializedStation< Station, false >::GetIfValid(), SpecializedStation< Waypoint, true >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::GetIfValid(), Order::GetLoadType(), Order::GetNonStopType(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetOrderDistance(), Order::GetStopLocation(), GetTileOwner(), Order::GetType(), Order::GetUnloadType(), Airport::HasHangar(), InsertOrder(), Vehicle::IsGroundVehicle(), Vehicle::IsPrimaryVehicle(), IsRailDepotTile(), IsRoadDepotTile(), IsShipDepotTile(), Order::IsType(), Vehicle::list, MAX_VEH_ORDER_ID, Vehicle::NextShared(), OCC_EQUALS, OCC_IS_FALSE, OCC_IS_TRUE, OCV_LOAD_PERCENTAGE, OCV_RELIABILITY, OCV_REQUIRES_SERVICE, OCV_UNCONDITIONALLY, ODATFB_HALT, ODATFB_NEAREST_DEPOT, ODTFB_PART_OF_ORDERS, ODTFB_SERVICE, OLF_FULL_LOAD_ANY, OLF_LOAD_IF_POSSIBLE, OLFB_FULL_LOAD, OLFB_NO_LOAD, ONSF_STOP_EVERYWHERE, Vehicle::orders, OSL_PLATFORM_FAR_END, OSL_PLATFORM_MIDDLE, OSL_PLATFORM_NEAR_END, OUF_UNLOAD_IF_POSSIBLE, OUFB_NO_UNLOAD, OUFB_TRANSFER, OUFB_UNLOAD, BaseStation::owner, Vehicle::owner, OWNER_NONE, PathfinderSettings::pathfinder_for_ships, GameSettings::pf, return_cmd_error, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and VPF_NPF.

CommandCost CmdModifyOrder | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Modify an order in the orderlist of a vehicle.

Parameters

  tile | unused
  flags | operation to perform
  p1 | various bitstuffed elements p1 = (bit 0 - 19) - ID of the vehicle p1 = (bit 24 - 31) - the selected order (if any). If the last order is given, the order will be inserted before that one the maximum vehicle order id is 254.
  p2 | various bitstuffed elements p2 = (bit 0 - 3) - what data to modify (

See Also
  ModifyOrderFlags)
  - p2 = (bit 4 - 15) - the data to modify

Parameters

  text | unused

Returns
  the cost of this operation or an error

Definition at line 1289 of file order_cmd.cpp.

References CheckOwnership(), CMD_ERROR, CT_NO_REFIT, BaseConsist::cur_real_order_index, Vehicle::current_order, DA_ALWAYS_GO, DA_SERVICE, DA_STOP, DC_EXEC, DeleteOrderWarnings(), CommandCost::Failed(), Vehicle::FirstShared(), GB(), Order::GetConditionComparator(), Order::GetConditionValue(), Order::GetConditionVariable(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Order::GetLoadType(), Order::GetNonStopType(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Order::GetType(), Order::GetUnloadType(), InvalidateVehicleOrder(), Vehicle::IsGroundVehicle(), Vehicle::IsPrimaryVehicle(), Order::IsType(), MOF_COND_COMPARATOR, MOF_COND_DESTINATION, MOF_COND_VALUE, MOF_COND_VARIABLE, MOF_DEPOT_ACTION, MOF_LOAD, MOF_NON_STOP, MOF_STOP_LOCATION, MOF_UNLOAD, Vehicle::NextShared(), OCC_EQUALS, OCC_IS_FALSE, OCC_IS_TRUE, OCV_LOAD_PERCENTAGE, OCV_RELIABILITY, OCV_REQUIRES_SERVICE, OCV_UNCONDITIONALLY, ODATFB_HALT, ODTFB_SERVICE, OLF_LOAD_IF_POSSIBLE, OLFB_NO_LOAD, ONSF_NO_STOP_AT_DESTINATION_STATION, OUF_UNLOAD_IF_POSSIBLE, OUFB_NO_UNLOAD, OUFB_TRANSFER, OUFB_UNLOAD, Vehicle::owner, Order::SetConditionComparator(), Order::SetConditionSkipToOrder(), Order::SetConditionValue(), Order::SetConditionVariable(), Order::SetDepotActionType(), Order::SetDepotOrderType(), Order::SetLoadType(), Order::SetNonStopType(), Order::SetRefit(), Order::SetStopLocation(), Order::SetUnloadType(), BaseVehicle::type, VEH_TRAIN, and VIWD_MODIFY_ORDERS.

CommandCost CmdMoveOrder | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Move an order inside the orderlist.

Parameters

  tile | unused
  flags | operation to perform
  p1 | the ID of the vehicle
  p2 | order to move and target bit 0-15 : the order to move bit 16-31 : the target order
  text | unused

Returns
  the cost of this operation or an error

Note
  The target order will move one place down in the orderlist if you move the order upwards else it'll move it one place down

Definition at line 1185 of file order_cmd.cpp.

References CheckOwnership(), CMD_ERROR, BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, DC_EXEC, DeleteOrderWarnings(), CommandCost::Failed(), Vehicle::FirstShared(), GB(), Order::GetConditionSkipToOrder(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetWindowClassForVehicleType(), InvalidateVehicleOrder(), InvalidateWindowClassesData(), Vehicle::IsPrimaryVehicle(), Order::IsType(), Vehicle::list, OrderList::MoveOrder(), Vehicle::NextShared(), Vehicle::orders, Vehicle::owner, Order::SetConditionSkipToOrder(), and BaseVehicle::type.

CommandCost CmdOrderRefit | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Add/remove refit orders from an order.

Parameters

  tile | Not used
  flags | operation to perform
  p1 | VehicleIndex of the vehicle having the order
  p2 | bitmask bit 0-7 CargoID bit 16-23 number of order to modify
  text | unused

Returns
  the cost of this operation or an error

Definition at line 1708 of file order_cmd.cpp.

References CheckOwnership(), CMD_ERROR, CT_AUTO_REFIT, CT_NO_REFIT, DC_EXEC, CommandCost::Failed(), Vehicle::FirstShared(), GB(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Order::GetLoadType(), Vehicle::GetOrder(), InvalidateVehicleOrder(), Vehicle::IsPrimaryVehicle(), Order::IsType(), Vehicle::NextShared(), NUM_CARGO, ODATFB_HALT, ODTFB_PART_OF_ORDERS, ODTFB_SERVICE, OLFB_NO_LOAD, Vehicle::owner, Order::SetDepotActionType(), Order::SetDepotOrderType(), Order::SetRefit(), and VIWD_MODIFY_ORDERS.

CommandCost CmdSkipToOrder | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Goto order of order-list.

Parameters

  tile | unused
  flags | operation to perform
  p1 | The ID of the vehicle which order is skipped
  p2 | the selected order to which we want to skip
  text | unused

Returns
  the cost of this operation or an error

Definition at line 1144 of file order_cmd.cpp.

References CheckOwnership(), CMD_ERROR, BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, DC_EXEC, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), InvalidateVehicleOrder(), Vehicle::IsPrimaryVehicle(), Order::IsType(), Vehicle::LeaveStation(), Vehicle::owner, SetWindowClassesDirty(), BaseVehicle::type, Vehicle::UpdateRealOrderIndex(), VEH_AIRCRAFT, VEH_SHIP, VIWD_MODIFY_ORDERS, WC_AIRCRAFT_LIST, and WC_SHIPS_LIST.

static CommandCost DecloneOrder | ( | Vehicle * | dst,
|  | DoCommandFlag | flags
| ) |  |
| static

Declone an order-list.

Parameters

  *dst | delete the orders of this vehicle
  flags | execution flags

Definition at line 1019 of file order_cmd.cpp.

References DC_EXEC, DeleteVehicleOrders(), GetWindowClassForVehicleType(), InvalidateVehicleOrder(), InvalidateWindowClassesData(), BaseVehicle::type, and VIWD_REMOVE_ALL_ORDERS.

Referenced by CmdCloneOrder(), and CmdDeleteOrder().

void DeleteOrder | ( | Vehicle * | v,
|  | VehicleOrderID | sel_ord
| ) |  |

Delete an order but skip the parameter validation.

Parameters

  v | The vehicle to delete the order from.
  sel_ord | The id of the order to be deleted.

Definition at line 1079 of file order_cmd.cpp.

References CancelLoadingDueToDeletedOrder(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, OrderList::DeleteOrderAt(), DeleteOrderWarnings(), Vehicle::FirstShared(), Order::GetConditionSkipToOrder(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetWindowClassForVehicleType(), INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), InvalidateWindowClassesData(), Order::IsType(), Vehicle::list, max(), Vehicle::NextShared(), Vehicle::orders, Order::SetConditionSkipToOrder(), BaseVehicle::type, and Vehicle::UpdateRealOrderIndex().

Referenced by Vehicle::BeginLoading(), CmdDeleteOrder(), Vehicle::DeleteUnreachedImplicitOrders(), and RemoveOrderFromAllVehicles().

void DeleteVehicleOrders | ( | Vehicle * | v,
|  | bool | keep_orderlist,
|  | bool | reset_order_indices
| ) |  |

Delete all orders from a vehicle.

Parameters

  v | Vehicle whose orders to reset
  keep_orderlist | If true, do not free the order list, only empty it.
  reset_order_indices | If true, reset cur_implicit_order_index and cur_real_order_index and cancel the current full load order (if the vehicle is loading). If false, you have to make sure the order indices are valid after your messing with them!

Definition at line 1922 of file order_cmd.cpp.

References CancelLoadingDueToDeletedOrder(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, DeleteOrderWarnings(), OrderList::FreeChain(), Vehicle::IsOrderListShared(), Order::IsType(), Vehicle::list, Vehicle::orders, and Vehicle::RemoveFromShared().

Referenced by CmdCloneOrder(), CmdMoveRailVehicle(), CmdSellRailWagon(), DecloneOrder(), and Vehicle::PreDestructor().

uint GetOrderDistance | ( | const Order * | prev,
|  | const Order * | cur,
|  | const Vehicle * | v,
|  | int | conditional_depth
| ) |  |

Get the distance between two orders of a vehicle.

Conditional orders are resolved and the bigger distance of the two order branches is returned.

Parameters

  prev | Origin order.
  cur | Destination order.
  v | The vehicle to get the distance for.
  conditional_depth | Internal param for resolving conditional orders.

Returns
  Maximum distance between the two orders.

Definition at line 697 of file order_cmd.cpp.

References DistanceManhattan(), DistanceSquare(), Order::GetConditionSkipToOrder(), OrderList::GetFirstOrder(), Order::GetLocation(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetOrderDistance(), INVALID_TILE, Order::IsType(), Vehicle::list, max(), Order::next, Vehicle::orders, BaseVehicle::type, and VEH_AIRCRAFT.

Referenced by CheckAircraftOrderDistance(), CmdInsertOrder(), DrawOrderString(), and GetOrderDistance().

uint16 GetServiceIntervalClamped | ( | uint | interval,
|  | bool | ispercent
| ) |  |

Clamp the service interval to the correct min/max.

The actual min/max values depend on whether it's in percent or days.

Parameters

  interval | proposed service interval
  company_id | the owner of the vehicle

Returns
  Clamped service interval

Definition at line 1951 of file order_cmd.cpp.

References Clamp().

Referenced by CmdChangeServiceInt(), VehicleDetailsWindow::OnClick(), and VehicleDetailsWindow::OnDropdownSelect().

void InsertOrder | ( | Vehicle * | v,
|  | Order * | new_o,
|  | VehicleOrderID | sel_ord
| ) |  |

Insert a new order but skip the validation.

Parameters

  v | The vehicle to insert the order to.
  new_o | The new order.
  sel_ord | The position the order should be inserted at.

Definition at line 951 of file order_cmd.cpp.

References BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, DeleteOrderWarnings(), Vehicle::FirstShared(), Order::GetConditionSkipToOrder(), Vehicle::GetGroundVehicleFlags(), Vehicle::GetNumOrders(), GetWindowClassForVehicleType(), GVF_SUPPRESS_IMPLICIT_ORDERS, OrderList::InsertOrderAt(), INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), InvalidateWindowClassesData(), Vehicle::IsGroundVehicle(), Order::IsType(), Vehicle::list, Vehicle::NextShared(), Vehicle::orders, SetBit(), Order::SetConditionSkipToOrder(), and BaseVehicle::type.

Referenced by Vehicle::BeginLoading(), and CmdInsertOrder().

void InvalidateVehicleOrder | ( | const Vehicle * | v,
|  | int | data
| ) |  |

Updates the widgets of a vehicle which contains the order-data.

Definition at line 252 of file order_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), SetWindowDirty(), WC_VEHICLE_ORDERS, WC_VEHICLE_TIMETABLE, and WC_VEHICLE_VIEW.

Referenced by Vehicle::BeginLoading(), CmdCloneOrder(), CmdModifyOrder(), CmdMoveOrder(), CmdOrderRefit(), CmdSkipToOrder(), DecloneOrder(), DeleteOrder(), Vehicle::DeleteUnreachedImplicitOrders(), Vehicle::IncrementImplicitOrderIndex(), Vehicle::IncrementRealOrderIndex(), InsertOrder(), ProcessOrders(), Vehicle::RemoveFromShared(), and RemoveOrderFromAllVehicles().

static bool OrderGoesToStation | ( | const Vehicle * | v,
|  | const Order * | o
| ) |  |
| inlinestatic

Checks whether the order goes to a station or not, i.e.

whether the destination is a station

Parameters

  v | the vehicle to check for
  o | the order to check

Returns
  true if the destination is a station

Definition at line 643 of file order_cmd.cpp.

References Order::GetDepotActionType(), Order::IsType(), ODATFB_NEAREST_DEPOT, BaseVehicle::type, and VEH_AIRCRAFT.

Referenced by CmdCloneOrder().

VehicleOrderID ProcessConditionalOrder | ( | const Order * | order,
|  | const Vehicle * | v
| ) |  |

Process a conditional order and determine the next order.

Parameters

  order | the order the vehicle currently has
  v | the vehicle to update

Returns
  index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order

Definition at line 2007 of file order_cmd.cpp.

References Vehicle::age, CalcPercentVehicleFilled(), DAYS_IN_LEAP_YEAR, Order::GetConditionComparator(), Order::GetConditionSkipToOrder(), Order::GetConditionValue(), Order::GetConditionVariable(), Vehicle::GetDisplayMaxSpeed(), Order::GetType(), INVALID_VEH_ORDER_ID, max(), Vehicle::max_age, Vehicle::NeedsServicing(), OCV_AGE, OCV_LOAD_PERCENTAGE, OCV_MAX_SPEED, OCV_RELIABILITY, OCV_REMAINING_LIFETIME, OCV_REQUIRES_SERVICE, OCV_UNCONDITIONALLY, OrderConditionCompare(), Vehicle::reliability, and ToPercent16().

Referenced by VehicleOrderSaver::SwitchToNextOrder(), and UpdateOrderDest().

bool ProcessOrders | ( | Vehicle * | v | ) |

Handle the orders of a vehicle and determine the next place to go to if needed.

Parameters

  v | the vehicle to do this for.

Returns
  true if the vehicle is eligible for reversing (basically only when leaving a station).

Reversing because of order change is allowed only just after leaving a station (and the difficulty setting to allowed, of course) this can be detected because only after OT_LEAVESTATION, current_order will be reset to nothing. (That also happens if no order, but in that case it won't hit the point in code where may_reverse is checked)

Definition at line 2157 of file order_cmd.cpp.

References CheckForValidOrders(), BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, Vehicle::DeleteUnreachedImplicitOrders(), Vehicle::dest_tile, Order::Equals(), Order::Free(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Station, false >::Get(), Order::GetDepotOrderType(), Order::GetDestination(), Order::GetNonStopType(), Vehicle::GetNumManualOrders(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetStationIndex(), Order::GetType(), GetWindowClassForVehicleType(), Vehicle::IncrementImplicitOrderIndex(), INVALID_TILE, InvalidateVehicleOrder(), IsTileType(), Order::IsType(), Vehicle::last_station_visited, MP_STATION, ODTFB_PART_OF_ORDERS, ONSF_NO_STOP_AT_DESTINATION_STATION, SetWindowClassesDirty(), Vehicle::tile, BaseVehicle::type, UpdateOrderDest(), Vehicle::UpdateRealOrderIndex(), UpdateVehicleTimetable(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and VIWD_MODIFY_ORDERS.

Referenced by CheckNextTrainTile().

void RemoveOrderFromAllVehicles | ( | OrderType | type,
|  | DestinationID | destination
| ) |  |

Removes an order from all vehicles.

Triggers when, say, a station is removed.

Parameters

  type | The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
  destination | The destination. Can be a StationID, DepotID or WaypointID.

Definition at line 1834 of file order_cmd.cpp.

References Vehicle::current_order, DeleteOrder(), Vehicle::FirstShared(), FOR_ALL_VEHICLES, Order::GetDepotActionType(), Order::GetDestination(), Order::GetTimetabledWait(), Order::GetType(), Order::GetWaitTime(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), Order::IsTravelTimetabled(), Order::IsType(), Order::IsWaitTimetabled(), Vehicle::list, Order::MakeDummy(), Order::next, Vehicle::NextShared(), ODATFB_NEAREST_DEPOT, Vehicle::orders, OrderBackup::RemoveOrder(), Order::SetTravelTimetabled(), Order::SetWaitTime(), Order::SetWaitTimetabled(), SetWindowDirty(), BaseVehicle::type, OrderList::UpdateTimetableDuration(), OrderList::UpdateTotalDuration(), VEH_AIRCRAFT, and WC_VEHICLE_VIEW.

Referenced by Depot::~Depot(), and Station::~Station().

bool UpdateOrderDest | ( | Vehicle * | v,
|  | const Order * | order,
|  | int | conditional_depth,
|  | bool | pbs_look_ahead
| ) |  |

Update the vehicle's destination tile from an order.

Parameters

  order | the order the vehicle currently has
  v | the vehicle to update
  conditional_depth | the depth (amount of steps) to go with conditional orders. This to prevent infinite loops.
  pbs_look_ahead | Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified.

Definition at line 2036 of file order_cmd.cpp.

References AircraftNextAirportPos_and_Order(), CMD_REVERSE_TRAIN_DIRECTION, BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::current_order, BaseConsist::current_order_time, DC_EXEC, Vehicle::dest_tile, DoCommand(), Vehicle::FindClosestDepot(), FLYING, Order::Free(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Waypoint, true >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::Get(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), Vehicle::GetGroundVehicleFlags(), Order::GetNonStopType(), Vehicle::GetNumManualOrders(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::GetOrderStationLocation(), Order::GetRefitCargo(), Order::GetTimetabledTravel(), Order::GetType(), GVF_SUPPRESS_IMPLICIT_ORDERS, Vehicle::IncrementRealOrderIndex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEH_ORDER_ID, Vehicle::IsGroundVehicle(), Order::MakeGoToDepot(), Vehicle::NeedsServicing(), ODATFB_NEAREST_DEPOT, ODTFB_SERVICE, ProcessConditionalOrder(), SetBit(), Aircraft::state, Aircraft::targetairport, Vehicle::tile, BaseVehicle::type, UpdateOrderDest(), Vehicle::UpdateRealOrderIndex(), UpdateVehicleTimetable(), VEH_AIRCRAFT, and VEH_TRAIN.

Referenced by ProcessOrders(), VehicleOrderSaver::SwitchToNextOrder(), and UpdateOrderDest().