OpenTTD Source: src/order_backup.h Source File

OpenTTD Source 15.0-RC2

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
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 using OrderBackupID = PoolID<uint8_t, struct OrderBackupIDTag, 255, 0xFF>;
22struct OrderBackup;
23
25 using OrderBackupPool = Pool<OrderBackup, OrderBackupID, 1>;
27extern OrderBackupPool _order_backup_pool;
28
33 struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool>, BaseConsist {
34private:
35 friend SaveLoadTable GetOrderBackupDescription();
36 friend struct BKORChunkHandler;
37 template <typename T>
38 friend class SlOrders;
39
40 uint32_t user = 0;
41 TileIndex tile = INVALID_TILE;
42 GroupID group = GroupID::Invalid();
43
44 const Vehicle *clone = nullptr;
45 std::vector<Order> orders;
46 uint32_t old_order_index = 0;
47
49 OrderBackup() = default;
50 OrderBackup(const Vehicle *v, uint32_t user);
51
52 void DoRestore(Vehicle *v);
53
54public:
55 ~OrderBackup();
56
57 static void Backup(const Vehicle *v, uint32_t user);
58 static void Restore(Vehicle *v, uint32_t user);
59
60 static void ResetOfUser(TileIndex tile, uint32_t user);
61 static void ResetUser(uint32_t user);
62 static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
63
64 static void ClearGroup(GroupID group);
65 static void ClearVehicle(const Vehicle *v);
66 static void RemoveOrder(OrderType type, DestinationID destination, bool hangar);
67};
68
69#endif /* ORDER_BACKUP_H */
base_consist.h
Properties for front vehicles/consists.
SlOrders
Definition order_sl.cpp:218
group_type.h
Types of a group.
_order_backup_pool
OrderBackupPool _order_backup_pool
The pool with order backups.
OrderType
OrderType
Order types.
Definition order_type.h:50
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
saveload.h
Functions/types related to saving and loading games.
SaveLoadTable
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition saveload.h:530
BKORChunkHandler
Definition order_sl.cpp:322
Backup
Class to backup a specific variable and restore it later.
Definition backup_type.hpp:21
BaseConsist
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition base_consist.h:33
DestinationID
Definition order_type.h:21
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:33
OrderBackup::Reset
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
Definition order_backup.cpp:165
OrderBackup::Restore
static void Restore(Vehicle *v, uint32_t user)
Restore the data of this order to the given vehicle.
Definition order_backup.cpp:102
OrderBackup::DoRestore
void DoRestore(Vehicle *v)
Restore the data of this order to the given vehicle.
Definition order_backup.cpp:54
OrderBackup::ClearVehicle
static void ClearVehicle(const Vehicle *v)
Clear/update the (clone) vehicle from an order backup.
Definition order_backup.cpp:210
OrderBackup::clone
const Vehicle * clone
Vehicle this vehicle was a clone of.
Definition order_backup.h:44
OrderBackup::GetOrderBackupDescription
friend SaveLoadTable GetOrderBackupDescription()
Saving and loading of order backups.
Definition order_sl.cpp:296
OrderBackup::tile
TileIndex tile
Tile of the depot where the order was changed.
Definition order_backup.h:41
OrderBackup::user
uint32_t user
The user that requested the backup.
Definition order_backup.h:40
OrderBackup::ClearGroup
static void ClearGroup(GroupID group)
Clear the group of all backups having this group ID.
Definition order_backup.cpp:196
OrderBackup::group
GroupID group
The group the vehicle was part of.
Definition order_backup.h:42
OrderBackup::OrderBackup
OrderBackup()=default
Creation for savegame restoration.
OrderBackup::ResetOfUser
static void ResetOfUser(TileIndex tile, uint32_t user)
Reset an OrderBackup given a tile and user.
Definition order_backup.cpp:118
OrderBackup::ResetUser
static void ResetUser(uint32_t user)
Reset an user's OrderBackup if needed.
Definition order_backup.cpp:146
OrderBackup::orders
std::vector< Order > orders
The actual orders if the vehicle was not a clone.
Definition order_backup.h:45
OrderBackup::RemoveOrder
static void RemoveOrder(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition order_backup.cpp:231
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
Pool::PoolItem
Base class for all PoolItems.
Definition pool_type.hpp:285
Pool
Base class for all pools.
Definition pool_type.hpp:133
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
tile_type.h
Types related to tiles.
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
vehicle_type.h
Types related to vehicles.