186 return true; |
186 return true; |
187 } |
187 } |
188 |
188 |
189 static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost) |
189 static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost) |
190 { |
190 { |
191 p->player_money -= cost.GetCost(); |
191 CommandCost tmp((int32)p->player_money); |
192 |
192 tmp.AddCost(-cost.GetCost()); |
193 p->yearly_expenses[0][_yearly_expenses_type] += cost.GetCost(); |
193 p->player_money = tmp.GetCost(); |
|
194 |
|
195 tmp = CommandCost((int32)p->yearly_expenses[0][_yearly_expenses_type]); |
|
196 tmp.AddCost(cost); |
|
197 p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost(); |
194 |
198 |
195 if (HASBIT(1 << EXPENSES_TRAIN_INC | |
199 if (HASBIT(1 << EXPENSES_TRAIN_INC | |
196 1 << EXPENSES_ROADVEH_INC | |
200 1 << EXPENSES_ROADVEH_INC | |
197 1 << EXPENSES_AIRCRAFT_INC | |
201 1 << EXPENSES_AIRCRAFT_INC | |
198 1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) { |
202 1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) { |
199 p->cur_economy.income -= cost.GetCost(); |
203 tmp = CommandCost(p->cur_economy.income); |
|
204 tmp.AddCost(-cost.GetCost()); |
|
205 p->cur_economy.income = tmp.GetCost(); |
200 } else if (HASBIT(1 << EXPENSES_TRAIN_RUN | |
206 } else if (HASBIT(1 << EXPENSES_TRAIN_RUN | |
201 1 << EXPENSES_ROADVEH_RUN | |
207 1 << EXPENSES_ROADVEH_RUN | |
202 1 << EXPENSES_AIRCRAFT_RUN | |
208 1 << EXPENSES_AIRCRAFT_RUN | |
203 1 << EXPENSES_SHIP_RUN | |
209 1 << EXPENSES_SHIP_RUN | |
204 1 << EXPENSES_PROPERTY | |
210 1 << EXPENSES_PROPERTY | |
205 1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) { |
211 1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) { |
206 p->cur_economy.expenses -= cost.GetCost(); |
212 tmp = CommandCost(p->cur_economy.expenses); |
|
213 tmp.AddCost(-cost.GetCost()); |
|
214 p->cur_economy.expenses = tmp.GetCost(); |
207 } |
215 } |
208 |
216 |
209 InvalidatePlayerWindows(p); |
217 InvalidatePlayerWindows(p); |
210 } |
218 } |
211 |
219 |
218 |
226 |
219 void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) |
227 void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) |
220 { |
228 { |
221 Player *p = GetPlayer(player); |
229 Player *p = GetPlayer(player); |
222 byte m = p->player_money_fraction; |
230 byte m = p->player_money_fraction; |
223 int32 cost = cst.GetCost(); |
231 Money cost = cst.GetCost(); |
224 |
232 |
225 p->player_money_fraction = m - (byte)cost; |
233 p->player_money_fraction = m - (byte)cost; |
226 cost >>= 8; |
234 cost >>= 8; |
227 if (p->player_money_fraction > m) cost++; |
235 if (p->player_money_fraction > m) cost++; |
228 if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cost)); |
236 if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cost)); |