author | tron |
Thu, 02 Dec 2004 22:53:07 +0000 | |
changeset 534 | 17ab2f22ff74 |
parent 507 | 8aa8100b0b22 |
child 543 | e3b43338096b |
permissions | -rw-r--r-- |
0 | 1 |
|
2 |
#include "stdafx.h" |
|
3 |
#include "ttd.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" |
|
9 |
#include "saveload.h" |
|
10 |
#include "economy.h" |
|
11 |
||
12 |
/* p1 = player |
|
13 |
p2 = face |
|
14 |
*/ |
|
15 |
||
16 |
int32 CmdSetPlayerFace(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
17 |
{ |
|
18 |
if (flags & DC_EXEC) { |
|
19 |
DEREF_PLAYER(p1)->face = p2; |
|
20 |
MarkWholeScreenDirty(); |
|
21 |
} |
|
22 |
return 0; |
|
23 |
} |
|
24 |
||
25 |
/* p1 = player |
|
26 |
* p2 = color |
|
27 |
*/ |
|
28 |
int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
29 |
{ |
|
30 |
Player *p,*pp; |
|
31 |
||
32 |
// /* can only set color for itself */ |
|
33 |
// if ( (byte)p1 != _current_player) |
|
34 |
// return CMD_ERROR; |
|
35 |
||
36 |
p = DEREF_PLAYER(p1); |
|
37 |
||
38 |
/* ensure no dups */ |
|
39 |
FOR_ALL_PLAYERS(pp) { |
|
40 |
if (pp->is_active && pp != p && pp->player_color == (byte)p2) |
|
41 |
return CMD_ERROR; |
|
42 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
43 |
|
0 | 44 |
if (flags & DC_EXEC) { |
45 |
_player_colors[p1] = (byte)p2; |
|
46 |
p->player_color = (byte)p2; |
|
47 |
MarkWholeScreenDirty(); |
|
48 |
} |
|
49 |
return 0; |
|
50 |
} |
|
51 |
||
52 |
int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
53 |
{ |
|
54 |
Player *p; |
|
55 |
int32 size; |
|
56 |
||
57 |
if ( (byte)p1 != _current_player) |
|
58 |
return CMD_ERROR; |
|
59 |
||
60 |
p = DEREF_PLAYER(p1); |
|
61 |
||
62 |
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
|
63 |
SetDParam(0, _economy.max_loan); |
0 | 64 |
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN); |
65 |
} |
|
66 |
||
67 |
if (flags & DC_EXEC) { |
|
68 |
if (p2) |
|
69 |
size = _economy.max_loan - p->current_loan; |
|
70 |
else |
|
71 |
size = IS_HUMAN_PLAYER((byte)p1) ? 10000 : 50000; |
|
72 |
||
73 |
p->money64 += size; |
|
74 |
p->current_loan += size; |
|
75 |
UpdatePlayerMoney32(p); |
|
76 |
InvalidatePlayerWindows(p); |
|
77 |
} |
|
78 |
||
79 |
return 0; |
|
80 |
} |
|
81 |
||
82 |
int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
83 |
{ |
|
84 |
Player *p; |
|
85 |
int32 size; |
|
86 |
if ( (byte)p1 != _current_player) |
|
87 |
return CMD_ERROR; |
|
88 |
||
89 |
p = DEREF_PLAYER(p1); |
|
90 |
||
91 |
if (p->current_loan == 0) |
|
92 |
return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED); |
|
93 |
||
94 |
size = p->current_loan; |
|
95 |
||
96 |
// 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
|
97 |
if (!p2) { |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
98 |
if (_patches.ainew_active) |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
99 |
size = min(size, 10000); |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
100 |
else |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
101 |
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
|
102 |
} else { // only repay in chunks of 10K |
0 | 103 |
size = min(size, p->player_money); |
104 |
size = max(size, 10000); |
|
105 |
size -= size % 10000; |
|
106 |
} |
|
107 |
||
108 |
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
|
109 |
SetDParam(0, size); |
0 | 110 |
return_cmd_error(STR_702E_REQUIRED); |
111 |
} |
|
112 |
||
113 |
if (flags & DC_EXEC) { |
|
114 |
p->money64 -= size; |
|
115 |
p->current_loan -= size; |
|
116 |
UpdatePlayerMoney32(p); |
|
117 |
InvalidatePlayerWindows(p); |
|
118 |
} |
|
119 |
return 0; |
|
120 |
} |
|
121 |
||
122 |
int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
123 |
{ |
|
124 |
StringID str,old_str; |
|
125 |
Player *p; |
|
126 |
||
127 |
str = AllocateName((byte*)_decode_parameters, 4); |
|
128 |
if (str == 0) |
|
129 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
130 |
|
0 | 131 |
if (flags & DC_EXEC) { |
132 |
p = DEREF_PLAYER(p1); |
|
133 |
old_str = p->name_1; |
|
134 |
p->name_1 = str; |
|
135 |
DeleteName(old_str); |
|
136 |
MarkWholeScreenDirty(); |
|
137 |
} else { |
|
138 |
DeleteName(str); |
|
139 |
} |
|
140 |
||
141 |
return 0; |
|
142 |
} |
|
143 |
||
144 |
int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
145 |
{ |
|
146 |
StringID str,old_str; |
|
147 |
Player *p; |
|
148 |
||
149 |
str = AllocateName((byte*)_decode_parameters, 4); |
|
150 |
if (str == 0) |
|
151 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
152 |
|
0 | 153 |
if (flags & DC_EXEC) { |
154 |
p = DEREF_PLAYER(p1); |
|
155 |
old_str = p->president_name_1; |
|
156 |
p->president_name_1 = str; |
|
157 |
DeleteName(old_str); |
|
158 |
||
159 |
if (p->name_1 == STR_SV_UNNAMED) { |
|
160 |
byte *s = " Transport"; |
|
161 |
byte *d = (byte*)_decode_parameters, b; |
|
162 |
d--; do d++; while (*d); |
|
163 |
do *d++ = b = *s++; while(d != (byte*)endof(_decode_parameters) && b != 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 |
static void UpdateSignVirtCoords(SignStruct *ss) |
|
175 |
{ |
|
176 |
Point pt = RemapCoords(ss->x, ss->y, ss->z); |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
177 |
SetDParam(0, ss->str); |
0 | 178 |
UpdateViewportSignPos(&ss->sign, pt.x, pt.y - 6, STR_2806); |
179 |
} |
|
180 |
||
181 |
void UpdateAllSignVirtCoords() |
|
182 |
{ |
|
183 |
SignStruct *ss; |
|
184 |
for(ss=_sign_list; ss != endof(_sign_list); ss++) |
|
185 |
if (ss->str != 0) |
|
186 |
UpdateSignVirtCoords(ss); |
|
187 |
||
188 |
} |
|
189 |
||
190 |
static void MarkSignDirty(SignStruct *ss) |
|
191 |
{ |
|
192 |
MarkAllViewportsDirty( |
|
193 |
ss->sign.left-6, |
|
194 |
ss->sign.top-3, |
|
195 |
ss->sign.left+ss->sign.width_1*4+12, |
|
196 |
ss->sign.top + 45 |
|
197 |
); |
|
198 |
} |
|
199 |
||
200 |
||
201 |
int32 CmdPlaceSign(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
202 |
{ |
|
203 |
SignStruct *ss; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
204 |
|
0 | 205 |
for(ss=_sign_list; ss != endof(_sign_list); ss++) { |
206 |
if (ss->str == 0) { |
|
207 |
if (flags & DC_EXEC) { |
|
208 |
ss->str = STR_280A_SIGN; |
|
209 |
ss->x = x; |
|
210 |
ss->y = y; |
|
211 |
ss->z = GetSlopeZ(x,y); |
|
212 |
UpdateSignVirtCoords(ss); |
|
213 |
MarkSignDirty(ss); |
|
214 |
_new_sign_struct = ss; |
|
215 |
} |
|
216 |
return 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
217 |
} |
0 | 218 |
} |
219 |
||
220 |
return_cmd_error(STR_2808_TOO_MANY_SIGNS); |
|
221 |
} |
|
222 |
||
223 |
// p1 = sign index |
|
224 |
// p2: 1 -> remove sign |
|
225 |
int32 CmdRenameSign(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
226 |
{ |
|
227 |
StringID str,old_str; |
|
228 |
SignStruct *ss; |
|
229 |
||
230 |
if (_decode_parameters[0] != 0 && !p2) { |
|
231 |
str = AllocateName((byte*)_decode_parameters, 0); |
|
232 |
if (str == 0) |
|
233 |
return CMD_ERROR; |
|
234 |
||
235 |
if (flags & DC_EXEC) { |
|
236 |
ss = &_sign_list[p1]; |
|
237 |
MarkSignDirty(ss); |
|
238 |
DeleteName(ss->str); |
|
239 |
ss->str = str; |
|
240 |
UpdateSignVirtCoords(ss); |
|
241 |
MarkSignDirty(ss); |
|
242 |
} else { |
|
243 |
DeleteName(str); |
|
244 |
} |
|
245 |
} else { |
|
246 |
if (flags & DC_EXEC) { |
|
247 |
ss = &_sign_list[p1]; |
|
248 |
old_str = ss->str; |
|
249 |
ss->str = 0; |
|
250 |
DeleteName(old_str); |
|
251 |
MarkSignDirty(ss); |
|
252 |
} |
|
253 |
} |
|
254 |
return 0; |
|
255 |
} |
|
256 |
||
257 |
// p1 = 0 decrease pause counter |
|
258 |
// p1 = 1 increase pause counter |
|
259 |
int32 CmdPause(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
260 |
{ |
|
261 |
if (flags & DC_EXEC) { |
|
262 |
_pause += p1?1:-1; |
|
263 |
if(_pause==(byte)-1) _pause = 0; |
|
264 |
InvalidateWindow(WC_STATUS_BAR, 0); |
|
265 |
InvalidateWindow(WC_MAIN_TOOLBAR, 0); |
|
266 |
} |
|
267 |
return 0; |
|
268 |
} |
|
269 |
||
270 |
||
271 |
||
272 |
int32 CmdResume(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
273 |
{ |
|
274 |
return 0; |
|
275 |
} |
|
276 |
||
277 |
int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
278 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
279 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
0 | 280 |
return (int32)p1; |
281 |
} |
|
282 |
||
283 |
int32 CmdChangeDifficultyLevel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
284 |
{ |
|
285 |
if (flags & DC_EXEC) { |
|
286 |
if (p1 != (uint32)-1L) { |
|
287 |
((int*)&_opt_mod_ptr->diff)[p1] = p2; |
|
288 |
_opt_mod_ptr->diff_level = 3; |
|
289 |
} else { |
|
290 |
_opt_mod_ptr->diff_level = p2; |
|
291 |
} |
|
292 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
|
293 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
294 |
return 0; |
0 | 295 |
} |
296 |
||
297 |
static const byte _sign_desc[] = { |
|
298 |
SLE_VAR(SignStruct,str, SLE_UINT16), |
|
299 |
SLE_VAR(SignStruct,x, SLE_INT16), |
|
300 |
SLE_VAR(SignStruct,y, SLE_INT16), |
|
301 |
SLE_VAR(SignStruct,z, SLE_UINT8), |
|
302 |
SLE_END() |
|
303 |
}; |
|
304 |
||
305 |
static void Save_SIGN() |
|
306 |
{ |
|
307 |
SignStruct *s; |
|
308 |
int i; |
|
309 |
for(i=0,s=_sign_list; i!=lengthof(_sign_list); i++,s++) { |
|
310 |
if (s->str != 0) { |
|
311 |
SlSetArrayIndex(i); |
|
312 |
SlObject(s, _sign_desc); |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
static void Load_SIGN() |
|
318 |
{ |
|
319 |
int index; |
|
320 |
while ((index = SlIterateArray()) != -1) { |
|
321 |
SlObject(&_sign_list[index], _sign_desc); |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
const ChunkHandler _sign_chunk_handlers[] = { |
|
326 |
{ 'SIGN', Save_SIGN, Load_SIGN, CH_ARRAY | CH_LAST}, |
|
327 |
}; |
|
328 |
||
329 |