OpenTTD Source  20241108-master-g80f628063a
Order Struct Reference
Inheritance diagram for Order:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >

Public Member Functions

 Order (uint8_t type, uint8_t flags, DestinationID dest)
 
 ~Order ()
 Clean everything up.
 
bool IsType (OrderType type) const
 Check whether this order is of the given type. More...
 
OrderType GetType () const
 Get the type of order of this order. More...
 
void Free ()
 'Free' the order More...
 
void MakeGoToStation (StationID destination)
 Makes this order a Go To Station order. More...
 
void MakeGoToDepot (DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CARGO_NO_REFIT)
 Makes this order a Go To Depot order. More...
 
void MakeGoToWaypoint (StationID destination)
 Makes this order a Go To Waypoint order. More...
 
void MakeLoading (bool ordered)
 Makes this order a Loading order. More...
 
void MakeLeaveStation ()
 Makes this order a Leave Station order.
 
void MakeDummy ()
 Makes this order a Dummy order.
 
void MakeConditional (VehicleOrderID order)
 Makes this order an conditional order. More...
 
void MakeImplicit (StationID destination)
 Makes this order an implicit order. More...
 
bool IsGotoOrder () const
 Is this a 'goto' order with a real destination? More...
 
DestinationID GetDestination () const
 Gets the destination of this order. More...
 
void SetDestination (DestinationID destination)
 Sets the destination of this order. More...
 
bool IsRefit () const
 Is this order a refit order. More...
 
bool IsAutoRefit () const
 Is this order a auto-refit order. More...
 
CargoID GetRefitCargo () const
 Get the cargo to to refit to. More...
 
void SetRefit (CargoID cargo)
 Make this depot/station order also a refit order. More...
 
OrderLoadFlags GetLoadType () const
 How must the consist be loaded?
 
OrderUnloadFlags GetUnloadType () const
 How must the consist be unloaded?
 
OrderNonStopFlags GetNonStopType () const
 At which stations must we stop?
 
OrderStopLocation GetStopLocation () const
 Where must we stop at the platform?
 
OrderDepotTypeFlags GetDepotOrderType () const
 What caused us going to the depot?
 
OrderDepotActionFlags GetDepotActionType () const
 What are we going to do when in the depot.
 
OrderConditionVariable GetConditionVariable () const
 What variable do we have to compare?
 
OrderConditionComparator GetConditionComparator () const
 What is the comparator to use?
 
VehicleOrderID GetConditionSkipToOrder () const
 Get the order to skip to.
 
uint16_t GetConditionValue () const
 Get the value to base the skip on.
 
void SetLoadType (OrderLoadFlags load_type)
 Set how the consist must be loaded.
 
void SetUnloadType (OrderUnloadFlags unload_type)
 Set how the consist must be unloaded.
 
void SetNonStopType (OrderNonStopFlags non_stop_type)
 Set whether we must stop at stations or not.
 
void SetStopLocation (OrderStopLocation stop_location)
 Set where we must stop at the platform.
 
void SetDepotOrderType (OrderDepotTypeFlags depot_order_type)
 Set the cause to go to the depot.
 
void SetDepotActionType (OrderDepotActionFlags depot_service_type)
 Set what we are going to do in the depot.
 
void SetConditionVariable (OrderConditionVariable condition_variable)
 Set variable we have to compare.
 
void SetConditionComparator (OrderConditionComparator condition_comparator)
 Set the comparator to use.
 
void SetConditionSkipToOrder (VehicleOrderID order_id)
 Get the order to skip to.
 
void SetConditionValue (uint16_t value)
 Set the value to base the skip on.
 
bool IsWaitTimetabled () const
 Does this order have an explicit wait time set?
 
bool IsTravelTimetabled () const
 Does this order have an explicit travel time set?
 
uint16_t GetTimetabledWait () const
 Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
 
uint16_t GetTimetabledTravel () const
 Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
 
uint16_t GetWaitTime () const
 Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
 
uint16_t GetTravelTime () const
 Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
 
uint16_t GetMaxSpeed () const
 Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination. More...
 
