OpenTTD Source 20241224-master-gf74b0cf984
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.
 
- 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.
 
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.
 
- Public Member Functions inherited from BaseConsist
void CopyConsistPropertiesFrom (const BaseConsist *src)
 Copy properties of other BaseConsist.
 
void ResetDepotUnbunching ()
 Resets all the data used for depot unbunching.
 

Static Public Member Functions

static void Backup (const Vehicle *v, uint32_t user)
 Create an order backup for the given vehicle.
 
static void Restore (Vehicle *v, uint32_t user)
 Restore the data of this order to the given vehicle.
 
static void ResetOfUser (TileIndex tile, uint32_t user)
 Reset an OrderBackup given a tile and user.
 
static void ResetUser (uint32_t user)
 Reset an user's OrderBackup if needed.
 
static void Reset (TileIndex tile=INVALID_TILE, bool from_gui=true)
 Reset the OrderBackups from GUI/game logic.
 
static void ClearGroup (GroupID group)
 Clear the group of all backups having this group ID.
 
static void ClearVehicle (const Vehicle *v)
 Clear/update the (clone) vehicle from an order backup.
 
static void RemoveOrder (OrderType type, DestinationID destination, bool hangar)
 Removes an order from all vehicles.
 
- 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()
 
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.
 

Private Member Functions

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

Private Attributes

uint32_t 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

struct BKORChunkHandler
 Creating empty orders upon savegame loading.
 
SaveLoadTable GetOrderBackupDescription ()
 Saving and loading of order backups.
 

Additional Inherited Members

- Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_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.
 
- 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
std::string name
 Name of vehicle.
 
TimerGameTick::Ticks current_order_time
 How many ticks have passed since this order started.
 
TimerGameTick::Ticks lateness_counter
 How many ticks late (or early if negative) this vehicle is.
 
TimerGameTick::TickCounter timetable_start
 At what tick of TimerGameTick::counter the vehicle should start its timetable.
 
TimerGameTick::TickCounter depot_unbunching_last_departure
 When the vehicle last left its unbunching depot.
 
TimerGameTick::TickCounter depot_unbunching_next_departure
 When the vehicle will next try to leave its unbunching depot.
 
TimerGameTick::Ticks round_trip_time
 How many ticks for a single circumnavigation of the orders.
 
uint16_t 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_t vehicle_flags
 Used for gradual loading and other miscellaneous things (.
 

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 33 of file order_backup.h.

Constructor & Destructor Documentation

◆ OrderBackup() [1/2]

OrderBackup::OrderBackup ( )
inlineprivate

Creation for savegame restoration.

Definition at line 45 of file order_backup.h.

Referenced by Backup().

◆ OrderBackup() [2/2]

OrderBackup::OrderBackup ( const Vehicle v,
uint32_t  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 46 of file order_backup.cpp.

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

◆ ~OrderBackup()

OrderBackup::~OrderBackup ( )

Free everything that is allocated.

Definition at line 29 of file order_backup.cpp.

References Order::next.

Member Function Documentation

◆ Backup()

void OrderBackup::Backup ( const Vehicle v,
uint32_t  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 106 of file order_backup.cpp.

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

Referenced by CmdSellRailWagon(), and CmdSellVehicle().

◆ 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 218 of file order_backup.cpp.

References DEFAULT_GROUP, group, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate().

Referenced by CmdDeleteGroup().

◆ ClearVehicle()

void OrderBackup::ClearVehicle ( const Vehicle v)
static

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

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

Definition at line 232 of file order_backup.cpp.

References Vehicle::FirstShared(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate(), and Vehicle::NextShared().

Referenced by Vehicle::PreDestructor().

◆ DoRestore()

◆ RemoveOrder()

void OrderBackup::RemoveOrder ( OrderType  type,
DestinationID  destination,
bool  hangar 
)
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.
hangarOnly used for airports in the destination. When false, remove airport and hangar orders. When true, remove either airport or hangar order.

Definition at line 253 of file order_backup.cpp.

References IsHangarTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate(), and ODATFB_NEAREST_DEPOT.

Referenced by RemoveOrderFromAllVehicles().

◆ 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 187 of file order_backup.cpp.

References _network_own_client_id, _network_server, _networking, CLIENT_ID_SERVER, INVALID_TILE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate(), and user.

Referenced by DepotWindow::Close(), RemoveAirport(), and Depot::~Depot().

◆ ResetOfUser()

void OrderBackup::ResetOfUser ( TileIndex  tile,
uint32_t  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 140 of file order_backup.cpp.

References INVALID_TILE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate(), tile, and user.

Referenced by CmdClearOrderBackup().

◆ ResetUser()

void OrderBackup::ResetUser ( uint32_t  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 168 of file order_backup.cpp.

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

Referenced by ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().

◆ Restore()

void OrderBackup::Restore ( Vehicle v,
uint32_t  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 124 of file order_backup.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate(), Vehicle::tile, and user.

Referenced by CmdBuildVehicle().

Friends And Related Symbol Documentation

◆ BKORChunkHandler

friend struct BKORChunkHandler
friend

Creating empty orders upon savegame loading.

Definition at line 36 of file order_backup.h.

◆ GetOrderBackupDescription

SaveLoadTable GetOrderBackupDescription ( )
friend

Saving and loading of order backups.

Definition at line 246 of file order_sl.cpp.

Field Documentation

◆ clone

const Vehicle* OrderBackup::clone
private

Vehicle this vehicle was a clone of.

Definition at line 41 of file order_backup.h.

Referenced by DoRestore(), and OrderBackup().

◆ group

GroupID OrderBackup::group
private

The group the vehicle was part of.

Definition at line 39 of file order_backup.h.

Referenced by ClearGroup(), DoRestore(), and OrderBackup().

◆ orders

Order* OrderBackup::orders
private

The actual orders if the vehicle was not a clone.

Definition at line 42 of file order_backup.h.

Referenced by DoRestore(), and OrderBackup().

◆ tile

TileIndex OrderBackup::tile
private

Tile of the depot where the order was changed.

Definition at line 38 of file order_backup.h.

Referenced by OrderBackup(), and ResetOfUser().

◆ user

uint32_t OrderBackup::user
private

The user that requested the backup.

Definition at line 37 of file order_backup.h.

Referenced by Backup(), OrderBackup(), Reset(), ResetOfUser(), ResetUser(), and Restore().


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