OpenTTD
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
OrderBackup Struct Reference

Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the same depot. More...

#include <order_backup.h>

Inheritance diagram for OrderBackup:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool > BaseConsist

Public Member Functions

 ~OrderBackup ()
 Free everything that is allocated. More...
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_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 size, void *ptr)
 Allocates space for new Titem at given memory address. More...
 
void operator delete (void *p)
 Marks Titem as free. More...
 
- Public Member Functions inherited from BaseConsist
void CopyConsistPropertiesFrom (const BaseConsist *src)
 Copy properties of other BaseConsist. More...
 

Static Public Member Functions

static void Backup (const Vehicle *v, uint32 user)
 Create an order backup for the given vehicle. More...
 
static void Restore (Vehicle *v, uint32 user)
 Restore the data of this order to the given vehicle. More...
 
static void ResetOfUser (TileIndex tile, uint32 user)
 Reset an OrderBackup given a tile and user. More...
 
static void ResetUser (uint32 user)
 Reset an user's OrderBackup if needed. More...
 
static void Reset (TileIndex tile=INVALID_TILE, bool from_gui=true)
 Reset the OrderBackups from GUI/game logic. More...
 
static void ClearGroup (GroupID group)
 Clear the group of all backups having this group ID. More...
 
static void ClearVehicle (const Vehicle *v)
 Clear/update the (clone) vehicle from an order backup. More...
 
static void RemoveOrder (OrderType type, DestinationID destination)
 Removes an order from all vehicles. More...
 
- Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_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-NULL) 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 (size_t index)
 Dummy function called after destructor of each member. More...
 

Private Member Functions

 OrderBackup ()
 Creation for savegame restoration. More...
 
 OrderBackup (const Vehicle *v, uint32 user)
 Create an order backup for the given vehicle. More...
 
void DoRestore (Vehicle *v)
 Restore the data of this order to the given vehicle. More...
 

Private Attributes

uint32 user
 The user that requested the backup.
 
TileIndex tile
 Tile of the depot where the order was changed.
 
GroupID group
 The group the vehicle was part of.
 
const Vehicleclone
 Vehicle this vehicle was a clone of.
 
Orderorders
 The actual orders if the vehicle was not a clone.
 

Friends

const struct SaveLoadGetOrderBackupDescription ()
 Saving and loading of order backups.
 
void Load_BKOR ()
 Creating empty orders upon savegame loading.
 

Additional Inherited Members

- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >
Tindex index
 Index of this pool item.
 
- Data Fields inherited from BaseConsist
char * name
 Name of vehicle.
 
uint32 current_order_time
 How many ticks have passed since this order started.
 
int32 lateness_counter
 How many ticks late (or early if negative) this vehicle is.
 
Date timetable_start
 When the vehicle is supposed to start the timetable.
 
uint16 service_interval
 The interval for (automatic) servicing; either in days or %.
 
VehicleOrderID cur_real_order_index
 The index to the current real (non-implicit) order.
 
VehicleOrderID cur_implicit_order_index
 The index to the current implicit order.
 