void SetWaitTimetabled (bool timetabled)
 Set if the wait time is explicitly timetabled (unless the order is conditional).
 
void SetTravelTimetabled (bool timetabled)
 Set if the travel time is explicitly timetabled (unless the order is conditional).
 
void SetWaitTime (uint16_t time)
 Set the time in ticks to wait at the destination. More...
 
void SetTravelTime (uint16_t time)
 Set the time in ticks to take for travelling to the destination. More...
 
void SetMaxSpeed (uint16_t speed)
 Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination. More...
 
bool ShouldStopAtStation (const Vehicle *v, StationID station) const
 Check whether the given vehicle should stop at the given station based on this order and the non-stop settings. More...
 
bool CanLoadOrUnload () const
 
bool CanLeaveWithCargo (bool has_cargo) const
 A vehicle can leave the current station with cargo if: More...
 
TileIndex GetLocation (const Vehicle *v, bool airport=false) const
 Returns a tile somewhat representing the order destination (not suitable for pathfinding). More...
 
bool IsCompletelyTimetabled () const
 Checks if travel_time and wait_time apply to this order and if they are timetabled.
 
void AssignOrder (const Order &other)
 Assign data to an order (from another order) This function makes sure that the index is maintained correctly. More...
 
bool Equals (const Order &other) const
 Does this order have the same type, flags and destination? More...
 
uint32_t Pack () const
 Pack this order into a 32 bits integer, or actually only the type, flags and destination. More...
 
uint16_t MapOldOrder () const
 Pack this order into a 16 bits integer as close to the TTD representation as possible. More...
 
void ConvertFromOldSavegame ()
 Converts this order from an old savegame's version; it moves all bits to the new location.
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >
void * operator new (size_t size)
 Allocates space for new Titem. More...
 
void * operator new (size_t size, size_t index)
 Allocates space for new Titem with given index. More...
 
void * operator new (size_t, void *ptr)
 Allocates space for new Titem at given memory address. More...
 
void operator delete (void *p)
 Marks Titem as free. More...
 

Data Fields

Ordernext = nullptr
 Pointer to next order. If nullptr, end of list.
 
- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >
Tindex index
 Index of this pool item.
 

Private Attributes

uint8_t type = 0
 The type of order + non-stop flags.
 
uint8_t flags = 0
 Load/unload types, depot order/action types.
 
DestinationID dest = 0
 The destination of the order.
 
CargoID refit_cargo = CARGO_NO_REFIT
 Refit CargoID.
 
uint16_t wait_time = 0
 How long in ticks to wait at the destination.
 
uint16_t travel_time = 0
 How long in ticks the journey to this destination should take.
 
uint16_t max_speed = UINT16_MAX
 How fast the vehicle may go on the way to the destination.
 

Friends

struct VEHSChunkHandler
 Loading of ancient vehicles.
 
class SlVehicleCommon
 
class SlVehicleDisaster
 
SaveLoadTable GetOrderDescription ()
 Saving and loading of orders.
 
template<typename Tcont , typename Titer >
EndianBufferWriter< Tcont, Titer > & operator<< (EndianBufferWriter< Tcont, Titer > &buffer, const Order &data)
 
class EndianBufferReaderoperator>> (class EndianBufferReader &buffer, Order &order)
 

Additional Inherited Members

- Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero > Pool
 Type of the pool this item is going to be part of.
 
- Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() More...
 
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no. More...
 
static bool IsValidID (size_t index)
 Tests whether given index can be used to get valid (non-nullptr) Titem. More...
 
static Titem * Get (size_t index)
 Returns Titem with given index. More...
 
static Titem * GetIfValid (size_t index)
 Returns Titem with given index. More...
 
static size_t GetPoolSize ()
 Returns first unused index. More...
 
static size_t GetNumItems ()
 Returns number of valid items in the pool. More...
 
static void PostDestructor ([[maybe_unused]] size_t index)
 Dummy function called after destructor of each member. More...
 
