59 #include "bridge_map.h" |
59 #include "bridge_map.h" |
60 #include "bridge.h" |
60 #include "bridge.h" |
61 #include "rail_map.h" |
61 #include "rail_map.h" |
62 #include "table/sprites.h" |
62 #include "table/sprites.h" |
63 #include "table/elrail_data.h" |
63 #include "table/elrail_data.h" |
|
64 #include "vehicle.h" |
|
65 #include "train.h" |
|
66 #include "gui.h" |
64 |
67 |
65 static inline TLG GetTLG(TileIndex t) |
68 static inline TLG GetTLG(TileIndex t) |
66 { |
69 { |
67 return (HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0); |
70 return (HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0); |
68 } |
71 } |
383 |
388 |
384 default: return; |
389 default: return; |
385 } |
390 } |
386 DrawCatenaryRailway(ti); |
391 DrawCatenaryRailway(ti); |
387 } |
392 } |
|
393 |
|
394 int32 SettingsDisableElrail(int32 p1) |
|
395 { |
|
396 EngineID e_id; |
|
397 Vehicle* v; |
|
398 Player *p; |
|
399 bool disable = (p1 != 0); |
|
400 |
|
401 /* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/ |
|
402 const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; |
|
403 const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; |
|
404 |
|
405 /* walk through all train engines */ |
|
406 for (e_id = 0; e_id < NUM_TRAIN_ENGINES; e_id++) |
|
407 { |
|
408 const RailVehicleInfo *rv_info = RailVehInfo(e_id); |
|
409 Engine *e = GetEngine(e_id); |
|
410 /* if it is an electric rail engine and its railtype is the wrong one */ |
|
411 if (rv_info->engclass == 2 && e->railtype == old_railtype) { |
|
412 /* change it to the proper one */ |
|
413 e->railtype = new_railtype; |
|
414 } |
|
415 } |
|
416 |
|
417 /* when disabling elrails, make sure that all existing trains can run on |
|
418 * normal rail too */ |
|
419 if (disable) { |
|
420 FOR_ALL_VEHICLES(v) { |
|
421 if (v->type == VEH_Train && v->u.rail.railtype == RAILTYPE_ELECTRIC) { |
|
422 /* this railroad vehicle is now compatible only with elrail, |
|
423 * so add there also normal rail compatibility */ |
|
424 v->u.rail.compatible_railtypes |= (1 << RAILTYPE_RAIL); |
|
425 v->u.rail.railtype = RAILTYPE_RAIL; |
|
426 SETBIT(v->u.rail.flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL); |
|
427 } |
|
428 } |
|
429 } |
|
430 |
|
431 /* setup total power for trains */ |
|
432 FOR_ALL_VEHICLES(v) { |
|
433 /* power is cached only for front engines */ |
|
434 if (v->type == VEH_Train && IsFrontEngine(v)) TrainPowerChanged(v); |
|
435 } |
|
436 |
|
437 FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index); |
|
438 |
|
439 /* This resets the _last_built_railtype, which will be invalid for electric |
|
440 * rails. It may have unintended consequences if that function is ever |
|
441 * extended, though. */ |
|
442 ReinitGuiAfterToggleElrail(disable); |
|
443 return 0; |
|
444 } |