diff options
author | rubidium <rubidium@openttd.org> | 2008-01-09 16:55:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-01-09 16:55:48 +0000 |
commit | 46650c54b6a13ef5980eadb24995481f1fd83712 (patch) | |
tree | a0181571819fca45c3cc170c7ce718009cb12535 /src/players.cpp | |
parent | b4337eba83e34ddaac29684d78202ae9623e9240 (diff) | |
download | openttd-46650c54b6a13ef5980eadb24995481f1fd83712.tar.xz |
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
Diffstat (limited to 'src/players.cpp')
-rw-r--r-- | src/players.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
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) |