author | dominik |
Wed, 15 Sep 2004 06:51:23 +0000 | |
changeset 257 | 0ff8a2e60a0d |
parent 220 | dc1710f96b39 |
child 292 | 16c136eaffcb |
permissions | -rw-r--r-- |
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; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
127 |
|
0 | 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 |
uint32 _engine_refit_masks[256]; |
|
168 |
||
169 |
||
170 |
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky |
|
171 |
||
172 |
struct WagonOverride { |
|
173 |
byte *train_id; |
|
174 |
int trains; |
|
175 |
struct SpriteSuperSet superset; |
|
176 |
}; |
|
177 |
||
178 |
static struct WagonOverrides { |
|
179 |
int overrides_count; |
|
180 |
struct WagonOverride *overrides; |
|
181 |
} _engine_wagon_overrides[256]; |
|
182 |
||
183 |
void SetWagonOverrideSprites(byte engine, struct SpriteSuperSet *superset, |
|
184 |
byte *train_id, int trains) |
|
185 |
{ |
|
186 |
struct WagonOverrides *wos; |
|
187 |
struct WagonOverride *wo; |
|
188 |
||
189 |
wos = &_engine_wagon_overrides[engine]; |
|
190 |
wos->overrides_count++; |
|
191 |
wos->overrides = realloc(wos->overrides, |
|
192 |
wos->overrides_count * sizeof(struct WagonOverride)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
193 |
|
0 | 194 |
wo = &wos->overrides[wos->overrides_count - 1]; |
195 |
wo->superset = *superset; |
|
196 |
wo->trains = trains; |
|
197 |
wo->train_id = malloc(trains); |
|
198 |
memcpy(wo->train_id, train_id, trains); |
|
199 |
} |
|
200 |
||
201 |
static struct SpriteSuperSet *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine) |
|
202 |
{ |
|
203 |
struct WagonOverrides *wos = &_engine_wagon_overrides[engine]; |
|
204 |
int i; |
|
205 |
||
206 |
// XXX: This could turn out to be a timesink on profiles. We could always just |
|
207 |
// dedicate 65535 bytes for an [engine][train] trampoline. |
|
208 |
||
209 |
for (i = 0; i < wos->overrides_count; i++) { |
|
210 |
struct WagonOverride *wo = &wos->overrides[i]; |
|
211 |
int j; |
|
212 |
||
213 |
for (j = 0; j < wo->trains; j++) { |
|
214 |
if (wo->train_id[j] == overriding_engine) |
|
215 |
return &wo->superset; |
|
216 |
} |
|
217 |
} |
|
218 |
return NULL; |
|
219 |
} |
|
220 |
||
221 |
||
222 |
byte _engine_original_sprites[256]; |
|
223 |
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list) |
|
224 |
// (It isn't and shouldn't be like this in the GRF files since new cargo types |
|
225 |
// may appear in future - however it's more convenient to store it like this in |
|
226 |
// memory. --pasky) |
|
227 |
static struct SpriteSuperSet _engine_custom_sprites[256][NUM_CID]; |
|
228 |
||
229 |
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteSuperSet *superset) |
|
230 |
{ |
|
231 |
assert(superset->sprites_per_set == 4 || superset->sprites_per_set == 8); |
|
232 |
_engine_custom_sprites[engine][cargo] = *superset; |
|
233 |
} |
|
234 |
||
235 |
int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo, |
|
236 |
byte loaded, byte in_motion, byte direction) |
|
237 |
{ |
|
238 |
struct SpriteSuperSet *superset = &_engine_custom_sprites[engine][cargo]; |
|
239 |
int totalsets, spriteset; |
|
240 |
int r; |
|
241 |
||
242 |
if (overriding_engine != 0xffff) { |
|
243 |
struct SpriteSuperSet *overset; |
|
244 |
||
245 |
overset = GetWagonOverrideSpriteSet(engine, overriding_engine); |
|
246 |
if (overset) superset = overset; |
|
247 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
248 |
|
0 | 249 |
if (!superset->sprites_per_set && cargo != 29) { |
250 |
// This superset is empty but perhaps there'll be a default one. |
|
251 |
superset = &_engine_custom_sprites[engine][29]; |
|
252 |
} |
|
253 |
||
254 |
if (!superset->sprites_per_set) { |
|
255 |
// This superset is empty. This function users should therefore |
|
256 |
// look up the sprite number in _engine_original_sprites. |
|
257 |
return 0; |
|
258 |
} |
|
259 |
||
260 |
direction %= 8; |
|
261 |
if (superset->sprites_per_set == 4) |
|
262 |
direction %= 4; |
|
263 |
||
264 |
totalsets = in_motion ? superset->loaded_count : superset->loading_count; |
|
265 |
||
266 |
// My aim here is to make it possible to visually determine absolutely |
|
267 |
// empty and totally full vehicles. --pasky |
|
268 |
if (loaded == 100 || totalsets == 1) { // full |
|
269 |
spriteset = totalsets - 1; |
|
270 |
} else if (loaded == 0 || totalsets == 2) { // empty |
|
271 |
spriteset = 0; |
|
272 |
} else { // something inbetween |
|
273 |
spriteset = loaded * (totalsets - 2) / 100 + 1; |
|
274 |
// correct possible rounding errors |
|
275 |
if (!spriteset) |
|
276 |
spriteset = 1; |
|
277 |
else if (spriteset == totalsets - 1) |
|
278 |
spriteset--; |
|
279 |
} |
|
280 |
||
281 |
r = (in_motion ? superset->loaded[spriteset] : superset->loading[spriteset]) + direction; |
|
282 |
return r; |
|
283 |
} |
|
284 |
||
285 |
||
286 |
static char *_engine_custom_names[256]; |
|
287 |
||
288 |
void SetCustomEngineName(int engine, char *name) |
|
289 |
{ |
|
290 |
_engine_custom_names[engine] = strdup(name); |
|
291 |
} |
|
292 |
||
293 |
StringID GetCustomEngineName(int engine) |
|
294 |
{ |
|
295 |
if (!_engine_custom_names[engine]) |
|
296 |
return _engine_name_strings[engine]; |
|
297 |
strcpy(_userstring, _engine_custom_names[engine]); |
|
298 |
return STR_SPEC_USERSTRING; |
|
299 |
} |
|
300 |
||
301 |
||
302 |
void AcceptEnginePreview(Engine *e, int player) |
|
303 |
{ |
|
304 |
Player *p; |
|
305 |
||
306 |
SETBIT(e->player_avail, player); |
|
307 |
||
308 |
p = DEREF_PLAYER(player); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
309 |
|
0 | 310 |
UPDATE_PLAYER_RAILTYPE(e,p); |
311 |
||
312 |
e->preview_player = 0xFF; |
|
313 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
|
314 |
} |
|
315 |
||
316 |
void EnginesDailyLoop() |
|
317 |
{ |
|
318 |
Engine *e; |
|
319 |
int i,num; |
|
320 |
Player *p; |
|
321 |
uint mask; |
|
322 |
int32 best_hist; |
|
323 |
int best_player; |
|
324 |
||
325 |
if (_cur_year >= 130) |
|
326 |
return; |
|
327 |
||
328 |
for(e=_engines,i=0; i!=TOTAL_NUM_ENGINES; e++,i++) { |
|
329 |
if (e->flags & ENGINE_INTRODUCING) { |
|
330 |
if (e->flags & ENGINE_PREVIEWING) { |
|
331 |
if (!--e->preview_wait) { |
|
332 |
e->flags &= ~ENGINE_PREVIEWING; |
|
333 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
|
334 |
e->preview_player++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
335 |
} |
0 | 336 |
} else if (e->preview_player != 0xFF) { |
337 |
num = e->preview_player; |
|
338 |
mask = 0; |
|
339 |
do { |
|
340 |
best_hist = -1; |
|
341 |
best_player = -1; |
|
342 |
FOR_ALL_PLAYERS(p) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
343 |
if (p->is_active && p->block_preview == 0 && !HASBIT(mask,p->index) && |
0 | 344 |
p->old_economy[0].performance_history > best_hist) { |
345 |
best_hist = p->old_economy[0].performance_history; |
|
346 |
best_player = p->index; |
|
347 |
} |
|
348 |
} |
|
349 |
if (best_player == -1) { |
|
350 |
e->preview_player = 0xFF; |
|
351 |
goto next_engine; |
|
352 |
} |
|
353 |
mask |= (1 << best_player); |
|
354 |
} while (--num != 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
355 |
|
0 | 356 |
if (!IS_HUMAN_PLAYER(best_player)) { |
357 |
/* TTDBUG: TTD has a bug here */ |
|
358 |
AcceptEnginePreview(e, best_player); |
|
359 |
} else { |
|
360 |
e->flags |= ENGINE_PREVIEWING; |
|
361 |
e->preview_wait = 20; |
|
362 |
if (IS_INTERACTIVE_PLAYER(best_player)) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
363 |
ShowEnginePreviewWindow(i); |
0 | 364 |
} |
365 |
} |
|
366 |
} |
|
367 |
} |
|
368 |
next_engine:; |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
373 |
{ |
|
374 |
if (flags & DC_EXEC) { |
|
375 |
AcceptEnginePreview(&_engines[p1], _current_player); |
|
376 |
} |
|
377 |
return 0; |
|
378 |
} |
|
379 |
||
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
380 |
// Determine if an engine type is a wagon (and not a loco) |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
381 |
bool isWagon(byte index) |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
382 |
{ |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
383 |
if (index < NUM_TRAIN_ENGINES) { |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
384 |
const RailVehicleInfo *rvi = &_rail_vehicle_info[index]; |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
385 |
if(rvi->flags & RVI_WAGON) |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
386 |
return true; |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
387 |
} |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
388 |
return false; |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
389 |
} |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
390 |
|
0 | 391 |
void NewVehicleAvailable(Engine *e) |
392 |
{ |
|
393 |
Vehicle *v; |
|
394 |
Player *p; |
|
395 |
int index = e - _engines; |
|
396 |
||
397 |
// In case the player didn't build the vehicle during the intro period, |
|
398 |
// prevent that player from getting future intro periods for a while. |
|
399 |
if (e->flags&ENGINE_INTRODUCING) { |
|
400 |
FOR_ALL_PLAYERS(p) { |
|
401 |
if (!HASBIT(e->player_avail,p->index)) |
|
402 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
403 |
|
0 | 404 |
for(v=_vehicles;;) { |
405 |
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship || |
|
406 |
(v->type == VEH_Aircraft && v->subtype <= 2)) { |
|
407 |
if (v->owner == p->index && v->engine_type == index) break; |
|
408 |
} |
|
409 |
if (++v == endof(_vehicles)) { |
|
410 |
p->block_preview = 20; |
|
411 |
break; |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
} |
|
416 |
||
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
417 |
e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE; |
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
418 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
419 |
|
0 | 420 |
// Now available for all players |
421 |
e->player_avail = (byte)-1; |
|
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
422 |
|
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
423 |
// Do not introduce new rail wagons |
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
424 |
if(isWagon(index)) |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
425 |
return; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
426 |
|
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
427 |
// make maglev / monorail available |
0 | 428 |
FOR_ALL_PLAYERS(p) { |
429 |
if (p->is_active) |
|
430 |
UPDATE_PLAYER_RAILTYPE(e,p); |
|
431 |
} |
|
432 |
||
433 |
if ((byte)index < NUM_TRAIN_ENGINES) { |
|
434 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0); |
|
435 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) { |
|
436 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0); |
|
437 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) { |
|
438 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0); |
|
439 |
} else { |
|
440 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0); |
|
441 |
} |
|
442 |
} |
|
443 |
||
444 |
void EnginesMonthlyLoop() |
|
445 |
{ |
|
446 |
Engine *e; |
|
447 |
||
448 |
if (_cur_year < 130) { |
|
449 |
for(e=_engines; e != endof(_engines); e++) { |
|
450 |
// Age the vehicle |
|
451 |
if (e->flags&ENGINE_AVAILABLE && e->age != 0xFFFF) { |
|
452 |
e->age++; |
|
453 |
CalcEngineReliability(e); |
|
454 |
} |
|
455 |
||
456 |
if (!(e->flags & ENGINE_AVAILABLE) && (uint16)(_date - min(_date, 365)) >= e->intro_date) { |
|
457 |
// Introduce it to all players |
|
458 |
NewVehicleAvailable(e); |
|
459 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) { |
|
460 |
// Introduction date has passed.. show introducing dialog to one player. |
|
461 |
e->flags |= ENGINE_INTRODUCING; |
|
257
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
462 |
|
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
463 |
// Do not introduce new rail wagons |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
464 |
if(!isWagon(e - _engines)) |
0ff8a2e60a0d
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
465 |
e->preview_player = 1; // Give to the player with the highest rating. |
0 | 466 |
} |
467 |
} |
|
468 |
} |
|
469 |
AdjustAvailAircraft(); |
|
470 |
} |
|
471 |
||
472 |
int32 CmdRenameEngine(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
473 |
{ |
|
474 |
StringID str; |
|
475 |
||
476 |
str = AllocateName((byte*)_decode_parameters, 0); |
|
477 |
if (str == 0) |
|
478 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
479 |
|
0 | 480 |
if (flags & DC_EXEC) { |
481 |
StringID old_str = _engine_name_strings[p1]; |
|
482 |
_engine_name_strings[p1] = str; |
|
483 |
DeleteName(old_str); |
|
484 |
_vehicle_design_names |= 3; |
|
485 |
MarkWholeScreenDirty(); |
|
486 |
} else { |
|
487 |
DeleteName(str); |
|
488 |
} |
|
489 |
||
490 |
return 0; |
|
491 |
} |
|
492 |
||
493 |
int GetPlayerMaxRailtype(int p) |
|
494 |
{ |
|
495 |
Engine *e; |
|
496 |
int rt = 0; |
|
497 |
int i; |
|
498 |
||
499 |
for(e=_engines,i=0; i!=lengthof(_engines); e++,i++) { |
|
500 |
if (!HASBIT(e->player_avail, p)) |
|
501 |
continue; |
|
502 |
||
503 |
if ((i >= 27 && i < 54) || (i >= 57 && i < 84) || (i >= 89 && i < 116)) |
|
504 |
continue; |
|
505 |
||
506 |
if (rt < e->railtype) |
|
507 |
rt = e->railtype; |
|
508 |
} |
|
509 |
||
510 |
return rt + 1; |
|
511 |
} |
|
512 |
||
513 |
||
514 |
static const byte _engine_desc[] = { |
|
515 |
SLE_VAR(Engine,intro_date, SLE_UINT16), |
|
516 |
SLE_VAR(Engine,age, SLE_UINT16), |
|
517 |
SLE_VAR(Engine,reliability, SLE_UINT16), |
|
518 |
SLE_VAR(Engine,reliability_spd_dec, SLE_UINT16), |
|
519 |
SLE_VAR(Engine,reliability_start, SLE_UINT16), |
|
520 |
SLE_VAR(Engine,reliability_max, SLE_UINT16), |
|
521 |
SLE_VAR(Engine,reliability_final, SLE_UINT16), |
|
522 |
SLE_VAR(Engine,duration_phase_1, SLE_UINT16), |
|
523 |
SLE_VAR(Engine,duration_phase_2, SLE_UINT16), |
|
524 |
SLE_VAR(Engine,duration_phase_3, SLE_UINT16), |
|
525 |
||
526 |
SLE_VAR(Engine,lifelength, SLE_UINT8), |
|
527 |
SLE_VAR(Engine,flags, SLE_UINT8), |
|
528 |
SLE_VAR(Engine,preview_player, SLE_UINT8), |
|
529 |
SLE_VAR(Engine,preview_wait, SLE_UINT8), |
|
530 |
SLE_VAR(Engine,railtype, SLE_UINT8), |
|
531 |
SLE_VAR(Engine,player_avail, SLE_UINT8), |
|
532 |
||
533 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
534 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
535 |
||
536 |
SLE_END() |
|
537 |
}; |
|
538 |
||
539 |
static void Save_ENGN() |
|
540 |
{ |
|
541 |
Engine *e; |
|
542 |
int i; |
|
543 |
for(i=0,e=_engines; i != lengthof(_engines); i++,e++) { |
|
544 |
SlSetArrayIndex(i); |
|
545 |
SlObject(e, _engine_desc); |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
static void Load_ENGN() |
|
550 |
{ |
|
551 |
int index; |
|
552 |
while ((index = SlIterateArray()) != -1) { |
|
553 |
SlObject(&_engines[index], _engine_desc); |
|
554 |
} |
|
555 |
} |
|
556 |
||
557 |
static void LoadSave_ENGS() |
|
558 |
{ |
|
559 |
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID); |
|
560 |
} |
|
561 |
||
562 |
const ChunkHandler _engine_chunk_handlers[] = { |
|
563 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY}, |
|
564 |
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF | CH_LAST}, |
|
565 |
}; |
|
566 |
||
567 |
||
568 |