OpenTTD Source 20250604-master-g8f10f9fb5a
OrderList Struct Reference

Shared order list linking together the linked list of orders and the list of vehicles sharing this order list. More...

#include <order_base.h>

Inheritance diagram for OrderList:
Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >

Public Member Functions

 OrderList ()
 Default constructor producing an invalid order list.
 
 OrderList (Order &&order, Vehicle *v)
 Create an order list with the given order chain for the given vehicle.
 
 OrderList (std::vector< Order > &&orders, Vehicle *v)
 
 OrderList (Vehicle *v)
 
 ~OrderList ()
 Destructor.
 
void Initialize (Vehicle *v)
 Recomputes everything.
 
void RecalculateTimetableDuration ()
 Recomputes Timetable duration.
 
VehicleOrderID GetFirstOrder () const
 Get the first order of the order chain.
 
std::span< const OrderGetOrders () const
 
std::span< OrderGetOrders ()
 
const OrderGetOrderAt (VehicleOrderID index) const
 Get a certain order of the order chain.
 
OrderGetOrderAt (VehicleOrderID index)
 
VehicleOrderID GetLastOrder () const
 Get the last order of the order chain.
 
VehicleOrderID GetNext (VehicleOrderID cur) const
 Get the order after the given one or the first one, if the given one is the last one.
 
VehicleOrderID GetNumOrders () const
 Get number of orders in the order list.
 
VehicleOrderID GetNumManualOrders () const
 Get number of manually added orders in the order list.
 
StationIDStack GetNextStoppingStation (const Vehicle *v, VehicleOrderID first=INVALID_VEH_ORDER_ID, uint hops=0) const
 Recursively determine the next deterministic station to stop at.
 
VehicleOrderID GetNextDecisionNode (VehicleOrderID next, uint hops) const
 Get the next order which will make the given vehicle stop at a station or refit at a depot or evaluate a non-trivial condition.
 
void InsertOrderAt (Order &&order, VehicleOrderID index)
 Insert a new order into the order chain.
 
void DeleteOrderAt (VehicleOrderID index)
 Remove an order from the order list and delete it.
 
void MoveOrder (VehicleOrderID from, VehicleOrderID to)
 Move an order to another position within the order list.
 
bool IsShared () const
 Is this a shared order list?
 
VehicleGetFirstSharedVehicle () const
 Get the first vehicle of this vehicle chain.
 
uint GetNumVehicles () const
 Return the number of vehicles that share this orders list.
 
void AddVehicle (Vehicle *v)
 Adds the given vehicle to this shared order list.
 
void RemoveVehicle (Vehicle *v)
 Removes the vehicle from the shared order list.
 
bool IsCompleteTimetable () const
 Checks whether all orders of the list have a filled timetable.
 
TimerGameTick::Ticks GetTimetableTotalDuration () const
 Gets the total duration of the vehicles timetable or Ticks::INVALID_TICKS is the timetable is not complete.
 
TimerGameTick::Ticks GetTimetableDurationIncomplete () const
 Gets the known duration of the vehicles timetable even if the timetable is not complete.
 
TimerGameTick::Ticks GetTotalDuration () const
 Gets the known duration of the vehicles orders, timetabled or not.
 
void UpdateTimetableDuration (TimerGameTick::Ticks delta)
 Must be called if an order's timetable is changed to update internal book keeping.
 
void UpdateTotalDuration (TimerGameTick::Ticks delta)
 Must be called if an order's timetable is changed to update internal book keeping.
 
void FreeChain (bool keep_orderlist=false)
 Free a complete order chain.
 
void DebugCheckSanity () const
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >
void * operator new (size_t size)
 Allocates space for new Titem.
 
void * operator new (size_t size, Tindex index)
 Allocates space for new Titem with given index.
 
void * operator new (size_t, void *ptr)
 Allocates space for new Titem at given memory address.
 
void operator delete (void *p, size_t size)
 Marks Titem as free.
 

