OpenTTD Source 20241224-master-gee860a5c8e
|
Shared order list linking together the linked list of orders and the list of vehicles sharing this order list. More...
#include <order_base.h>
Public Member Functions | |
OrderList (VehicleOrderID num_orders=INVALID_VEH_ORDER_ID) | |
Default constructor producing an invalid order list. | |
OrderList (Order *chain, Vehicle *v) | |
Create an order list with the given order chain for the given vehicle. | |
~OrderList () | |
Destructor. | |
void | Initialize (Order *chain, Vehicle *v) |
Recomputes everything. | |
void | RecalculateTimetableDuration () |
Recomputes Timetable duration. | |
Order * | GetFirstOrder () const |
Get the first order of the order chain. | |
Order * | GetOrderAt (int index) const |
Get a certain order of the order chain. | |
Order * | GetLastOrder () const |
Get the last order of the order chain. | |
const Order * | GetNext (const Order *curr) 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, const Order *first=nullptr, uint hops=0) const |
Recursively determine the next deterministic station to stop at. | |
const Order * | GetNextDecisionNode (const Order *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 *new_order, int index) |
Insert a new order into the order chain. | |
void | DeleteOrderAt (int index) |
Remove an order from the order list and delete it. | |
void | MoveOrder (int from, int to) |
Move an order to another position within the order list. | |
bool | IsShared () const |
Is this a shared order list? | |
Vehicle * | GetFirstSharedVehicle () 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, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool > | |
void * | operator new (size_t size) |
Allocates space for new Titem. | |
void * | operator new (size_t size, size_t 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) |
Marks Titem as free. | |
Private Attributes | |
VehicleOrderID | num_orders |
NOSAVE: How many orders there are in the list. | |
VehicleOrderID | num_manual_orders |
NOSAVE: How many manually added orders are there in the list. | |
uint | num_vehicles |
NOSAVE: Number of vehicles that share this order list. | |
Vehicle * | first_shared |
NOSAVE: pointer to the first vehicle in the shared order chain. | |
Order * | first |
First order of the order list. | |
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 | |
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, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_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<&_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 (size_t index) |
Tests whether given index can be used to get valid (non-nullptr) Titem. | |
static Titem * | Get (size_t index) |
Returns Titem with given index. | |
static Titem * | GetIfValid (size_t 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, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool > | |
Tindex | index |
Index of this pool item. | |
Shared order list linking together the linked list of orders and the list of vehicles sharing this order list.
Definition at line 259 of file order_base.h.
|
inline |
Default constructor producing an invalid order list.
Definition at line 275 of file order_base.h.
Create an order list with the given order chain for the given vehicle.
chain | pointer to the first order of the order chain |
v | any vehicle using this orderlist |
Definition at line 284 of file order_base.h.
References Initialize().
|
inline |
Destructor.
Invalidates OrderList for re-usage by the pool.
Definition at line 287 of file order_base.h.
|
inline |
Adds the given vehicle to this shared order list.
v | vehicle to add to the list |
Definition at line 358 of file order_base.h.
References num_vehicles.
Referenced by Vehicle::AddToShared().
void OrderList::DeleteOrderAt | ( | int | index | ) |
Remove an order from the order list and delete it.
index | is the position of the order which is to be deleted. |
Definition at line 494 of file order_cmd.cpp.
References first, GetOrderAt(), Order::GetTimetabledTravel(), Order::GetTimetabledWait(), Order::GetTravelTime(), Order::GetWaitTime(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::index, Order::IsType(), Order::next, num_manual_orders, num_orders, timetable_duration, and total_duration.
Referenced by DeleteOrder().
void OrderList::FreeChain | ( | bool | keep_orderlist = false | ) |
Free a complete order chain.
keep_orderlist | If this is true only delete the orders, otherwise also delete the OrderList. |
Definition at line 318 of file order_cmd.cpp.
References first, Order::next, num_manual_orders, num_orders, and timetable_duration.
Referenced by DeleteVehicleOrders().
|
inline |
Get the first order of the order chain.
Definition at line 297 of file order_base.h.
References first.
Referenced by CheckOrders(), CmdCloneOrder(), FillTimetableArrivalDepartureTable(), Vehicle::GetFirstOrder(), GetNext(), GetNextStoppingStation(), and GetOrderDistance().
|
inline |
Get the first vehicle of this vehicle chain.
Definition at line 344 of file order_base.h.
References first_shared.
Referenced by CmdSetTimetableStart(), and Vehicle::FirstShared().
|
inline |
Get the last order of the order chain.
Definition at line 305 of file order_base.h.
References GetOrderAt().
Referenced by Vehicle::GetLastOrder(), and InsertOrderAt().
Get the order after the given one or the first one, if the given one is the last one.
curr | Order to find the next one for. |
Definition at line 313 of file order_base.h.
References GetFirstOrder(), and Order::next.
Referenced by GetNextDecisionNode(), GetNextStoppingStation(), and LinkRefresher::PredictNextOrder().
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.
next | The order to start looking at. |
hops | The number of orders we have already looked at. |
Definition at line 364 of file order_cmd.cpp.
References Order::GetConditionSkipToOrder(), Order::GetConditionVariable(), Order::GetDepotActionType(), GetNext(), GetNextDecisionNode(), GetNumOrders(), GetOrderAt(), Order::IsRefit(), Order::IsType(), OCV_UNCONDITIONALLY, and ODATFB_HALT.
Referenced by GetNextDecisionNode(), GetNextStoppingStation(), LinkRefresher::PredictNextOrder(), and LinkRefresher::Run().
StationIDStack OrderList::GetNextStoppingStation | ( | const Vehicle * | v, |
const Order * | first = nullptr , |
||
uint | hops = 0 |
||
) | const |
Recursively determine the next deterministic station to stop at.
v | The vehicle we're looking at. |
first | Order to start searching at or nullptr to start at cur_implicit_order_index + 1. |
hops | Number of orders we have already looked at. |
Definition at line 399 of file order_cmd.cpp.
References BaseConsist::cur_implicit_order_index, first, Order::GetConditionSkipToOrder(), Order::GetDestination(), GetFirstOrder(), GetNext(), GetNextDecisionNode(), GetNextStoppingStation(), GetOrderAt(), Order::GetUnloadType(), SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty(), Order::IsType(), Vehicle::last_station_visited, 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().
|
inline |
Get number of manually added orders in the order list.
Definition at line 325 of file order_base.h.
References num_manual_orders.
Referenced by Vehicle::GetNumManualOrders().
|
inline |
Get number of orders in the order list.
Definition at line 319 of file order_base.h.
References num_orders.
Referenced by Vehicle::BeginLoading(), CmdSellVehicle(), GetIncompatibleRefitOrderIdForAutoreplace(), GetNextDecisionNode(), Vehicle::GetNumOrders(), and LinkRefresher::PredictNextOrder().
|
inline |
Return the number of vehicles that share this orders list.
Definition at line 350 of file order_base.h.
References num_vehicles.
Referenced by Vehicle::RemoveFromShared().
Order * OrderList::GetOrderAt | ( | int | index | ) | const |
Get a certain order of the order chain.
index | zero-based index of the order within the chain. |
Definition at line 341 of file order_cmd.cpp.
References first, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::index, and Order::next.
Referenced by DeleteOrderAt(), GetIncompatibleRefitOrderIdForAutoreplace(), GetLastOrder(), GetNextDecisionNode(), GetNextStoppingStation(), Vehicle::GetOrder(), InsertOrderAt(), MoveOrder(), and LinkRefresher::PredictNextOrder().
|
inline |
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Definition at line 374 of file order_base.h.
References timetable_duration.
Referenced by TimetableWindow::DrawArrivalDeparturePanel(), and TimetableWindow::DrawSummaryPanel().
|
inline |
Gets the total duration of the vehicles timetable or Ticks::INVALID_TICKS is the timetable is not complete.
Definition at line 368 of file order_base.h.
References Ticks::INVALID_TICKS, IsCompleteTimetable(), and timetable_duration.
Referenced by CmdSetTimetableStart(), and UpdateVehicleTimetable().
|
inline |
Gets the known duration of the vehicles orders, timetabled or not.
Definition at line 380 of file order_base.h.
References total_duration.
Referenced by LinkRefresher::RefreshStats().
Recomputes everything.
chain | first order in the chain |
v | one of vehicle that is using this orderlist |
Definition at line 275 of file order_cmd.cpp.
References first, first_shared, Order::next, Vehicle::NextShared(), num_manual_orders, num_orders, num_vehicles, Vehicle::PreviousShared(), RecalculateTimetableDuration(), timetable_duration, and total_duration.
Referenced by OrderList().
void OrderList::InsertOrderAt | ( | Order * | new_order, |
int | index | ||
) |
Insert a new order into the order chain.
new_order | is the order to insert into the chain. |
index | is the position where the order is supposed to be inserted. |
Definition at line 456 of file order_cmd.cpp.
References first, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_station_pool >::Get(), Order::GetDestination(), GetLastOrder(), GetOrderAt(), Order::GetTimetabledTravel(), Order::GetTimetabledWait(), Order::GetTravelTime(), Order::GetWaitTime(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::index, InvalidateWindowClassesData(), Order::IsType(), Order::next, num_manual_orders, num_orders, BaseStation::owner, OWNER_NONE, timetable_duration, total_duration, and WC_STATION_LIST.
Referenced by InsertOrder().
bool OrderList::IsCompleteTimetable | ( | ) | const |
Checks whether all orders of the list have a filled timetable.
Definition at line 562 of file order_cmd.cpp.
References first, and Order::next.
Referenced by CmdSetTimetableStart(), TimetableWindow::DrawSummaryPanel(), and GetTimetableTotalDuration().
|
inline |
Is this a shared order list?
Definition at line 338 of file order_base.h.
Referenced by CmdCloneOrder(), CmdSellVehicle(), and Vehicle::IsOrderListShared().
void OrderList::MoveOrder | ( | int | from, |
int | to | ||
) |
Move an order to another position within the order list.
from | is the zero-based position of the order to move. |
to | is the zero-based position where the order is moved to. |
Definition at line 520 of file order_cmd.cpp.
References first, GetOrderAt(), Order::next, and num_orders.
Referenced by CmdMoveOrder().
void OrderList::RecalculateTimetableDuration | ( | ) |
Recomputes Timetable duration.
Split out into a separate function so it can be used by afterload.
Definition at line 305 of file order_cmd.cpp.
References first, Order::next, and timetable_duration.
Referenced by Initialize().
void OrderList::RemoveVehicle | ( | Vehicle * | v | ) |
Removes the vehicle from the shared order list.
v | vehicle to remove from the list |
Definition at line 552 of file order_cmd.cpp.
References first_shared, Vehicle::NextShared(), and num_vehicles.
Referenced by Vehicle::RemoveFromShared().
|
inline |
Must be called if an order's timetable is changed to update internal book keeping.
delta | By how many ticks has the timetable duration changed |
Definition at line 386 of file order_base.h.
Referenced by ChangeTimetable().
|
inline |
Must be called if an order's timetable is changed to update internal book keeping.
delta | By how many ticks has the total duration changed |
Definition at line 392 of file order_base.h.
Referenced by ChangeTimetable().
|
friend |
For instantiating the shared vehicle chain.
Definition at line 256 of file vehicle_sl.cpp.
|
friend |
Saving and loading of order lists.
Definition at line 201 of file order_sl.cpp.
|
private |
First order of the order list.
Definition at line 268 of file order_base.h.
Referenced by DeleteOrderAt(), FreeChain(), GetFirstOrder(), GetNextStoppingStation(), GetOrderAt(), Initialize(), InsertOrderAt(), IsCompleteTimetable(), MoveOrder(), and RecalculateTimetableDuration().
|
private |
NOSAVE: pointer to the first vehicle in the shared order chain.
Definition at line 267 of file order_base.h.
Referenced by GetFirstSharedVehicle(), Initialize(), and RemoveVehicle().
|
private |
NOSAVE: How many manually added orders are there in the list.
Definition at line 265 of file order_base.h.
Referenced by DeleteOrderAt(), FreeChain(), GetNumManualOrders(), Initialize(), and InsertOrderAt().
|
private |
NOSAVE: How many orders there are in the list.
Definition at line 264 of file order_base.h.
Referenced by DeleteOrderAt(), FreeChain(), GetNumOrders(), Initialize(), InsertOrderAt(), and MoveOrder().
|
private |
NOSAVE: Number of vehicles that share this order list.
Definition at line 266 of file order_base.h.
Referenced by AddVehicle(), GetNumVehicles(), Initialize(), and RemoveVehicle().
|
private |
NOSAVE: Total timetabled duration of the order list.
Definition at line 270 of file order_base.h.
Referenced by DeleteOrderAt(), FreeChain(), GetTimetableDurationIncomplete(), GetTimetableTotalDuration(), Initialize(), InsertOrderAt(), and RecalculateTimetableDuration().
|
private |
NOSAVE: Total (timetabled or not) duration of the order list.
Definition at line 271 of file order_base.h.
Referenced by DeleteOrderAt(), GetTotalDuration(), Initialize(), and InsertOrderAt().