summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lang/english.txt5
-rw-r--r--main_gui.c33
-rw-r--r--misc_cmd.c20
3 files changed, 32 insertions, 26 deletions
diff --git a/lang/english.txt b/lang/english.txt
index b2c6c8e13..f38a343c8 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -1806,8 +1806,8 @@ STR_4838_IMPROVED_FARMING_METHODS :{BLACK}{BIGFONT
STR_4839_PRODUCTION_DOWN_BY_50 :{BLACK}{BIGFONT}{TOWN} {STRING} production down by 50%
STR_483A_INSECT_INFESTATION_CAUSES :{BLACK}{BIGFONT}Insect infestation causes havoc at {TOWN} {STRING}!{}Production down by 50%
STR_483B_CAN_ONLY_BE_POSITIONED :{WHITE}...can only be positioned near edges of map
-STR_INDUSTRY_PROD_GOUP :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} goes up by {COMMA16}%!
-STR_INDUSTRY_PROD_GODOWN :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} goes down by {COMMA16}%!
+STR_INDUSTRY_PROD_GOUP :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} increases {COMMA16}%!
+STR_INDUSTRY_PROD_GODOWN :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} decreases {COMMA16}%!
##id 0x5000
STR_5000_TRAIN_IN_TUNNEL :{WHITE}Train in tunnel
@@ -2034,6 +2034,7 @@ STR_702C_CAN_T_BORROW_ANY_MORE_MONEY :{WHITE}Can't bo
STR_702D_LOAN_ALREADY_REPAYED :{WHITE}...no loan to repay
STR_702E_REQUIRED :{WHITE}...{CURRENCY} required
STR_702F_CAN_T_REPAY_LOAN :{WHITE}Can't repay loan...
+STR_INSUFFICIENT_FUNDS :{WHITE}Can't give away money that is loaned from the bank...
STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT :{BLACK}Select new face for manager
STR_7031_CHANGE_THE_COMPANY_VEHICLE :{BLACK}Change the company vehicle livery
STR_7032_CHANGE_THE_PRESIDENT_S :{BLACK}Change the manager's name
diff --git a/main_gui.c b/main_gui.c
index 39efb8f35..25a050246 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -59,43 +59,41 @@ void HandleOnEditTextCancel(void)
}
}
-void HandleOnEditText(WindowEvent *e) {
+void HandleOnEditText(WindowEvent *e)
+{
const char *b = e->edittext.str;
int id;
memcpy(_decode_parameters, b, 32);
id = _rename_id;
- switch(_rename_what) {
- case 0:
- // for empty string send "remove sign" parameter
+ switch (_rename_what) {
+ case 0: /* Rename a s sign, if string is empty, delete sign */
DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
break;
- case 1:
- if(*b == 0)
- return;
+ case 1: /* Rename a waypoint */
+ if (*b == 0) return;
DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
break;
#ifdef ENABLE_NETWORK
- case 2:
- // Speak to..
+ case 2: /* Speak to.. */
if (!_network_server)
SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str);
else
NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX);
break;
- case 3: {
- // Give money
- int32 money = atoi(e->edittext.str) / GetCurrentCurrencyRate();
- char msg[100];
+ case 3: { /* Give money, you can only give money in excess of loan */
+ const Player *p = DEREF_PLAYER(_current_player);
+ int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / GetCurrentCurrencyRate());
+ char msg[20];
- money = clamp(money, 0, 0xFFFFFF); // Clamp between 16 million and 0
+ money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
// Give 'id' the money, and substract it from ourself
- if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY)) break;
+ if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS))) break;
// Inform the player of this action
- snprintf(msg, 100, "%d", money);
+ snprintf(msg, sizeof(msg), "%d", money);
if (!_network_server)
SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg);
@@ -103,10 +101,9 @@ void HandleOnEditText(WindowEvent *e) {
NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg, NETWORK_SERVER_INDEX);
break;
}
- case 4: {// Game-Password and Company-Password
+ case 4: /* Game-Password and Company-Password */
SEND_COMMAND(PACKET_CLIENT_PASSWORD)(id, e->edittext.str);
break;
- }
#endif /* ENABLE_NETWORK */
}
}
diff --git a/misc_cmd.c b/misc_cmd.c
index 469f9d862..576e2e8bf 100644
--- a/misc_cmd.c
+++ b/misc_cmd.c
@@ -208,26 +208,34 @@ int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
/** Transfer funds (money) from one player to another.
+ * To prevent abuse in multiplayer games you can only send money to other
+ * players if you have paid off your loan (either explicitely, or implicitely
+ * given the fact that you have more money than loan).
* @param x,y unused
- * @param p1 the amount of money to transfer; max 16.000.000
+ * @param p1 the amount of money to transfer; max 20.000.000
* @param p2 the player to transfer the money to
*/
int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
+ const Player *p = DEREF_PLAYER(_current_player);
+ int32 amount = min((int32)p1, 20000000);
+
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- if (!_networking || (int32)p1 <= 0 || p2 >= MAX_PLAYERS) return CMD_ERROR;
+ /* You can only transfer funds that is in excess of your loan */
+ if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
+ if (!_networking || p2 >= MAX_PLAYERS) return CMD_ERROR;
if (flags & DC_EXEC) {
- /* Add money to player (cast to signed to prevent 'stealing' money) */
+ /* Add money to player */
PlayerID old_cp = _current_player;
_current_player = p2;
- SubtractMoneyFromPlayer(-(int32)p1);
+ SubtractMoneyFromPlayer(-amount);
_current_player = old_cp;
}
- /* Subtract money from local-player (cast to signed to prevent 'stealing' money) */
- return (int32)p1;
+ /* Subtract money from local-player */
+ return amount;
}
/** Change difficulty level/settings (server-only).