Private Attributes

VehicleOrderID num_manual_orders = 0
 NOSAVE: How many manually added orders are there in the list.
 
uint num_vehicles = 0
 NOSAVE: Number of vehicles that share this order list.
 
Vehiclefirst_shared = nullptr
 NOSAVE: pointer to the first vehicle in the shared order chain.
 
std::vector< Orderorders
 Orders of the order list.
 
uint32_t old_order_index = 0
 
TimerGameTick::Ticks timetable_duration {}
 NOSAVE: Total timetabled duration of the order list.
 
TimerGameTick::Ticks total_duration {}
 NOSAVE: Total (timetabled or not) duration of the order list.
 

Friends

struct ORDLChunkHandler
 
template<typename T >
class SlOrders
 
void AfterLoadVehiclesPhase1 (bool part_of_load)
 For instantiating the shared vehicle chain.
 
SaveLoadTable GetOrderListDescription ()
 Saving and loading of order lists.
 

Additional Inherited Members

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

Detailed Description

Shared order list linking together the linked list of orders and the list of vehicles sharing this order list.

Definition at line 264 of file order_base.h.

Constructor & Destructor Documentation

◆ OrderList() [1/4]

OrderList::OrderList ( )
inline

Default constructor producing an invalid order list.

Definition at line 283 of file order_base.h.

◆ OrderList() [2/4]

OrderList::OrderList ( Order &&  order,
Vehicle v 
)
inline

Create an order list with the given order chain for the given vehicle.

Parameters
chainpointer to the first order of the order chain
vany vehicle using this orderlist

Definition at line 290 of file order_base.h.

References Initialize().

◆ OrderList() [3/4]

OrderList::OrderList ( std::vector< Order > &&  orders,
Vehicle v 
)
inline

Definition at line 296 of file order_base.h.

◆ OrderList() [4/4]

OrderList::OrderList ( Vehicle v)
inline

Definition at line 302 of file order_base.h.

◆ ~OrderList()

OrderList::~OrderList ( )
inline

Destructor.

Invalidates OrderList for re-usage by the pool.

Definition at line 308 of file order_base.h.

Member Function Documentation

◆ AddVehicle()

void OrderList::AddVehicle ( Vehicle v)
inline

Adds the given vehicle to this shared order list.

Note
This is supposed to be called after the vehicle has been inserted into the shared vehicle chain.
Parameters
vvehicle to add to the list

Definition at line 401 of file order_base.h.

References num_vehicles.

Referenced by Vehicle::AddToShared().

◆ DeleteOrderAt()

void OrderList::DeleteOrderAt ( VehicleOrderID  index)

Remove an order from the order list and delete it.

Parameters
indexis the position of the order which is to be deleted.

Definition at line 441 of file order_cmd.cpp.

References num_manual_orders, orders, timetable_duration, and total_duration.

Referenced by DeleteOrder().

◆ FreeChain()

void OrderList::FreeChain ( bool  keep_orderlist = false)

Free a complete order chain.

Parameters
keep_orderlistIf this is true only delete the orders, otherwise also delete the OrderList.
Note
do not use on "current_order" vehicle orders!

Definition at line 294 of file order_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::GetIfValid(), InvalidateWindowClassesData(), num_manual_orders, orders, BaseStation::owner, OWNER_NONE, timetable_duration, and WC_STATION_LIST.

Referenced by DeleteVehicleOrders().

◆ GetFirstOrder()

VehicleOrderID OrderList::GetFirstOrder ( ) const
inline

Get the first order of the order chain.

Returns
the first order of the chain.

Definition at line 318 of file order_base.h.

References INVALID_VEH_ORDER_ID.

Referenced by Vehicle::GetFirstOrder(), and GetNextStoppingStation().

◆ GetFirstSharedVehicle()

Vehicle * OrderList::GetFirstSharedVehicle ( ) const
inline

Get the first vehicle of this vehicle chain.

Returns
the first vehicle of the chain.

