OpenTTD Source: src/order_cmd.cpp File Reference

OpenTTD Source 14.0-beta3

Functions | Variables
order_cmd.cpp File Reference
`#include "stdafx.h"`
`#include "debug.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 "order_cmd.h"`
`#include "train_cmd.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
void | InvalidateVehicleOrder (const Vehicle *v, int data)
| Updates the widgets of a vehicle which contains the order-data. More...
static bool | OrderGoesToStation (const Vehicle *v, const Order *o)
| Checks whether the order goes to a station or not, i.e. More...
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 they're 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. More...
CommandCost | CmdInsertOrder (DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, const Order &new_order)
| Add an order to the orderlist of a vehicle. More...
void | InsertOrder (Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
| Insert a new order but skip the validation. More...
static CommandCost | DecloneOrder (Vehicle *dst, DoCommandFlag flags)
| Declone an order-list. More...
CommandCost | CmdDeleteOrder (DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord)
| Delete an order from the orderlist of a vehicle. More...
static void | CancelLoadingDueToDeletedOrder (Vehicle *v)
| Cancel the current loading order of the vehicle as the order was deleted. More...
void | DeleteOrder (Vehicle *v, VehicleOrderID sel_ord)
| Delete an order but skip the parameter validation. More...
CommandCost | CmdSkipToOrder (DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord)
| Goto order of order-list. More...
CommandCost | CmdMoveOrder (DoCommandFlag flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order)
| Move an order inside the orderlist. More...
CommandCost | CmdModifyOrder (DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16_t data)
| Modify an order in the orderlist of a vehicle. More...
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. More...
CommandCost | CmdCloneOrder (DoCommandFlag flags, CloneOptions action, VehicleID veh_dst, VehicleID veh_src)
| Clone/share/copy an order-list of another vehicle. More...
CommandCost | CmdOrderRefit (DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo)
| Add/remove refit orders from an order. More...
void | CheckOrders (const Vehicle *v)
| Check the orders of a vehicle, to see if there are invalid orders and stuff. More...
void | RemoveOrderFromAllVehicles (OrderType type, DestinationID destination, bool hangar)
| Removes an order from all vehicles. More...
void | DeleteVehicleOrders (Vehicle *v, bool keep_orderlist, bool reset_order_indices)
| Delete all orders from a vehicle. More...
uint16_t | GetServiceIntervalClamped (int interval, bool ispercent)
| Clamp the service interval to the correct min/max. More...
static bool | CheckForValidOrders (const Vehicle *v)
| Check if a vehicle has any valid orders. More...
static bool | OrderConditionCompare (OrderConditionComparator occ, int variable, int value)
| Compare the variable and value based on the given comparator.
template<typename T , std::enable_if_t< std::is_base_of< StrongTypedefBase, T >::value, int > = 0>
static bool | OrderConditionCompare (OrderConditionComparator occ, T variable, int value)
VehicleOrderID | ProcessConditionalOrder (const Order *order, const Vehicle *v)
| Process a conditional order and determine the next order. More...
bool | UpdateOrderDest (Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
| Update the vehicle's destination tile from an order. More...
bool | ProcessOrders (Vehicle *v)
| Handle the orders of a vehicle and determine the next place to go to if needed. More...

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

## Detailed Description

Handling of orders.

Definition in file order_cmd.cpp.

## Function Documentation

## ◆ CancelLoadingDueToDeletedOrder()

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 1020 of file order_cmd.cpp.

References Vehicle::current_order, and Order::IsType().

## ◆ CheckAircraftOrderDistance()

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 1492 of file order_cmd.cpp.

References AircraftCache::cached_max_range, and Order::next.

## ◆ CheckForValidOrders()

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 1921 of file order_cmd.cpp.

References Vehicle::Orders().

## ◆ CheckOrders()

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

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

Definition at line 1711 of file order_cmd.cpp.

References _local_company, _settings_client, Vehicle::day_counter, Vehicle::FirstShared(), ClientSettings::gui, INVALID_STRING_ID, GUISettings::order_review_system, Vehicle::Orders(), Vehicle::owner, Vehicle::vehstatus, VS_CRASHED, and VS_STOPPED.

Referenced by Aircraft::OnNewEconomyDay().

## ◆ CmdCloneOrder()

CommandCost CmdCloneOrder | ( | DoCommandFlag | flags,
|  | CloneOptions | action,
|  | VehicleID | veh_dst,
|  | VehicleID | veh_src
| ) |  |

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

Parameters

  flags | operation to perform
  action | action to perform
  veh_dst | destination vehicle to clone orders to
  veh_src | source vehicle to clone orders from, if any (none for CO_UNSHARE)

Returns
  the cost of this operation or an error

Definition at line 1522 of file order_cmd.cpp.

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

## ◆ CmdDeleteOrder()

CommandCost CmdDeleteOrder | ( | DoCommandFlag | flags,
|  | VehicleID | veh_id,
|  | VehicleOrderID | sel_ord
| ) |  |

Delete an order from the orderlist of a vehicle.

Parameters

  flags | operation to perform
  veh_id | the ID of the vehicle
  sel_ord | the order to delete (max 255)

Returns
  the cost of this operation or an error

Definition at line 998 of file order_cmd.cpp.

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

## ◆ CmdInsertOrder()

CommandCost CmdInsertOrder | ( | DoCommandFlag | flags,
|  | VehicleID | veh,
|  | VehicleOrderID | sel_ord,
|  | const Order & | new_order
| ) |  |

Add an order to the orderlist of a vehicle.

Parameters

  flags | operation to perform
  veh | ID of the vehicle
  sel_ord | 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.
  new_order | order to insert

Returns
  the cost of this operation or an error

Definition at line 713 of file order_cmd.cpp.

References CARGO_NO_REFIT, CheckOwnership(), CMD_ERROR, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Order::GetMaxSpeed(), Order::GetRefitCargo(), Order::GetTravelTime(), Order::GetType(), Order::GetWaitTime(), Vehicle::IsPrimaryVehicle(), and Vehicle::owner.

## ◆ CmdModifyOrder()

CommandCost CmdModifyOrder | ( | DoCommandFlag | flags,
|  | VehicleID | veh,
|  | VehicleOrderID | sel_ord,
|  | ModifyOrderFlags | mof,
|  | uint16_t | data
| ) |  |

Modify an order in the orderlist of a vehicle.

Parameters

  flags | operation to perform
  veh | ID of the vehicle
  sel_ord | 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.
  mof | what data to modify (

See also
  ModifyOrderFlags)

Parameters

  data | the data to modify

Returns
  the cost of this operation or an error

Definition at line 1236 of file order_cmd.cpp.

## ◆ CmdMoveOrder()

CommandCost CmdMoveOrder | ( | DoCommandFlag | flags,
|  | VehicleID | veh,
|  | VehicleOrderID | moving_order,
|  | VehicleOrderID | target_order
| ) |  |

Move an order inside the orderlist.

Parameters

  flags | operation to perform
  veh | the ID of the vehicle
  moving_order | the order to move
  target_order | the target order

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 1138 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(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), InvalidateVehicleOrder(), Vehicle::IsPrimaryVehicle(), OrderList::MoveOrder(), Vehicle::NextShared(), Vehicle::orders, Vehicle::Orders(), Vehicle::owner, and BaseConsist::ResetDepotUnbunching().

## ◆ CmdOrderRefit()

CommandCost CmdOrderRefit | ( | DoCommandFlag | flags,
|  | VehicleID | veh,
|  | VehicleOrderID | order_number,
|  | CargoID | cargo
| ) |  |

Add/remove refit orders from an order.

Parameters

  flags | operation to perform
  veh | VehicleIndex of the vehicle having the order
  order_number | number of order to modify
  cargo | CargoID

Returns
  the cost of this operation or an error

Definition at line 1664 of file order_cmd.cpp.

References CARGO_AUTO_REFIT, CARGO_NO_REFIT, CheckOwnership(), CMD_ERROR, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetOrder(), Vehicle::IsPrimaryVehicle(), Order::IsType(), NUM_CARGO, and Vehicle::owner.

## ◆ CmdSkipToOrder()

CommandCost CmdSkipToOrder | ( | DoCommandFlag | flags,
|  | VehicleID | veh_id,
|  | VehicleOrderID | sel_ord
| ) |  |

Goto order of order-list.

Parameters

  flags | operation to perform
  veh_id | The ID of the vehicle which order is skipped
  sel_ord | the selected order to which we want to skip

Returns
  the cost of this operation or an error

Definition at line 1100 of file order_cmd.cpp.

References CheckOwnership(), CMD_ERROR, BaseConsist::cur_implicit_order_index, Vehicle::current_order, DC_EXEC, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::GetNumOrders(), Vehicle::IsPrimaryVehicle(), Order::IsType(), and Vehicle::owner.

## ◆ DecloneOrder()

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 981 of file order_cmd.cpp.

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

Referenced by CmdDeleteOrder().

## ◆ DeleteOrder()

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 1036 of file order_cmd.cpp.

References BaseConsist::cur_real_order_index, Vehicle::current_order, OrderList::DeleteOrderAt(), DeleteOrderWarnings(), Vehicle::FirstShared(), Order::IsType(), Vehicle::NextShared(), and Vehicle::orders.

Referenced by CmdDeleteOrder().

## ◆ DeleteVehicleOrders()

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 1869 of file order_cmd.cpp.

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

Referenced by CmdSellRailWagon(), and DecloneOrder().

## ◆ GetOrderDistance()

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 685 of file order_cmd.cpp.

References Order::IsType().

## ◆ GetServiceIntervalClamped()

uint16_t GetServiceIntervalClamped | ( | int | interval,
|  | bool | ispercent
| ) |  |

Clamp the service interval to the correct min/max.

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

Parameters

  interval | The proposed service interval.
  ispercent | Whether the interval is a percent.

Returns
  The service interval clamped to use the chosen units.

Definition at line 1901 of file order_cmd.cpp.

## ◆ InsertOrder()

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 911 of file order_cmd.cpp.

References BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, DeleteOrderWarnings(), Vehicle::FirstShared(), OrderList::InsertOrderAt(), Vehicle::IsGroundVehicle(), Vehicle::NextShared(), and Vehicle::orders.

## ◆ InvalidateVehicleOrder()

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

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

Definition at line 251 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 CmdMoveOrder(), DecloneOrder(), and Vehicle::IncrementRealOrderIndex().

## ◆ OrderGoesToStation()

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 631 of file order_cmd.cpp.

References Order::IsType().

## ◆ ProcessConditionalOrder()

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 1968 of file order_cmd.cpp.

References Order::GetType().

## ◆ ProcessOrders()

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 2127 of file order_cmd.cpp.

References Vehicle::current_order, and Order::GetType().

## ◆ RemoveOrderFromAllVehicles()

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

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.
  hangar | Only used for airports in the destination. When false, remove airport and hangar orders. When true, remove either airport or hangar order.

Definition at line 1787 of file order_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), and VEH_AIRCRAFT.

Referenced by Depot::~Depot().

## ◆ UpdateOrderDest()

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 1998 of file order_cmd.cpp.

References Vehicle::current_order, Order::Free(), Vehicle::GetNumOrders(), and Order::GetType().