MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateDisableElrailSettingState

Function UpdateDisableElrailSettingState

src/elrail.cpp:581–624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579}
580
581void UpdateDisableElrailSettingState(bool disable, bool update_vehicles)
582{
583 /* walk through all train engines */
584 for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
585 RailVehicleInfo *rv_info = &e->VehInfo<RailVehicleInfo>();
586 /* update railtype of engines intended to use elrail */
587 if (rv_info->intended_railtypes.Test(RAILTYPE_ELECTRIC)) {
588 rv_info->railtypes.Set(RAILTYPE_ELECTRIC, !disable);
589 rv_info->railtypes.Set(RAILTYPE_RAIL, disable || rv_info->intended_railtypes.Test(RAILTYPE_RAIL));
590 }
591 }
592
593 /* when disabling elrails, make sure that all existing trains can run on
594 * normal rail too */
595 if (disable) {
596 for (Train *t : Train::Iterate()) {
597 if (t->railtypes.Test(RAILTYPE_ELECTRIC)) {
598 /* this railroad vehicle is now compatible only with elrail,
599 * so add there also normal rail compatibility */
600 t->compatible_railtypes.Set(RAILTYPE_RAIL);
601 t->railtypes.Reset(RAILTYPE_ELECTRIC);
602 t->railtypes.Set(RAILTYPE_RAIL);
603 t->flags.Set(VehicleRailFlag::AllowedOnNormalRail);
604 }
605 }
606 }
607
608 /* Fix the total power and acceleration for trains */
609 if (update_vehicles) {
610 for (Train *t : Train::Iterate()) {
611 /* power and acceleration is cached only for front engines */
612 if (t->IsFrontEngine()) {
613 t->ConsistChanged(CCF_TRACK);
614 }
615 }
616 }
617
618 for (Company *c : Company::Iterate()) c->avail_railtypes = GetCompanyRailTypes(c->index);
619
620 /* This resets the _last_built_railtype, which will be invalid for electric
621 * rails. It may have unintended consequences if that function is ever
622 * extended, though. */
623 ReinitGuiAfterToggleElrail(disable);
624}

Callers 2

SettingsDisableElrailFunction · 0.85
AfterLoadGameFunction · 0.85

Calls 7

GetCompanyRailTypesFunction · 0.85
TestMethod · 0.80
IsFrontEngineMethod · 0.80
ConsistChangedMethod · 0.80
SetMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected