0
|
1 |
#include "stdafx.h"
|
|
2 |
#include "ttd.h"
|
|
3 |
#include "engine.h"
|
|
4 |
#include "table/engines.h"
|
|
5 |
#include "player.h"
|
|
6 |
#include "command.h"
|
|
7 |
#include "vehicle.h"
|
|
8 |
#include "news.h"
|
|
9 |
#include "saveload.h"
|
|
10 |
|
|
11 |
#define UPDATE_PLAYER_RAILTYPE(e,p) if ((byte)(e->railtype + 1) > p->max_railtype) p->max_railtype = e->railtype + 1;
|
|
12 |
|
|
13 |
enum {
|
|
14 |
ENGINE_AVAILABLE = 1,
|
|
15 |
ENGINE_INTRODUCING = 2,
|
|
16 |
ENGINE_PREVIEWING = 4,
|
|
17 |
};
|
|
18 |
|
|
19 |
/* This maps per-landscape cargo ids to globally unique cargo ids usable ie. in
|
|
20 |
* the custom GRF files. It is basically just a transcribed table from
|
|
21 |
* TTDPatch's newgrf.txt. */
|
|
22 |
byte _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO] = {
|
|
23 |
/* LT_NORMAL */ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12 },
|
|
24 |
/* LT_HILLY */ { 0, 1, 2, 3, 4, 5, 6, 7, 28, 11, 10, 12 },
|
|
25 |
/* LT_DESERT */ { 0, 16, 2, 3, 13, 5, 6, 7, 14, 15, 10, 12 },
|
|
26 |
/* LT_CANDY */ { 0, 17, 2, 18, 19, 20, 21, 22, 23, 24, 25, 26 },
|
|
27 |
// 27 is paper in temperate climate in TTDPatch
|
|
28 |
// Following can be renumbered:
|
|
29 |
// 29 is the default cargo for the purpose of spritesets
|
|
30 |
// 30 is the purchase list image (the equivalent of 0xff) for the purpose of spritesets
|
|
31 |
};
|
|
32 |
|
|
33 |
/* These two arrays provide a reverse mapping. */
|
|
34 |
byte _local_cargo_id_ctype[NUM_CID] = {
|
|
35 |
CT_PASSENGERS, CT_COAL, CT_MAIL, CT_OIL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, // 0-7
|
|
36 |
CT_IRON_ORE, CT_STEEL, CT_VALUABLES, CT_PAPER, CT_FOOD, CT_FRUIT, CT_COPPER_ORE, CT_WATER, // 8-15
|
|
37 |
CT_RUBBER, CT_SUGAR, CT_TOYS, CT_BATTERIES, CT_CANDY, CT_TOFFEE, CT_COLA, CT_COTTON_CANDY, // 16-23
|
|
38 |
CT_BUBBLES, CT_PLASTIC, CT_FIZZY_DRINKS, CT_PAPER /* unsup. */, CT_HILLY_UNUSED // 24-28
|
|
39 |
};
|
|
40 |
|
|
41 |
/* LT'th bit is set of the particular landscape if cargo available there.
|
|
42 |
* 1: LT_NORMAL, 2: LT_HILLY, 4: LT_DESERT, 8: LT_CANDY */
|
|
43 |
byte _local_cargo_id_landscape[NUM_CID] = {
|
|
44 |
15, 3, 15, 7, 3, 7, 7, 7, 1, 1, 7, 2, 7, // 0-12
|
|
45 |
4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 2, // 13-28
|
|
46 |
};
|
|
47 |
|
|
48 |
void ShowEnginePreviewWindow(int engine);
|
|
49 |
|
|
50 |
void DeleteCustomEngineNames()
|
|
51 |
{
|
|
52 |
uint i;
|
|
53 |
StringID old;
|
|
54 |
|
|
55 |
for(i=0; i!=TOTAL_NUM_ENGINES; i++) {
|
|
56 |
old = _engine_name_strings[i];
|
|
57 |
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM;
|
|
58 |
DeleteName(old);
|
|
59 |
}
|
|
60 |
|
|
61 |
_vehicle_design_names &= ~1;
|
|
62 |
}
|
|
63 |
|
|
64 |
void LoadCustomEngineNames()
|
|
65 |
{
|
|
66 |
// XXX: not done */
|
|
67 |
DEBUG(misc, 1) ("LoadCustomEngineNames: not done");
|
|
68 |
}
|
|
69 |
|
|
70 |
static void SetupEngineNames()
|
|
71 |
{
|
|
72 |
uint i;
|
|
73 |
|
|
74 |
for(i=0; i!=TOTAL_NUM_ENGINES; i++)
|
|
75 |
_engine_name_strings[i] = STR_SV_EMPTY;
|
|
76 |
|
|
77 |
DeleteCustomEngineNames();
|
|
78 |
LoadCustomEngineNames();
|
|
79 |
}
|
|
80 |
|
|
81 |
static void AdjustAvailAircraft()
|
|
82 |
{
|
|
83 |
uint16 date = _date;
|
|
84 |
byte avail = 0;
|
|
85 |
if (date >= 12784) avail |= 2; // big airport
|
|
86 |
if (date < 14610 || _patches.always_small_airport) avail |= 1; // small airport
|
|
87 |
if (date >= 15706) avail |= 4; // enable heliport
|
|
88 |
|
|
89 |
if (avail != _avail_aircraft) {
|
|
90 |
_avail_aircraft = avail;
|
|
91 |
InvalidateWindow(WC_BUILD_STATION, 0);
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
static void CalcEngineReliability(Engine *e)
|
|
96 |
{
|
|
97 |
uint age = e->age;
|
|
98 |
|
|
99 |
if (age < e->duration_phase_1) {
|
|
100 |
uint start = e->reliability_start;
|
|
101 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
|
|
102 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2) {
|
|
103 |
e->reliability = e->reliability_max;
|
|
104 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
|
|
105 |
uint max = e->reliability_max;
|
|
106 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
|
|
107 |
} else {
|
|
108 |
e->player_avail = _patches.never_expire_vehicles ? -1 : 0;
|
|
109 |
e->reliability = e->reliability_final;
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
void StartupEngines()
|
|
114 |
{
|
|
115 |
Engine *e;
|
|
116 |
const EngineInfo *ei;
|
|
117 |
uint32 r;
|
|
118 |
|
|
119 |
SetupEngineNames();
|
|
120 |
|
|
121 |
|
|
122 |
for(e=_engines, ei=_engine_info; e != endof(_engines); e++,ei++) {
|
|
123 |
e->age = 0;
|
|
124 |
e->railtype = ei->railtype_climates >> 4;
|
|
125 |
e->flags = 0;
|
|
126 |
e->player_avail = 0;
|
|
127 |
|
|
128 |
r = Random();
|
|
129 |
e->intro_date = (uint16)((r & 0x1FF) + ei->base_intro);
|
|
130 |
if (e->intro_date <= _date) {
|
|
131 |
e->age = (_date - e->intro_date) >> 5;
|
|
132 |
e->player_avail = (byte)-1;
|
|
133 |
e->flags |= ENGINE_AVAILABLE;
|
|
134 |
}
|
|
135 |
|
|
136 |
e->reliability_start = (uint16)(((r >> 16) & 0x3fff) + 0x7AE0);
|
|
137 |
r = Random();
|
|
138 |
e->reliability_max = (uint16)((r & 0x3fff) + 0xbfff);
|
|
139 |
e->reliability_final = (uint16)(((r>>16) & 0x3fff) + 0x3fff);
|
|
140 |
|
|
141 |
r = Random();
|
|
142 |
e->duration_phase_1 = (uint16)((r & 0x1F) + 7);
|
|
143 |
e->duration_phase_2 = (uint16)(((r >> 5) & 0xF) + ei->base_life * 12 - 96);
|
|
144 |
e->duration_phase_3 = (uint16)(((r >> 9) & 0x7F) + 120);
|
|
145 |
|
|
146 |
e->reliability_spd_dec = (ei->unk2&0x7F) << 2;
|
|
147 |
|
|
148 |
/* my invented flag for something that is a wagon */
|
|
149 |
if (ei->unk2 & 0x80) {
|
|
150 |
e->age = 0xFFFF;
|
|
151 |
} else {
|
|
152 |
CalcEngineReliability(e);
|
|
153 |
}
|
|
154 |
|
|
155 |
e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
|
|
156 |
|
|
157 |
// prevent certain engines from ever appearing.
|
|
158 |
if (!HASBIT(ei->railtype_climates, _opt.landscape)) {
|
|
159 |
e->flags |= ENGINE_AVAILABLE;
|
|
160 |
e->player_avail = 0;
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
AdjustAvailAircraft();
|
|
165 |
}
|
|
166 |
|
|
167 |
|
|
168 |
uint32 _engine_refit_masks[256];
|
|
169 |
|
|
170 |
|
|
171 |
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky
|
|
172 |
|
|
173 |
struct WagonOverride {
|
|
174 |
byte *train_id;
|
|
175 |
int trains;
|
|
176 |
struct SpriteSuperSet superset;
|
|
177 |
};
|
|
178 |
|
|
179 |
static struct WagonOverrides {
|
|
180 |
int overrides_count;
|
|
181 |
struct WagonOverride *overrides;
|
|
182 |
} _engine_wagon_overrides[256];
|
|
183 |
|
|
184 |
void SetWagonOverrideSprites(byte engine, struct SpriteSuperSet *superset,
|
|
185 |
byte *train_id, int trains)
|
|
186 |
{
|
|
187 |
struct WagonOverrides *wos;
|
|
188 |
struct WagonOverride *wo;
|
|
189 |
|
|
190 |
wos = &_engine_wagon_overrides[engine];
|
|
191 |
wos->overrides_count++;
|
|
192 |
wos->overrides = realloc(wos->overrides,
|
|
193 |
wos->overrides_count * sizeof(struct WagonOverride));
|
|
194 |
|
|
195 |
wo = &wos->overrides[wos->overrides_count - 1];
|
|
196 |
wo->superset = *superset;
|
|
197 |
wo->trains = trains;
|
|
198 |
wo->train_id = malloc(trains);
|
|
199 |
memcpy(wo->train_id, train_id, trains);
|
|
200 |
}
|
|
201 |
|
|
202 |
static struct SpriteSuperSet *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine)
|
|
203 |
{
|
|
204 |
struct WagonOverrides *wos = &_engine_wagon_overrides[engine];
|
|
205 |
int i;
|
|
206 |
|
|
207 |
// XXX: This could turn out to be a timesink on profiles. We could always just
|
|
208 |
// dedicate 65535 bytes for an [engine][train] trampoline.
|
|
209 |
|
|
210 |
for (i = 0; i < wos->overrides_count; i++) {
|
|
211 |
struct WagonOverride *wo = &wos->overrides[i];
|
|
212 |
int j;
|
|
213 |
|
|
214 |
for (j = 0; j < wo->trains; j++) {
|
|
215 |
if (wo->train_id[j] == overriding_engine)
|
|
216 |
return &wo->superset;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
return NULL;
|
|
220 |
}
|
|
221 |
|
|
222 |
|
|
223 |
byte _engine_original_sprites[256];
|
|
224 |
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list)
|
|
225 |
// (It isn't and shouldn't be like this in the GRF files since new cargo types
|
|
226 |
// may appear in future - however it's more convenient to store it like this in
|
|
227 |
// memory. --pasky)
|
|
228 |
static struct SpriteSuperSet _engine_custom_sprites[256][NUM_CID];
|
|
229 |
|
|
230 |
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteSuperSet *superset)
|
|
231 |
{
|
|
232 |
assert(superset->sprites_per_set == 4 || superset->sprites_per_set == 8);
|
|
233 |
_engine_custom_sprites[engine][cargo] = *superset;
|
|
234 |
}
|
|
235 |
|
|
236 |
int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo,
|
|
237 |
byte loaded, byte in_motion, byte direction)
|
|
238 |
{
|
|
239 |
struct SpriteSuperSet *superset = &_engine_custom_sprites[engine][cargo];
|
|
240 |
int totalsets, spriteset;
|
|
241 |
int r;
|
|
242 |
|
|
243 |
if (overriding_engine != 0xffff) {
|
|
244 |
struct SpriteSuperSet *overset;
|
|
245 |
|
|
246 |
overset = GetWagonOverrideSpriteSet(engine, overriding_engine);
|
|
247 |
if (overset) superset = overset;
|
|
248 |
}
|
|
249 |
|
|
250 |
if (!superset->sprites_per_set && cargo != 29) {
|
|
251 |
// This superset is empty but perhaps there'll be a default one.
|
|
252 |
superset = &_engine_custom_sprites[engine][29];
|
|
253 |
}
|
|
254 |
|
|
255 |
if (!superset->sprites_per_set) {
|
|
256 |
// This superset is empty. This function users should therefore
|
|
257 |
// look up the sprite number in _engine_original_sprites.
|
|
258 |
return 0;
|
|
259 |
}
|
|
260 |
|
|
261 |
direction %= 8;
|
|
262 |
if (superset->sprites_per_set == 4)
|
|
263 |
direction %= 4;
|
|
264 |
|
|
265 |
totalsets = in_motion ? superset->loaded_count : superset->loading_count;
|
|
266 |
|
|
267 |
// My aim here is to make it possible to visually determine absolutely
|
|
268 |
// empty and totally full vehicles. --pasky
|
|
269 |
if (loaded == 100 || totalsets == 1) { // full
|
|
270 |
spriteset = totalsets - 1;
|
|
271 |
} else if (loaded == 0 || totalsets == 2) { // empty
|
|
272 |
spriteset = 0;
|
|
273 |
} else { // something inbetween
|
|
274 |
spriteset = loaded * (totalsets - 2) / 100 + 1;
|
|
275 |
// correct possible rounding errors
|
|
276 |
if (!spriteset)
|
|
277 |
spriteset = 1;
|
|
278 |
else if (spriteset == totalsets - 1)
|
|
279 |
spriteset--;
|
|
280 |
}
|
|
281 |
|
|
282 |
r = (in_motion ? superset->loaded[spriteset] : superset->loading[spriteset]) + direction;
|
|
283 |
return r;
|
|
284 |
}
|
|
285 |
|
|
286 |
|
|
287 |
static char *_engine_custom_names[256];
|
|
288 |
|
|
289 |
void SetCustomEngineName(int engine, char *name)
|
|
290 |
{
|
|
291 |
_engine_custom_names[engine] = strdup(name);
|
|
292 |
}
|
|
293 |
|
|
294 |
StringID GetCustomEngineName(int engine)
|
|
295 |
{
|
|
296 |
if (!_engine_custom_names[engine])
|
|
297 |
return _engine_name_strings[engine];
|
|
298 |
strcpy(_userstring, _engine_custom_names[engine]);
|
|
299 |
return STR_SPEC_USERSTRING;
|
|
300 |
}
|
|
301 |
|
|
302 |
|
|
303 |
void AcceptEnginePreview(Engine *e, int player)
|
|
304 |
{
|
|
305 |
Player *p;
|
|
306 |
|
|
307 |
SETBIT(e->player_avail, player);
|
|
308 |
|
|
309 |
p = DEREF_PLAYER(player);
|
|
310 |
|
|
311 |
UPDATE_PLAYER_RAILTYPE(e,p);
|
|
312 |
|
|
313 |
e->preview_player = 0xFF;
|
|
314 |
InvalidateWindowClasses(WC_BUILD_VEHICLE);
|
|
315 |
}
|
|
316 |
|
|
317 |
void EnginesDailyLoop()
|
|
318 |
{
|
|
319 |
Engine *e;
|
|
320 |
int i,num;
|
|
321 |
Player *p;
|
|
322 |
uint mask;
|
|
323 |
int32 best_hist;
|
|
324 |
int best_player;
|
|
325 |
|
|
326 |
if (_cur_year >= 130)
|
|
327 |
return;
|
|
328 |
|
|
329 |
for(e=_engines,i=0; i!=TOTAL_NUM_ENGINES; e++,i++) {
|
|
330 |
if (e->flags & ENGINE_INTRODUCING) {
|
|
331 |
if (e->flags & ENGINE_PREVIEWING) {
|
|
332 |
if (!--e->preview_wait) {
|
|
333 |
e->flags &= ~ENGINE_PREVIEWING;
|
|
334 |
DeleteWindowById(WC_ENGINE_PREVIEW, i);
|
|
335 |
e->preview_player++;
|
|
336 |
}
|
|
337 |
} else if (e->preview_player != 0xFF) {
|
|
338 |
num = e->preview_player;
|
|
339 |
mask = 0;
|
|
340 |
do {
|
|
341 |
best_hist = -1;
|
|
342 |
best_player = -1;
|
|
343 |
FOR_ALL_PLAYERS(p) {
|
|
344 |
if (p->is_active && p->block_preview == 0 && !HASBIT(mask,p->index) &&
|
|
345 |
p->old_economy[0].performance_history > best_hist) {
|
|
346 |
best_hist = p->old_economy[0].performance_history;
|
|
347 |
best_player = p->index;
|
|
348 |
}
|
|
349 |
}
|
|
350 |
if (best_player == -1) {
|
|
351 |
e->preview_player = 0xFF;
|
|
352 |
goto next_engine;
|
|
353 |
}
|
|
354 |
mask |= (1 << best_player);
|
|
355 |
} while (--num != 0);
|
|
356 |
|
|
357 |
if (!IS_HUMAN_PLAYER(best_player)) {
|
|
358 |
/* TTDBUG: TTD has a bug here */
|
|
359 |
AcceptEnginePreview(e, best_player);
|
|
360 |
} else {
|
|
361 |
e->flags |= ENGINE_PREVIEWING;
|
|
362 |
e->preview_wait = 20;
|
|
363 |
if (IS_INTERACTIVE_PLAYER(best_player)) {
|
|
364 |
ShowEnginePreviewWindow(i);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
}
|
|
368 |
}
|
|
369 |
next_engine:;
|
|
370 |
}
|
|
371 |
}
|
|
372 |
|
|
373 |
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
374 |
{
|
|
375 |
if (flags & DC_EXEC) {
|
|
376 |
AcceptEnginePreview(&_engines[p1], _current_player);
|
|
377 |
}
|
|
378 |
return 0;
|
|
379 |
}
|
|
380 |
|
|
381 |
void NewVehicleAvailable(Engine *e)
|
|
382 |
{
|
|
383 |
Vehicle *v;
|
|
384 |
Player *p;
|
|
385 |
int index = e - _engines;
|
|
386 |
|
|
387 |
// In case the player didn't build the vehicle during the intro period,
|
|
388 |
// prevent that player from getting future intro periods for a while.
|
|
389 |
if (e->flags&ENGINE_INTRODUCING) {
|
|
390 |
FOR_ALL_PLAYERS(p) {
|
|
391 |
if (!HASBIT(e->player_avail,p->index))
|
|
392 |
continue;
|
|
393 |
|
|
394 |
for(v=_vehicles;;) {
|
|
395 |
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship ||
|
|
396 |
(v->type == VEH_Aircraft && v->subtype <= 2)) {
|
|
397 |
if (v->owner == p->index && v->engine_type == index) break;
|
|
398 |
}
|
|
399 |
if (++v == endof(_vehicles)) {
|
|
400 |
p->block_preview = 20;
|
|
401 |
break;
|
|
402 |
}
|
|
403 |
}
|
|
404 |
}
|
|
405 |
}
|
|
406 |
|
|
407 |
// Now available for all players
|
|
408 |
e->player_avail = (byte)-1;
|
|
409 |
FOR_ALL_PLAYERS(p) {
|
|
410 |
if (p->is_active)
|
|
411 |
UPDATE_PLAYER_RAILTYPE(e,p);
|
|
412 |
}
|
|
413 |
|
|
414 |
e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE;
|
|
415 |
|
|
416 |
if ((byte)index < NUM_TRAIN_ENGINES) {
|
|
417 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0);
|
|
418 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) {
|
|
419 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0);
|
|
420 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) {
|
|
421 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0);
|
|
422 |
} else {
|
|
423 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0);
|
|
424 |
}
|
|
425 |
|
|
426 |
InvalidateWindowClasses(WC_BUILD_VEHICLE);
|
|
427 |
}
|
|
428 |
|
|
429 |
void EnginesMonthlyLoop()
|
|
430 |
{
|
|
431 |
Engine *e;
|
|
432 |
|
|
433 |
if (_cur_year < 130) {
|
|
434 |
for(e=_engines; e != endof(_engines); e++) {
|
|
435 |
// Age the vehicle
|
|
436 |
if (e->flags&ENGINE_AVAILABLE && e->age != 0xFFFF) {
|
|
437 |
e->age++;
|
|
438 |
CalcEngineReliability(e);
|
|
439 |
}
|
|
440 |
|
|
441 |
if (!(e->flags & ENGINE_AVAILABLE) && (uint16)(_date - min(_date, 365)) >= e->intro_date) {
|
|
442 |
// Introduce it to all players
|
|
443 |
NewVehicleAvailable(e);
|
|
444 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) {
|
|
445 |
// Introduction date has passed.. show introducing dialog to one player.
|
|
446 |
e->flags |= ENGINE_INTRODUCING;
|
|
447 |
e->preview_player = 1; // Give to the player with the highest rating.
|
|
448 |
}
|
|
449 |
}
|
|
450 |
}
|
|
451 |
AdjustAvailAircraft();
|
|
452 |
}
|
|
453 |
|
|
454 |
int32 CmdRenameEngine(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
455 |
{
|
|
456 |
StringID str;
|
|
457 |
|
|
458 |
str = AllocateName((byte*)_decode_parameters, 0);
|
|
459 |
if (str == 0)
|
|
460 |
return CMD_ERROR;
|
|
461 |
|
|
462 |
if (flags & DC_EXEC) {
|
|
463 |
StringID old_str = _engine_name_strings[p1];
|
|
464 |
_engine_name_strings[p1] = str;
|
|
465 |
DeleteName(old_str);
|
|
466 |
_vehicle_design_names |= 3;
|
|
467 |
MarkWholeScreenDirty();
|
|
468 |
} else {
|
|
469 |
DeleteName(str);
|
|
470 |
}
|
|
471 |
|
|
472 |
return 0;
|
|
473 |
}
|
|
474 |
|
|
475 |
int GetPlayerMaxRailtype(int p)
|
|
476 |
{
|
|
477 |
Engine *e;
|
|
478 |
int rt = 0;
|
|
479 |
int i;
|
|
480 |
|
|
481 |
for(e=_engines,i=0; i!=lengthof(_engines); e++,i++) {
|
|
482 |
if (!HASBIT(e->player_avail, p))
|
|
483 |
continue;
|
|
484 |
|
|
485 |
if ((i >= 27 && i < 54) || (i >= 57 && i < 84) || (i >= 89 && i < 116))
|
|
486 |
continue;
|
|
487 |
|
|
488 |
if (rt < e->railtype)
|
|
489 |
rt = e->railtype;
|
|
490 |
}
|
|
491 |
|
|
492 |
return rt + 1;
|
|
493 |
}
|
|
494 |
|
|
495 |
|
|
496 |
static const byte _engine_desc[] = {
|
|
497 |
SLE_VAR(Engine,intro_date, SLE_UINT16),
|
|
498 |
SLE_VAR(Engine,age, SLE_UINT16),
|
|
499 |
SLE_VAR(Engine,reliability, SLE_UINT16),
|
|
500 |
SLE_VAR(Engine,reliability_spd_dec, SLE_UINT16),
|
|
501 |
SLE_VAR(Engine,reliability_start, SLE_UINT16),
|
|
502 |
SLE_VAR(Engine,reliability_max, SLE_UINT16),
|
|
503 |
SLE_VAR(Engine,reliability_final, SLE_UINT16),
|
|
504 |
SLE_VAR(Engine,duration_phase_1, SLE_UINT16),
|
|
505 |
SLE_VAR(Engine,duration_phase_2, SLE_UINT16),
|
|
506 |
SLE_VAR(Engine,duration_phase_3, SLE_UINT16),
|
|
507 |
|
|
508 |
SLE_VAR(Engine,lifelength, SLE_UINT8),
|
|
509 |
SLE_VAR(Engine,flags, SLE_UINT8),
|
|
510 |
SLE_VAR(Engine,preview_player, SLE_UINT8),
|
|
511 |
SLE_VAR(Engine,preview_wait, SLE_UINT8),
|
|
512 |
SLE_VAR(Engine,railtype, SLE_UINT8),
|
|
513 |
SLE_VAR(Engine,player_avail, SLE_UINT8),
|
|
514 |
|
|
515 |
// reserve extra space in savegame here. (currently 16 bytes)
|
|
516 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255),
|
|
517 |
|
|
518 |
SLE_END()
|
|
519 |
};
|
|
520 |
|
|
521 |
static void Save_ENGN()
|
|
522 |
{
|
|
523 |
Engine *e;
|
|
524 |
int i;
|
|
525 |
for(i=0,e=_engines; i != lengthof(_engines); i++,e++) {
|
|
526 |
SlSetArrayIndex(i);
|
|
527 |
SlObject(e, _engine_desc);
|
|
528 |
}
|
|
529 |
}
|
|
530 |
|
|
531 |
static void Load_ENGN()
|
|
532 |
{
|
|
533 |
int index;
|
|
534 |
while ((index = SlIterateArray()) != -1) {
|
|
535 |
SlObject(&_engines[index], _engine_desc);
|
|
536 |
}
|
|
537 |
}
|
|
538 |
|
|
539 |
static void LoadSave_ENGS()
|
|
540 |
{
|
|
541 |
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID);
|
|
542 |
}
|
|
543 |
|
|
544 |
const ChunkHandler _engine_chunk_handlers[] = {
|
|
545 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY},
|
|
546 |
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF | CH_LAST},
|
|
547 |
};
|
|
548 |
|
|
549 |
|
|
550 |
|