From 0365c1f33ba130bcfc663309b806fe65d730381f Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 9 Jan 2008 16:55:48 +0000 Subject: (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114). --- src/players.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/players.cpp') diff --git a/src/players.cpp b/src/players.cpp index b8dff5971..b0314f685 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -192,30 +192,24 @@ bool CheckPlayerHasMoney(CommandCost cost) static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost) { - CommandCost tmp(p->player_money); - tmp.AddCost(-cost.GetCost()); - p->player_money = tmp.GetCost(); + if (cost.GetCost() == 0) return; + assert(cost.GetExpensesType() != INVALID_EXPENSES); - tmp = CommandCost(p->yearly_expenses[0][_yearly_expenses_type]); - tmp.AddCost(cost); - p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost(); + p->player_money -= cost.GetCost(); + p->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost(); if (HasBit(1 << EXPENSES_TRAIN_INC | 1 << EXPENSES_ROADVEH_INC | 1 << EXPENSES_AIRCRAFT_INC | - 1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) { - tmp = CommandCost(p->cur_economy.income); - tmp.AddCost(-cost.GetCost()); - p->cur_economy.income = tmp.GetCost(); + 1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) { + p->cur_economy.income += cost.GetCost(); } else if (HasBit(1 << EXPENSES_TRAIN_RUN | 1 << EXPENSES_ROADVEH_RUN | 1 << EXPENSES_AIRCRAFT_RUN | 1 << EXPENSES_SHIP_RUN | 1 << EXPENSES_PROPERTY | - 1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) { - tmp = CommandCost(p->cur_economy.expenses); - tmp.AddCost(-cost.GetCost()); - p->cur_economy.expenses = tmp.GetCost(); + 1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) { + p->cur_economy.expenses += cost.GetCost(); } InvalidatePlayerWindows(p); @@ -237,7 +231,7 @@ void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) p->player_money_fraction = m - (byte)cost; cost >>= 8; if (p->player_money_fraction > m) cost++; - if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cost)); + if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cst.GetExpensesType(), cost)); } void GetNameOfOwner(Owner owner, TileIndex tile) -- cgit v1.2.3-54-g00ecf