static Pool::IterateWrapper< Titem > Iterate (size_t from=0)
 Returns an iterable ensemble of all valid Titem. More...
 

Detailed Description

Definition at line 36 of file order_base.h.

Member Function Documentation

◆ AssignOrder()

void Order::AssignOrder ( const Order other)

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

Parameters
otherthe data to copy (except next pointer).

Definition at line 257 of file order_cmd.cpp.

References dest, flags, max_speed, refit_cargo, travel_time, type, and wait_time.

Referenced by OrderBackup::OrderBackup().

◆ CanLeaveWithCargo()

bool Order::CanLeaveWithCargo ( bool  has_cargo) const

A vehicle can leave the current station with cargo if:

  1. it can load cargo here OR 2a. it could leave the last station with cargo AND 2b. it doesn't have to unload all cargo here.

Definition at line 2249 of file order_cmd.cpp.

References GetLoadType(), GetUnloadType(), OLFB_NO_LOAD, OUFB_TRANSFER, and OUFB_UNLOAD.

◆ Equals()

bool Order::Equals ( const Order other) const

Does this order have the same type, flags and destination?

Parameters
otherthe second order to compare to.
Returns
true if the type, flags and destination match.

Definition at line 175 of file order_cmd.cpp.

References IsType().

Referenced by VehiclesHaveSameOrderList().

◆ Free()

void Order::Free ( )

'Free' the order

Note
ONLY use on "current_order" vehicle orders!

Definition at line 63 of file order_cmd.cpp.

References type.

Referenced by GetOrderCmdFromTile(), and UpdateOrderDest().

◆ GetDestination()

DestinationID Order::GetDestination ( ) const
inline

Gets the destination of this order.

Precondition
IsType(OT_GOTO_WAYPOINT) || IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION).
Returns
the destination of the order.

Definition at line 103 of file order_base.h.

References dest.

Referenced by AircraftController(), and LinkRefresher::RefreshStats().

◆ GetLocation()

TileIndex Order::GetLocation ( const Vehicle v,
bool  airport = false 
) const

Returns a tile somewhat representing the order destination (not suitable for pathfinding).

Parameters
vThe vehicle to get the location for.
airportGet the airport tile and not the station location for aircraft.
Returns
destination of order, or INVALID_TILE if none.

Definition at line 642 of file order_cmd.cpp.

References GetType().

Referenced by VehicleViewWindow::OnPaint().

◆ GetMaxSpeed()

uint16_t Order::GetMaxSpeed ( ) const
inline

Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.

Returns
maximum speed.

Definition at line 201 of file order_base.h.

Referenced by CmdInsertOrder(), and ShipAccelerate().

◆ GetRefitCargo()

CargoID Order::GetRefitCargo ( ) const
inline

Get the cargo to to refit to.

Precondition
IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
Returns
the cargo type.

Definition at line 131 of file order_base.h.

References refit_cargo.

Referenced by CmdInsertOrder(), GetIncompatibleRefitOrderIdForAutoreplace(), and ReserveConsist().

◆ GetType()

OrderType Order::GetType ( ) const
inline

◆ IsAutoRefit()

bool Order::IsAutoRefit ( ) const
inline

Is this order a auto-refit order.

Precondition
IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
Returns
true if a auto-refit should happen.

Definition at line 124 of file order_base.h.

References CARGO_AUTO_REFIT.

◆ IsGotoOrder()

bool Order::IsGotoOrder ( ) const
inline

Is this a 'goto' order with a real destination?

Returns
True if the type is either #OT_GOTO_WAYPOINT, #OT_GOTO_DEPOT or #OT_GOTO_STATION.

Definition at line 93 of file order_base.h.

References IsType().

◆ IsRefit()

bool Order::IsRefit ( ) const
inline

Is this order a refit order.

Precondition
IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
Returns
true if a refit should happen.

Definition at line 117 of file order_base.h.

References CARGO_AUTO_REFIT, and NUM_CARGO.

Referenced by GetIncompatibleRefitOrderIdForAutoreplace(), and ReserveConsist().

◆ IsType()

