order_backup.h

Go to the documentation of this file.
00001 /* $Id: order_backup.h 23795 2012-01-13 21:54:59Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef ORDER_BACKUP_H
00013 #define ORDER_BACKUP_H
00014 
00015 #include "core/pool_type.hpp"
00016 #include "date_type.h"
00017 #include "group_type.h"
00018 #include "order_type.h"
00019 #include "tile_type.h"
00020 #include "vehicle_type.h"
00021 
00023 typedef uint8 OrderBackupID;
00024 struct OrderBackup;
00025 
00027 typedef Pool<OrderBackup, OrderBackupID, 1, 256> OrderBackupPool;
00029 extern OrderBackupPool _order_backup_pool;
00030 
00032 static const uint32 MAKE_ORDER_BACKUP_FLAG = 1U << 31;
00033 
00038 struct OrderBackup : OrderBackupPool::PoolItem<&_order_backup_pool> {
00039 private:
00040   friend const struct SaveLoad *GetOrderBackupDescription(); 
00041   friend void Load_BKOR();   
00042   uint32 user;               
00043   TileIndex tile;            
00044   GroupID group;             
00045   Date service_interval;     
00046   char *name;                
00047 
00048   const Vehicle *clone;      
00049   VehicleOrderID orderindex; 
00050   Order *orders;             
00051 
00053   OrderBackup() {}
00054   OrderBackup(const Vehicle *v, uint32 user);
00055 
00056   void DoRestore(Vehicle *v);
00057 
00058 public:
00059   ~OrderBackup();
00060 
00061   static void Backup(const Vehicle *v, uint32 user);
00062   static void Restore(Vehicle *v, uint32 user);
00063 
00064   static void ResetOfUser(TileIndex tile, uint32 user);
00065   static void ResetUser(uint32 user);
00066   static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
00067 
00068   static void ClearGroup(GroupID group);
00069   static void ClearVehicle(const Vehicle *v);
00070   static void RemoveOrder(OrderType type, DestinationID destination);
00071 };
00072 
00073 #define FOR_ALL_ORDER_BACKUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderBackup, order_backup_index, var, start)
00074 #define FOR_ALL_ORDER_BACKUPS(var) FOR_ALL_ORDER_BACKUPS_FROM(var, 0)
00075 
00076 #endif /* ORDER_BACKUP_H */