206 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
206 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
207 return (int32)p1; |
207 return (int32)p1; |
208 } |
208 } |
209 |
209 |
210 /** Transfer funds (money) from one player to another. |
210 /** Transfer funds (money) from one player to another. |
211 * @param x,y unused |
211 * To prevent abuse in multiplayer games you can only send money to other |
212 * @param p1 the amount of money to transfer; max 16.000.000 |
212 * players if you have paid off your loan (either explicitely, or implicitely |
|
213 * given the fact that you have more money than loan). |
|
214 * @param x,y unused |
|
215 * @param p1 the amount of money to transfer; max 20.000.000 |
213 * @param p2 the player to transfer the money to |
216 * @param p2 the player to transfer the money to |
214 */ |
217 */ |
215 int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
218 int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
216 { |
219 { |
|
220 const Player *p = DEREF_PLAYER(_current_player); |
|
221 int32 amount = min((int32)p1, 20000000); |
|
222 |
217 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
223 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
218 |
224 |
219 if (!_networking || (int32)p1 <= 0 || p2 >= MAX_PLAYERS) return CMD_ERROR; |
225 /* You can only transfer funds that is in excess of your loan */ |
220 |
226 if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR; |
221 if (flags & DC_EXEC) { |
227 if (!_networking || p2 >= MAX_PLAYERS) return CMD_ERROR; |
222 /* Add money to player (cast to signed to prevent 'stealing' money) */ |
228 |
|
229 if (flags & DC_EXEC) { |
|
230 /* Add money to player */ |
223 PlayerID old_cp = _current_player; |
231 PlayerID old_cp = _current_player; |
224 _current_player = p2; |
232 _current_player = p2; |
225 SubtractMoneyFromPlayer(-(int32)p1); |
233 SubtractMoneyFromPlayer(-amount); |
226 _current_player = old_cp; |
234 _current_player = old_cp; |
227 } |
235 } |
228 |
236 |
229 /* Subtract money from local-player (cast to signed to prevent 'stealing' money) */ |
237 /* Subtract money from local-player */ |
230 return (int32)p1; |
238 return amount; |
231 } |
239 } |
232 |
240 |
233 /** Change difficulty level/settings (server-only). |
241 /** Change difficulty level/settings (server-only). |
234 * We cannot really check for valid values of p2 (too much work mostly); stored |
242 * We cannot really check for valid values of p2 (too much work mostly); stored |
235 * in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows |
243 * in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows |