OpenTTD

order_backup.h
Go to the documentation of this file.
1 /* $Id: order_backup.h 24444 2012-07-29 16:45:34Z frosch $ */
2
3 /*
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/>.
8 */
9
12 #ifndef ORDER_BACKUP_H
13 #define ORDER_BACKUP_H
14
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"
20
22 typedef uint8 OrderBackupID;
23 struct OrderBackup;
24
26 typedef Pool<OrderBackup, OrderBackupID, 1, 256> OrderBackupPool;
28 extern OrderBackupPool _order_backup_pool;
29
31 static const uint32 MAKE_ORDER_BACKUP_FLAG = 1U << 31;
32
37 struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool>, BaseConsist {
38 private:
39 friend const struct SaveLoad *GetOrderBackupDescription();
40 friend void Load_BKOR();
41 uint32 user;
42 TileIndex tile;
43 GroupID group;
44
45 const Vehicle *clone;
46 Order *orders;
47
49 OrderBackup() {}
50 OrderBackup(const Vehicle *v, uint32 user);
51
52 void DoRestore(Vehicle *v);
53
54 public:
55 ~OrderBackup();
56
57 static void Backup(const Vehicle *v, uint32 user);
58 static void Restore(Vehicle *v, uint32 user);
59
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);
63
64 static void ClearGroup(GroupID group);
65 static void ClearVehicle(const Vehicle *v);
66 static void RemoveOrder(OrderType type, DestinationID destination);
67 };
68
74 #define FOR_ALL_ORDER_BACKUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderBackup, order_backup_index, var, start)
75
80 #define FOR_ALL_ORDER_BACKUPS(var) FOR_ALL_ORDER_BACKUPS_FROM(var, 0)
81
82 #endif /* ORDER_BACKUP_H */
OrderBackup::orders
Order * orders
The actual orders if the vehicle was not a clone.
Definition: order_backup.h:46
OrderBackup::ResetUser
static void ResetUser(uint32 user)
Reset an user&#39;s OrderBackup if needed.
Definition: order_backup.cpp:170
OrderBackup::user
uint32 user
The user that requested the backup.
Definition: order_backup.h:41
OrderBackup::~OrderBackup
~OrderBackup()
Free everything that is allocated.
Definition: order_backup.cpp:28
OrderBackup::tile
TileIndex tile
Tile of the depot where the order was changed.
Definition: order_backup.h:42
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:212
OrderBackup::GetOrderBackupDescription
friend const struct SaveLoad * GetOrderBackupDescription()
Saving and loading of order backups.
Definition: order_sl.cpp:250
OrderBackupID
uint8 OrderBackupID
Unique identifier for an order backup.
Definition: order_backup.h:22
Order
Definition: order_base.h:34
pool_type.hpp
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
OrderBackup::ResetOfUser
static void ResetOfUser(TileIndex tile, uint32 user)
Reset an OrderBackup given a tile and user.
Definition: order_backup.cpp:139
OrderBackup::clone
const Vehicle * clone
Vehicle this vehicle was a clone of.
Definition: order_backup.h:45
_order_backup_pool
OrderBackupPool _order_backup_pool
The pool with order backups.
MAKE_ORDER_BACKUP_FLAG
static const uint32 MAKE_ORDER_BACKUP_FLAG
Flag to pass to the vehicle construction command when an order should be preserved.
Definition: order_backup.h:31
BaseConsist
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition: base_consist.h:19
GroupID
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:15
base_consist.h
Properties for front vehicles/consists.
OrderBackupPool
Pool< OrderBackup, OrderBackupID, 1, 256 > OrderBackupPool
The pool type for order backups.
Definition: order_backup.h:23
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:146
OrderType
OrderType
Order types.
Definition: order_type.h:37
Pool
Base class for all pools.
Definition: pool_type.hpp:83
OrderBackup::Reset
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
Definition: order_backup.cpp:190
OrderBackup::RemoveOrder
static void RemoveOrder(OrderType type, DestinationID destination)
Removes an order from all vehicles.
Definition: order_backup.cpp:260
OrderBackup::DoRestore
void DoRestore(Vehicle *v)
Restore the data of this order to the given vehicle.
Definition: order_backup.cpp:75
OrderBackup::ClearVehicle
static void ClearVehicle(const Vehicle *v)
Clear/update the (clone) vehicle from an order backup.
Definition: order_backup.cpp:241
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
vehicle_type.h
Types related to vehicles.
OrderBackup::ClearGroup
static void ClearGroup(GroupID group)
Clear the group of all backups having this group ID.
Definition: order_backup.cpp:226
OrderBackup::OrderBackup
OrderBackup()
Creation for savegame restoration.
Definition: order_backup.h:49
SaveLoad
SaveLoad type struct.
Definition: saveload.h:208
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
OrderBackup::group
GroupID group
The group the vehicle was part of.
Definition: order_backup.h:43
OrderBackup::Restore
static void Restore(Vehicle *v, uint32 user)
Restore the data of this order to the given vehicle.
Definition: order_backup.cpp:122
OrderBackup::Backup
static void Backup(const Vehicle *v, uint32 user)
Create an order backup for the given vehicle.
Definition: order_backup.cpp:103
tile_type.h
Types related to tiles.
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:37
group_type.h
Types of a group.
OrderBackup::Load_BKOR
friend void Load_BKOR()
Creating empty orders upon savegame loading.
Definition: order_sl.cpp:289