(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

@@ -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;