diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index e34dbc252..d5c74020d 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1902,6 +1902,9 @@ class TMoverParameters int FastSerialCircuit = 0; /*0 - po kolei zamyka styczniki az do osiagniecia szeregowej, 1 - natychmiastowe wejscie na szeregowa*/ /*hunter-111012*/ int BackwardsBranchesAllowed = 1; int AutoRelayType = 0; /*0 -brak, 1 - jest, 2 - opcja*/ + // FieldShuntSwitch=Yes: the switch of AutoRelay=Optional of a diesel-electric is its switch of the field shunting, as the SU45's + // and SP45's (fieldshunting.h): off, the field stays full. without it, off hands the shunting to the second controller, as before + bool FieldShuntSwitch = false; bool CoupledCtrl = false; /*czy mainctrl i scndctrl sa sprzezone*/ bool HasCamshaft{false}; int DynamicBrakeType = 0; /*patrz dbrake_**/ diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 31e811871..1b4903af8 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -3662,7 +3662,7 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed) // TBD, TODO: refactor this validation as part of relay check routine (currently in tractionforce() // TBD, TODO: diesel electric engine utilize scndctrlactualpos like the other types? if (EngineType == TEngineType::DieselElectric && - (IsMainCtrlNoPowerPos() || fieldshunting::diesel_electric(AutoRelayType, AutoRelayFlag) != fieldshunting::control::manual || ShuntMode || false == Mains)) + (IsMainCtrlNoPowerPos() || fieldshunting::diesel_electric(AutoRelayType, FieldShuntSwitch, AutoRelayFlag) != fieldshunting::control::manual || ShuntMode || false == Mains)) { OK = false; } @@ -7416,7 +7416,7 @@ void TMoverParameters::DieselElectricTractionForce(double tmp) EngineVoltage = 0; // przekazniki bocznikowania, kazdy inny dla kazdej pozycji - if (auto const fieldshuntingcontrol{fieldshunting::diesel_electric(AutoRelayType, AutoRelayFlag)}; + if (auto const fieldshuntingcontrol{fieldshunting::diesel_electric(AutoRelayType, FieldShuntSwitch, AutoRelayFlag)}; false == StLinFlag || ShuntMode || fieldshuntingcontrol == fieldshunting::control::off) { ScndCtrlPos = 0; @@ -13255,6 +13255,9 @@ void TMoverParameters::LoadFIZ_CntrlControllers(std::string const &line) { AutoRelayType = 0; } + // a key of its own rather than a new AutoRelay value: an exe that doesn't know it reads the line as before, and the value + // stays Optional, which every check of the switch looks for + extract_value(FieldShuntSwitch, "FieldShuntSwitch", line, ""); extract_value(CoupledCtrl, "CoupledCtrl", line, ""); extract_value(HasCamshaft, "Camshaft", line, ""); diff --git a/tests/unit/drive.cpp b/tests/unit/drive.cpp index 4510203b1..02fc74c03 100644 --- a/tests/unit/drive.cpp +++ b/tests/unit/drive.cpp @@ -5,6 +5,7 @@ #include "doctest.h" #include "McZapkie/hamulce.h" +#include "vehicle/fieldshunting.h" namespace test { @@ -138,7 +139,7 @@ void close_line_breaker(driven const &Driven) { } // the converter, the compressor and the motor blowers, once the line breaker is closed; and the switch of the -// field shunting of a diesel-electric that has one (AutoRelay=Optional) +// field shunting of a diesel-electric that has one (AutoRelay=Optional with FieldShuntSwitch=Yes), as the AI does void switch_auxiliaries_on(TMoverParameters &Cab) { Cab.ConverterSwitch(true); Cab.CompressorSwitch(true); @@ -148,7 +149,7 @@ void switch_auxiliaries_on(TMoverParameters &Cab) { Cab.MotorBlowersSwitch(true, side); } } - if (Cab.EngineType == TEngineType::DieselElectric && Cab.AutoRelayType == 2) { + if (Cab.EngineType == TEngineType::DieselElectric && fieldshunting::has_switch(Cab.AutoRelayType, Cab.FieldShuntSwitch)) { Cab.AutoRelaySwitch(true); } } diff --git a/tests/unit/test_field_shunting.cpp b/tests/unit/test_field_shunting.cpp index d52fbe759..e61783b0e 100644 --- a/tests/unit/test_field_shunting.cpp +++ b/tests/unit/test_field_shunting.cpp @@ -11,32 +11,43 @@ using test::definition; using test::scenario; using namespace test::channels; -TEST_CASE("field shunting: who shunts the field of a diesel-electric, by AutoRelay and its switch") { +TEST_CASE("field shunting: who shunts the field of a diesel-electric, by AutoRelay, FieldShuntSwitch and the switch") { using enum fieldshunting::control; struct setting { int type; // AutoRelay: 0 No, 1 Yes, 2 Optional + bool fieldshuntswitch; // FieldShuntSwitch bool flag; // the switch, AutoRelayFlag fieldshunting::control expected; }; - for (auto const &[type, flag, expected] : {setting{0, false, manual}, setting{1, true, automatic}, setting{2, true, automatic}, setting{2, false, off}, - // AutoRelaySwitch from a coupled vehicle turns the flag of every one off, as before - setting{1, false, manual}}) { + for (auto const &[type, fieldshuntswitch, flag, expected] : + {setting{0, false, false, manual}, setting{1, false, true, automatic}, + // AutoRelay=Optional alone, as before: off, the driver shunts by hand + setting{2, false, true, automatic}, setting{2, false, false, manual}, + // with FieldShuntSwitch=Yes the switch of the field shunting: off, nobody + setting{2, true, true, automatic}, setting{2, true, false, off}, + // FieldShuntSwitch=Yes without the switch (AutoRelay=Yes or No) changes nothing + setting{1, true, true, automatic}, setting{0, true, false, manual}, + // AutoRelaySwitch from a coupled vehicle turns the flag of every one off, as before + setting{1, false, false, manual}, setting{1, true, false, manual}}) { CAPTURE(type); + CAPTURE(fieldshuntswitch); CAPTURE(flag); - CHECK(fieldshunting::diesel_electric(type, flag) == expected); + CHECK(fieldshunting::diesel_electric(type, fieldshuntswitch, flag) == expected); + CHECK(fieldshunting::has_switch(type, fieldshuntswitch) == (type == 2 && fieldshuntswitch)); } } TEST_CASE("field shunting: the SU45 with its switch, off at full power and switched on and off on the move") { - // the SU45 (RelayType 45) given the switch (AutoRelay=Optional) its cab has, with a coach: off, the field stays - // full and the second controller can't shunt it; on, the relays shunt it as they do with AutoRelay=Yes; off - // again, the shunting drops + // the SU45 (RelayType 45) given the switch (AutoRelay=Optional, FieldShuntSwitch=Yes) its cab has, with a coach: + // off, the field stays full and the second controller can't shunt it; on, the relays shunt it as they do with + // AutoRelay=Yes; off again, the shunting drops scenario scenario{"traction/field shunting switch/su45", motion() + traction()}; - scenario.train().add(definition::fiz("su45_v2/301d").set("Cntrl", "AutoRelay", "Optional"), 1); + scenario.train().add(definition::fiz("su45_v2/301d").set("Cntrl", "AutoRelay", "Optional").set("Cntrl", "FieldShuntSwitch", "Yes"), 1); scenario.add("bdhpumn_v3/bdhpumn"); REQUIRE(scenario.start_up()); auto &su45{scenario.driver().controlling}; REQUIRE(su45.AutoRelayType == 2); + REQUIRE(su45.FieldShuntSwitch); // the driver switches it on as the AI does, getting the locomotive ready CHECK(su45.AutoRelayFlag); scenario.act("field shunting off"); @@ -61,3 +72,28 @@ TEST_CASE("field shunting: the SU45 with its switch, off at full power and switc CHECK(su45.ScndCtrlPos == 0); scenario.check(); } + +TEST_CASE("field shunting: a diesel-electric with AutoRelay=Optional alone shunts by hand with the switch off, as before") { + // the SU45 with AutoRelay=Optional but no FieldShuntSwitch: the switch is the old one, off hands the shunting to the + // second controller, and the start-up (as the AI) leaves it off + scenario scenario{"traction/field shunting switch/su45 optional alone", motion() + traction()}; + scenario.train().add(definition::fiz("su45_v2/301d").set("Cntrl", "AutoRelay", "Optional"), 1); + scenario.add("bdhpumn_v3/bdhpumn"); + REQUIRE(scenario.start_up()); + auto &su45{scenario.driver().controlling}; + REQUIRE(su45.AutoRelayType == 2); + REQUIRE_FALSE(su45.FieldShuntSwitch); + CHECK_FALSE(su45.AutoRelayFlag); + scenario.get_going(); + scenario.full_power(120.0); + CHECK(su45.IsMainCtrlMaxPowerPos()); + CHECK(su45.StLinFlag); + // over 50 km/h: the relays don't shunt, the driver does + CHECK(su45.Vel > 50.0); + CHECK(su45.ScndCtrlPos == 0); + scenario.act("field shunting by hand"); + CHECK(su45.IncScndCtrl(1)); + scenario.wait(1.0); + CHECK(su45.ScndCtrlPos == 1); + scenario.check(); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 3fce1f556..bf9cbf936 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -22,6 +22,7 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/Train.h" #include "vehicle/brakesetting.h" #include "vehicle/brakingcurve.h" +#include "vehicle/fieldshunting.h" #include "vehicle/handover.h" #include "vehicle/timetableservice.h" #include "world/mtable.h" @@ -8709,13 +8710,14 @@ TController::control_tractive_and_braking_force() { #endif } -// the switch of the field shunting of a diesel-electric that has one (AutoRelay=Optional): off, the field stays full. -// checked while running too, since a vehicle taken over with its engine running doesn't go through PrepareEngine() +// the switch of the field shunting of a diesel-electric that has one (AutoRelay=Optional with FieldShuntSwitch=Yes): off, +// the field stays full. checked while running too, since a vehicle taken over with its engine running doesn't go through +// PrepareEngine(). a diesel-electric with AutoRelay=Optional alone is left as before, shunting by hand with the switch off void TController::control_field_shunting() { if( AIControllFlag && mvControlling->EngineType == TEngineType::DieselElectric - && mvControlling->AutoRelayType == 2 + && fieldshunting::has_switch( mvControlling->AutoRelayType, mvControlling->FieldShuntSwitch ) && false == mvControlling->AutoRelayFlag ) { mvControlling->AutoRelaySwitch( true ); } diff --git a/vehicle/fieldshunting.cpp b/vehicle/fieldshunting.cpp index 3681033bf..49300f50b 100644 --- a/vehicle/fieldshunting.cpp +++ b/vehicle/fieldshunting.cpp @@ -12,12 +12,16 @@ http://mozilla.org/MPL/2.0/. namespace fieldshunting { -control diesel_electric(int const Autorelaytype, bool const Autorelayflag) { +bool has_switch(int const Autorelaytype, bool const Fieldshuntswitch) { + return Autorelaytype == 2 && Fieldshuntswitch; +} + +control diesel_electric(int const Autorelaytype, bool const Fieldshuntswitch, bool const Autorelayflag) { using enum control; if (Autorelayflag) { return automatic; } - return Autorelaytype == 2 ? off : manual; + return has_switch(Autorelaytype, Fieldshuntswitch) ? off : manual; } } // namespace fieldshunting diff --git a/vehicle/fieldshunting.h b/vehicle/fieldshunting.h index 747af7430..2dec04be5 100644 --- a/vehicle/fieldshunting.h +++ b/vehicle/fieldshunting.h @@ -19,10 +19,14 @@ enum class control : int { off // nobody: the shunting is switched off, the field stays full }; -// who sets the field shunting of a diesel-electric locomotive, by its AutoRelay (Autorelaytype: 0 No, 1 Yes, -// 2 Optional) and its AutoRelayFlag (Autorelayflag). with the flag set, the relays. AutoRelay=Optional is a switch -// that lets the relays shunt the field, as the SU45's and SP45's "załączenie bocznikowania" (eu07/maszyna#167): -// switched off, nobody. otherwise the driver -control diesel_electric(int Autorelaytype, bool Autorelayflag); +// whether a diesel-electric has the switch that lets the relays shunt the field, as the SU45's and SP45's "załączenie +// bocznikowania" (eu07/maszyna#167): AutoRelay=Optional (Autorelaytype 2) with FieldShuntSwitch=Yes (Fieldshuntswitch) +bool has_switch(int Autorelaytype, bool Fieldshuntswitch); + +// who sets the field shunting of a diesel-electric locomotive, by its AutoRelay (Autorelaytype: 0 No, 1 Yes, 2 Optional), +// its FieldShuntSwitch (Fieldshuntswitch) and its AutoRelayFlag (Autorelayflag). with the flag set, the relays. with the +// switch of the field shunting (has_switch()) switched off, nobody. otherwise the driver, AutoRelay=Optional without +// FieldShuntSwitch included +control diesel_electric(int Autorelaytype, bool Fieldshuntswitch, bool Autorelayflag); } // namespace fieldshunting