Definition at line 387 of file order_base.h.

References first_shared.

Referenced by CmdSetTimetableStart(), and Vehicle::FirstShared().

◆ GetLastOrder()

VehicleOrderID OrderList::GetLastOrder ( ) const
inline

Get the last order of the order chain.

Returns
the last order of the chain.

Definition at line 344 of file order_base.h.

References GetNumOrders(), and INVALID_VEH_ORDER_ID.

Referenced by Vehicle::GetLastOrder().

◆ GetNext()

VehicleOrderID OrderList::GetNext ( VehicleOrderID  cur) const
inline

Get the order after the given one or the first one, if the given one is the last one.

Parameters
currOrder to find the next one for.
Returns
Next order.

Definition at line 352 of file order_base.h.

References GetNumOrders(), and INVALID_VEH_ORDER_ID.

Referenced by CheckAircraftOrderDistance(), DrawOrderString(), TimetableWindow::DrawTimetablePanel(), FillTimetableArrivalDepartureTable(), GetNextDecisionNode(), GetNextStoppingStation(), GetOrderDistance(), and LinkRefresher::PredictNextOrder().

◆ GetNextDecisionNode()

VehicleOrderID OrderList::GetNextDecisionNode ( VehicleOrderID  next,
uint  hops 
) const

Get the next order which will make the given vehicle stop at a station or refit at a depot or evaluate a non-trivial condition.

Parameters
nextThe order to start looking at.
hopsThe number of orders we have already looked at.
Returns
Either of
  • a station order
  • a refitting depot order
  • a non-trivial conditional order
  • INVALID_VEH_ORDER_ID if the vehicle won't stop anymore.

Definition at line 328 of file order_cmd.cpp.

References Order::GetConditionSkipToOrder(), Order::GetConditionVariable(), Order::GetDepotActionType(), GetNext(), GetNextDecisionNode(), GetNumOrders(), INVALID_VEH_ORDER_ID, Order::IsRefit(), Order::IsType(), OCV_UNCONDITIONALLY, ODATFB_HALT, and orders.

Referenced by GetNextDecisionNode(), GetNextStoppingStation(), LinkRefresher::PredictNextOrder(), and LinkRefresher::Run().

◆ GetNextStoppingStation()

StationIDStack OrderList::GetNextStoppingStation ( const Vehicle v,
VehicleOrderID  first = INVALID_VEH_ORDER_ID,
uint  hops = 0 
) const

Recursively determine the next deterministic station to stop at.

Parameters
vThe vehicle we're looking at.
firstOrder to start searching at or INVALID_VEH_ORDER_ID to start at cur_implicit_order_index + 1.
hopsNumber of orders we have already looked at.
Returns
Next stopping station or StationID::Invalid().
Precondition
The vehicle is currently loading and v->last_station_visited is meaningful.
Note
This function may draw a random number. Don't use it from the GUI.

Definition at line 364 of file order_cmd.cpp.

References BaseConsist::cur_implicit_order_index, GetFirstOrder(), GetNext(), GetNextDecisionNode(), GetNextStoppingStation(), GetNumOrders(), INVALID_VEH_ORDER_ID, SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty(), Vehicle::last_station_visited, orders, OUFB_TRANSFER, OUFB_UNLOAD, SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop(), and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Push().

Referenced by Vehicle::GetNextStoppingStation(), and GetNextStoppingStation().

◆ GetNumManualOrders()

VehicleOrderID OrderList::GetNumManualOrders ( ) const
inline

Get number of manually added orders in the order list.

Returns
number of manual orders in the chain.

Definition at line 368 of file order_base.h.

References num_manual_orders.

Referenced by Vehicle::GetNumManualOrders().

◆ GetNumOrders()

◆ GetNumVehicles()

uint OrderList::GetNumVehicles ( ) const
inline

Return the number of vehicles that share this orders list.

Returns
the count of vehicles that use this shared orders list

