155 p->player_money += loan; |
155 p->player_money += loan; |
156 p->current_loan += loan; |
156 p->current_loan += loan; |
157 InvalidatePlayerWindows(p); |
157 InvalidatePlayerWindows(p); |
158 } |
158 } |
159 |
159 |
160 return CommandCost(); |
160 return CommandCost(EXPENSES_OTHER); |
161 } |
161 } |
162 |
162 |
163 /** Decrease the loan of your company. |
163 /** Decrease the loan of your company. |
164 * @param tile unused |
164 * @param tile unused |
165 * @param flags operation to perform |
165 * @param flags operation to perform |
355 CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
355 CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
356 { |
356 { |
357 #ifndef _DEBUG |
357 #ifndef _DEBUG |
358 if (_networking) return CMD_ERROR; |
358 if (_networking) return CMD_ERROR; |
359 #endif |
359 #endif |
360 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
360 return CommandCost(EXPENSES_OTHER, -(Money)p1); |
361 return CommandCost(-(Money)p1); |
|
362 } |
361 } |
363 |
362 |
364 /** Transfer funds (money) from one player to another. |
363 /** Transfer funds (money) from one player to another. |
365 * To prevent abuse in multiplayer games you can only send money to other |
364 * To prevent abuse in multiplayer games you can only send money to other |
366 * players if you have paid off your loan (either explicitely, or implicitely |
365 * players if you have paid off your loan (either explicitely, or implicitely |
373 CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
372 CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
374 { |
373 { |
375 if (!_patches.give_money) return CMD_ERROR; |
374 if (!_patches.give_money) return CMD_ERROR; |
376 |
375 |
377 const Player *p = GetPlayer(_current_player); |
376 const Player *p = GetPlayer(_current_player); |
378 CommandCost amount(min((Money)p1, (Money)20000000LL)); |
377 CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL)); |
379 |
|
380 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
381 |
378 |
382 /* You can only transfer funds that is in excess of your loan */ |
379 /* You can only transfer funds that is in excess of your loan */ |
383 if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR; |
380 if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR; |
384 if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR; |
381 if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR; |
385 |
382 |
386 if (flags & DC_EXEC) { |
383 if (flags & DC_EXEC) { |
387 /* Add money to player */ |
384 /* Add money to player */ |
388 PlayerID old_cp = _current_player; |
385 PlayerID old_cp = _current_player; |
389 _current_player = (PlayerID)p2; |
386 _current_player = (PlayerID)p2; |
390 SubtractMoneyFromPlayer(CommandCost(-amount.GetCost())); |
387 SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -amount.GetCost())); |
391 _current_player = old_cp; |
388 _current_player = old_cp; |
392 } |
389 } |
393 |
390 |
394 /* Subtract money from local-player */ |
391 /* Subtract money from local-player */ |
395 return amount; |
392 return amount; |