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 8 /** @file order_backup.h Functions related to order backups. */ 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 20 /** Unique identifier for an order backup. */ 21 typedef uint8 OrderBackupID; 22 struct OrderBackup; 23 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; 28 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; 31 32 /** 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. 35 */ 36 struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool>, BaseConsist { 37 private: 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. 43 44 const Vehicle *clone; ///< Vehicle this vehicle was a clone of. 45 Order *orders; ///< The actual orders if the vehicle was not a clone. 46 47 /** Creation for savegame restoration. */ OrderBackupOrderBackup48 OrderBackup() {} 49 OrderBackup(const Vehicle *v, uint32 user); 50 51 void DoRestore(Vehicle *v); 52 53 public: 54 ~OrderBackup(); 55 56 static void Backup(const Vehicle *v, uint32 user); 57 static void Restore(Vehicle *v, uint32 user); 58 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); 62 63 static void ClearGroup(GroupID group); 64 static void ClearVehicle(const Vehicle *v); 65 static void RemoveOrder(OrderType type, DestinationID destination, bool hangar); 66 }; 67 68 #endif /* ORDER_BACKUP_H */ 69