OpenTTD Source 20260711-master-g3fb3006dff
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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
22struct OrderBackup;
23enum class ClientID : uint32_t;
24
28extern OrderBackupPool _order_backup_pool;
30using OrderBackupPoolItem = OrderBackupPool::PoolItem<&_order_backup_pool>;
31
37private:
39 friend struct BKORChunkHandler;
40 template <typename T>
41 friend class SlOrders;
42
45 GroupID group = GroupID::Invalid();
46
47 const Vehicle *clone = nullptr;
48 std::vector<Order> orders;
49 uint32_t old_order_index = 0;
50
51 void DoRestore(Vehicle *v);
52
56
57public:
59
60 static void Backup(const Vehicle *v, ClientID user);
61 static void Restore(Vehicle *v, ClientID user);
62
64 static void ResetUser(ClientID user);
65 static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
66
67 static void ClearGroup(GroupID group);
68 static void ClearVehicle(const Vehicle *v);
69 static void RemoveOrder(OrderType type, DestinationID destination, bool hangar);
70};
71
72#endif /* ORDER_BACKUP_H */
Properties for front vehicles/consists.
Types of a group.
ClientID
'Unique' identifier to be given to clients
Pool< OrderBackup, OrderBackupID, 1 > OrderBackupPool
The pool type for order backups.
OrderBackupPool::PoolItem<&_order_backup_pool > OrderBackupPoolItem
An item in the OrderBackupPool.
PoolID< uint8_t, struct OrderBackupIDTag, 255, 0xFF > OrderBackupID
Unique identifier for an order backup.
OrderType
Order types.
Definition order_type.h:50
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:536
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the sam...
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
static void ResetUser(ClientID user)
Reset an user's OrderBackup if needed.
void DoRestore(Vehicle *v)
Restore the data of this order to the given vehicle.
static void Backup(const Vehicle *v, ClientID user)
Create an order backup for the given vehicle.
static void ClearVehicle(const Vehicle *v)
Clear/update the (clone) vehicle from an order backup.
OrderBackup(OrderBackupID index)
Create an order backup for savegame loading.
const Vehicle * clone
Vehicle this vehicle was a clone of.
friend SaveLoadTable GetOrderBackupDescription()
Saving and loading of order backups.
Definition order_sl.cpp:296
TileIndex tile
Tile of the depot where the order was changed.
static void ClearGroup(GroupID group)
Clear the group of all backups having this group ID.
GroupID group
The group the vehicle was part of.
ClientID user
The user that requested the backup.
friend struct BKORChunkHandler
Creating empty orders upon savegame loading.
static void Restore(Vehicle *v, ClientID user)
Restore the data of this order to the given vehicle.
friend OrderBackupPoolItem
Loading of order backups.
static void ResetOfUser(TileIndex tile, ClientID user)
Reset an OrderBackup given a tile and user.
std::vector< Order > orders
The actual orders if the vehicle was not a clone.
static void RemoveOrder(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:50
Base class for all pools.
Vehicle data structure.
Types related to tiles.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
Types related to vehicles.