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. | |
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. | |
StationID | GetNextStoppingStation (const Vehicle *v) const |
Recursively determine the next deterministic station to stop at. | |
const Order * | GetNextStoppingOrder (const Vehicle *v, const Order *next, uint hops, bool is_loading=false) const |
Get the next order which will make the given vehicle stop at a station or refit at a depot if its state doesn't change. | |
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. | |
bool | IsVehicleInSharedOrdersList (const Vehicle *v) const |
Checks whether a vehicle is part of the shared vehicle chain. | |
int | GetPositionInSharedOrderList (const Vehicle *v) const |
Gets the position of the given vehicle within the shared order vehicle 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. | |
Ticks | GetTimetableTotalDuration () const |
Gets the total duration of the vehicles timetable or INVALID_TICKS is the timetable is not complete. | |
Ticks | GetTimetableDurationIncomplete () const |
Gets the known duration of the vehicles timetable even if the timetable is not complete. | |
void | UpdateOrderTimetable (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 |
Checks for internal consistency of order list. | |
Private Member Functions | |
const Order * | GetBestLoadableNext (const Vehicle *v, const Order *o1, const Order *o2) const |
Choose between the two possible next orders so that the given consist can load most cargo. | |
Private Attributes | |
Order * | first |
First order of the order list. | |
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. | |
Ticks | timetable_duration |
NOSAVE: Total duration of the order list. | |
Friends | |
void | AfterLoadVehicles (bool part_of_load) |
For instantiating the shared vehicle chain. | |
struct SaveLoad * | GetOrderListDescription () |
Saving and loading of order lists. |
Shared order list linking together the linked list of orders and the list of vehicles sharing this order list.
Definition at line 207 of file order_base.h.
OrderList::OrderList | ( | VehicleOrderID | num_orders = INVALID_VEH_ORDER_ID |
) | [inline] |
Default constructor producing an invalid order list.
Definition at line 224 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 233 of file order_base.h.
References Initialize().
OrderList::~OrderList | ( | ) | [inline] |
Destructor.
Invalidates OrderList for re-usage by the pool.
Definition at line 236 of file order_base.h.
void OrderList::AddVehicle | ( | Vehicle * | v | ) | [inline] |
Adds the given vehicle to this shared order list.
v | vehicle to add to the list |
Definition at line 308 of file order_base.h.
References num_vehicles.
Referenced by Vehicle::AddToShared().
void OrderList::DebugCheckSanity | ( | ) | const |
Checks for internal consistency of order list.
Triggers assertion if something is wrong.
Definition at line 632 of file order_cmd.cpp.
References DEBUG, first, first_shared, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::index, Order::next, Vehicle::NextShared(), num_manual_orders, num_orders, num_vehicles, and timetable_duration.
Referenced by CheckOrders().
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 527 of file order_cmd.cpp.
References first, GetOrderAt(), Order::IsType(), Order::next, num_manual_orders, num_orders, timetable_duration, Order::travel_time, and Order::wait_time.
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 323 of file order_cmd.cpp.
References first, Order::next, num_manual_orders, num_orders, and timetable_duration.
Referenced by AfterLoadGame(), and DeleteVehicleOrders().
const Order * OrderList::GetBestLoadableNext | ( | const Vehicle * | v, | |
const Order * | o2, | |||
const Order * | o1 | |||
) | const [private] |
Choose between the two possible next orders so that the given consist can load most cargo.
v | Head of the consist. | |
o1 | First order to choose from. | |
o2 | Second order to choose from. |
Definition at line 367 of file order_cmd.cpp.
References SmallVector< SmallPair< T, U >, S >::Begin(), GoodsEntry::cargo, SmallVector< SmallPair< T, U >, S >::End(), MultiMap< Tkey, Tvalue, Tcompare >::equal_range(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::Get(), Vehicle::GetConsistFreeCapacities(), Order::GetDestination(), Station::goods, Vehicle::last_station_visited, min(), and CargoList< Tinst, Tcont >::Packets().
Referenced by GetNextStoppingOrder().
Order* OrderList::GetFirstOrder | ( | ) | const [inline] |
Get the first order of the order chain.
Definition at line 244 of file order_base.h.
References first.
Referenced by AfterLoadGame(), CheckOrders(), CmdCloneOrder(), FillTimetableArrivalDepartureTable(), GetNext(), GetNextStoppingStation(), GetOrderDistance(), MoveBuoysToWaypoints(), and MoveWaypointsToBaseStations().
Vehicle* OrderList::GetFirstSharedVehicle | ( | ) | const [inline] |
Get the first vehicle of this vehicle chain.
Definition at line 291 of file order_base.h.
References first_shared.
Referenced by AfterLoadVehicles(), MoveBuoysToWaypoints(), and MoveWaypointsToBaseStations().
Order* OrderList::GetLastOrder | ( | ) | const [inline] |
Get the last order of the order chain.
Definition at line 252 of file order_base.h.
References GetOrderAt(), and num_orders.
Referenced by 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 260 of file order_base.h.
References GetFirstOrder(), and Order::next.
Referenced by GetNextStoppingOrder(), and GetNextStoppingStation().
const Order * OrderList::GetNextStoppingOrder | ( | const Vehicle * | v, | |
const Order * | next, | |||
uint | hops, | |||
bool | is_loading = false | |||
) | const |
Get the next order which will make the given vehicle stop at a station or refit at a depot if its state doesn't change.
v | The vehicle in question. | |
next | The order to start looking at. | |
hops | The number of orders we have already looked at. | |
is_loading | If the vehicle is loading. This triggers a different behaviour on conditional orders based on load percentage. |
Definition at line 408 of file order_cmd.cpp.
References GetBestLoadableNext(), Order::GetConditionSkipToOrder(), Order::GetConditionVariable(), Order::GetDepotActionType(), GetNext(), GetNumOrders(), GetOrderAt(), INVALID_VEH_ORDER_ID, Order::IsRefit(), Order::IsType(), and ProcessConditionalOrder().
Referenced by GetNextStoppingStation().
StationID OrderList::GetNextStoppingStation | ( | const Vehicle * | v | ) | const |
Recursively determine the next deterministic station to stop at.
v | The vehicle we're looking at. |
Definition at line 461 of file order_cmd.cpp.
References BaseConsist::cur_implicit_order_index, Order::GetDestination(), GetFirstOrder(), GetNext(), GetNextStoppingOrder(), GetOrderAt(), Order::GetUnloadType(), Order::IsType(), Vehicle::last_station_visited, and OUFB_TRANSFER.
VehicleOrderID OrderList::GetNumManualOrders | ( | ) | const [inline] |
Get number of manually added orders in the order list.
Definition at line 272 of file order_base.h.
References num_manual_orders.
VehicleOrderID OrderList::GetNumOrders | ( | ) | const [inline] |
Get number of orders in the order list.
Definition at line 266 of file order_base.h.
References num_orders.
Referenced by CmdSellVehicle(), and GetNextStoppingOrder().
uint OrderList::GetNumVehicles | ( | ) | const [inline] |
Return the number of vehicles that share this orders list.
Definition at line 297 of file order_base.h.
References num_vehicles.
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 346 of file order_cmd.cpp.
References first, and Order::next.
Referenced by DeleteOrderAt(), GetLastOrder(), GetNextStoppingOrder(), GetNextStoppingStation(), InsertOrderAt(), and MoveOrder().
int OrderList::GetPositionInSharedOrderList | ( | const Vehicle * | v | ) | const |
Gets the position of the given vehicle within the shared order vehicle list.
v | is the vehicle of which to get the position |
Definition at line 608 of file order_cmd.cpp.
References Vehicle::PreviousShared().
Ticks OrderList::GetTimetableDurationIncomplete | ( | ) | const [inline] |
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Definition at line 324 of file order_base.h.
References timetable_duration.
Referenced by TimetableWindow::DrawWidget().
Ticks OrderList::GetTimetableTotalDuration | ( | ) | const [inline] |
Gets the total duration of the vehicles timetable or INVALID_TICKS is the timetable is not complete.
Definition at line 318 of file order_base.h.
References INVALID_TICKS, IsCompleteTimetable(), and timetable_duration.
Referenced by UpdateVehicleTimetable().
Recomputes everything.
chain | first order in the chain | |
v | one of vehicle that is using this orderlist |
Definition at line 294 of file order_cmd.cpp.
References first, first_shared, Order::next, Vehicle::NextShared(), num_manual_orders, num_orders, num_vehicles, Vehicle::PreviousShared(), and timetable_duration.
Referenced by AfterLoadVehicles(), and 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 490 of file order_cmd.cpp.
References first, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::Get(), Order::GetDestination(), GetLastOrder(), GetOrderAt(), InvalidateWindowClassesData(), Order::IsType(), Order::next, num_manual_orders, num_orders, BaseStation::owner, OWNER_NONE, timetable_duration, Order::travel_time, Order::wait_time, 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 619 of file order_cmd.cpp.
References first, and Order::next.
Referenced by TimetableWindow::DrawWidget(), and GetTimetableTotalDuration().
bool OrderList::IsShared | ( | ) | const [inline] |
Is this a shared order list?
Definition at line 285 of file order_base.h.
References num_vehicles.
Referenced by CmdCloneOrder(), and CmdSellVehicle().
bool OrderList::IsVehicleInSharedOrdersList | ( | const Vehicle * | v | ) | const |
Checks whether a vehicle is part of the shared vehicle chain.
v | is the vehicle to search in the shared vehicle chain. |
Definition at line 594 of file order_cmd.cpp.
References first_shared, and Vehicle::NextShared().
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 552 of file order_cmd.cpp.
References first, GetOrderAt(), Order::next, and num_orders.
Referenced by CmdMoveOrder().
void OrderList::RemoveVehicle | ( | Vehicle * | v | ) |
Removes the vehicle from the shared order list.
v | vehicle to remove from the list |
Definition at line 584 of file order_cmd.cpp.
References first_shared, Vehicle::NextShared(), and num_vehicles.
void OrderList::UpdateOrderTimetable | ( | Ticks | delta | ) | [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 330 of file order_base.h.
References timetable_duration.
Referenced by ChangeTimetable().