OpenTTD Source: src/order_backup.h Source File

OpenTTD Source 13.1

order_backup.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef ORDER_BACKUP_H
11 #define ORDER_BACKUP_H
12
13 #include "core/pool_type.hpp"
14 #include "group_type.h"
15 #include "tile_type.h"
16 #include "vehicle_type.h"
17 #include "base_consist.h"
18 #include "saveload/saveload.h"
19
21 typedef uint8 OrderBackupID;
22 struct OrderBackup;
23
25 typedef Pool<OrderBackup, OrderBackupID, 1, 256> OrderBackupPool;
27 extern OrderBackupPool _order_backup_pool;
28
30 static const uint32 MAKE_ORDER_BACKUP_FLAG = 1U << 31;
31
36 struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool>, BaseConsist {
37 private:
38 friend SaveLoadTable GetOrderBackupDescription();
39 friend struct BKORChunkHandler;
40 uint32 user;
41 TileIndex tile;
42 GroupID group;
43
44 const Vehicle *clone;
45 Order *orders;
46
48 OrderBackup() {}
49 OrderBackup(const Vehicle *v, uint32 user);
50
51 void DoRestore(Vehicle *v);
52
53 public:
54 ~OrderBackup();
55
56 static void Backup(const Vehicle *v, uint32 user);
57 static void Restore(Vehicle *v, uint32 user);
58
59 static void ResetOfUser(TileIndex tile, uint32 user);
60 static void ResetUser(uint32 user);
61 static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
62
63 static void ClearGroup(GroupID group);
64 static void ClearVehicle(const Vehicle *v);
65 static void RemoveOrder(OrderType type, DestinationID destination, bool hangar);
66 };
67
68 #endif /* ORDER_BACKUP_H */
_order_backup_pool
OrderBackupPool _order_backup_pool
The pool with order backups.
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
saveload.h
ChunkHandler::type
ChunkType type
Type of the chunk.
Definition: saveload.h:414
OrderBackup::ResetOfUser
static void ResetOfUser(TileIndex tile, uint32 user)
Reset an OrderBackup given a tile and user.
Definition: order_backup.cpp:136
base_consist.h
OrderBackup::clone
const Vehicle * clone
Vehicle this vehicle was a clone of.
Definition: order_backup.h:44
OrderBackup::ClearVehicle
static void ClearVehicle(const Vehicle *v)
Clear/update the (clone) vehicle from an order backup.
Definition: order_backup.cpp:228
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
OrderBackupPool
Pool< OrderBackup, OrderBackupID, 1, 256 > OrderBackupPool
The pool type for order backups.
Definition: order_backup.h:22
span
A trimmed down version of what std::span will be in C++20.
Definition: span_type.hpp:60
OrderBackupID
uint8 OrderBackupID
Unique identifier for an order backup.
Definition: order_backup.h:21
MAKE_ORDER_BACKUP_FLAG
static const uint32 MAKE_ORDER_BACKUP_FLAG
Flag to pass to the vehicle construction command when an order should be preserved.
Definition: order_backup.h:30
OrderBackup::Restore
static void Restore(Vehicle *v, uint32 user)
Restore the data of this order to the given vehicle.
Definition: order_backup.cpp:120
OrderBackup::Reset
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
Definition: order_backup.cpp:183
OrderBackup::user
uint32 user
The user that requested the backup.
Definition: order_backup.h:40
OrderBackup::DoRestore
void DoRestore(Vehicle *v)
Restore the data of this order to the given vehicle.
Definition: order_backup.cpp:74
OrderBackup::GetOrderBackupDescription
friend SaveLoadTable GetOrderBackupDescription()
Saving and loading of order backups.
Definition: order_sl.cpp:250
vehicle_type.h
Pool
Base class for all pools.
Definition: pool_type.hpp:81
OrderBackup::~OrderBackup
~OrderBackup()
Free everything that is allocated.
Definition: order_backup.cpp:28
GroupID
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:13
tile_type.h
OrderBackup::orders
Order * orders
The actual orders if the vehicle was not a clone.
Definition: order_backup.h:45
OrderBackup::tile
TileIndex tile
Tile of the depot where the order was changed.
Definition: order_backup.h:41
OrderBackup::ClearGroup
static void ClearGroup(GroupID group)
Clear the group of all backups having this group ID.
Definition: order_backup.cpp:214
OrderBackup::RemoveOrder
static void RemoveOrder(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition: order_backup.cpp:249
BKORChunkHandler
Definition: order_sl.cpp:273
OrderType
OrderType
Order types.
Definition: order_type.h:35
OrderBackup::Backup
static void Backup(const Vehicle *v, uint32 user)
Create an order backup for the given vehicle.
Definition: order_backup.cpp:102
OrderBackup::ResetUser
static void ResetUser(uint32 user)
Reset an user's OrderBackup if needed.
Definition: order_backup.cpp:164
OrderBackup::group
GroupID group
The group the vehicle was part of.
Definition: order_backup.h:42
OrderBackup::OrderBackup
OrderBackup()
Creation for savegame restoration.
Definition: order_backup.h:48
pool_type.hpp
OrderBackup
Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the sam...
Definition: order_backup.h:36
group_type.h
BaseConsist
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition: base_consist.h:18
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:234
Order
Definition: order_base.h:36