# order_func.h File Reference

Functions related to orders. More...

`#include "order_type.h"`
`#include "vehicle_type.h"`
`#include "tile_type.h"`
`#include "group_type.h"`
`#include "company_type.h"`

Go to the source code of this file.

## Data Structures
struct | BackuppedOrders
## Defines
#define | MIN_SERVINT_PERCENT 5
#define | MAX_SERVINT_PERCENT 90
#define | MIN_SERVINT_DAYS 30
#define | MAX_SERVINT_DAYS 800
## Functions
void | BackupVehicleOrders (const Vehicle *v, BackuppedOrders *order=&_backup_orders_data)
| Backup a vehicle order-list, so you can replace a vehicle without losing the order-list.
void | RestoreVehicleOrders (const Vehicle *v, const BackuppedOrders *order=&_backup_orders_data)
| Restore vehicle orders that are backupped via BackupVehicleOrders.
void | RemoveOrderFromAllVehicles (OrderType type, DestinationID destination)
| Removes an order from all vehicles.
void | InvalidateVehicleOrder (const Vehicle *v, int data)
| Updates the widgets of a vehicle which contains the order-data.
bool | VehicleHasDepotOrders (const Vehicle *v)
| Checks if a vehicle has a GOTO_DEPOT in his order list.
void | CheckOrders (const Vehicle *)
| Check the orders of a vehicle, to see if there are invalid orders and stuff.
void | DeleteVehicleOrders (Vehicle *v, bool keep_orderlist=false)
| Delete all orders from a vehicle.
bool | ProcessOrders (Vehicle *v)
| Handle the orders of a vehicle and determine the next place to go to if needed.
bool | UpdateOrderDest (Vehicle *v, const Order *order, int conditional_depth=0)
| Update the vehicle's destination tile from an order.
VehicleOrderID | ProcessConditionalOrder (const Order *order, const Vehicle *v)
| Process a conditional order and determine the next order.
void | DrawOrderString (const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
| Draws an order in order or timetable GUI.
uint16 | GetServiceIntervalClamped (uint interval, CompanyID company_id)
| Clamp the service interval to the correct min/max.
## Variables
TileIndex | _backup_orders_tile
BackuppedOrders | _backup_orders_data

## Detailed Description

Functions related to orders.

Definition in file order_func.h.

## Function Documentation

void BackupVehicleOrders | ( | const Vehicle * | v,
|  | BackuppedOrders * | bak |
| ) |  |  |

Backup a vehicle order-list, so you can replace a vehicle without losing the order-list.

Definition at line 1295 of file order_cmd.cpp.

References Vehicle::cur_order_index, Vehicle::FirstShared(), Vehicle::group_id, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEHICLE, Vehicle::IsOrderListShared(), Vehicle::name, and Vehicle::NextShared().

Referenced by DepotWindow::OnDragDrop().

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

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

Definition at line 1436 of file order_cmd.cpp.

References _settings_client, AddVehicleNewsItem(), CanVehicleUseStation(), Vehicle::day_counter, OrderList::DebugCheckSanity(), Order::Equals(), Vehicle::FirstShared(), SpecializedStation< Station, false >::Get(), Order::GetDestination(), OrderList::GetFirstOrder(), Vehicle::GetLastOrder(), Vehicle::GetNumOrders(), ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Order::IsType(), Vehicle::list, NS_ADVICE, GUISettings::order_review_system, SetDParam(), and Vehicle::vehstatus.

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

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

Delete all orders from a vehicle.

Definition at line 1572 of file order_cmd.cpp.

References DeleteOrderWarnings(), OrderList::FreeChain(), Vehicle::IsOrderListShared(), Vehicle::list, and Vehicle::RemoveFromShared().

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

void DrawOrderString | ( | const Vehicle * | v,
|  | const Order * | order,
|  | int | order_index,
|  | int | y,
|  | bool | selected,
|  | bool | timetable,
|  | int | left,
|  | int | middle,
|  | int | right |
| ) |  |  |

Draws an order in order or timetable GUI.

Parameters:

  | v | Vehicle the order belongs to
  | order | The order to draw
  | order_index | Index of the order in the orders of the vehicle
  | y | Y position for drawing
  | selected | True, if the order is selected
  | timetable | True, when drawing in the timetable GUI
  | left | Left border for text drawing
  | middle | X position between order index and order text
  | right | Right border for text drawing

Definition at line 190 of file order_gui.cpp.

References _dynlang, _station_load_types, ConvertSpeedToDisplaySpeed(), Vehicle::cur_order_index, DrawSprite(), DrawString(), FONT_HEIGHT_NORMAL, CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_depot_pool >::Get(), Order::GetConditionComparator(), Order::GetConditionSkipToOrder(), Order::GetConditionValue(), Order::GetConditionVariable(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), Order::GetLoadType(), Order::GetNonStopType(), Order::GetRefitCargo(), GetSpriteSize(), Order::GetStopLocation(), Order::GetType(), Order::GetUnloadType(), Order::IsRefit(), OCC_IS_FALSE, OCC_IS_TRUE, OCV_MAX_SPEED, OCV_UNCONDITIONALLY, ODATFB_HALT, ODATFB_NEAREST_DEPOT, ODTFB_SERVICE, ONSF_NO_STOP_AT_DESTINATION_STATION, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, SA_FORCE, SA_RIGHT, SetDParam(), SetTimetableParams(), TD_RTL, DynamicLanguages::text_dir, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_TRAIN, and Order::wait_time.

Referenced by TimetableWindow::DrawWidget(), and OrdersWindow::DrawWidget().

uint16 GetServiceIntervalClamped | ( | uint | interval,
|  | CompanyID | company_id |
| ) |  |  |

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

References Clamp(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get().

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

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

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

Definition at line 175 of file order_cmd.cpp.

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

Referenced by CmdCloneOrder(), CmdDeleteOrder(), CmdInsertOrder(), CmdModifyOrder(), CmdMoveOrder(), CmdOrderRefit(), CmdSkipToOrder(), DecloneOrder(), Vehicle::IncrementOrderIndex(), ProcessOrders(), Vehicle::RemoveFromShared(), and RemoveOrderFromAllVehicles().

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

References CalcPercentVehicleFilled(), DAYS_IN_LEAP_YEAR, Order::GetConditionComparator(), Order::GetConditionSkipToOrder(), Order::GetConditionValue(), Order::GetConditionVariable(), Vehicle::GetDisplayMaxSpeed(), Order::GetType(), INVALID_VEH_ORDER_ID, Vehicle::NeedsServicing(), OCV_AGE, OCV_LOAD_PERCENTAGE, OCV_MAX_SPEED, OCV_RELIABILITY, OCV_REQUIRES_SERVICE, OCV_UNCONDITIONALLY, OrderConditionCompare(), 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 1754 of file order_cmd.cpp.

References CheckForValidOrders(), Vehicle::cur_order_index, Vehicle::current_order, Vehicle::dest_tile, Order::Free(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Station, false >::Get(), Order::GetDepotOrderType(), Order::GetDestination(), Order::GetNonStopType(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), GetStationIndex(), Order::GetType(), GetWindowClassForVehicleType(), Vehicle::IncrementOrderIndex(), INVALID_TILE, InvalidateVehicleOrder(), IsTileType(), Order::IsType(), MP_STATION, ODTFB_PART_OF_ORDERS, ONSF_NO_STOP_AT_DESTINATION_STATION, SetWindowClassesDirty(), Vehicle::tile, BaseVehicle::type, UpdateOrderDest(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

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

References Vehicle::current_order, Vehicle::FirstShared(), Order::GetDepotActionType(), Order::GetDestination(), Order::GetType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), Order::IsType(), Order::MakeDummy(), Vehicle::NextShared(), ODATFB_NEAREST_DEPOT, SetWindowDirty(), BaseVehicle::type, and VEH_AIRCRAFT.

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

void RestoreVehicleOrders | ( | const Vehicle * | v,
|  | const BackuppedOrders * | bak |
| ) |  |  |

Restore vehicle orders that are backupped via BackupVehicleOrders.

Definition at line 1346 of file order_cmd.cpp.

References _settings_game, CMD_ADD_VEHICLE_GROUP, CMD_CHANGE_TIMETABLE, CMD_CLONE_ORDER, CMD_INSERT_ORDER, CMD_MODIFY_ORDER, CMD_NO_TEST_IF_IN_NETWORK, CMD_RENAME_VEHICLE, CMD_RESTORE_ORDER_INDEX, DoCommandP(), Order::GetConditionSkipToOrder(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEHICLE, Order::IsType(), MOF_LOAD, GameSettings::order, Order::Pack(), Order::SetConditionSkipToOrder(), OrderSettings::timetabling, Order::travel_time, and Order::wait_time.

Referenced by CcBuildPrimaryVehicle().

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

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.

Definition at line 1670 of file order_cmd.cpp.

References AircraftNextAirportPos_and_Order(), CMD_REVERSE_TRAIN_DIRECTION, Vehicle::cur_order_index, Vehicle::current_order, Vehicle::current_order_time, DC_EXEC, Vehicle::dest_tile, DoCommand(), Vehicle::FindClosestDepot(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Waypoint, true >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_depot_pool >::Get(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), Order::GetNonStopType(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::GetOrderStationLocation(), Order::GetRefitCargo(), Order::GetRefitSubtype(), Order::GetType(), Vehicle::IncrementOrderIndex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_VEH_ORDER_ID, Order::MakeGoToDepot(), Vehicle::NeedsServicing(), ODATFB_NEAREST_DEPOT, ODTFB_SERVICE, ProcessConditionalOrder(), Vehicle::tile, Order::travel_time, BaseVehicle::type, UpdateOrderDest(), VEH_AIRCRAFT, and VEH_TRAIN.

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

bool VehicleHasDepotOrders | ( | const Vehicle * | v | ) |

Checks if a vehicle has a GOTO_DEPOT in his order list.

Returns:
  True if this is true (lol ;))

Definition at line 1555 of file order_cmd.cpp.

References Order::IsType().

Referenced by Vehicle::NeedsAutomaticServicing().