author | Darkvater |
Mon, 30 May 2005 14:45:36 +0000 | |
changeset 1877 | e7318705dd04 |
parent 1858 | 70c82f2343bd |
child 1878 | 622765748231 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1317
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1147
diff
changeset
|
3 |
#include "string.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
4 |
#include "table/strings.h" |
0 | 5 |
#include "command.h" |
6 |
#include "player.h" |
|
7 |
#include "gfx.h" |
|
8 |
#include "window.h" |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
9 |
#include "gui.h" |
0 | 10 |
#include "saveload.h" |
11 |
#include "economy.h" |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
12 |
#include "network.h" |
0 | 13 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
14 |
/** Change the player's face. |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
15 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
16 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
17 |
* @param p2 face bitmasked |
0 | 18 |
*/ |
19 |
int32 CmdSetPlayerFace(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
20 |
{ |
|
21 |
if (flags & DC_EXEC) { |
|
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1728
diff
changeset
|
22 |
GetPlayer(_current_player)->face = p2; |
0 | 23 |
MarkWholeScreenDirty(); |
24 |
} |
|
25 |
return 0; |
|
26 |
} |
|
27 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
28 |
/** Change the player's company-colour |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
29 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
30 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
31 |
* @param p2 new colour for vehicles, property, etc. |
0 | 32 |
*/ |
33 |
int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
34 |
{ |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
35 |
Player *p, *pp; |
0 | 36 |
|
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1728
diff
changeset
|
37 |
p = GetPlayer(_current_player); |
0 | 38 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
39 |
/* Ensure no two companies have the same colour */ |
0 | 40 |
FOR_ALL_PLAYERS(pp) { |
41 |
if (pp->is_active && pp != p && pp->player_color == (byte)p2) |
|
42 |
return CMD_ERROR; |
|
43 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
44 |
|
0 | 45 |
if (flags & DC_EXEC) { |
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1728
diff
changeset
|
46 |
_player_colors[_current_player] = (byte)p2; |
0 | 47 |
p->player_color = (byte)p2; |
48 |
MarkWholeScreenDirty(); |
|
49 |
} |
|
50 |
return 0; |
|
51 |
} |
|
52 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
53 |
/** Increase the loan of your company. |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
54 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
55 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
56 |
* @param p2 when set, loans the maximum amount in one go (press CTRL) |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
57 |
*/ |
0 | 58 |
int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
59 |
{ |
|
60 |
Player *p; |
|
61 |
||
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1728
diff
changeset
|
62 |
p = GetPlayer(_current_player); |
0 | 63 |
|
64 |
if (p->current_loan >= _economy.max_loan) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
65 |
SetDParam(0, _economy.max_loan); |
0 | 66 |
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN); |
67 |
} |
|
68 |
||
69 |
if (flags & DC_EXEC) { |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
70 |
/* Loan the maximum amount or not? */ |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
71 |
int32 loan = (p2) ? _economy.max_loan - p->current_loan : IS_HUMAN_PLAYER(_current_player) ? 10000 : 50000; |
0 | 72 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
73 |
p->money64 += loan; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
74 |
p->current_loan += loan; |
0 | 75 |
UpdatePlayerMoney32(p); |
76 |
InvalidatePlayerWindows(p); |
|
77 |
} |
|
78 |
||
79 |
return 0; |
|
80 |
} |
|
81 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
82 |
/** Decrease the loan of your company. |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
83 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
84 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
85 |
* @param p2 when set, pays back the maximum loan permitting money (press CTRL) |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
86 |
*/ |
0 | 87 |
int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
88 |
{ |
|
89 |
Player *p; |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
90 |
int32 loan; |
0 | 91 |
|
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1728
diff
changeset
|
92 |
p = GetPlayer(_current_player); |
0 | 93 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
94 |
if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED); |
0 | 95 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
96 |
loan = p->current_loan; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
97 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
98 |
/* p2 is true while CTRL is pressed (repay all possible loan, or max money you have) |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
99 |
* Repay any loan in chunks of 10.000 pounds */ |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
100 |
if (p2) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
101 |
loan = min(loan, p->player_money); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
102 |
loan = max(loan, 10000); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
103 |
loan -= loan % 10000; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
104 |
} else { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
105 |
loan = (_patches.ainew_active) ? min(loan, 10000) : min(loan, IS_HUMAN_PLAYER(_current_player) ? 10000 : 50000); |
0 | 106 |
} |
107 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
108 |
if (p->player_money < loan) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
109 |
SetDParam(0, loan); |
0 | 110 |
return_cmd_error(STR_702E_REQUIRED); |
111 |
} |
|
112 |
||
113 |
if (flags & DC_EXEC) { |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
114 |
p->money64 -= loan; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
115 |
p->current_loan -= loan; |
0 | 116 |
UpdatePlayerMoney32(p); |
117 |
InvalidatePlayerWindows(p); |
|
118 |
} |
|
119 |
return 0; |
|
120 |
} |
|
121 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
122 |
/** Change the name of the company. |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
123 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
124 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
125 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
126 |
*/ |
0 | 127 |
int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
128 |
{ |
|
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
129 |
StringID str; |
0 | 130 |
Player *p; |
131 |
||
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
132 |
if (_cmd_text[0] == '\0') return CMD_ERROR; |
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
133 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
134 |
str = AllocateNameUnique(_cmd_text, 4); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
135 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
136 |
|
0 | 137 |
if (flags & DC_EXEC) { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
138 |
p = DEREF_PLAYER(_current_player); |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
139 |
DeleteName(p->name_1); |
0 | 140 |
p->name_1 = str; |
141 |
MarkWholeScreenDirty(); |
|
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
142 |
} else |
0 | 143 |
DeleteName(str); |
144 |
||
145 |
return 0; |
|
146 |
} |
|
147 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
148 |
/** Change the name of the president. |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
149 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
150 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
151 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
152 |
*/ |
0 | 153 |
int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
154 |
{ |
|
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
155 |
StringID str; |
0 | 156 |
Player *p; |
157 |
||
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
158 |
if (_cmd_text[0] == '\0') return CMD_ERROR; |
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
159 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
160 |
str = AllocateNameUnique(_cmd_text, 4); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
161 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
162 |
|
0 | 163 |
if (flags & DC_EXEC) { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
164 |
p = DEREF_PLAYER(_current_player); |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
165 |
DeleteName(p->president_name_1); |
0 | 166 |
p->president_name_1 = str; |
167 |
||
168 |
if (p->name_1 == STR_SV_UNNAMED) { |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
169 |
char buf[80]; |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
170 |
|
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
171 |
snprintf(buf, lengthof(buf), "%s Transport", _cmd_text); |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
172 |
_cmd_text = buf; |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
173 |
DoCommandByTile(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
174 |
} |
0 | 175 |
MarkWholeScreenDirty(); |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
176 |
} else |
0 | 177 |
DeleteName(str); |
178 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
179 |
return 0; |
0 | 180 |
} |
181 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
182 |
/** Pause/Unpause the game (server-only). |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
183 |
* Increase or decrease the pause counter. If the counter is zero, |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
184 |
* the game is unpaused. A counter is used instead of a boolean value |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
185 |
* to have more control over the game when saving/loading, etc. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
186 |
* @param x,y unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
187 |
* @param p1 0 = decrease pause counter; 1 = increase pause counter |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
188 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
189 |
*/ |
0 | 190 |
int32 CmdPause(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
191 |
{ |
|
192 |
if (flags & DC_EXEC) { |
|
1147
3fae4b3e16a0
(svn r1648) -Fix: server can now pause and unpause a game through the console. Use 'pause' and 'unpause'
darkvater
parents:
1115
diff
changeset
|
193 |
_pause += (p1 == 1) ? 1 : -1; |
3fae4b3e16a0
(svn r1648) -Fix: server can now pause and unpause a game through the console. Use 'pause' and 'unpause'
darkvater
parents:
1115
diff
changeset
|
194 |
if (_pause == (byte)-1) _pause = 0; |
0 | 195 |
InvalidateWindow(WC_STATUS_BAR, 0); |
196 |
InvalidateWindow(WC_MAIN_TOOLBAR, 0); |
|
197 |
} |
|
198 |
return 0; |
|
199 |
} |
|
200 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
201 |
/** Change the financial flow of your company. |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
202 |
* This is normally only enabled in offline mode, but if there is a debug |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
203 |
* build, you can cheat (to test). |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
204 |
* @param x,y unused |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
205 |
* @param p1 the amount of money to receive (if negative), or spend (if positive) |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
206 |
* @param p2 unused |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
207 |
*/ |
0 | 208 |
int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
209 |
{ |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
210 |
#ifndef _DEBUG |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
211 |
if (_networking) return CMD_ERROR; |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
212 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
213 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
0 | 214 |
return (int32)p1; |
215 |
} |
|
216 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
217 |
/** Transfer funds (money) from one player to another. |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
218 |
* To prevent abuse in multiplayer games you can only send money to other |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
219 |
* players if you have paid off your loan (either explicitely, or implicitely |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
220 |
* given the fact that you have more money than loan). |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
221 |
* @param x,y unused |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
222 |
* @param p1 the amount of money to transfer; max 20.000.000 |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
223 |
* @param p2 the player to transfer the money to |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
224 |
*/ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
225 |
int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
226 |
{ |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
227 |
const Player *p = DEREF_PLAYER(_current_player); |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
228 |
int32 amount = min((int32)p1, 20000000); |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
229 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
230 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
231 |
|
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
232 |
/* You can only transfer funds that is in excess of your loan */ |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
233 |
if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR; |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
234 |
if (!_networking || p2 >= MAX_PLAYERS) return CMD_ERROR; |
813
90d6adb8d4ad
(svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents:
543
diff
changeset
|
235 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
236 |
if (flags & DC_EXEC) { |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
237 |
/* Add money to player */ |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
238 |
PlayerID old_cp = _current_player; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
239 |
_current_player = p2; |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
240 |
SubtractMoneyFromPlayer(-amount); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
241 |
_current_player = old_cp; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
242 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
243 |
|
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
244 |
/* Subtract money from local-player */ |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
245 |
return amount; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
246 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
247 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
248 |
/** Change difficulty level/settings (server-only). |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
249 |
* We cannot really check for valid values of p2 (too much work mostly); stored |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
250 |
* in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
251 |
* what to do and does this correctly |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
252 |
* @param x,y unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
253 |
* @param p1 the difficulty setting being changed. If it is -1, the difficulty level |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
254 |
* itself is changed. The new value is inside p2 |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
255 |
* @param p2 new value for a difficulty setting or difficulty level |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
256 |
*/ |
0 | 257 |
int32 CmdChangeDifficultyLevel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
258 |
{ |
|
1877
e7318705dd04
(svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents:
1858
diff
changeset
|
259 |
if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
260 |
|
0 | 261 |
if (flags & DC_EXEC) { |
262 |
if (p1 != (uint32)-1L) { |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
263 |
((int*)&_opt_ptr->diff)[p1] = p2; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
264 |
_opt_ptr->diff_level = 3; // custom difficulty level |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
265 |
} else |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
266 |
_opt_ptr->diff_level = p2; |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
267 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
268 |
/* If we are a network-client, update the difficult setting (if it is open). |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
269 |
* Use this instead of just dirtying the window because we need to load in |
1877
e7318705dd04
(svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents:
1858
diff
changeset
|
270 |
* the new difficulty settings */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
271 |
if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL) |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
272 |
ShowGameDifficulty(); |
0 | 273 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
274 |
return 0; |
0 | 275 |
} |