OpenTTD Source  20241124-master-g9399a92a4f
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_t OrderBackupID;
22 struct OrderBackup;
23 
28 
33 struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool>, BaseConsist {
34 private:
36  friend struct BKORChunkHandler;
37  uint32_t user;
40 
41  const Vehicle *clone;
43 
46  OrderBackup(const Vehicle *v, uint32_t user);
47 
48  void DoRestore(Vehicle *v);
49 
50 public:
51  ~OrderBackup();
52 
53  static void Backup(const Vehicle *v, uint32_t user);
54  static void Restore(Vehicle *v, uint32_t user);
55 
56  static void ResetOfUser(TileIndex tile, uint32_t user);
57  static void ResetUser(uint32_t user);
58  static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
59 
60  static void ClearGroup(GroupID group);
61  static void ClearVehicle(const Vehicle *v);
62  static void RemoveOrder(OrderType type, DestinationID destination, bool hangar);
63 };
64 
65 #endif /* ORDER_BACKUP_H */
Properties for front vehicles/consists.
Types of a group.
uint16_t GroupID
Type for all group identifiers.
Definition: group_type.h:13
uint8_t OrderBackupID
Unique identifier for an order backup.
Definition: order_backup.h:21
Pool< OrderBackup, OrderBackupID, 1, 256 > OrderBackupPool
The pool type for order backups.
Definition: order_backup.h:22
OrderBackupPool _order_backup_pool
The pool with order backups.
OrderType
Order types.
Definition: order_type.h:35
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
Functions/types related to saving and loading games.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition: saveload.h:513
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition: base_consist.h:17
ChunkType type
Type of the chunk.
Definition: saveload.h:463
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:33
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
static void Restore(Vehicle *v, uint32_t user)
Restore the data of this order to the given vehicle.
void DoRestore(Vehicle *v)
Restore the data of this order to the given vehicle.
~OrderBackup()
Free everything that is allocated.
Order * orders
The actual orders if the vehicle was not a clone.
Definition: order_backup.h:42
static void Backup(const Vehicle *v, uint32_t user)
Create an order backup for the given vehicle.
static void ClearVehicle(const Vehicle *v)
Clear/update the (clone) vehicle from an order backup.
const Vehicle * clone
Vehicle this vehicle was a clone of.
Definition: order_backup.h:41
friend SaveLoadTable GetOrderBackupDescription()
Saving and loading of order backups.
Definition: order_sl.cpp:246
TileIndex tile
Tile of the depot where the order was changed.
Definition: order_backup.h:38
uint32_t user
The user that requested the backup.
Definition: order_backup.h:37
static void ClearGroup(GroupID group)
Clear the group of all backups having this group ID.
GroupID group
The group the vehicle was part of.
Definition: order_backup.h:39
OrderBackup()
Creation for savegame restoration.
Definition: order_backup.h:45
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 RemoveOrder(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Base class for all PoolItems.
Definition: pool_type.hpp:237
Base class for all pools.
Definition: pool_type.hpp:80
Vehicle data structure.
Definition: vehicle_base.h:244
Types related to tiles.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
Types related to vehicles.