4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file order_backup.h Functions related to order backups. */
12 #ifndef ORDER_BACKUP_H
13 #define ORDER_BACKUP_H
15 #include "core/pool_type.hpp"
16 #include "group_type.h"
17 #include "tile_type.h"
18 #include "vehicle_type.h"
19 #include "base_consist.h"
21 /** Unique identifier for an order backup. */
22 typedef uint8 OrderBackupID
;
25 /** The pool type for order backups. */
26 typedef Pool
<OrderBackup
, OrderBackupID
, 1, 256> OrderBackupPool
;
27 /** The pool with order backups. */
28 extern OrderBackupPool _order_backup_pool
;
30 /** Flag to pass to the vehicle construction command when an order should be preserved. */
31 static const uint32 MAKE_ORDER_BACKUP_FLAG
= 1U << 31;
34 * Data for backing up an order of a vehicle so it can be
35 * restored after a vehicle is rebuilt in the same depot.
37 struct OrderBackup
: OrderBackupPool::PoolItem
<&_order_backup_pool
>, BaseConsist
{
39 friend const struct SaveLoad
*GetOrderBackupDescription(); ///< Saving and loading of order backups.
40 friend void Load_BKOR(); ///< Creating empty orders upon savegame loading.
41 uint32 user
; ///< The user that requested the backup.
42 TileIndex tile
; ///< Tile of the depot where the order was changed.
43 GroupID group
; ///< The group the vehicle was part of.
45 const Vehicle
*clone
; ///< Vehicle this vehicle was a clone of.
46 Order
*orders
; ///< The actual orders if the vehicle was not a clone.
48 /** Creation for savegame restoration. */
50 OrderBackup(const Vehicle
*v
, uint32 user
);
52 void DoRestore(Vehicle
*v
);
57 static void Backup(const Vehicle
*v
, uint32 user
);
58 static void Restore(Vehicle
*v
, uint32 user
);
60 static void ResetOfUser(TileIndex tile
, uint32 user
);
61 static void ResetUser(uint32 user
);
62 static void Reset(TileIndex tile
= INVALID_TILE
, bool from_gui
= true);
64 static void ClearGroup(GroupID group
);
65 static void ClearVehicle(const Vehicle
*v
);
66 static void RemoveOrder(OrderType type
, DestinationID destination
);
70 * Iterator over all order backups from a given ID.
71 * @param var The variable to iterate with.
72 * @param start The start of the iteration.
74 #define FOR_ALL_ORDER_BACKUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderBackup, order_backup_index, var, start)
77 * Iterator over all order backups.
78 * @param var The variable to iterate with.
80 #define FOR_ALL_ORDER_BACKUPS(var) FOR_ALL_ORDER_BACKUPS_FROM(var, 0)
82 #endif /* ORDER_BACKUP_H */