author | Darkvater |
Sat, 12 Mar 2005 21:21:47 +0000 | |
changeset 1500 | 228f77e88adf |
parent 1328 | e069d2db0e4c |
child 1728 | 7cd90080eff5 |
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 |
|
14 |
/* p1 = player |
|
15 |
p2 = face |
|
16 |
*/ |
|
17 |
||
18 |
int32 CmdSetPlayerFace(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
19 |
{ |
|
20 |
if (flags & DC_EXEC) { |
|
21 |
DEREF_PLAYER(p1)->face = p2; |
|
22 |
MarkWholeScreenDirty(); |
|
23 |
} |
|
24 |
return 0; |
|
25 |
} |
|
26 |
||
27 |
/* p1 = player |
|
28 |
* p2 = color |
|
29 |
*/ |
|
30 |
int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
31 |
{ |
|
32 |
Player *p,*pp; |
|
33 |
||
34 |
// /* can only set color for itself */ |
|
35 |
// if ( (byte)p1 != _current_player) |
|
36 |
// return CMD_ERROR; |
|
37 |
||
38 |
p = DEREF_PLAYER(p1); |
|
39 |
||
40 |
/* ensure no dups */ |
|
41 |
FOR_ALL_PLAYERS(pp) { |
|
42 |
if (pp->is_active && pp != p && pp->player_color == (byte)p2) |
|
43 |
return CMD_ERROR; |
|
44 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
45 |
|
0 | 46 |
if (flags & DC_EXEC) { |
47 |
_player_colors[p1] = (byte)p2; |
|
48 |
p->player_color = (byte)p2; |
|
49 |
MarkWholeScreenDirty(); |
|
50 |
} |
|
51 |
return 0; |
|
52 |
} |
|
53 |
||
54 |
int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
55 |
{ |
|
56 |
Player *p; |
|
57 |
int32 size; |
|
58 |
||
59 |
if ( (byte)p1 != _current_player) |
|
60 |
return CMD_ERROR; |
|
61 |
||
62 |
p = DEREF_PLAYER(p1); |
|
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) { |
|
70 |
if (p2) |
|
71 |
size = _economy.max_loan - p->current_loan; |
|
72 |
else |
|
73 |
size = IS_HUMAN_PLAYER((byte)p1) ? 10000 : 50000; |
|
74 |
||
75 |
p->money64 += size; |
|
76 |
p->current_loan += size; |
|
77 |
UpdatePlayerMoney32(p); |
|
78 |
InvalidatePlayerWindows(p); |
|
79 |
} |
|
80 |
||
81 |
return 0; |
|
82 |
} |
|
83 |
||
84 |
int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
85 |
{ |
|
86 |
Player *p; |
|
87 |
int32 size; |
|
88 |
if ( (byte)p1 != _current_player) |
|
89 |
return CMD_ERROR; |
|
90 |
||
91 |
p = DEREF_PLAYER(p1); |
|
92 |
||
93 |
if (p->current_loan == 0) |
|
94 |
return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED); |
|
95 |
||
96 |
size = p->current_loan; |
|
97 |
||
98 |
// p2 is true while CTRL is pressed (repay all possible loan, or max money you have) |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
99 |
if (!p2) { |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
100 |
if (_patches.ainew_active) |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
101 |
size = min(size, 10000); |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
102 |
else |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
103 |
size = min(size, IS_HUMAN_PLAYER((byte)p1) ? 10000 : 50000); |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
104 |
} else { // only repay in chunks of 10K |
0 | 105 |
size = min(size, p->player_money); |
106 |
size = max(size, 10000); |
|
107 |
size -= size % 10000; |
|
108 |
} |
|
109 |
||
110 |
if (p->player_money < size) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
111 |
SetDParam(0, size); |
0 | 112 |
return_cmd_error(STR_702E_REQUIRED); |
113 |
} |
|
114 |
||
115 |
if (flags & DC_EXEC) { |
|
116 |
p->money64 -= size; |
|
117 |
p->current_loan -= size; |
|
118 |
UpdatePlayerMoney32(p); |
|
119 |
InvalidatePlayerWindows(p); |
|
120 |
} |
|
121 |
return 0; |
|
122 |
} |
|
123 |
||
124 |
int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
125 |
{ |
|
126 |
StringID str,old_str; |
|
127 |
Player *p; |
|
128 |
||
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1317
diff
changeset
|
129 |
str = AllocateNameUnique((const char*)_decode_parameters, 4); |
0 | 130 |
if (str == 0) |
131 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
132 |
|
0 | 133 |
if (flags & DC_EXEC) { |
134 |
p = DEREF_PLAYER(p1); |
|
135 |
old_str = p->name_1; |
|
136 |
p->name_1 = str; |
|
137 |
DeleteName(old_str); |
|
138 |
MarkWholeScreenDirty(); |
|
139 |
} else { |
|
140 |
DeleteName(str); |
|
141 |
} |
|
142 |
||
143 |
return 0; |
|
144 |
} |
|
145 |
||
146 |
int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
147 |
{ |
|
148 |
StringID str,old_str; |
|
149 |
Player *p; |
|
150 |
||
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1317
diff
changeset
|
151 |
str = AllocateNameUnique((const char*)_decode_parameters, 4); |
0 | 152 |
if (str == 0) |
153 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
154 |
|
0 | 155 |
if (flags & DC_EXEC) { |
156 |
p = DEREF_PLAYER(p1); |
|
157 |
old_str = p->president_name_1; |
|
158 |
p->president_name_1 = str; |
|
159 |
DeleteName(old_str); |
|
160 |
||
161 |
if (p->name_1 == STR_SV_UNNAMED) { |
|
1115
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
988
diff
changeset
|
162 |
ttd_strlcat( |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
988
diff
changeset
|
163 |
(char*)_decode_parameters, " Transport", sizeof(_decode_parameters)); |
0 | 164 |
DoCommandByTile(0, p1, 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
|
165 |
} |
0 | 166 |
MarkWholeScreenDirty(); |
167 |
} else { |
|
168 |
DeleteName(str); |
|
169 |
} |
|
170 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
171 |
return 0; |
0 | 172 |
} |
173 |
||
174 |
// p1 = 0 decrease pause counter |
|
175 |
// p1 = 1 increase pause counter |
|
176 |
int32 CmdPause(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
177 |
{ |
|
178 |
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
|
179 |
_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
|
180 |
if (_pause == (byte)-1) _pause = 0; |
0 | 181 |
InvalidateWindow(WC_STATUS_BAR, 0); |
182 |
InvalidateWindow(WC_MAIN_TOOLBAR, 0); |
|
183 |
} |
|
184 |
return 0; |
|
185 |
} |
|
186 |
||
187 |
||
188 |
||
189 |
int32 CmdResume(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
190 |
{ |
|
191 |
return 0; |
|
192 |
} |
|
193 |
||
194 |
int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
195 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
196 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
0 | 197 |
return (int32)p1; |
198 |
} |
|
199 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
200 |
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
|
201 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
202 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
203 |
|
815
633faa72f094
(svn r1286) -Fix: oeps, I clamp'd some numbers wrong :$
truelight
parents:
813
diff
changeset
|
204 |
p1 = clamp(p1, 0, 0xFFFFFF); // Clamp between 16 million and 0 |
813
90d6adb8d4ad
(svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents:
543
diff
changeset
|
205 |
|
90d6adb8d4ad
(svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents:
543
diff
changeset
|
206 |
if (p1 == 0) |
90d6adb8d4ad
(svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents:
543
diff
changeset
|
207 |
return CMD_ERROR; |
90d6adb8d4ad
(svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents:
543
diff
changeset
|
208 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
209 |
if (flags & DC_EXEC) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
210 |
// Add money to player |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
211 |
byte old_cp = _current_player; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
212 |
_current_player = p2; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
213 |
SubtractMoneyFromPlayer(-(int32)p1); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
214 |
_current_player = old_cp; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
215 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
216 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
217 |
// Subtract money from local-player |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
218 |
return (int32)p1; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
219 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
220 |
|
0 | 221 |
int32 CmdChangeDifficultyLevel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
222 |
{ |
|
223 |
if (flags & DC_EXEC) { |
|
224 |
if (p1 != (uint32)-1L) { |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
225 |
((int*)&_opt_ptr->diff)[p1] = p2; |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
226 |
_opt_ptr->diff_level = 3; |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
227 |
} else |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
228 |
_opt_ptr->diff_level = p2; |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
229 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
230 |
// If we are a network-client, update the difficult setting (if it is open) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
231 |
if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL) |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
232 |
ShowGameDifficulty(); |
0 | 233 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
234 |
return 0; |
0 | 235 |
} |