summaryrefslogtreecommitdiff
path: root/src/players.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2008-04-27 20:09:29 +0000
committerbjarni <bjarni@openttd.org>2008-04-27 20:09:29 +0000
commit757de2bdf567f5c8eb40578b949875eefe1c9335 (patch)
treeefbff2346a07d27ade486566153b76347444eb3f /src/players.cpp
parent9f5f4e59cdc9a9a8225131c7a007acb009016dfb (diff)
downloadopenttd-757de2bdf567f5c8eb40578b949875eefe1c9335.tar.xz
(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
Diffstat (limited to 'src/players.cpp')
-rw-r--r--src/players.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/players.cpp b/src/players.cpp
index fc90dc2fb..f4cd472f8 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -208,6 +208,24 @@ bool CheckPlayerHasMoney(CommandCost cost)
return true;
}
+/** Backs up current economic data for a player
+ */
+PlayerMoneyBackup::PlayerMoneyBackup(Player *player)
+{
+ p = player;
+ memcpy(backup_yearly_expenses, p->yearly_expenses, EXPENSES_END * sizeof(Money));
+ backup_cur_economy = p->cur_economy;
+}
+
+/** Restore the economic data from last backup
+ * This should only be used right after Player::BackupEconomy()
+ */
+void PlayerMoneyBackup::Restore()
+{
+ memcpy(p->yearly_expenses, backup_yearly_expenses, EXPENSES_END * sizeof(Money));
+ p->cur_economy = backup_cur_economy;
+}
+
static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost)
{
if (cost.GetCost() == 0) return;