# order.h File Reference

`#include "oldpool.h"`
`#include "core/bitmath_func.hpp"`
`#include "cargo_type.h"`
`#include "vehicle_type.h"`
`#include "tile_type.h"`
`#include "date_type.h"`

Go to the source code of this file.

## Data Structures

struct | EnumPropsT< OrderType >
| Define basic enum properties. More...
struct | Order
struct | BackuppedOrders

## Defines

#define | FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid())
#define | FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
#define | FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
#define | MIN_SERVINT_PERCENT 5
#define | MAX_SERVINT_PERCENT 90
#define | MIN_SERVINT_DAYS 30
#define | MAX_SERVINT_DAYS 800

## Typedefs

typedef TinyEnumT< OrderType > | OrderTypeByte

## Enumerations

enum | { INVALID_VEH_ORDER_ID = 0xFF }
enum | OrderType { OT_BEGIN = 0, OT_NOTHING = 0, OT_GOTO_STATION = 1, OT_GOTO_DEPOT = 2, OT_LOADING = 3, OT_LEAVESTATION = 4, OT_DUMMY = 5, OT_GOTO_WAYPOINT = 6, OT_END }
enum | OrderFlagMasks { OFB_TRANSFER = 0x1, OFB_UNLOAD = 0x2, OFB_FULL_LOAD = 0x4, OFB_PART_OF_ORDERS = 0x2, OFB_HALT_IN_DEPOT = 0x4, OFB_SERVICE_IF_NEEDED = 0x4, OFB_NON_STOP = 0x8 }
| Order flag masks - these are for direct bit operations. More...
enum | { OF_TRANSFER = 0, OF_UNLOAD = 1, OF_FULL_LOAD = 2, OF_PART_OF_ORDERS = 1, OF_HALT_IN_DEPOT = 2, OF_SERVICE_IF_NEEDED = 2, OF_NON_STOP = 3 }
| Order flags bits - these are for the *BIT macros for descrption of flags, see OrderFlagMasks. More...
enum | { CO_SHARE = 0, CO_COPY = 1, CO_UNSHARE = 2 }

## Functions

static VehicleOrderID | GetMaxOrderIndex ()
static VehicleOrderID | GetNumOrders ()
static bool | HasOrderPoolFree (uint amount)
static uint32 | PackOrder (const Order *order)
static Order | UnpackOrder (uint32 packed)
void | BackupVehicleOrders (const Vehicle *v, BackuppedOrders *order=&_backup_orders_data)
| Backup a vehicle order-list, so you can replace a vehicle without loosing 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)
| 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)
| Delete all orders from a vehicle.
void | AssignOrder (Order *order, Order data)
| Assign data to an order (from an other order) This function makes sure that the index is maintained correctly.
bool | CheckForValidOrders (const Vehicle *v)
| Check if a vehicle has any valid orders.
Order | UnpackOldOrder (uint16 packed)
| Unpacks a order from savegames made with TTD(Patch).
Date | GetServiceIntervalClamped (uint index)
| Get the service interval domain.

## Variables

static const OrderID | INVALID_ORDER = 0xFFFF
TileIndex | _backup_orders_tile
BackuppedOrders | _backup_orders_data

## Detailed Description

Definition in file order.h.

## Enumeration Type Documentation

anonymous enum

Order flags bits - these are for the *BIT macros for descrption of flags, see OrderFlagMasks.

See also:
  OrderFlagMasks

Definition at line 72 of file order.h.

enum OrderFlagMasks

Order flag masks - these are for direct bit operations.

Enumerator:

  OFB_TRANSFER | vehicle will transfer cargo (i. e. not deliver to nearby industry/town even if accepted there)
  OFB_UNLOAD | If OFB_TRANSFER is not set, drop any cargo loaded. If accepted, deliver, otherwise cargo remains at the station. No new cargo is loaded onto the vehicle whatsoever

  OFB_FULL_LOAD

  Wait for full load of all vehicles, or of at least one cargo type, depending on patch setting.
  Todo:
    make this two different flags

  OFB_PART_OF_ORDERS | The current depot-order was initiated because it was in the vehicle's order list.
  OFB_HALT_IN_DEPOT | if OFB_PART_OF_ORDERS is not set, this will cause the vehicle to be stopped in the depot
  OFB_SERVICE_IF_NEEDED | if OFB_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing

  OFB_NON_STOP

  This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings).
  Todo:
    make this two different flags

Definition at line 43 of file order.h.

## Function Documentation

void AssignOrder | ( | Order * | order,
|  | Order | data |
| ) |  |  |

Assign data to an order (from an other order) This function makes sure that the index is maintained correctly.

Definition at line 116 of file order_cmd.cpp.

Referenced by CmdCloneOrder(), CmdInsertOrder(), and SwapOrders().

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

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

Definition at line 926 of file order_cmd.cpp.

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

Check if a vehicle has any valid orders.

Returns:
  false if there are no valid orders

Definition at line 1282 of file order_cmd.cpp.

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

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

Definition at line 1075 of file order_cmd.cpp.

References AddNewsItem(), GetLastVehicleOrder(), NEWS_FLAGS, NF_VEHICLE, NF_VIEWPORT, NM_SMALL, and NT_ADVICE.

void DeleteVehicleOrders | ( | Vehicle * | v | ) |

Delete all orders from a vehicle.

Definition at line 1220 of file order_cmd.cpp.

References DeleteOrderWarnings(), InvalidateVehicleOrder(), and RemoveSharedOrderVehicleList().

Referenced by CmdCloneOrder(), CmdMoveRailVehicle(), and DecloneOrder().

Date GetServiceIntervalClamped | ( | uint | index | ) |

Get the service interval domain.

Get the new proposed service interval for the vehicle is indeed, clamped within the given bounds.

See also:
  MIN_SERVINT_PERCENT ,etc.

Parameters:

  | index | proposed service interval

Returns:
  service interval

Definition at line 1269 of file order_cmd.cpp.

References Clamp().

Referenced by CmdChangeServiceInt(), CmdRestoreOrderIndex(), and VehicleDetailsWndProc().

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

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

Definition at line 87 of file order_cmd.cpp.

Referenced by CmdCloneOrder(), CmdDeleteOrder(), CmdInsertOrder(), CmdModifyOrder(), CmdMoveOrder(), CmdOrderRefit(), CmdSkipToOrder(), DecloneOrder(), DeleteVehicleOrders(), ProcessTrainOrder(), and RemoveOrderFromAllVehicles().

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

References GetFirstVehicleFromSharedList(), and InvalidateVehicleOrder().

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

Restore vehicle orders that are backupped via BackupVehicleOrders.

Definition at line 977 of file order_cmd.cpp.

References _cmd_text, CMD_ADD_VEHICLE_GROUP, CMD_CHANGE_TIMETABLE, CMD_CLONE_ORDER, CMD_INSERT_ORDER, CMD_NAME_VEHICLE, CMD_NO_TEST_IF_IN_NETWORK, CMD_RESTORE_ORDER_INDEX, and DoCommandP().

Referenced by CcBuildAircraft().

Order UnpackOldOrder | ( | uint16 | packed | ) |

Unpacks a order from savegames made with TTD(Patch).

Definition at line 38 of file order_cmd.cpp.

References GB().

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

Referenced by CheckSendAircraftToHangarForReplacement().