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:

PoolItem< T, Tid, Tpool >

Public Member Functions

 OrderList ()
 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.
bool IsValid () const
 Checks, if this is a valid order list.
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.
VehicleOrderID GetNumOrders () const
 Get number of orders in the order list.
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.
int GetTimetableTotalDuration () const
 Gets the total duration of the vehicles timetable or -1 is the timetable is not complete.
int GetTimetableDurationIncomplete () const
 Gets the known duration of the vehicles timetable even if the timetable is not complete.
void UpdateOrderTimetable (int delta)
 Must be called if an order's timetable is changed to update internal book keeping.
void ResetOrderTimetable ()
 Must be called if the whole timetable is cleared 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 Attributes

Order * first
 First order of the order list.
VehicleOrderID num_orders
 NOSAVE: How many orders there are 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.
uint timetable_duration
 NOSAVE: Total duration of the order list.

Friends

void AfterLoadVehicles (bool part_of_load)
 For instantiating the shared vehicle chain.
struct SaveLoadGetOrderListDescription ()
 Saving and loading of order lists.

Detailed Description

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

Definition at line 267 of file order_base.h.


Constructor & Destructor Documentation

OrderList::OrderList (  )  [inline]

Default constructor producing an invalid order list.

Definition at line 281 of file order_base.h.

Referenced by CmdCloneOrder(), and CmdInsertOrder().

OrderList::OrderList ( Order *  chain,
Vehicle *  v 
)

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

Parameters:
chain is the pointer to the first order of the order chain
v is any vehicle of the shared order vehicle chain (does not need to be the first)

Definition at line 202 of file order_cmd.cpp.

References first, first_shared, num_orders, num_vehicles, and timetable_duration.

OrderList::~OrderList (  )  [inline]

Destructor.

Invalidates OrderList for re-usage by the pool.

Definition at line 292 of file order_base.h.

References INVALID_VEH_ORDER_ID, and num_orders.


Member Function Documentation

bool OrderList::IsValid (  )  const [inline]

Checks, if this is a valid order list.

Definition at line 295 of file order_base.h.

References INVALID_VEH_ORDER_ID, and num_orders.

Order* OrderList::GetFirstOrder (  )  const [inline]

Get the first order of the order chain.

Returns:
the first order of the chain.

Definition at line 301 of file order_base.h.

References first.

Order * OrderList::GetOrderAt ( int  index  )  const

Get a certain order of the order chain.

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

Definition at line 236 of file order_cmd.cpp.

References first.

Referenced by DeleteOrderAt(), GetLastOrder(), InsertOrderAt(), and MoveOrder().

Order* OrderList::GetLastOrder (  )  const [inline]

Get the last order of the order chain.

Returns:
the last order of the chain.

Definition at line 314 of file order_base.h.

References GetOrderAt(), and num_orders.

Referenced by InsertOrderAt().

VehicleOrderID OrderList::GetNumOrders (  )  const [inline]

Get number of orders in the order list.

Returns:
number of orders in the chain.

Definition at line 319 of file order_base.h.

References num_orders.

Referenced by CmdInsertOrder().

void OrderList::InsertOrderAt ( Order *  new_order,
int  index 
)

Insert a new order into the order chain.

Parameters:
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 248 of file order_cmd.cpp.

References first, GetLastOrder(), GetOrderAt(), num_orders, and timetable_duration.

void OrderList::DeleteOrderAt ( int  index  ) 

Remove an order from the order list and delete it.

Parameters:
index is the position of the order which is to be deleted.

Definition at line 272 of file order_cmd.cpp.

References first, GetOrderAt(), num_orders, and timetable_duration.

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

Move an order to another position within the order list.

Parameters:
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 291 of file order_cmd.cpp.

References first, GetOrderAt(), and num_orders.

bool OrderList::IsShared (  )  const [inline]

Is this a shared order list?

Returns:
whether this order list is shared among multiple vehicles

Definition at line 343 of file order_base.h.

References num_vehicles.

Vehicle* OrderList::GetFirstSharedVehicle (  )  const [inline]

Get the first vehicle of this vehicle chain.

Returns:
the first vehicle of the chain.

Definition at line 349 of file order_base.h.

References first_shared.

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 355 of file order_base.h.

References num_vehicles.

bool OrderList::IsVehicleInSharedOrdersList ( const Vehicle *  v  )  const

Checks whether a vehicle is part of the shared vehicle chain.

Parameters:
v is the vehicle to search in the shared vehicle chain.

Definition at line 324 of file order_cmd.cpp.

References first_shared.

int OrderList::GetPositionInSharedOrderList ( const Vehicle *  v  )  const

Gets the position of the given vehicle within the shared order vehicle list.

Parameters:
v is the vehicle of which to get the position
Returns:
position of v within the shared vehicle chain.

Definition at line 333 of file order_cmd.cpp.

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:
v vehicle to add to the list

Definition at line 376 of file order_base.h.

References num_vehicles.

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:
v vehicle to remove from the list

Definition at line 318 of file order_cmd.cpp.

References first_shared, and num_vehicles.

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

References first.

Referenced by GetTimetableTotalDuration().

int OrderList::GetTimetableTotalDuration (  )  const [inline]

Gets the total duration of the vehicles timetable or -1 is the timetable is not complete.

Returns:
total timetable duration or -1 for incomplete timetables

Definition at line 395 of file order_base.h.

References IsCompleteTimetable(), and timetable_duration.

int 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 401 of file order_base.h.

References timetable_duration.

void OrderList::UpdateOrderTimetable ( int  delta  )  [inline]

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

Parameters:
delta By how many ticks has the timetable duration changed

Definition at line 407 of file order_base.h.

References timetable_duration.

void OrderList::FreeChain ( bool  keep_orderlist = false  ) 

Free a complete order chain.

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

Definition at line 219 of file order_cmd.cpp.

References first, num_orders, and timetable_duration.

void OrderList::DebugCheckSanity (  )  const

Checks for internal consistency of order list.

Triggers assertion if something is wrong.

Definition at line 348 of file order_cmd.cpp.

References first, first_shared, PoolItem< T, Tid, Tpool >::index, num_orders, num_vehicles, and timetable_duration.


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

Generated on Wed Jul 15 20:36:31 2009 for OpenTTD by  doxygen 1.5.6