author | truelight |
Thu, 16 Dec 2004 11:36:57 +0000 | |
changeset 688 | 1bf7db6d29b7 |
parent 679 | 04ca2cd69420 |
child 690 | 3afcad69d4f7 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
337
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
670
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "player.h" |
6 |
#include "town.h" |
|
7 |
#include "vehicle.h" |
|
8 |
#include "station.h" |
|
9 |
#include "gfx.h" |
|
10 |
#include "news.h" |
|
11 |
#include "saveload.h" |
|
12 |
#include "command.h" |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
13 |
#include "ai.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
206
diff
changeset
|
14 |
#include "sound.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
15 |
#include "network.h" |
0 | 16 |
|
17 |
extern void StartupEconomy(); |
|
18 |
||
19 |
static const SpriteID cheeks_table[4] = { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
20 |
0x325, 0x326, |
0 | 21 |
0x390, 0x3B0, |
22 |
}; |
|
23 |
||
24 |
static const SpriteID mouth_table[3] = { |
|
25 |
0x34C, 0x34D, 0x34F |
|
26 |
}; |
|
27 |
||
28 |
void DrawPlayerFace(uint32 face, int color, int x, int y) |
|
29 |
{ |
|
30 |
byte flag = 0; |
|
31 |
||
32 |
if ( (int32)face < 0) |
|
33 |
flag |= 1; |
|
34 |
if ((((((face >> 7) ^ face) >> 7) ^ face) & 0x8080000) == 0x8000000) |
|
35 |
flag |= 2; |
|
36 |
||
37 |
/* draw the gradient */ |
|
38 |
DrawSprite( (color<<16) + 0x0307836A, x, y); |
|
39 |
||
40 |
/* draw the cheeks */ |
|
41 |
DrawSprite(cheeks_table[flag&3], x, y); |
|
42 |
||
43 |
/* draw the chin */ |
|
44 |
/* FIXME: real code uses -2 in zoomlevel 1 */ |
|
45 |
{ |
|
46 |
uint val = (face >> 4) & 3; |
|
47 |
if (!(flag & 2)) { |
|
48 |
DrawSprite(0x327 + (flag&1?0:val), x, y); |
|
49 |
} else { |
|
50 |
DrawSprite((flag&1?0x3B1:0x391) + (val>>1), x, y); |
|
51 |
} |
|
52 |
} |
|
53 |
/* draw the eyes */ |
|
54 |
{ |
|
55 |
uint val1 = (face >> 6)&15; |
|
56 |
uint val2 = (face >> 20)&7; |
|
57 |
uint32 high = 0x314<<16; |
|
58 |
||
59 |
if (val2 >= 6) { |
|
60 |
high = 0x30F<<16; |
|
61 |
if (val2 != 6) |
|
62 |
high = 0x30D<<16; |
|
63 |
} |
|
64 |
||
65 |
if (!(flag & 2)) { |
|
66 |
if (!(flag & 1)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
67 |
DrawSprite(high+((val1 * 12 >> 4) + 0x832B), x, y); |
0 | 68 |
} else { |
69 |
DrawSprite(high+(val1 + 0x8337), x, y); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
70 |
} |
0 | 71 |
} else { |
72 |
if (!(flag & 1)) { |
|
73 |
DrawSprite(high+((val1 * 11 >> 4) + 0x839A), x, y); |
|
74 |
} else { |
|
75 |
DrawSprite(high+(val1 + 0x83B8), x, y); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
/* draw the mouth */ |
|
81 |
{ |
|
82 |
uint val = (face >> 10) & 63; |
|
83 |
uint val2; |
|
84 |
||
85 |
if (!(flag&1)) { |
|
86 |
val2 = ((val&0xF) * 15 >> 4); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
87 |
|
0 | 88 |
if (val2 < 3) { |
89 |
DrawSprite((flag&2 ? 0x397 : 0x367) + val2, x, y); |
|
90 |
/* skip the rest */ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
91 |
goto skip_mouth; |
0 | 92 |
} |
93 |
||
94 |
val2 -= 3; |
|
95 |
if (flag & 2) { |
|
96 |
if (val2 > 8) val2 = 0; |
|
97 |
val2 += 0x3A5 - 0x35B; |
|
98 |
} |
|
99 |
DrawSprite(val2 + 0x35B, x, y); |
|
100 |
} else if (!(flag&2)) { |
|
101 |
DrawSprite(((val&0xF) * 10 >> 4) + 0x351, x, y); |
|
102 |
} else { |
|
103 |
DrawSprite(((val&0xF) * 9 >> 4) + 0x3C8, x, y); |
|
104 |
} |
|
105 |
||
106 |
val >>= 3; |
|
107 |
||
108 |
if (!(flag&2)) { |
|
109 |
if (!(flag&1)) { |
|
110 |
DrawSprite(0x349 + val, x, y); |
|
111 |
} else { |
|
112 |
DrawSprite( mouth_table[(val*3>>3)], x, y); |
|
113 |
} |
|
114 |
} else { |
|
115 |
if (!(flag&1)) { |
|
116 |
DrawSprite(0x393 + (val&3), x, y); |
|
117 |
} else { |
|
118 |
DrawSprite(0x3B3 + (val*5>>3), x, y); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
skip_mouth:; |
|
123 |
} |
|
124 |
||
125 |
||
126 |
/* draw the hair */ |
|
127 |
{ |
|
128 |
uint val = (face >> 16) & 15; |
|
129 |
if (!(flag&2)) { |
|
130 |
if (!(flag&1)) { |
|
131 |
DrawSprite(0x382 + (val*9>>4), x, y); |
|
132 |
} else { |
|
133 |
DrawSprite(0x38B + (val*5>>4), x, y); |
|
134 |
} |
|
135 |
} else { |
|
136 |
if (!(flag&1)) { |
|
137 |
DrawSprite(0x3D4 + (val*5>>4), x, y); |
|
138 |
} else { |
|
139 |
DrawSprite(0x3D9 + (val*5>>4), x, y); |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
/* draw the tie */ |
|
145 |
{ |
|
146 |
uint val = (face >> 20) & 0xFF; |
|
147 |
||
148 |
if (!(flag&1)) { |
|
149 |
DrawSprite(0x36B + ((val&3)*3>>2), x, y); |
|
150 |
DrawSprite(0x36E + ((val>>2)&3), x, y); |
|
151 |
DrawSprite(0x372 + ((val>>4)*6>>4), x, y); |
|
152 |
} else { |
|
153 |
DrawSprite(0x378 + ((val&3)*3>>2), x, y); |
|
154 |
DrawSprite(0x37B + ((val>>2)&3), x, y); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
155 |
|
0 | 156 |
val >>= 4; |
157 |
if (val < 3) { |
|
158 |
DrawSprite((flag&2 ? 0x3D1 : 0x37F) + val, x, y); |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
/* draw the glasses */ |
|
164 |
{ |
|
165 |
uint val = (face >> 28) & 7; |
|
166 |
||
167 |
if (!(flag&2)) { |
|
168 |
if (val<=1) { |
|
169 |
DrawSprite(0x347 + val, x, y); |
|
170 |
} |
|
171 |
} else { |
|
172 |
if (val<=1) { |
|
173 |
DrawSprite(0x3AE + val, x, y); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
void InvalidatePlayerWindows(Player *p) |
|
180 |
{ |
|
181 |
uint pid = p->index; |
|
182 |
if ( (byte)pid == _local_player) |
|
183 |
InvalidateWindow(WC_STATUS_BAR, 0); |
|
184 |
||
185 |
InvalidateWindow(WC_FINANCES, pid); |
|
186 |
} |
|
187 |
||
188 |
bool CheckPlayerHasMoney(int32 cost) |
|
189 |
{ |
|
190 |
if (cost > 0) { |
|
191 |
uint pid = _current_player; |
|
192 |
if (pid < MAX_PLAYERS && cost > DEREF_PLAYER(pid)->player_money) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
193 |
SetDParam(0, cost); |
0 | 194 |
_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
195 |
return false; |
|
196 |
} |
|
197 |
} |
|
198 |
return true; |
|
199 |
} |
|
200 |
||
201 |
static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost) |
|
202 |
{ |
|
203 |
p->money64 -= cost; |
|
204 |
UpdatePlayerMoney32(p); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
205 |
|
0 | 206 |
p->yearly_expenses[0][_yearly_expenses_type] += cost; |
207 |
||
208 |
if ( ( 1 << _yearly_expenses_type ) & (1<<7|1<<8|1<<9|1<<10)) |
|
209 |
p->cur_economy.income -= cost; |
|
210 |
else if (( 1 << _yearly_expenses_type ) & (1<<2|1<<3|1<<4|1<<5|1<<6|1<<11)) |
|
211 |
p->cur_economy.expenses -= cost; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
212 |
|
0 | 213 |
InvalidatePlayerWindows(p); |
214 |
} |
|
215 |
||
216 |
void SubtractMoneyFromPlayer(int32 cost) |
|
217 |
{ |
|
218 |
uint pid = _current_player; |
|
219 |
if (pid < MAX_PLAYERS) |
|
220 |
SubtractMoneyFromAnyPlayer(DEREF_PLAYER(pid), cost); |
|
221 |
} |
|
222 |
||
223 |
void SubtractMoneyFromPlayerFract(byte player, int32 cost) |
|
224 |
{ |
|
225 |
Player *p = DEREF_PLAYER(player); |
|
226 |
byte m = p->player_money_fraction; |
|
227 |
p->player_money_fraction = m - (byte)cost; |
|
228 |
cost >>= 8; |
|
229 |
if (p->player_money_fraction > m) |
|
230 |
cost++; |
|
231 |
if (cost != 0) |
|
232 |
SubtractMoneyFromAnyPlayer(p, cost); |
|
233 |
} |
|
234 |
||
235 |
// the player_money field is kept as it is, but money64 contains the actual amount of money. |
|
236 |
void UpdatePlayerMoney32(Player *p) |
|
237 |
{ |
|
238 |
if (p->money64 < -2000000000) |
|
239 |
p->player_money = -2000000000; |
|
240 |
else if (p->money64 > 2000000000) |
|
241 |
p->player_money = 2000000000; |
|
242 |
else |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
243 |
p->player_money = (int32)p->money64; |
0 | 244 |
} |
245 |
||
246 |
void GetNameOfOwner(byte owner, uint tile) |
|
247 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
248 |
SetDParam(2, owner); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
249 |
|
0 | 250 |
if (owner != OWNER_TOWN) { |
251 |
if (owner >= 8) |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
252 |
SetDParam(0, STR_0150_SOMEONE); |
0 | 253 |
else { |
254 |
Player *p = DEREF_PLAYER(owner); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
255 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
256 |
SetDParam(1, p->name_2); |
0 | 257 |
} |
258 |
} else { |
|
259 |
Town *t = ClosestTownFromTile(tile, (uint)-1); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
260 |
SetDParam(0, t->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
261 |
SetDParam(1, t->townnameparts); |
0 | 262 |
} |
263 |
} |
|
264 |
||
265 |
||
266 |
bool CheckOwnership(byte owner) |
|
267 |
{ |
|
268 |
assert(owner <= OWNER_WATER); |
|
269 |
||
270 |
if (owner == _current_player) |
|
271 |
return true; |
|
272 |
_error_message = STR_013B_OWNED_BY; |
|
273 |
GetNameOfOwner(owner, 0); |
|
274 |
return false; |
|
275 |
} |
|
276 |
||
277 |
bool CheckTileOwnership(uint tile) |
|
278 |
{ |
|
279 |
byte owner = _map_owner[tile]; |
|
280 |
assert(owner <= OWNER_WATER); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
281 |
if (owner == _current_player) |
0 | 282 |
return true; |
283 |
_error_message = STR_013B_OWNED_BY; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
284 |
|
0 | 285 |
// no need to get the name of the owner unless we're the local player (saves some time) |
286 |
if (_current_player == _local_player) |
|
287 |
GetNameOfOwner(owner, tile); |
|
288 |
return false; |
|
289 |
} |
|
290 |
||
291 |
static void GenerateCompanyName(Player *p) |
|
292 |
{ |
|
293 |
uint tile; |
|
294 |
Town *t; |
|
295 |
StringID str; |
|
296 |
Player *pp; |
|
297 |
uint32 strp; |
|
298 |
char buffer[100]; |
|
299 |
||
300 |
if (p->name_1 != STR_SV_UNNAMED) |
|
301 |
return; |
|
302 |
||
303 |
tile = p->last_build_coordinate; |
|
304 |
if (tile == 0) |
|
305 |
return; |
|
306 |
||
307 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
308 |
||
309 |
if (IS_INT_INSIDE(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST+1)) { |
|
310 |
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; |
|
311 |
strp = t->townnameparts; |
|
312 |
||
313 |
verify_name:; |
|
314 |
// No player must have this name already |
|
315 |
FOR_ALL_PLAYERS(pp) { |
|
316 |
if (pp->name_1 == str && pp->name_2 == strp) |
|
317 |
goto bad_town_name; |
|
318 |
} |
|
319 |
||
320 |
GetString(buffer, str); |
|
321 |
if (strlen(buffer) >= 32 || GetStringWidth(buffer) >= 150) |
|
322 |
goto bad_town_name; |
|
323 |
||
324 |
set_name:; |
|
325 |
p->name_1 = str; |
|
326 |
p->name_2 = strp; |
|
327 |
||
328 |
MarkWholeScreenDirty(); |
|
329 |
||
330 |
if (!IS_HUMAN_PLAYER(p->index)) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
331 |
SetDParam(0, t->index); |
0 | 332 |
AddNewsItem(p->index + (4 << 4), NEWS_FLAGS(NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY), p->last_build_coordinate, 0); |
333 |
} |
|
334 |
return; |
|
335 |
} |
|
336 |
bad_town_name:; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
337 |
|
0 | 338 |
if (p->president_name_1 == SPECSTR_PRESIDENT_NAME) { |
339 |
str = SPECSTR_ANDCO_NAME; |
|
340 |
strp = p->president_name_2; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
341 |
goto set_name; |
0 | 342 |
} else { |
343 |
str = SPECSTR_ANDCO_NAME; |
|
344 |
strp = Random(); |
|
345 |
goto verify_name; |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
#define COLOR_SWAP(i,j) do { byte t=colors[i];colors[i]=colors[j];colors[j]=t; } while(0) |
|
350 |
||
351 |
static const byte _color_sort[16] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1}; |
|
352 |
static const byte _color_similar_1[16] = {8, 6, 255, 12, 255, 0, 1, 1, 0, 13, 11, 10, 3, 9, 15, 14}; |
|
353 |
static const byte _color_similar_2[16] = {5, 7, 255, 255, 255, 8, 7, 6, 5, 12, 255, 255, 9, 255, 255, 255}; |
|
354 |
||
355 |
static byte GeneratePlayerColor() |
|
356 |
{ |
|
357 |
byte colors[16], pcolor, t2; |
|
358 |
int i,j,n; |
|
359 |
uint32 r; |
|
360 |
Player *p; |
|
361 |
||
362 |
// Initialize array |
|
363 |
for(i=0; i!=16; i++) |
|
364 |
colors[i] = i; |
|
365 |
||
366 |
// And randomize it |
|
367 |
n = 100; |
|
368 |
do { |
|
369 |
r = Random(); |
|
370 |
COLOR_SWAP(r & 0xF, (r >> 4) & 0xF); |
|
371 |
} while (--n); |
|
372 |
||
373 |
// Bubble sort it according to the values in table 1 |
|
374 |
i = 16; |
|
375 |
do { |
|
376 |
for(j=0; j!=15; j++) { |
|
377 |
if (_color_sort[colors[j]] < _color_sort[colors[j+1]]) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
378 |
COLOR_SWAP(j,j+1); |
0 | 379 |
} |
380 |
} |
|
381 |
} while (--i); |
|
382 |
||
383 |
// Move the colors that look similar to each player's color to the side |
|
384 |
FOR_ALL_PLAYERS(p) if (p->is_active) { |
|
385 |
pcolor = p->player_color; |
|
386 |
for(i=0; i!=16; i++) if (colors[i] == pcolor) { |
|
387 |
colors[i] = 0xFF; |
|
388 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
389 |
t2 = _color_similar_1[pcolor]; |
0 | 390 |
if (t2 == 0xFF) break; |
391 |
for(i=0; i!=15; i++) { |
|
392 |
if (colors[i] == t2) { |
|
393 |
do COLOR_SWAP(i,i+1); while (++i != 15); |
|
394 |
break; |
|
395 |
} |
|
396 |
} |
|
397 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
398 |
t2 = _color_similar_2[pcolor]; |
0 | 399 |
if (t2 == 0xFF) break; |
400 |
for(i=0; i!=15; i++) { |
|
401 |
if (colors[i] == t2) { |
|
402 |
do COLOR_SWAP(i,i+1); while (++i != 15); |
|
403 |
break; |
|
404 |
} |
|
405 |
} |
|
406 |
break; |
|
407 |
} |
|
408 |
} |
|
409 |
||
410 |
// Return the first available color |
|
411 |
i = 0; |
|
412 |
for(;;) { |
|
413 |
if (colors[i] != 0xFF) |
|
414 |
return colors[i]; |
|
415 |
i++; |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
static void GeneratePresidentName(Player *p) |
|
420 |
{ |
|
421 |
Player *pp; |
|
422 |
char buffer[100], buffer2[40]; |
|
423 |
||
424 |
for(;;) { |
|
425 |
restart:; |
|
426 |
||
427 |
p->president_name_2 = Random(); |
|
428 |
p->president_name_1 = SPECSTR_PRESIDENT_NAME; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
429 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
430 |
SetDParam(0, p->president_name_2); |
0 | 431 |
GetString(buffer, p->president_name_1); |
432 |
if (strlen(buffer) >= 32 || GetStringWidth(buffer) >= 94) |
|
433 |
continue; |
|
434 |
||
435 |
FOR_ALL_PLAYERS(pp) { |
|
436 |
if (pp->is_active && p != pp) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
437 |
SetDParam(0, pp->president_name_2); |
0 | 438 |
GetString(buffer2, pp->president_name_1); |
439 |
if (str_eq(buffer2, buffer)) |
|
440 |
goto restart; |
|
441 |
} |
|
442 |
} |
|
443 |
return; |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
extern int GetPlayerMaxRailtype(int p); |
|
448 |
||
449 |
static Player *AllocatePlayer() |
|
450 |
{ |
|
451 |
Player *p; |
|
452 |
// Find a free slot |
|
453 |
FOR_ALL_PLAYERS(p) { |
|
454 |
if (!p->is_active) { |
|
455 |
int i = p->index; |
|
456 |
memset(p, 0, sizeof(Player)); |
|
457 |
p->index = i; |
|
458 |
return p; |
|
459 |
} |
|
460 |
} |
|
461 |
return NULL; |
|
462 |
} |
|
463 |
||
464 |
Player *DoStartupNewPlayer(bool is_ai) |
|
465 |
{ |
|
466 |
Player *p; |
|
467 |
int index; |
|
468 |
||
469 |
p = AllocatePlayer(); |
|
470 |
if (p == NULL) return NULL; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
471 |
|
0 | 472 |
index = p->index; |
473 |
||
474 |
// Make a color |
|
475 |
p->player_color = GeneratePlayerColor(); |
|
476 |
_player_colors[index] = p->player_color; |
|
477 |
p->name_1 = STR_SV_UNNAMED; |
|
478 |
p->is_active = true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
479 |
|
0 | 480 |
p->money64 = p->player_money = p->current_loan = 100000; |
481 |
||
482 |
p->is_ai = is_ai; |
|
483 |
p->ai.state = 5; /* AIS_WANT_NEW_ROUTE */ |
|
484 |
p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = 0xFF; |
|
485 |
||
486 |
p->max_railtype = GetPlayerMaxRailtype(index); |
|
487 |
p->inaugurated_year = _cur_year; |
|
488 |
p->face = Random(); |
|
489 |
||
490 |
GeneratePresidentName(p); |
|
491 |
||
492 |
InvalidateWindow(WC_GRAPH_LEGEND, 0); |
|
493 |
InvalidateWindow(WC_TOOLBAR_MENU, 0); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
494 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
0 | 495 |
|
496 |
return p; |
|
497 |
} |
|
498 |
||
499 |
void StartupPlayers() |
|
500 |
{ |
|
23 | 501 |
// The AI starts like in the setting with +2 month max |
165
f81fa8c27236
(svn r166) -Codechange: change 74 for constant DAY_TICKS
darkvater
parents:
84
diff
changeset
|
502 |
_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 503 |
} |
504 |
||
505 |
static void MaybeStartNewPlayer() |
|
506 |
{ |
|
507 |
uint n; |
|
508 |
Player *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
509 |
|
0 | 510 |
// count number of competitors |
511 |
n = 0; |
|
512 |
for(p=_players; p!=endof(_players); p++) |
|
513 |
if (p->is_active && p->is_ai) |
|
514 |
n++; |
|
515 |
||
516 |
// when there's a lot of computers in game, the probability that a new one starts is lower |
|
23 | 517 |
if (n < (uint)_opt.diff.max_no_competitors && n < RandomRange(_opt.diff.max_no_competitors + 2)) |
0 | 518 |
DoStartupNewPlayer(true); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
519 |
|
23 | 520 |
// The next AI starts like the difficulty setting said, with +2 month max |
165
f81fa8c27236
(svn r166) -Codechange: change 74 for constant DAY_TICKS
darkvater
parents:
84
diff
changeset
|
521 |
_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 522 |
} |
523 |
||
524 |
void InitializePlayers() |
|
525 |
{ |
|
526 |
int i; |
|
527 |
memset(_players, 0, sizeof(_players)); |
|
528 |
for(i = 0; i != MAX_PLAYERS; i++) |
|
529 |
_players[i].index=i; |
|
530 |
_cur_player_tick_index = 0; |
|
531 |
} |
|
532 |
||
533 |
void OnTick_Players() |
|
534 |
{ |
|
535 |
Player *p; |
|
536 |
||
537 |
if (_game_mode == GM_EDITOR) |
|
538 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
539 |
|
0 | 540 |
p = DEREF_PLAYER(_cur_player_tick_index); |
541 |
_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS; |
|
542 |
if (p->name_1 != 0) GenerateCompanyName(p); |
|
543 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
544 |
if (!_networking && _game_mode != GM_MENU && !--_next_competitor_start) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
545 |
MaybeStartNewPlayer(); |
0 | 546 |
} |
547 |
} |
|
548 |
||
549 |
void RunOtherPlayersLoop() |
|
550 |
{ |
|
551 |
Player *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
552 |
|
0 | 553 |
_is_ai_player = true; |
554 |
||
555 |
FOR_ALL_PLAYERS(p) { |
|
206 | 556 |
if (p->is_active && p->is_ai) { |
0 | 557 |
_current_player = p->index; |
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
558 |
if (_patches.ainew_active) |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
559 |
AiNewDoGameLoop(p); |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
560 |
else |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
23
diff
changeset
|
561 |
AiDoGameLoop(p); |
0 | 562 |
} |
563 |
} |
|
564 |
||
565 |
_is_ai_player = false; |
|
206 | 566 |
_current_player = OWNER_NONE; |
0 | 567 |
} |
568 |
||
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
569 |
// index is the next parameter in _decode_parameters to set up |
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
570 |
StringID GetPlayerNameString(byte player, byte index) |
0 | 571 |
{ |
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
572 |
if (IS_HUMAN_PLAYER(player) && player < MAX_PLAYERS) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
573 |
SetDParam(index, player+1); |
2
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
574 |
return STR_7002_PLAYER; |
104b2984cd3e
(svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents:
1
diff
changeset
|
575 |
} |
0 | 576 |
return STR_EMPTY; |
577 |
} |
|
578 |
||
579 |
extern void ShowPlayerFinances(int player); |
|
580 |
||
581 |
void PlayersYearlyLoop() |
|
582 |
{ |
|
583 |
Player *p; |
|
584 |
||
585 |
// Copy statistics |
|
586 |
FOR_ALL_PLAYERS(p) { |
|
587 |
if (p->is_active) { |
|
588 |
memmove(&p->yearly_expenses[1], &p->yearly_expenses[0], sizeof(p->yearly_expenses) - sizeof(p->yearly_expenses[0])); |
|
589 |
memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0])); |
|
590 |
InvalidateWindow(WC_FINANCES, p->index); |
|
591 |
} |
|
592 |
} |
|
593 |
||
1 | 594 |
if (_patches.show_finances && _local_player != OWNER_SPECTATOR) { |
0 | 595 |
ShowPlayerFinances(_local_player); |
596 |
p = DEREF_PLAYER(_local_player); |
|
597 |
if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) { |
|
541 | 598 |
SndPlayFx(SND_01_BAD_YEAR); |
0 | 599 |
} else { |
541 | 600 |
SndPlayFx(SND_00_GOOD_YEAR); |
0 | 601 |
} |
602 |
} |
|
603 |
} |
|
604 |
||
605 |
void DeletePlayerWindows(int pi) |
|
606 |
{ |
|
607 |
DeleteWindowById(WC_COMPANY, pi); |
|
608 |
DeleteWindowById(WC_FINANCES, pi); |
|
609 |
DeleteWindowById(WC_STATION_LIST, pi); |
|
610 |
DeleteWindowById(WC_TRAINS_LIST, pi); |
|
611 |
DeleteWindowById(WC_ROADVEH_LIST, pi); |
|
612 |
DeleteWindowById(WC_SHIPS_LIST, pi); |
|
613 |
DeleteWindowById(WC_AIRCRAFT_LIST, pi); |
|
614 |
DeleteWindowById(WC_BUY_COMPANY, pi); |
|
615 |
} |
|
616 |
||
617 |
static void DeletePlayerStuff(int pi) |
|
618 |
{ |
|
619 |
Player *p; |
|
620 |
||
621 |
DeletePlayerWindows(pi); |
|
622 |
p = DEREF_PLAYER(pi); |
|
623 |
DeleteName(p->name_1); |
|
624 |
DeleteName(p->president_name_1); |
|
625 |
p->name_1 = 0; |
|
626 |
p->president_name_1 = 0; |
|
627 |
} |
|
628 |
||
629 |
// functionality. |
|
630 |
// 0 - make new player |
|
631 |
// 1 - make new AI player |
|
688
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
632 |
// 2 - delete player (p2) |
0 | 633 |
// 3 - join player (p1 >> 8) & 0xFF with (p1 >> 16) & 0xFF |
634 |
int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
635 |
{ |
|
636 |
int pi; |
|
637 |
Player *p; |
|
638 |
||
639 |
if (!(flags & DC_EXEC)) |
|
640 |
return 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
641 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
642 |
_current_player = OWNER_NONE; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
643 |
|
0 | 644 |
switch(p1 & 0xff) { |
645 |
case 0: // make new player |
|
646 |
p = DoStartupNewPlayer(false); |
|
670
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
647 |
|
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
648 |
#ifdef ENABLE_NETWORK |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
649 |
if (_networking && !_network_server && _local_player == OWNER_SPECTATOR) |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
650 |
/* In case we are a client joining a server... */ |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
651 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
652 |
#endif /* ENABLE_NETWORK */ |
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
653 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
654 |
if (p != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
655 |
if (_local_player == OWNER_SPECTATOR) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
656 |
_local_player = p->index; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
657 |
MarkWholeScreenDirty(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
658 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
659 |
#ifdef ENABLE_NETWORK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
660 |
if (_network_server) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
661 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
662 |
// 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
|
663 |
ci = &_network_client_info[p2]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
664 |
ci->client_playas = p->index + 1; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
665 |
NetworkUpdateClientInfo(ci->client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
666 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
667 |
if (ci->client_playas != 0 && ci->client_playas <= MAX_PLAYERS) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
668 |
memcpy(_decode_parameters, ci->client_name, 32); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
669 |
/* 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
|
670 |
_docommand_recursive = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
671 |
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
|
672 |
} |
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 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
675 |
if (_network_server) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
676 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
677 |
// 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
|
678 |
ci = &_network_client_info[p2]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
679 |
ci->client_playas = OWNER_SPECTATOR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
680 |
NetworkUpdateClientInfo(ci->client_index); |
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 |
#endif /* ENABLE_NETWORK */ |
0 | 683 |
} |
684 |
break; |
|
685 |
case 1: // make new ai player |
|
686 |
DoStartupNewPlayer(true); |
|
687 |
break; |
|
688 |
case 2: // delete player |
|
688
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
689 |
p = DEREF_PLAYER(p2); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
690 |
|
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
691 |
/* 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
|
692 |
if (IS_HUMAN_PLAYER(p2)) { |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
693 |
/* 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
|
694 |
DeletePlayerWindows(p2); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
695 |
|
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
696 |
/* Show the bankrupt news */ |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
697 |
SetDParam(0, p->name_1); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
698 |
SetDParam(1, p->name_2); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
699 |
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
|
700 |
|
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
701 |
/* Remove the company */ |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
702 |
ChangeOwnershipOfPlayerItems(p2, 255); |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
703 |
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
|
704 |
p->is_active = false; |
1bf7db6d29b7
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
705 |
} |
0 | 706 |
break; |
707 |
||
708 |
case 3: // join player |
|
709 |
pi = (byte)(p1 >> 8); |
|
710 |
ChangeOwnershipOfPlayerItems(pi, (byte)(p1 >> 16)); |
|
711 |
DeletePlayerStuff(pi); |
|
712 |
break; |
|
713 |
} |
|
714 |
||
715 |
||
716 |
return 0; |
|
717 |
} |
|
718 |
||
719 |
// Save/load of players |
|
720 |
static const byte _player_desc[] = { |
|
721 |
SLE_VAR(Player,name_2, SLE_UINT32), |
|
722 |
SLE_VAR(Player,name_1, SLE_STRINGID), |
|
723 |
||
724 |
SLE_VAR(Player,president_name_1,SLE_UINT16), |
|
725 |
SLE_VAR(Player,president_name_2,SLE_UINT32), |
|
726 |
||
727 |
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
|
728 |
|
0 | 729 |
// money was changed to a 64 bit field in savegame version 1. |
730 |
SLE_CONDVAR(Player,money64, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), |
|
731 |
SLE_CONDVAR(Player,money64, SLE_INT64, 1, 255), |
|
732 |
||
733 |
SLE_VAR(Player,current_loan, SLE_INT32), |
|
734 |
||
735 |
SLE_VAR(Player,player_color, SLE_UINT8), |
|
736 |
SLE_VAR(Player,player_money_fraction,SLE_UINT8), |
|
737 |
SLE_VAR(Player,max_railtype, SLE_UINT8), |
|
738 |
SLE_VAR(Player,block_preview, SLE_UINT8), |
|
739 |
||
740 |
SLE_VAR(Player,cargo_types, SLE_UINT16), |
|
741 |
SLE_VAR(Player,location_of_house,SLE_UINT16), |
|
742 |
SLE_VAR(Player,last_build_coordinate,SLE_UINT16), |
|
743 |
SLE_VAR(Player,inaugurated_year,SLE_UINT8), |
|
744 |
||
745 |
SLE_ARR(Player,share_owners, SLE_UINT8, 4), |
|
746 |
||
747 |
SLE_VAR(Player,num_valid_stat_ent,SLE_UINT8), |
|
748 |
||
749 |
SLE_VAR(Player,quarters_of_bankrupcy,SLE_UINT8), |
|
750 |
SLE_VAR(Player,bankrupt_asked, SLE_UINT8), |
|
751 |
SLE_VAR(Player,bankrupt_timeout,SLE_INT16), |
|
752 |
SLE_VAR(Player,bankrupt_value, SLE_INT32), |
|
753 |
||
754 |
// yearly expenses was changed to 64-bit in savegame version 2. |
|
755 |
SLE_CONDARR(Player,yearly_expenses, SLE_FILE_I32|SLE_VAR_I64, 3*13, 0, 1), |
|
756 |
SLE_CONDARR(Player,yearly_expenses, SLE_INT64, 3*13, 2, 255), |
|
757 |
||
758 |
SLE_CONDVAR(Player,is_ai, SLE_UINT8, 2, 255), |
|
759 |
SLE_CONDVAR(Player,is_active, SLE_UINT8, 4, 255), |
|
760 |
||
761 |
// reserve extra space in savegame here. (currently 64 bytes) |
|
762 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 8, 2, 255), |
|
763 |
||
764 |
SLE_END() |
|
765 |
}; |
|
766 |
||
767 |
static const byte _player_economy_desc[] = { |
|
768 |
// these were changed to 64-bit in savegame format 2 |
|
769 |
SLE_CONDVAR(PlayerEconomyEntry,income, SLE_INT32, 0, 1), |
|
770 |
SLE_CONDVAR(PlayerEconomyEntry,expenses, SLE_INT32, 0, 1), |
|
771 |
SLE_CONDVAR(PlayerEconomyEntry,company_value, SLE_INT32, 0, 1), |
|
772 |
SLE_CONDVAR(PlayerEconomyEntry,income, SLE_FILE_I64 | SLE_VAR_I32, 2, 255), |
|
773 |
SLE_CONDVAR(PlayerEconomyEntry,expenses,SLE_FILE_I64 | SLE_VAR_I32, 2, 255), |
|
774 |
SLE_CONDVAR(PlayerEconomyEntry,company_value,SLE_FILE_I64 | SLE_VAR_I32, 2, 255), |
|
775 |
||
776 |
SLE_VAR(PlayerEconomyEntry,delivered_cargo, SLE_INT32), |
|
777 |
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
|
778 |
|
0 | 779 |
SLE_END() |
780 |
}; |
|
781 |
||
782 |
static const byte _player_ai_desc[] = { |
|
783 |
SLE_VAR(PlayerAI,state, SLE_UINT8), |
|
784 |
SLE_VAR(PlayerAI,tick, SLE_UINT8), |
|
785 |
SLE_VAR(PlayerAI,state_counter, SLE_UINT16), |
|
786 |
SLE_VAR(PlayerAI,timeout_counter, SLE_UINT16), |
|
787 |
||
788 |
SLE_VAR(PlayerAI,state_mode, SLE_UINT8), |
|
789 |
SLE_VAR(PlayerAI,banned_tile_count, SLE_UINT8), |
|
790 |
SLE_VAR(PlayerAI,railtype_to_use, SLE_UINT8), |
|
791 |
||
792 |
SLE_VAR(PlayerAI,cargo_type, SLE_UINT8), |
|
793 |
SLE_VAR(PlayerAI,num_wagons, SLE_UINT8), |
|
794 |
SLE_VAR(PlayerAI,build_kind, SLE_UINT8), |
|
795 |
SLE_VAR(PlayerAI,num_build_rec, SLE_UINT8), |
|
796 |
SLE_VAR(PlayerAI,num_loco_to_build, SLE_UINT8), |
|
797 |
SLE_VAR(PlayerAI,num_want_fullload, SLE_UINT8), |
|
798 |
||
799 |
SLE_VAR(PlayerAI,route_type_mask, SLE_UINT8), |
|
800 |
||
801 |
SLE_VAR(PlayerAI,start_tile_a, SLE_UINT16), |
|
802 |
SLE_VAR(PlayerAI,cur_tile_a, SLE_UINT16), |
|
803 |
SLE_VAR(PlayerAI,start_dir_a, SLE_UINT8), |
|
804 |
SLE_VAR(PlayerAI,cur_dir_a, SLE_UINT8), |
|
805 |
||
806 |
SLE_VAR(PlayerAI,start_tile_b, SLE_UINT16), |
|
807 |
SLE_VAR(PlayerAI,cur_tile_b, SLE_UINT16), |
|
808 |
SLE_VAR(PlayerAI,start_dir_b, SLE_UINT8), |
|
809 |
SLE_VAR(PlayerAI,cur_dir_b, SLE_UINT8), |
|
810 |
||
811 |
SLE_REF(PlayerAI,cur_veh, REF_VEHICLE), |
|
812 |
||
813 |
SLE_ARR(PlayerAI,wagon_list, SLE_UINT16, 9), |
|
814 |
SLE_ARR(PlayerAI,order_list_blocks, SLE_UINT8, 20), |
|
815 |
SLE_ARR(PlayerAI,banned_tiles, SLE_UINT16, 16), |
|
816 |
||
817 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 8, 2, 255), |
|
818 |
SLE_END() |
|
819 |
}; |
|
820 |
||
821 |
static const byte _player_ai_build_rec_desc[] = { |
|
822 |
SLE_VAR(AiBuildRec,spec_tile, SLE_UINT16), |
|
823 |
SLE_VAR(AiBuildRec,use_tile, SLE_UINT16), |
|
824 |
SLE_VAR(AiBuildRec,rand_rng, SLE_UINT8), |
|
825 |
SLE_VAR(AiBuildRec,cur_building_rule,SLE_UINT8), |
|
826 |
SLE_VAR(AiBuildRec,unk6, SLE_UINT8), |
|
827 |
SLE_VAR(AiBuildRec,unk7, SLE_UINT8), |
|
828 |
SLE_VAR(AiBuildRec,buildcmd_a, SLE_UINT8), |
|
829 |
SLE_VAR(AiBuildRec,buildcmd_b, SLE_UINT8), |
|
830 |
SLE_VAR(AiBuildRec,direction, SLE_UINT8), |
|
831 |
SLE_VAR(AiBuildRec,cargo, SLE_UINT8), |
|
832 |
SLE_END() |
|
833 |
}; |
|
834 |
||
835 |
static void SaveLoad_PLYR(Player *p) { |
|
836 |
int i; |
|
837 |
||
838 |
SlObject(p, _player_desc); |
|
839 |
||
840 |
// Write AI? |
|
841 |
if (!IS_HUMAN_PLAYER(p->index)) { |
|
842 |
SlObject(&p->ai, _player_ai_desc); |
|
843 |
for(i=0; i!=p->ai.num_build_rec; i++) |
|
844 |
SlObject(&p->ai.src + i, _player_ai_build_rec_desc); |
|
845 |
} |
|
846 |
||
847 |
// Write economy |
|
848 |
SlObject(&p->cur_economy, _player_economy_desc); |
|
849 |
||
850 |
// Write old economy entries. |
|
851 |
{ |
|
852 |
PlayerEconomyEntry *pe; |
|
853 |
for(i=p->num_valid_stat_ent,pe=p->old_economy; i!=0; i--,pe++) |
|
854 |
SlObject(pe, _player_economy_desc); |
|
855 |
} |
|
856 |
} |
|
857 |
||
858 |
static void Save_PLYR() |
|
859 |
{ |
|
860 |
Player *p; |
|
861 |
FOR_ALL_PLAYERS(p) { |
|
862 |
if (p->is_active) { |
|
863 |
SlSetArrayIndex(p->index); |
|
864 |
SlAutolength((AutolengthProc*)SaveLoad_PLYR, p); |
|
865 |
} |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
static void Load_PLYR() |
|
870 |
{ |
|
871 |
int index; |
|
872 |
while ((index = SlIterateArray()) != -1) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
873 |
Player *p = DEREF_PLAYER(index); |
0 | 874 |
p->is_ai = (index != 0); |
875 |
SaveLoad_PLYR(p); |
|
876 |
_player_colors[index] = p->player_color; |
|
877 |
UpdatePlayerMoney32(p); |
|
878 |
} |
|
879 |
} |
|
880 |
||
881 |
const ChunkHandler _player_chunk_handlers[] = { |
|
882 |
{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |
|
883 |
}; |
|
884 |