Definition at line 393 of file order_base.h.

References num_vehicles.

◆ GetOrderAt() [1/2]

Order * OrderList::GetOrderAt ( VehicleOrderID  index)
inline

Definition at line 334 of file order_base.h.

◆ GetOrderAt() [2/2]

const Order * OrderList::GetOrderAt ( VehicleOrderID  index) const
inline

Get a certain order of the order chain.

Parameters
indexzero-based index of the order within the chain.
Returns
the order at position index.

Definition at line 328 of file order_base.h.

References GetNumOrders(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >::index.

Referenced by GetIncompatibleRefitOrderIdForAutoreplace(), Vehicle::GetLastOrder(), Vehicle::GetOrder(), and LinkRefresher::RefreshLinks().

◆ GetOrders() [1/2]

std::span< Order > OrderList::GetOrders ( )
inline

Definition at line 321 of file order_base.h.

◆ GetOrders() [2/2]

std::span< const Order > OrderList::GetOrders ( ) const
inline

Definition at line 320 of file order_base.h.

◆ GetTimetableDurationIncomplete()

TimerGameTick::Ticks OrderList::GetTimetableDurationIncomplete ( ) const
inline

Gets the known duration of the vehicles timetable even if the timetable is not complete.

Returns
known timetable duration

Definition at line 417 of file order_base.h.

References timetable_duration.

Referenced by TimetableWindow::DrawArrivalDeparturePanel(), and TimetableWindow::DrawSummaryPanel().

◆ GetTimetableTotalDuration()

TimerGameTick::Ticks OrderList::GetTimetableTotalDuration ( ) const
inline

Gets the total duration of the vehicles timetable or Ticks::INVALID_TICKS is the timetable is not complete.

Returns
total timetable duration or Ticks::INVALID_TICKS for incomplete timetables

Definition at line 411 of file order_base.h.

References Ticks::INVALID_TICKS, IsCompleteTimetable(), and timetable_duration.

Referenced by CmdSetTimetableStart(), and UpdateVehicleTimetable().

◆ GetTotalDuration()

TimerGameTick::Ticks OrderList::GetTotalDuration ( ) const
inline

Gets the known duration of the vehicles orders, timetabled or not.

Returns
known order duration.

Definition at line 423 of file order_base.h.

References total_duration.

Referenced by LinkRefresher::RefreshStats().

◆ Initialize()

void OrderList::Initialize ( Vehicle v)

Recomputes everything.

Parameters
chainfirst order in the chain
vone of vehicle that is using this orderlist

Definition at line 254 of file order_cmd.cpp.

References first_shared, Vehicle::NextShared(), num_manual_orders, num_vehicles, orders, Vehicle::PreviousShared(), RecalculateTimetableDuration(), timetable_duration, and total_duration.

Referenced by OrderList().

◆ InsertOrderAt()

void OrderList::InsertOrderAt ( Order &&  order,
VehicleOrderID  index 
)

Insert a new order into the order chain.

Parameters
new_orderis the order to insert into the chain.
indexis the position where the order is supposed to be inserted.

Definition at line 419 of file order_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::Get(), InvalidateWindowClassesData(), num_manual_orders, orders, BaseStation::owner, OWNER_NONE, timetable_duration, total_duration, and WC_STATION_LIST.

Referenced by InsertOrder().

◆ IsCompleteTimetable()

bool OrderList::IsCompleteTimetable ( ) const

Checks whether all orders of the list have a filled timetable.

Returns
whether all orders have a filled timetable.

Definition at line 488 of file order_cmd.cpp.

References orders.

Referenced by CmdSetTimetableStart(), and GetTimetableTotalDuration().

◆ IsShared()

bool OrderList::IsShared ( ) const
inline

Is this a shared order list?

Returns
whether this order list is shared among multiple vehicles

Definition at line 381 of file order_base.h.

Referenced by CmdCloneOrder(), CmdSellVehicle(), and Vehicle::IsOrderListShared().

◆ MoveOrder()

void OrderList::MoveOrder ( VehicleOrderID  from,
VehicleOrderID  to 
)

Move an order to another position within the order list.

Parameters
fromis the zero-based position of the order to move.
tois the zero-based position where the order is moved to.

Definition at line 459 of file order_cmd.cpp.

References GetNumOrders(), and orders.

Referenced by CmdMoveOrder().

◆ RecalculateTimetableDuration()

void OrderList::RecalculateTimetableDuration ( )

Recomputes Timetable duration.

Split out into a separate function so it can be used by afterload.

Definition at line 281 of file order_cmd.cpp.

References orders, and timetable_duration.

Referenced by Initialize().

◆ RemoveVehicle()

void OrderList::RemoveVehicle ( Vehicle v)

Removes the vehicle from the shared order list.

Note
This is supposed to be called when the vehicle is still in the chain
Parameters
vvehicle to remove from the list

Definition at line 478 of file order_cmd.cpp.

References first_shared, Vehicle::NextShared(), and num_vehicles.

◆ UpdateTimetableDuration()

void OrderList::UpdateTimetableDuration ( TimerGameTick::Ticks  delta)
inline

Must be called if an order's timetable is changed to update internal book keeping.

Parameters
deltaBy how many ticks has the timetable duration changed

Definition at line 429 of file order_base.h.

References timetable_duration.

Referenced by ChangeTimetable().

◆ UpdateTotalDuration()

void OrderList::UpdateTotalDuration ( TimerGameTick::Ticks  delta)
inline

Must be called if an order's timetable is changed to update internal book keeping.

Parameters
deltaBy how many ticks has the total duration changed

Definition at line 435 of file order_base.h.

References total_duration.

Referenced by ChangeTimetable().

Friends And Related Symbol Documentation

◆ AfterLoadVehiclesPhase1

void AfterLoadVehiclesPhase1 ( bool  part_of_load)
friend

For instantiating the shared vehicle chain.

Definition at line 256 of file vehicle_sl.cpp.

◆ GetOrderListDescription

SaveLoadTable GetOrderListDescription ( )
friend

Saving and loading of order lists.

Definition at line 237 of file order_sl.cpp.

◆ ORDLChunkHandler

friend struct ORDLChunkHandler
friend

Definition at line 268 of file order_base.h.

◆ SlOrders

template<typename T >
friend class SlOrders
friend

Definition at line 270 of file order_base.h.

Field Documentation

◆ first_shared

Vehicle* OrderList::first_shared = nullptr
private

NOSAVE: pointer to the first vehicle in the shared order chain.

Definition at line 274 of file order_base.h.

Referenced by GetFirstSharedVehicle(), Initialize(), and RemoveVehicle().

◆ num_manual_orders

VehicleOrderID OrderList::num_manual_orders = 0
private

NOSAVE: How many manually added orders are there in the list.

Definition at line 272 of file order_base.h.

Referenced by DeleteOrderAt(), FreeChain(), GetNumManualOrders(), Initialize(), and InsertOrderAt().

◆ num_vehicles

uint OrderList::num_vehicles = 0
private

NOSAVE: Number of vehicles that share this order list.

Definition at line 273 of file order_base.h.

Referenced by AddVehicle(), GetNumVehicles(), Initialize(), and RemoveVehicle().

◆ old_order_index

uint32_t OrderList::old_order_index = 0
private

Definition at line 276 of file order_base.h.

◆ orders

std::vector<Order> OrderList::orders
private

◆ timetable_duration

TimerGameTick::Ticks OrderList::timetable_duration {}
private

◆ total_duration

TimerGameTick::Ticks OrderList::total_duration {}
private

NOSAVE: Total (timetabled or not) duration of the order list.

Definition at line 279 of file order_base.h.

Referenced by DeleteOrderAt(), GetTotalDuration(), Initialize(), InsertOrderAt(), and UpdateTotalDuration().


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