◆ MakeConditional()

void Order::MakeConditional ( VehicleOrderID  order)

Makes this order an conditional order.

Parameters
orderthe order to jump to.

Definition at line 143 of file order_cmd.cpp.

References type.

◆ MakeGoToDepot()

void Order::MakeGoToDepot ( DepotID  destination,
OrderDepotTypeFlags  order,
OrderNonStopFlags  non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS,
OrderDepotActionFlags  action = ODATF_SERVICE_ONLY,
CargoID  cargo = CARGO_NO_REFIT 
)

Makes this order a Go To Depot order.

Parameters
destinationthe depot to go to.
orderis this order a 'default' order, or an overridden vehicle order?
non_stop_typehow to get to the depot?
actionwhat to do in the depot?
cargothe cargo type to change to.

Definition at line 90 of file order_cmd.cpp.

References type.

Referenced by GetOrderCmdFromTile(), and OrdersWindow::OrderClick_NearestDepot().

◆ MakeGoToStation()

void Order::MakeGoToStation ( StationID  destination)

Makes this order a Go To Station order.

Parameters
destinationthe station to go to.

Definition at line 75 of file order_cmd.cpp.

References type.

◆ MakeGoToWaypoint()

void Order::MakeGoToWaypoint ( StationID  destination)

Makes this order a Go To Waypoint order.

Parameters
destinationthe waypoint to go to.

Definition at line 104 of file order_cmd.cpp.

References type.

Referenced by GetOrderCmdFromTile().

◆ MakeImplicit()

void Order::MakeImplicit ( StationID  destination)

Makes this order an implicit order.

Parameters
destinationthe station to go to.

Definition at line 154 of file order_cmd.cpp.

References type.

◆ MakeLoading()

void Order::MakeLoading ( bool  ordered)

Makes this order a Loading order.

Parameters
orderedis this an ordered stop?

Definition at line 115 of file order_cmd.cpp.

References type.

◆ MapOldOrder()

uint16_t Order::MapOldOrder ( ) const

Pack this order into a 16 bits integer as close to the TTD representation as possible.

Returns
the TTD-like packed representation.

Definition at line 208 of file order_cmd.cpp.

◆ Pack()

uint32_t Order::Pack ( ) const

Pack this order into a 32 bits integer, or actually only the type, flags and destination.

Returns
the packed representation.
Note
unpacking is done in the constructor.

Definition at line 198 of file order_cmd.cpp.

References dest, flags, and type.

◆ SetDestination()

void Order::SetDestination ( DestinationID  destination)
inline

Sets the destination of this order.

Parameters
destinationthe new destination of the order.
Precondition
IsType(OT_GOTO_WAYPOINT) || IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION).

Definition at line 110 of file order_base.h.

◆ SetMaxSpeed()

void Order::SetMaxSpeed ( uint16_t  speed)
inline

Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.

Parameters
speedSpeed to be set.

Definition at line 225 of file order_base.h.

◆ SetRefit()

void Order::SetRefit ( CargoID  cargo)

Make this depot/station order also a refit order.

Parameters
cargothe cargo type to change to.
Precondition
IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION).

Definition at line 165 of file order_cmd.cpp.

References refit_cargo.

◆ SetTravelTime()

void Order::SetTravelTime ( uint16_t  time)
inline

Set the time in ticks to take for travelling to the destination.

Parameters
timeTime to set as travel time.

Definition at line 218 of file order_base.h.

◆ SetWaitTime()

void Order::SetWaitTime ( uint16_t  time)
inline

Set the time in ticks to wait at the destination.

Parameters
timeTime to set as wait time.

Definition at line 212 of file order_base.h.

◆ ShouldStopAtStation()

bool Order::ShouldStopAtStation ( const Vehicle v,
StationID  station 
) const

Check whether the given vehicle should stop at the given station based on this order and the non-stop settings.

Parameters
vthe vehicle that might be stopping.
stationthe station to stop at.
Returns
true if the vehicle should stop.

Definition at line 2225 of file order_cmd.cpp.

References IsType().


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