uint16 vehicle_flags
 Used for gradual loading and other miscellaneous things (. More...
 

Detailed Description

Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the same depot.

Definition at line 37 of file order_backup.h.

Constructor & Destructor Documentation

◆ OrderBackup() [1/2]

OrderBackup::OrderBackup ( )
inlineprivate

Creation for savegame restoration.

Definition at line 49 of file order_backup.h.

References Backup(), ClearGroup(), ClearVehicle(), DoRestore(), INVALID_TILE, RemoveOrder(), Reset(), ResetOfUser(), ResetUser(), Restore(), and ~OrderBackup().

Referenced by Backup().

◆ OrderBackup() [2/2]

OrderBackup::OrderBackup ( const Vehicle v,
uint32  user 
)
private

Create an order backup for the given vehicle.

Parameters
vThe vehicle to make a backup of.
userThe user that is requesting the backup.

Definition at line 45 of file order_backup.cpp.

References clone, BaseConsist::CopyConsistPropertiesFrom(), Vehicle::FirstShared(), group, Vehicle::group_id, Vehicle::IsOrderListShared(), Vehicle::NextShared(), orders, tile, Vehicle::tile, and user.

◆ ~OrderBackup()

OrderBackup::~OrderBackup ( )

Free everything that is allocated.

Definition at line 28 of file order_backup.cpp.

References Order::next.

Referenced by OrderBackup().

Member Function Documentation

◆ Backup()

void OrderBackup::Backup ( const Vehicle v,
uint32  user 
)
static

Create an order backup for the given vehicle.

Parameters
vThe vehicle to make a backup of.
userThe user that is requesting the backup.
Note
Will automatically remove any previous backups of this user.

Definition at line 103 of file order_backup.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::CanAllocateItem(), FOR_ALL_ORDER_BACKUPS, OrderBackup(), and user.

Referenced by CmdSellRailWagon(), CmdSellVehicle(), and OrderBackup().

◆ ClearGroup()

void OrderBackup::ClearGroup ( GroupID  group)
static

Clear the group of all backups having this group ID.

Parameters
groupThe group to clear.

Definition at line 226 of file order_backup.cpp.

References DEFAULT_GROUP, FOR_ALL_ORDER_BACKUPS, and group.

Referenced by OrderBackup().

◆ ClearVehicle()

void OrderBackup::ClearVehicle ( const Vehicle v)
static

Clear/update the (clone) vehicle from an order backup.

Parameters
vThe vehicle to clear.
Precondition
v != NULL
Note
If it is not possible to set another vehicle as clone "example", then this backed up order will be removed.

Definition at line 241 of file order_backup.cpp.

Referenced by OrderBackup().

◆ DoRestore()

void OrderBackup::DoRestore ( Vehicle v)
private

Restore the data of this order to the given vehicle.

Parameters
vThe vehicle to restore to.

Definition at line 75 of file order_backup.cpp.

References clone, DoCommand(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index.

Referenced by OrderBackup(), and Restore().

◆ RemoveOrder()

void OrderBackup::RemoveOrder ( OrderType  type,
DestinationID  destination 
)
static

Removes an order from all vehicles.

Triggers when, say, a station is removed.

Parameters
typeThe type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
destinationThe destination. Can be a StationID, DepotID or WaypointID.

Definition at line 260 of file order_backup.cpp.

References FOR_ALL_ORDER_BACKUPS, Order::next, and orders.

Referenced by OrderBackup().

◆ Reset()

void OrderBackup::Reset ( TileIndex  t = INVALID_TILE,
bool  from_gui = true 
)
static

Reset the OrderBackups from GUI/game logic.

Parameters
tThe tile of the order backup.
from_guiWhether the call came from the GUI, i.e. whether it must be synced over the network.

Definition at line 190 of file order_backup.cpp.

References _network_own_client_id, _network_server, _networking, CLIENT_ID_SERVER, CMD_CLEAR_ORDER_BACKUP, DoCommandPInternal(), FOR_ALL_ORDER_BACKUPS, INVALID_TILE, tile, and user.

Referenced by OrderBackup(), and Depot::~Depot().

◆ ResetOfUser()

void OrderBackup::ResetOfUser ( TileIndex  tile,
uint32  user 
)
static

Reset an OrderBackup given a tile and user.

Parameters
tileThe tile associated with the OrderBackup.
userThe user associated with the OrderBackup.
Note
Must not be used from the GUI!

Definition at line 139 of file order_backup.cpp.

References FOR_ALL_ORDER_BACKUPS, INVALID_TILE, tile, and user.

Referenced by CmdClearOrderBackup(), and OrderBackup().

◆ ResetUser()

void OrderBackup::ResetUser ( uint32  user)
static

Reset an user's OrderBackup if needed.

Parameters
userThe user associated with the OrderBackup.
Precondition
_network_server.
Note
Must not be used from a command.

Definition at line 170 of file order_backup.cpp.

Referenced by OrderBackup(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().

◆ Restore()

void OrderBackup::Restore ( Vehicle v,
uint32  user 
)
static

Restore the data of this order to the given vehicle.

Parameters
vThe vehicle to restore to.
userThe user that built the vehicle, thus wants to restore.
Note
After restoration the backup will automatically be removed.

Definition at line 122 of file order_backup.cpp.

References DoRestore(), FOR_ALL_ORDER_BACKUPS, tile, Vehicle::tile, and user.

Referenced by OrderBackup().


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