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