(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)

Autoreplace uses this with the following benefits:
  -Mass autoreplace (the button in the depot window) will now estimate costs correctly
  -Autoreplace now either replaces correctly or manages to keep the original vehicle (no more broken trains)
  Thanks to Ammler for testing this
This commit is contained in:
bjarni
2008-04-27 20:09:29 +00:00
parent d6c971fd9b
commit 783e20a263
8 changed files with 208 additions and 30 deletions

View File

@@ -14,6 +14,7 @@
#include "gfx_type.h"
#include "command_type.h"
#include "date_type.h"
#include "player_base.h"
#include "player_type.h"
#include "oldpool.h"
#include "order_base.h"
@@ -21,6 +22,7 @@
#include "texteff.hpp"
#include "group_type.h"
#include "engine_type.h"
#include "order_func.h"
/** Road vehicle states */
enum RoadVehicleStates {
@@ -520,6 +522,9 @@ public:
* @return the cost of the depot action.
*/
CommandCost SendToDepot(uint32 flags, DepotCommand command);
Vehicle* BackupVehicle() const;
Vehicle* RestoreBackupVehicle();
};
/**
@@ -649,4 +654,21 @@ Trackdir GetVehicleTrackdir(const Vehicle* v);
void CheckVehicle32Day(Vehicle *v);
struct BackuppedVehicle {
private:
Vehicle *vehicles;
BackuppedOrders *orders;
PlayerMoneyBackup *economy;
public:
BackuppedVehicle(bool include_orders) : vehicles(NULL), economy(NULL) {
orders = include_orders ? new BackuppedOrders() : NULL;
}
~BackuppedVehicle() { free(vehicles); delete orders; delete economy; }
void Backup(const Vehicle *v, Player *p = NULL);
Vehicle *Restore(Vehicle *v);
bool ContainsBackup() { return vehicles != NULL; }
};
#endif /* VEHICLE_BASE_H */