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/>.
8 /** @file order_backup.h Functions related to order backups. */
10 #ifndef ORDER_BACKUP_H
11 #define ORDER_BACKUP_H
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"
20 /** Unique identifier for an order backup. */
21 typedef uint8 OrderBackupID
;
24 /** The pool type for order backups. */
25 typedef Pool
<OrderBackup
, OrderBackupID
, 1, 256> OrderBackupPool
;
26 /** The pool with order backups. */
27 extern OrderBackupPool _order_backup_pool
;
29 /** Flag to pass to the vehicle construction command when an order should be preserved. */
30 static const uint32 MAKE_ORDER_BACKUP_FLAG
= 1U << 31;
33 * Data for backing up an order of a vehicle so it can be
34 * restored after a vehicle is rebuilt in the same depot.
36 struct OrderBackup
: OrderBackupPool::PoolItem
<&_order_backup_pool
>, BaseConsist
{
38 friend SaveLoadTable
GetOrderBackupDescription(); ///< Saving and loading of order backups.
39 friend struct BKORChunkHandler
; ///< Creating empty orders upon savegame loading.
40 uint32 user
; ///< The user that requested the backup.
41 TileIndex tile
; ///< Tile of the depot where the order was changed.
42 GroupID group
; ///< The group the vehicle was part of.
44 const Vehicle
*clone
; ///< Vehicle this vehicle was a clone of.
45 Order
*orders
; ///< The actual orders if the vehicle was not a clone.
47 /** Creation for savegame restoration. */
49 OrderBackup(const Vehicle
*v
, uint32 user
);
51 void DoRestore(Vehicle
*v
);
56 static void Backup(const Vehicle
*v
, uint32 user
);
57 static void Restore(Vehicle
*v
, uint32 user
);
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);
63 static void ClearGroup(GroupID group
);
64 static void ClearVehicle(const Vehicle
*v
);
65 static void RemoveOrder(OrderType type
, DestinationID destination
, bool hangar
);
68 #endif /* ORDER_BACKUP_H */