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