author | bjarni |
Sat, 22 Jan 2005 23:55:45 +0000 | |
changeset 1099 | ad7522bd5c1c |
parent 1093 | 4fdc46eaf423 |
child 1174 | 6a5e747f3ba6 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
337
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
670
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "player.h" |
6 |
#include "town.h" |
|
7 |
#include "vehicle.h" |
|
8 |
#include "station.h" |
|
9 |
#include "gfx.h" |
|
10 |
#include "news.h" |
|
11 |
#include "saveload.h" |
|
12 |
#include "command.h" |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
13 |
#include "ai.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
206
diff
changeset
|
14 |
#include "sound.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
15 |
#include "network.h" |
0 | 16 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
17 |
extern void StartupEconomy(void); |
0 | 18 |
|
19 |
static const SpriteID cheeks_table[4] = { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
20 |
0x325, 0x326, |
0 | 21 |
0x390, 0x3B0, |
22 |
}; |
|
23 |
||
24 |
static const SpriteID mouth_table[3] = { |
|
25 |
0x34C, 0x34D, 0x34F |
|
26 |
}; |
|
27 |
||
28 |
void DrawPlayerFace(uint32 face, int color, int x, int y) |
|
29 |
{ |
|
30 |
byte flag = 0; |
|
31 |
||
32 |
if ( (int32)face < 0) |
|
33 |
flag |= 1; |
|
34 |
if ((((((face >> 7) ^ face) >> 7) ^ face) & 0x8080000) == 0x8000000) |
|
35 |
flag |= 2; |
|
36 |
||
37 |
/* draw the gradient */ |
|
38 |
DrawSprite( (color<<16) + 0x0307836A, x, y); |
|
39 |
||
40 |
/* draw the cheeks */ |
|
41 |
DrawSprite(cheeks_table[flag&3], x, y); |
|
42 |
||
43 |
/* draw the chin */ |
|
44 |
/* FIXME: real code uses -2 in zoomlevel 1 */ |
|
45 |
{ |
|
46 |
uint val = (face >> 4) & 3; |
|
47 |
if (!(flag & 2)) { |
|
48 |
DrawSprite(0x327 + (flag&1?0:val), x, y); |
|
49 |
} else { |
|
50 |
DrawSprite((flag&1?0x3B1:0x391) + (val>>1), x, y); |
|
51 |
} |
|
52 |
} |
|
53 |
/* draw the eyes */ |
|
54 |
{ |
|
55 |
uint val1 = (face >> 6)&15; |
|
56 |
uint val2 = (face >> 20)&7; |
|
57 |
uint32 high = 0x314<<16; |
|
58 |
||
59 |
if (val2 >= 6) { |
|
60 |
high = 0x30F<<16; |
|
61 |
if (val2 != 6) |
|
62 |
high = 0x30D<<16; |
|
63 |
} |
|
64 |
||
65 |
if (!(flag & 2)) { |
|
66 |
if (!(flag & 1)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
67 |
DrawSprite(high+((val1 * 12 >> 4) + 0x832B), x, y); |
0 | 68 |
} else { |
69 |
DrawSprite(high+(val1 + 0x8337), x, y); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
70 |
} |
0 | 71 |
} else { |
72 |
if (!(flag & 1)) { |
|
73 |
DrawSprite(high+((val1 * 11 >> 4) + 0x839A), x, y); |
|
74 |
} else { |
|
75 |
DrawSprite(high+(val1 + 0x83B8), x, y); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
/* draw the mouth */ |
|
81 |
{ |
|
82 |
uint val = (face >> 10) & 63; |
|
83 |
uint val2; |
|
84 |
||
85 |
if (!(flag&1)) { |
|
86 |
val2 = ((val&0xF) * 15 >> 4); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
87 |
|
0 | 88 |
if (val2 < 3) { |
89 |
DrawSprite((flag&2 ? 0x397 : 0x367) + val2, x, y); |
|
90 |
/* skip the rest */ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
91 |
goto skip_mouth; |
0 | 92 |
} |
93 |
||
94 |
val2 -= 3; |
|
95 |
if (flag & 2) { |
|
96 |
if (val2 > 8) val2 = 0; |
|
97 |
val2 += 0x3A5 - 0x35B; |
|
98 |
} |
|
99 |
DrawSprite(val2 + 0x35B, x, y); |
|
100 |
} else if (!(flag&2)) { |
|
101 |
DrawSprite(((val&0xF) * 10 >> 4) + 0x351, x, y); |
|
102 |
} else { |
|
103 |
DrawSprite(((val&0xF) * 9 >> 4) + 0x3C8, x, y); |
|
104 |
} |
|
105 |
||
106 |
val >>= 3; |
|
107 |
||
108 |
if (!(flag&2)) { |
|
109 |
if (!(flag&1)) { |
|
110 |
DrawSprite(0x349 + val, x, y); |
|
111 |
} else { |
|
112 |
DrawSprite( mouth_table[(val*3>>3)], x, y); |
|
113 |
} |
|
114 |
} else { |
|
115 |
if (!(flag&1)) { |
|
116 |
DrawSprite(0x393 + (val&3), x, y); |
|
117 |
} else { |
|
118 |
DrawSprite(0x3B3 + (val*5>>3), x, y); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
skip_mouth:; |
|
123 |
} |
|
124 |
||
125 |
||
126 |
/* draw the hair */ |
|
127 |
{ |
|
128 |
uint val = (face >> 16) & 15; |
|
129 |
if (!(flag&2)) { |
|
130 |
if (!(flag&1)) { |
|
131 |
DrawSprite(0x382 + (val*9>>4), x, y); |
|
132 |
} else { |
|
133 |
DrawSprite(0x38B + (val*5>>4), x, y); |
|
134 |
} |
|
135 |
} else { |
|
136 |
if (!(flag&1)) { |
|
137 |
DrawSprite(0x3D4 + (val*5>>4), x, y); |
|
138 |
} else { |
|
139 |
DrawSprite(0x3D9 + (val*5>>4), x, y); |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
/* draw the tie */ |
|
145 |
{ |
|
146 |
uint val = (face >> 20) & 0xFF; |
|
147 |
||
148 |
if (!(flag&1)) { |
|
149 |
DrawSprite(0x36B + ((val&3)*3>>2), x, y); |
|
150 |
DrawSprite(0x36E + ((val>>2)&3), x, y); |
|
151 |
DrawSprite(0x372 + ((val>>4)*6>>4), x, y); |
|
152 |
} else { |
|
153 |
DrawSprite(0x378 + ((val&3)*3>>2), x, y); |
|
154 |
DrawSprite(0x37B + ((val>>2)&3), x, y); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
155 |
|
0 | 156 |
val >>= 4; |
157 |
if (val < 3) { |
|
158 |
DrawSprite((flag&2 ? 0x3D1 : 0x37F) + val, x, y); |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
/* draw the glasses */ |
|
164 |
{ |
|
165 |
uint val = (face >> 28) & 7; |
|
166 |
||
167 |
if (!(flag&2)) { |
|
168 |
if (val<=1) { |
|
169 |
DrawSprite(0x347 + val, x, y); |
|
170 |
} |
|
171 |
} else { |
|
172 |
if (val<=1) { |
|
173 |
DrawSprite(0x3AE + val, x, y); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
void InvalidatePlayerWindows(Player *p) |
|
180 |
{ |
|
181 |
uint pid = p->index; |
|
182 |
if ( (byte)pid == _local_player) |
|
183 |
InvalidateWindow(WC_STATUS_BAR, 0); |
|
184 |
||
185 |
InvalidateWindow(WC_FINANCES, pid); |
|
186 |
} |
|
187 |
||
188 |
bool CheckPlayerHasMoney(int32 cost) |
|
189 |
{ |
|
190 |
if (cost > 0) { |
|
191 |
uint pid = _current_player; |
|
192 |
if (pid < MAX_PLAYERS && cost > DEREF_PLAYER(pid)->player_money) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
193 |
SetDParam(0, cost); |
0 | 194 |
_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
195 |
return false; |
|
196 |
} |
|
197 |
} |
|
198 |
return true; |
|
199 |
} |
|
200 |
||
201 |
static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost) |
|
202 |
{ |
|
203 |
p->money64 -= cost; |
|
204 |
UpdatePlayerMoney32(p); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
205 |
|
0 | 206 |
p->yearly_expenses[0][_yearly_expenses_type] += cost; |
207 |
||
208 |
if ( ( 1 << _yearly_expenses_type ) & (1<<7|1<<8|1<<9|1<<10)) |
|
209 |
p->cur_economy.income -= cost; |
|
210 |
else if (( 1 << _yearly_expenses_type ) & (1<<2|1<<3|1<<4|1<<5|1<<6|1<<11)) |
|
211 |
p->cur_economy.expenses -= cost; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
212 |
|
0 | 213 |
InvalidatePlayerWindows(p); |
214 |
} |
|
215 |
||
216 |
void SubtractMoneyFromPlayer(int32 cost) |
|
217 |
{ |
|
218 |
uint pid = _current_player; |
|
219 |
if (pid < MAX_PLAYERS) |
|
220 |
SubtractMoneyFromAnyPlayer(DEREF_PLAYER(pid), cost); |
|
221 |
} |
|
222 |
||
223 |
void SubtractMoneyFromPlayerFract(byte player, int32 cost) |
|
224 |
{ |
|
225 |
Player *p = DEREF_PLAYER(player); |
|
226 |
byte m = p->player_money_fraction; |
|
227 |
p->player_money_fraction = m - (byte)cost; |
|
228 |
cost >>= 8; |
|
229 |
if (p->player_money_fraction > m) |
|
230 |
cost++; |
|
231 |
if (cost != 0) |
|
232 |
SubtractMoneyFromAnyPlayer(p, cost); |
|
233 |
} |
|
234 |
||
235 |
// the player_money field is kept as it is, but money64 contains the actual amount of money. |
|
236 |
void UpdatePlayerMoney32(Player *p) |
|
237 |
{ |
|
238 |
if (p->money64 < -2000000000) |
|
239 |
p->player_money = -2000000000; |
|
240 |
else if (p->money64 > 2000000000) |
|
241 |
p->player_money = 2000000000; |
|
242 |
else |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
243 |
p->player_money = (int32)p->money64; |
0 | 244 |
} |
245 |
||
246 |
void GetNameOfOwner(byte owner, uint tile) |
|
247 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
248 |
SetDParam(2, owner); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
249 |
|
0 | 250 |
if (owner != OWNER_TOWN) { |
251 |
if (owner >= 8) |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
252 |
SetDParam(0, STR_0150_SOMEONE); |
0 | 253 |
else { |
254 |
Player *p = DEREF_PLAYER(owner); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
255 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
256 |
SetDParam(1, p->name_2); |
0 | 257 |
} |
258 |
} else { |
|
259 |
Town *t = ClosestTownFromTile(tile, (uint)-1); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
260 |
SetDParam(0, t->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
261 |
SetDParam(1, t->townnameparts); |
0 | 262 |
} |
263 |
} |
|
264 |
||
265 |
||
266 |
bool CheckOwnership(byte owner) |
|
267 |
{ |
|
268 |
assert(owner <= OWNER_WATER); |
|
269 |
||
270 |
if (owner == _current_player) |
|
271 |
return true; |
|
272 |
_error_message = STR_013B_OWNED_BY; |
|
273 |
GetNameOfOwner(owner, 0); |
|
274 |
return false; |
|
275 |
} |
|
276 |
||
277 |
bool CheckTileOwnership(uint tile) |
|
278 |
{ |
|
279 |
byte owner = _map_owner[tile]; |
|
280 |
assert(owner <= OWNER_WATER); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
281 |
if (owner == _current_player) |
0 | 282 |
return true; |
283 |
_error_message = STR_013B_OWNED_BY; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
284 |
|
0 | 285 |
// no need to get the name of the owner unless we're the local player (saves some time) |
286 |
if (_current_player == _local_player) |
|
287 |
GetNameOfOwner(owner, tile); |
|
288 |
return false; |
|
289 |
} |
|
290 |
||
291 |
static void GenerateCompanyName(Player *p) |
|
292 |
{ |
|
293 |
uint tile; |
|
294 |
Town *t; |
|
295 |
StringID str; |
|
296 |
Player *pp; |
|
297 |
uint32 strp; |
|
298 |
char buffer[100]; |
|
299 |
||
300 |
if (p->name_1 != STR_SV_UNNAMED) |
|
301 |
return; |
|
302 |
||
303 |
tile = p->last_build_coordinate; |
|
304 |
if (tile == 0) |
|
305 |
return; |
|
306 |
||
307 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
308 |
||
309 |
if (IS_INT_INSIDE(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST+1)) { |
|
310 |
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; |
|
311 |
strp = t->townnameparts; |
|
312 |
||
313 |
verify_name:; |
|
314 |
// No player must have this name already |
|
315 |
FOR_ALL_PLAYERS(pp) { |
|
316 |
if (pp->name_1 == str && pp->name_2 == strp) |
|
317 |
goto bad_town_name; |
|
318 |
} |
|
319 |
||
320 |
GetString(buffer, str); |
|
321 |
if (strlen(buffer) >= 32 || GetStringWidth(buffer) >= 150) |
|
322 |
goto bad_town_name; |
|
323 |
||
324 |
set_name:; |
|
325 |
p->name_1 = str; |
|
326 |
p->name_2 = strp; |
|
327 |
||
328 |
MarkWholeScreenDirty(); |
|
329 |
||
330 |
if (!IS_HUMAN_PLAYER(p->index)) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
331 |
SetDParam(0, t->index); |
0 | 332 |
AddNewsItem(p->index + (4 << 4), NEWS_FLAGS(NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY), p->last_build_coordinate, 0); |
333 |
} |
|
334 |
return; |
|
335 |
} |
|
336 |
bad_town_name:; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
337 |
|
0 | 338 |
if (p->president_name_1 == SPECSTR_PRESIDENT_NAME) { |
339 |
str = SPECSTR_ANDCO_NAME; |
|
340 |
strp = p->president_name_2; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
341 |
goto set_name; |
0 | 342 |
} else { |
343 |
str = SPECSTR_ANDCO_NAME; |
|
344 |
strp = Random(); |
|
345 |
goto verify_name; |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
#define COLOR_SWAP(i,j) do { byte t=colors[i];colors[i]=colors[j];colors[j]=t; } while(0) |
|
350 |
||
351 |
static const byte _color_sort[16] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1}; |
|
352 |
static const byte _color_similar_1[16] = {8, 6, 255, 12, 255, 0, 1, 1, 0, 13, 11, 10, 3, 9, 15, 14}; |
|
353 |
static const byte _color_similar_2[16] = {5, 7, 255, 255, 255, 8, 7, 6, 5, 12, 255, 255, 9, 255, 255, 255}; |
|
354 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
355 |
static byte GeneratePlayerColor(void) |
0 | 356 |
{ |
357 |
byte colors[16], pcolor, t2; |
|
358 |
int i,j,n; |
|
359 |
uint32 r; |
|
360 |
Player *p; |
|
361 |
||
362 |
// Initialize array |
|
363 |
for(i=0; i!=16; i++) |
|
364 |
colors[i] = i; |
|
365 |
||
366 |
// And randomize it |
|
367 |
n = 100; |
|
368 |
do { |
|
369 |
r = Random(); |
|
370 |
COLOR_SWAP(r & 0xF, (r >> 4) & 0xF); |
|
371 |
} while (--n); |
|
372 |
||
373 |
// Bubble sort it according to the values in table 1 |
|
374 |
i = 16; |
|
375 |
do { |
|
376 |
for(j=0; j!=15; j++) { |
|
377 |
if (_color_sort[colors[j]] < _color_sort[colors[j+1]]) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
378 |
COLOR_SWAP(j,j+1); |
0 | 379 |
} |
380 |
} |
|
381 |
} while (--i); |
|
382 |
||
383 |
// Move the colors that look similar to each player's color to the side |
|
384 |
FOR_ALL_PLAYERS(p) if (p->is_active) { |
|
385 |
pcolor = p->player_color; |
|
386 |
for(i=0; i!=16; i++) if (colors[i] == pcolor) { |
|
387 |
colors[i] = 0xFF; |
|
388 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
389 |
t2 = _color_similar_1[pcolor]; |
0 | 390 |
if (t2 == 0xFF) break; |
391 |
for(i=0; i!=15; i++) { |
|
392 |
if (colors[i] == t2) { |
|
393 |
do COLOR_SWAP(i,i+1); while (++i != 15); |
|
394 |
break; |
|
395 |
} |
|
396 |
} |
|
397 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
398 |
t2 = _color_similar_2[pcolor]; |
0 | 399 |
if (t2 == 0xFF) break; |
400 |
for(i=0; i!=15; i++) { |
|
401 |
if (colors[i] == t2) { |
|
402 |
do COLOR_SWAP(i,i+1); while (++i != 15); |
|
403 |
break; |
|
404 |
} |
|
405 |
} |
|
406 |
break; |
|
407 |
} |
|
408 |
} |
|
409 |
||
410 |
// Return the first available color |
|
411 |
i = 0; |
|
412 |
for(;;) { |
|
413 |
if (colors[i] != 0xFF) |
|
414 |
return colors[i]; |
|
415 |
i++; |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
static void GeneratePresidentName(Player *p) |
|
420 |
{ |
|
421 |
Player *pp; |
|
422 |
char buffer[100], buffer2[40]; |
|
423 |
||
424 |
for(;;) { |
|
425 |
restart:; |
|
426 |
||
427 |
p->president_name_2 = Random(); |
|
428 |
p->president_name_1 = SPECSTR_PRESIDENT_NAME; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
429 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
430 |
SetDParam(0, p->president_name_2); |
0 | 431 |
GetString(buffer, p->president_name_1); |
432 |
if (strlen(buffer) >= 32 || GetStringWidth(buffer) >= 94) |
|
433 |
continue; |
|
434 |
||
435 |
FOR_ALL_PLAYERS(pp) { |
|
436 |
if (pp->is_active && p != pp) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
437 |
SetDParam(0, pp->president_name_2); |
0 | 438 |
GetString(buffer2, pp->president_name_1); |
439 |
if (str_eq(buffer2, buffer)) |
|
440 |
goto restart; |
|
441 |
} |
|
442 |
} |
|
443 |
return; |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
extern int GetPlayerMaxRailtype(int p); |
|
448 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
449 |
static Player *AllocatePlayer(void) |
0 | 450 |
{ |
451 |
Player *p; |
|
452 |
// Find a free slot |
|
453 |
FOR_ALL_PLAYERS(p) { |
|
454 |
if (!p->is_active) { |
|
455 |
int i = p->index; |
|
456 |
memset(p, 0, sizeof(Player)); |
|
457 |
p->index = i; |
|
458 |
return p; |
|
459 |
} |
|
460 |
} |
|
461 |
return NULL; |
|
462 |
} |
|
463 |
||
464 |
Player *DoStartupNewPlayer(bool is_ai) |
|
465 |
{ |
|
466 |
Player *p; |
|
467 |
int index; |
|
468 |
||
469 |
p = AllocatePlayer(); |
|
470 |
if (p == NULL) return NULL; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
471 |
|
0 | 472 |
index = p->index; |
473 |
||
474 |
// Make a color |
|
475 |
p->player_color = GeneratePlayerColor(); |
|
476 |
_player_colors[index] = p->player_color; |
|
477 |
p->name_1 = STR_SV_UNNAMED; |
|
478 |
p->is_active = true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
479 |
|
0 | 480 |
p->money64 = p->player_money = p->current_loan = 100000; |
481 |
||
482 |
p->is_ai = is_ai; |
|
483 |
p->ai.state = 5; /* AIS_WANT_NEW_ROUTE */ |
|
484 |
p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = 0xFF; |
|
485 |
||
486 |
p->max_railtype = GetPlayerMaxRailtype(index); |
|
487 |
p->inaugurated_year = _cur_year; |
|
488 |
p->face = Random(); |
|
489 |
||
490 |
GeneratePresidentName(p); |
|
491 |
||
492 |
InvalidateWindow(WC_GRAPH_LEGEND, 0); |
|
493 |
InvalidateWindow(WC_TOOLBAR_MENU, 0); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
494 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
0 | 495 |
|
496 |
return p; |
|
497 |
} |
|
498 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
499 |
void StartupPlayers(void) |
0 | 500 |
{ |
23 | 501 |
// The AI starts like in the setting with +2 month max |
165
f81fa8c27236
(svn r166) -Codechange: change 74 for constant DAY_TICKS
darkvater
parents:
84
diff
changeset
|
502 |
_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 503 |
} |
504 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
505 |
static void MaybeStartNewPlayer(void) |
0 | 506 |
{ |
507 |
uint n; |
|
508 |
Player *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
509 |
|
0 | 510 |
// count number of competitors |
511 |
n = 0; |
|
512 |
for(p=_players; p!=endof(_players); p++) |
|
513 |
if (p->is_active && p->is_ai) |
|
514 |
n++; |
|
515 |
||
516 |
// when there's a lot of computers in game, the probability that a new one starts is lower |
|
23 | 517 |
if (n < (uint)_opt.diff.max_no_competitors && n < RandomRange(_opt.diff.max_no_competitors + 2)) |
0 | 518 |
DoStartupNewPlayer(true); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
519 |
|
23 | 520 |
// The next AI starts like the difficulty setting said, with +2 month max |
165
f81fa8c27236
(svn r166) -Codechange: change 74 for constant DAY_TICKS
darkvater
parents:
84
diff
changeset
|
521 |
_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 522 |
} |
523 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
524 |
void InitializePlayers(void) |
0 | 525 |
{ |
526 |
int i; |
|
527 |
memset(_players, 0, sizeof(_players)); |
|
528 |
for(i = 0; i != MAX_PLAYERS; i++) |
|
529 |
_players[i].index=i; |
|
530 |
_cur_player_tick_index = 0; |
|
531 |
} |
|
532 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
533 |
void OnTick_Players(void) |
0 | 534 |
{ |
535 |
Player *p; |
|
536 |
||
537 |
if (_game_mode == GM_EDITOR) |
|
538 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
539 |
|
0 | 540 |
p = DEREF_PLAYER(_cur_player_tick_index); |
541 |
_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS; |
|
542 |
if (p->name_1 != 0) GenerateCompanyName(p); |
|
543 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
544 |
if (!_networking && _game_mode != GM_MENU && !--_next_competitor_start) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
545 |
MaybeStartNewPlayer(); |
0 | 546 |
} |
547 |
} |
|
548 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
549 |
void RunOtherPlayersLoop(void) |
0 | 550 |
{ |
551 |
Player *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
552 |
|
0 | 553 |
_is_ai_player = true; |
554 |
||
555 |
FOR_ALL_PLAYERS(p) { |
|
206 | 556 |
if (p->is_active && p->is_ai) { |
0 | 557 |
_current_player = p->index; |
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
558 |
if (_patches.ainew_active) |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
559 |
AiNewDoGameLoop(p); |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
560 |
else |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
561 |
AiDoGameLoop(p); |
0 | 562 |
} |
563 |
} |
|
564 |
||
565 |
_is_ai_player = false; |
|
206 | 566 |
_current_player = OWNER_NONE; |
0 | 567 |
} |
568 |
||
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
569 |
// index is the next parameter in _decode_parameters to set up |
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
570 |
StringID GetPlayerNameString(byte player, byte index) |
0 | 571 |
{ |
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
572 |
if (IS_HUMAN_PLAYER(player) && player < MAX_PLAYERS) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
573 |
SetDParam(index, player+1); |
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
574 |
return STR_7002_PLAYER; |
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
575 |
} |
0 | 576 |
return STR_EMPTY; |
577 |
} |
|
578 |
||
579 |
extern void ShowPlayerFinances(int player); |
|
580 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
581 |
void PlayersYearlyLoop(void) |
0 | 582 |
{ |
583 |
Player *p; |
|
584 |
||
585 |
// Copy statistics |
|
586 |
FOR_ALL_PLAYERS(p) { |
|
587 |
if (p->is_active) { |
|
588 |
memmove(&p->yearly_expenses[1], &p->yearly_expenses[0], sizeof(p->yearly_expenses) - sizeof(p->yearly_expenses[0])); |
|
589 |
memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0])); |
|
590 |
InvalidateWindow(WC_FINANCES, p->index); |
|
591 |
} |
|
592 |
} |
|
593 |
||
1 | 594 |
if (_patches.show_finances && _local_player != OWNER_SPECTATOR) { |
0 | 595 |
ShowPlayerFinances(_local_player); |
596 |
p = DEREF_PLAYER(_local_player); |
|
597 |
if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) { |
|
541 | 598 |
SndPlayFx(SND_01_BAD_YEAR); |
0 | 599 |
} else { |
541 | 600 |
SndPlayFx(SND_00_GOOD_YEAR); |
0 | 601 |
} |
602 |
} |
|
603 |
} |
|
604 |
||
605 |
void DeletePlayerWindows(int pi) |
|
606 |
{ |
|
607 |
DeleteWindowById(WC_COMPANY, pi); |
|
608 |
DeleteWindowById(WC_FINANCES, pi); |
|
609 |
DeleteWindowById(WC_STATION_LIST, pi); |
|
610 |
DeleteWindowById(WC_TRAINS_LIST, pi); |
|
611 |
DeleteWindowById(WC_ROADVEH_LIST, pi); |
|
612 |
DeleteWindowById(WC_SHIPS_LIST, pi); |
|
613 |
DeleteWindowById(WC_AIRCRAFT_LIST, pi); |
|
614 |
DeleteWindowById(WC_BUY_COMPANY, pi); |
|
615 |
} |
|
616 |
||
617 |
static void DeletePlayerStuff(int pi) |
|
618 |
{ |
|
619 |
Player *p; |
|
620 |
||
621 |
DeletePlayerWindows(pi); |
|
622 |
p = DEREF_PLAYER(pi); |
|
623 |
DeleteName(p->name_1); |
|
624 |
DeleteName(p->president_name_1); |
|
625 |
p->name_1 = 0; |
|
626 |
p->president_name_1 = 0; |
|
627 |
} |
|
628 |
||
629 |
// functionality. |
|
630 |
// 0 - make new player |
|
631 |
// 1 - make new AI player |
|
688
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
632 |
// 2 - delete player (p2) |
0 | 633 |
// 3 - join player (p1 >> 8) & 0xFF with (p1 >> 16) & 0xFF |
634 |
int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
635 |
{ |
|
636 |
int pi; |
|
637 |
Player *p; |
|
638 |
||
639 |
if (!(flags & DC_EXEC)) |
|
640 |
return 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
641 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
642 |
_current_player = OWNER_NONE; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
643 |
|
0 | 644 |
switch(p1 & 0xff) { |
645 |
case 0: // make new player |
|
646 |
p = DoStartupNewPlayer(false); |
|
670
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
647 |
|
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
648 |
#ifdef ENABLE_NETWORK |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
649 |
if (_networking && !_network_server && _local_player == OWNER_SPECTATOR) |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
650 |
/* In case we are a client joining a server... */ |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
651 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
652 |
#endif /* ENABLE_NETWORK */ |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
653 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
654 |
if (p != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
655 |
if (_local_player == OWNER_SPECTATOR) { |
717
ca707fc756ed
(svn r1169) -Fix: [Network] [ 1087591 ] When you want to be a spectator, you now
truelight
parents:
690
diff
changeset
|
656 |
/* Check if we do not want to be a spectator in network */ |
ca707fc756ed
(svn r1169) -Fix: [Network] [ 1087591 ] When you want to be a spectator, you now
truelight
parents:
690
diff
changeset
|
657 |
if (!_networking || _network_server || _network_playas != OWNER_SPECTATOR) { |
ca707fc756ed
(svn r1169) -Fix: [Network] [ 1087591 ] When you want to be a spectator, you now
truelight
parents:
690
diff
changeset
|
658 |
_local_player = p->index; |
ca707fc756ed
(svn r1169) -Fix: [Network] [ 1087591 ] When you want to be a spectator, you now
truelight
parents:
690
diff
changeset
|
659 |
MarkWholeScreenDirty(); |
ca707fc756ed
(svn r1169) -Fix: [Network] [ 1087591 ] When you want to be a spectator, you now
truelight
parents:
690
diff
changeset
|
660 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
661 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
662 |
#ifdef ENABLE_NETWORK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
663 |
if (_network_server) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
664 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
665 |
// UGLY! p2 is mis-used to fetch the client-id |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
666 |
ci = &_network_client_info[p2]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
667 |
ci->client_playas = p->index + 1; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
668 |
NetworkUpdateClientInfo(ci->client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
669 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
670 |
if (ci->client_playas != 0 && ci->client_playas <= MAX_PLAYERS) { |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
688
diff
changeset
|
671 |
_network_player_info[p->index].months_empty = 0; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
688
diff
changeset
|
672 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
673 |
memcpy(_decode_parameters, ci->client_name, 32); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
674 |
/* XXX - What are the consequents of this? It is needed, but is it bad? */ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
675 |
_docommand_recursive = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
676 |
DoCommandP(0, ci->client_playas-1, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
677 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
678 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
679 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
680 |
if (_network_server) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
681 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
682 |
// UGLY! p2 is mis-used to fetch the client-id |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
683 |
ci = &_network_client_info[p2]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
684 |
ci->client_playas = OWNER_SPECTATOR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
685 |
NetworkUpdateClientInfo(ci->client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
686 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
687 |
#endif /* ENABLE_NETWORK */ |
0 | 688 |
} |
689 |
break; |
|
690 |
case 1: // make new ai player |
|
691 |
DoStartupNewPlayer(true); |
|
692 |
break; |
|
693 |
case 2: // delete player |
|
688
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
694 |
p = DEREF_PLAYER(p2); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
695 |
|
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
696 |
/* Only allow removal of HUMAN companies */ |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
697 |
if (IS_HUMAN_PLAYER(p2)) { |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
698 |
/* Delete any open window of the company */ |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
699 |
DeletePlayerWindows(p2); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
700 |
|
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
701 |
/* Show the bankrupt news */ |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
702 |
SetDParam(0, p->name_1); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
703 |
SetDParam(1, p->name_2); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
704 |
AddNewsItem( (StringID)(p2 + 16*3), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
705 |
|
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
706 |
/* Remove the company */ |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
707 |
ChangeOwnershipOfPlayerItems(p2, 255); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
708 |
p->money64 = p->player_money = 100000000; |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
709 |
p->is_active = false; |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
710 |
} |
0 | 711 |
break; |
712 |
||
713 |
case 3: // join player |
|
714 |
pi = (byte)(p1 >> 8); |
|
715 |
ChangeOwnershipOfPlayerItems(pi, (byte)(p1 >> 16)); |
|
716 |
DeletePlayerStuff(pi); |
|
717 |
break; |
|
718 |
} |
|
719 |
||
720 |
||
721 |
return 0; |
|
722 |
} |
|
723 |
||
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
724 |
static const StringID _endgame_performance_titles[16] = { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
725 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
726 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
727 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
728 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
729 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
730 |
STR_0214_ENTREPRENEUR, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
731 |
STR_0214_ENTREPRENEUR, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
732 |
STR_0215_INDUSTRIALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
733 |
STR_0215_INDUSTRIALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
734 |
STR_0216_CAPITALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
735 |
STR_0216_CAPITALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
736 |
STR_0217_MAGNATE, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
737 |
STR_0217_MAGNATE, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
738 |
STR_0218_MOGUL, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
739 |
STR_0218_MOGUL, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
740 |
STR_0219_TYCOON_OF_THE_CENTURY, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
741 |
}; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
742 |
|
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
743 |
StringID EndGameGetPerformanceTitleFromValue(uint value) |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
744 |
{ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
745 |
return _endgame_performance_titles[minu(value, 1000) >> 6]; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
746 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
747 |
|
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
748 |
/* Return true if any cheat has been used, false otherwise */ |
1021
d5738de2b051
(svn r1522) -Fix: warning players.c; forgot return type. Damn, makefile is too strict ;) (Thx Tron)
darkvater
parents:
1019
diff
changeset
|
749 |
static bool CheatHasBeenUsed(void) |
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
750 |
{ |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
751 |
const Cheat* cht = (Cheat*) &_cheats; |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
752 |
const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)]; |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
753 |
|
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
754 |
for (; cht != cht_last; cht++) { |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
755 |
if (cht->been_used) |
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
756 |
return true; |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
757 |
} |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
758 |
|
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
759 |
return false; |
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
760 |
} |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
761 |
|
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
762 |
/* Save the highscore for the player */ |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
763 |
int8 SaveHighScoreValue(const Player *p) |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
764 |
{ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
765 |
HighScore *hs = _highscore_table[_opt.diff_level]; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
766 |
uint i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
767 |
uint16 score = p->old_economy[0].performance_history; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
768 |
|
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
769 |
/* Exclude cheaters from the honour of being in the highscore table */ |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
770 |
if (CheatHasBeenUsed()) |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
771 |
return -1; |
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
772 |
|
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
773 |
for (i = 0; i < lengthof(_highscore_table[0]); i++) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
774 |
/* You are in the TOP5. Move all values one down and save us there */ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
775 |
if (hs[i].score <= score) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
776 |
byte buf[sizeof(hs[i].company)]; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
777 |
|
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
778 |
// move all elements one down starting from the replaced one |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
779 |
memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1)); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
780 |
SetDParam(0, p->president_name_1); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
781 |
SetDParam(1, p->president_name_2); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
782 |
SetDParam(2, p->name_1); |
1017
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1016
diff
changeset
|
783 |
SetDParam(3, p->name_2); |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
784 |
GetString(buf, STR_HIGHSCORE_NAME); // get manager/company name string |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
785 |
ttd_strlcpy(hs[i].company, buf, sizeof(buf)); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
786 |
hs[i].score = score; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
787 |
hs[i].title = EndGameGetPerformanceTitleFromValue(score); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
788 |
return i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
789 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
790 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
791 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
792 |
return -1; // too bad; we did not make it into the top5 |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
793 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
794 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
795 |
/* Sort all players given their performance */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
796 |
static int CDECL HighScoreSorter(const void *a, const void *b) |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
797 |
{ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
798 |
const Player *pa = *(const Player* const*)a; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
799 |
const Player *pb = *(const Player* const*)b; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
800 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
801 |
return pb->old_economy[0].performance_history - pa->old_economy[0].performance_history; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
802 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
803 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
804 |
/* Save the highscores in a network game when it has ended */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
805 |
#define LAST_HS_ITEM lengthof(_highscore_table) - 1 |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
806 |
int8 SaveHighScoreValueNetwork(void) |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
807 |
{ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
808 |
Player *p, *player_sort[MAX_PLAYERS]; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
809 |
size_t count = 0; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
810 |
int8 player = -1; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
811 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
812 |
/* Sort all active players with the highest score first */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
813 |
FOR_ALL_PLAYERS(p) { |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
814 |
if (p->is_active) |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
815 |
player_sort[count++] = p; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
816 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
817 |
qsort(player_sort, count, sizeof(player_sort[0]), HighScoreSorter); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
818 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
819 |
{ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
820 |
HighScore *hs; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
821 |
byte buf[sizeof(_highscore_table[0]->company)]; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
822 |
Player* const *p_cur = &player_sort[0]; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
823 |
uint8 i; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
824 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
825 |
memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
826 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
827 |
/* Copy over Top5 companies */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
828 |
for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < (uint8)count; i++) { |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
829 |
hs = &_highscore_table[LAST_HS_ITEM][i]; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
830 |
SetDParam(0, (*p_cur)->president_name_1); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
831 |
SetDParam(1, (*p_cur)->president_name_2); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
832 |
SetDParam(2, (*p_cur)->name_1); |
1017
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1016
diff
changeset
|
833 |
SetDParam(3, (*p_cur)->name_2); |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
834 |
GetString(buf, STR_HIGHSCORE_NAME); // get manager/company name string |
1017
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1016
diff
changeset
|
835 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
836 |
ttd_strlcpy(hs->company, buf, sizeof(buf)); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
837 |
hs->score = (*p_cur)->old_economy[0].performance_history; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
838 |
hs->title = EndGameGetPerformanceTitleFromValue(hs->score); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
839 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
840 |
// get the ranking of the local player |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
841 |
if ((*p_cur)->index == (int8)_local_player) |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
842 |
player = i; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
843 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
844 |
p_cur++; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
845 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
846 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
847 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
848 |
/* Add top5 players to highscore table */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
849 |
return player; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
850 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
851 |
|
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
852 |
/* Save HighScore table to file */ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
853 |
void SaveToHighScore(void) |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
854 |
{ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
855 |
FILE *fp = fopen(_highscore_file, "w"); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
856 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
857 |
if (fp != NULL) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
858 |
uint i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
859 |
HighScore *hs; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
860 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
861 |
for (i = 0; i < LAST_HS_ITEM; i++) { // don't save network highscores |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
862 |
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
863 |
/* First character is a command character, so strlen will fail on that */ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
864 |
byte length = min(sizeof(hs->company), (hs->company[0] == '\0') ? 0 : strlen(&hs->company[1]) + 1); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
865 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
866 |
fwrite(&length, sizeof(length), 1, fp); // write away string length |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
867 |
fwrite(hs->company, length, 1, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
868 |
fwrite(&hs->score, sizeof(hs->score), 1, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
869 |
fwrite(&hs->title, sizeof(hs->title), 1, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
870 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
871 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
872 |
fclose(fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
873 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
874 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
875 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
876 |
/* Initialize the highscore table to 0 and if any file exists, load in values */ |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
877 |
void LoadFromHighScore(void) |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
878 |
{ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
879 |
FILE *fp = fopen(_highscore_file, "r"); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
880 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
881 |
memset(_highscore_table, 0, sizeof(_highscore_table)); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
882 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
883 |
if (fp != NULL) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
884 |
uint i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
885 |
HighScore *hs; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
886 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
887 |
for (i = 0; i < LAST_HS_ITEM; i++) { // don't load network highscores |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
888 |
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
889 |
byte length; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
890 |
fread(&length, sizeof(length), 1, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
891 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
892 |
fread(hs->company, 1, length, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
893 |
fread(&hs->score, sizeof(hs->score), 1, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
894 |
fread(&hs->title, sizeof(hs->title), 1, fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
895 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
896 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
897 |
fclose(fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
898 |
} |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
899 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
900 |
/* Initialize end of game variable (when to show highscore chart) */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
901 |
_patches.ending_date = 2051; |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
902 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
903 |
|
0 | 904 |
// Save/load of players |
905 |
static const byte _player_desc[] = { |
|
906 |
SLE_VAR(Player,name_2, SLE_UINT32), |
|
907 |
SLE_VAR(Player,name_1, SLE_STRINGID), |
|
908 |
||
909 |
SLE_VAR(Player,president_name_1,SLE_UINT16), |
|
910 |
SLE_VAR(Player,president_name_2,SLE_UINT32), |
|
911 |
||
912 |
SLE_VAR(Player,face, SLE_UINT32), |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
913 |
|
0 | 914 |
// money was changed to a 64 bit field in savegame version 1. |
915 |
SLE_CONDVAR(Player,money64, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), |
|
916 |
SLE_CONDVAR(Player,money64, SLE_INT64, 1, 255), |
|
917 |
||
918 |
SLE_VAR(Player,current_loan, SLE_INT32), |
|
919 |
||
920 |
SLE_VAR(Player,player_color, SLE_UINT8), |
|
921 |
SLE_VAR(Player,player_money_fraction,SLE_UINT8), |
|
922 |
SLE_VAR(Player,max_railtype, SLE_UINT8), |
|
923 |
SLE_VAR(Player,block_preview, SLE_UINT8), |
|
924 |
||
925 |
SLE_VAR(Player,cargo_types, SLE_UINT16), |
|
926 |
SLE_VAR(Player,location_of_house,SLE_UINT16), |
|
927 |
SLE_VAR(Player,last_build_coordinate,SLE_UINT16), |
|
928 |
SLE_VAR(Player,inaugurated_year,SLE_UINT8), |
|
929 |
||
930 |
SLE_ARR(Player,share_owners, SLE_UINT8, 4), |
|
931 |
||
932 |
SLE_VAR(Player,num_valid_stat_ent,SLE_UINT8), |
|
933 |
||
934 |
SLE_VAR(Player,quarters_of_bankrupcy,SLE_UINT8), |
|
935 |
SLE_VAR(Player,bankrupt_asked, SLE_UINT8), |
|
936 |
SLE_VAR(Player,bankrupt_timeout,SLE_INT16), |
|
937 |
SLE_VAR(Player,bankrupt_value, SLE_INT32), |
|
938 |
||
939 |
// yearly expenses was changed to 64-bit in savegame version 2. |
|
940 |
SLE_CONDARR(Player,yearly_expenses, SLE_FILE_I32|SLE_VAR_I64, 3*13, 0, 1), |
|
941 |
SLE_CONDARR(Player,yearly_expenses, SLE_INT64, 3*13, 2, 255), |
|
942 |
||
943 |
SLE_CONDVAR(Player,is_ai, SLE_UINT8, 2, 255), |
|
944 |
SLE_CONDVAR(Player,is_active, SLE_UINT8, 4, 255), |
|
945 |
||
946 |
// reserve extra space in savegame here. (currently 64 bytes) |
|
947 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 8, 2, 255), |
|
948 |
||
949 |
SLE_END() |
|
950 |
}; |
|
951 |
||
952 |
static const byte _player_economy_desc[] = { |
|
953 |
// these were changed to 64-bit in savegame format 2 |
|
954 |
SLE_CONDVAR(PlayerEconomyEntry,income, SLE_INT32, 0, 1), |
|
955 |
SLE_CONDVAR(PlayerEconomyEntry,expenses, SLE_INT32, 0, 1), |
|
956 |
SLE_CONDVAR(PlayerEconomyEntry,company_value, SLE_INT32, 0, 1), |
|
957 |
SLE_CONDVAR(PlayerEconomyEntry,income, SLE_FILE_I64 | SLE_VAR_I32, 2, 255), |
|
958 |
SLE_CONDVAR(PlayerEconomyEntry,expenses,SLE_FILE_I64 | SLE_VAR_I32, 2, 255), |
|
959 |
SLE_CONDVAR(PlayerEconomyEntry,company_value,SLE_FILE_I64 | SLE_VAR_I32, 2, 255), |
|
960 |
||
961 |
SLE_VAR(PlayerEconomyEntry,delivered_cargo, SLE_INT32), |
|
962 |
SLE_VAR(PlayerEconomyEntry,performance_history, SLE_INT32), |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
963 |
|
0 | 964 |
SLE_END() |
965 |
}; |
|
966 |
||
967 |
static const byte _player_ai_desc[] = { |
|
968 |
SLE_VAR(PlayerAI,state, SLE_UINT8), |
|
969 |
SLE_VAR(PlayerAI,tick, SLE_UINT8), |
|
970 |
SLE_VAR(PlayerAI,state_counter, SLE_UINT16), |
|
971 |
SLE_VAR(PlayerAI,timeout_counter, SLE_UINT16), |
|
972 |
||
973 |
SLE_VAR(PlayerAI,state_mode, SLE_UINT8), |
|
974 |
SLE_VAR(PlayerAI,banned_tile_count, SLE_UINT8), |
|
975 |
SLE_VAR(PlayerAI,railtype_to_use, SLE_UINT8), |
|
976 |
||
977 |
SLE_VAR(PlayerAI,cargo_type, SLE_UINT8), |
|
978 |
SLE_VAR(PlayerAI,num_wagons, SLE_UINT8), |
|
979 |
SLE_VAR(PlayerAI,build_kind, SLE_UINT8), |
|
980 |
SLE_VAR(PlayerAI,num_build_rec, SLE_UINT8), |
|
981 |
SLE_VAR(PlayerAI,num_loco_to_build, SLE_UINT8), |
|
982 |
SLE_VAR(PlayerAI,num_want_fullload, SLE_UINT8), |
|
983 |
||
984 |
SLE_VAR(PlayerAI,route_type_mask, SLE_UINT8), |
|
985 |
||
986 |
SLE_VAR(PlayerAI,start_tile_a, SLE_UINT16), |
|
987 |
SLE_VAR(PlayerAI,cur_tile_a, SLE_UINT16), |
|
988 |
SLE_VAR(PlayerAI,start_dir_a, SLE_UINT8), |
|
989 |
SLE_VAR(PlayerAI,cur_dir_a, SLE_UINT8), |
|
990 |
||
991 |
SLE_VAR(PlayerAI,start_tile_b, SLE_UINT16), |
|
992 |
SLE_VAR(PlayerAI,cur_tile_b, SLE_UINT16), |
|
993 |
SLE_VAR(PlayerAI,start_dir_b, SLE_UINT8), |
|
994 |
SLE_VAR(PlayerAI,cur_dir_b, SLE_UINT8), |
|
995 |
||
996 |
SLE_REF(PlayerAI,cur_veh, REF_VEHICLE), |
|
997 |
||
998 |
SLE_ARR(PlayerAI,wagon_list, SLE_UINT16, 9), |
|
999 |
SLE_ARR(PlayerAI,order_list_blocks, SLE_UINT8, 20), |
|
1000 |
SLE_ARR(PlayerAI,banned_tiles, SLE_UINT16, 16), |
|
1001 |
||
1002 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 8, 2, 255), |
|
1003 |
SLE_END() |
|
1004 |
}; |
|
1005 |
||
1006 |
static const byte _player_ai_build_rec_desc[] = { |
|
1007 |
SLE_VAR(AiBuildRec,spec_tile, SLE_UINT16), |
|
1008 |
SLE_VAR(AiBuildRec,use_tile, SLE_UINT16), |
|
1009 |
SLE_VAR(AiBuildRec,rand_rng, SLE_UINT8), |
|
1010 |
SLE_VAR(AiBuildRec,cur_building_rule,SLE_UINT8), |
|
1011 |
SLE_VAR(AiBuildRec,unk6, SLE_UINT8), |
|
1012 |
SLE_VAR(AiBuildRec,unk7, SLE_UINT8), |
|
1013 |
SLE_VAR(AiBuildRec,buildcmd_a, SLE_UINT8), |
|
1014 |
SLE_VAR(AiBuildRec,buildcmd_b, SLE_UINT8), |
|
1015 |
SLE_VAR(AiBuildRec,direction, SLE_UINT8), |
|
1016 |
SLE_VAR(AiBuildRec,cargo, SLE_UINT8), |
|
1017 |
SLE_END() |
|
1018 |
}; |
|
1019 |
||
1020 |
static void SaveLoad_PLYR(Player *p) { |
|
1021 |
int i; |
|
1022 |
||
1023 |
SlObject(p, _player_desc); |
|
1024 |
||
1025 |
// Write AI? |
|
1026 |
if (!IS_HUMAN_PLAYER(p->index)) { |
|
1027 |
SlObject(&p->ai, _player_ai_desc); |
|
1028 |
for(i=0; i!=p->ai.num_build_rec; i++) |
|
1029 |
SlObject(&p->ai.src + i, _player_ai_build_rec_desc); |
|
1030 |
} |
|
1031 |
||
1032 |
// Write economy |
|
1033 |
SlObject(&p->cur_economy, _player_economy_desc); |
|
1034 |
||
1035 |
// Write old economy entries. |
|
1036 |
{ |
|
1037 |
PlayerEconomyEntry *pe; |
|
1038 |
for(i=p->num_valid_stat_ent,pe=p->old_economy; i!=0; i--,pe++) |
|
1039 |
SlObject(pe, _player_economy_desc); |
|
1040 |
} |
|
1041 |
} |
|
1042 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
1043 |
static void Save_PLYR(void) |
0 | 1044 |
{ |
1045 |
Player *p; |
|
1046 |
FOR_ALL_PLAYERS(p) { |
|
1047 |
if (p->is_active) { |
|
1048 |
SlSetArrayIndex(p->index); |
|
1049 |
SlAutolength((AutolengthProc*)SaveLoad_PLYR, p); |
|
1050 |
} |
|
1051 |
} |
|
1052 |
} |
|
1053 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1021
diff
changeset
|
1054 |
static void Load_PLYR(void) |
0 | 1055 |
{ |
1056 |
int index; |
|
1057 |
while ((index = SlIterateArray()) != -1) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
1058 |
Player *p = DEREF_PLAYER(index); |
0 | 1059 |
p->is_ai = (index != 0); |
1060 |
SaveLoad_PLYR(p); |
|
1061 |
_player_colors[index] = p->player_color; |
|
1062 |
UpdatePlayerMoney32(p); |
|
1063 |
} |
|
1064 |
} |
|
1065 |
||
1066 |
const ChunkHandler _player_chunk_handlers[] = { |
|
1067 |
{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |
|
1068 |
}; |
|
1069 |