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