diff --git a/application/consistviews.cpp b/application/consistviews.cpp index ca9d979dd..8c7847386 100644 --- a/application/consistviews.cpp +++ b/application/consistviews.cpp @@ -144,7 +144,7 @@ TDynamicObject *consist_views::pick(std::vector const &Train, double consist_views::gap_beyond(TDynamicObject const *Vehicle, int const End) { auto const &neighbour{Vehicle->MoverParameters->Neighbours[End]}; - if (neighbour.vehicle == nullptr || Vehicle->MoverParameters->Couplers[End].CouplingFlag != 0) { + if (neighbour.vehicle == nullptr || false == Vehicle->MoverParameters->Couplers[End].CouplingFlag.Empty()) { return -1.0; } if (neighbour.distance > cameraviews::coupler_watch_range) { diff --git a/application/driverhints.cpp b/application/driverhints.cpp index 3851b91e7..14d1f2f0c 100644 --- a/application/driverhints.cpp +++ b/application/driverhints.cpp @@ -330,7 +330,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) // the local switch of the converter too, where the line contactors wait for the vehicle's own converter // (LineContactorsInterlock): left off by the human driver, that vehicle would never take power pVehicle->for_each( - coupling::control, + Coupling::control, []( TDynamicObject * Vehicle ) { auto *vehicle { Vehicle->MoverParameters }; if( vehicle->LineContactorsHeldByLocalConverterSwitch() ) { @@ -1322,7 +1322,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) } case driver_hint::headcodepc5: { if( AIControllFlag - || ( Global.AITrainman && false == pVehicles[end::rear]->is_connected(pVehicle, coupling::control) ) ) { + || ( Global.AITrainman && false == pVehicles[end::rear]->is_connected(pVehicle, Coupling::control) ) ) { pVehicles[ end::rear ]->RaLightsSet( -1, light::redmarker_left | light::redmarker_right | light::rearendsignals ); } remove_hint( driver_hint::headcodetb1 ); diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 8d6e5829d..2d7c3fc9a 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -388,8 +388,8 @@ timetable_panel::update() { //odejmij lokomotywy czynne, a przynajmniej aktualną consistmass -= owner->pVehicle->MoverParameters->TotalMass; // subtract potential other half of a two-part vehicle - if( auto const *previous { owner->pVehicle->Prev( coupling::permanent ) }; previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; } - auto const *next { owner->pVehicle->Next( coupling::permanent ) }; + if( auto const *previous { owner->pVehicle->Prev( Coupling::permanent ) }; previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; } + auto const *next { owner->pVehicle->Next( Coupling::permanent ) }; if( next != nullptr ) { consistmass -= next->MoverParameters->TotalMass; } } std::snprintf( @@ -1632,7 +1632,7 @@ debug_panel::update_section_coupler( std::vector &Output ) { Global.UITextColor ); if( neighbour.vehicle != nullptr ) { Output.emplace_back( - std::format( "Neighbour: {} ({} end), coupling [{}], gap {:.1f} mm", neighbour.vehicle->name(), neighbour.vehicle_end == end::front ? "front" : "rear", coupler.CouplingFlag, neighbour.distance * 1000.0 ), + std::format( "Neighbour: {} ({} end), coupling [{}], gap {:.1f} mm", neighbour.vehicle->name(), neighbour.vehicle_end == end::front ? "front" : "rear", coupler.CouplingFlag.Bits(), neighbour.distance * 1000.0 ), Global.UITextColor ); } else { diff --git a/application/editormodeselftestscene.cpp b/application/editormodeselftestscene.cpp index f9315e9e5..2868b22db 100644 --- a/application/editormodeselftestscene.cpp +++ b/application/editormodeselftestscene.cpp @@ -268,7 +268,7 @@ editor_mode::selftest_result editor_mode::selftest_scene(std::string const &comm auto const front{vehicle->VectorFront()}; auto const coupler = [&](int const End) { auto const &coupler{vehicle->MoverParameters->Couplers[End]}; - return coupler.Connected != nullptr ? coupler.Connected->Name + "/" + std::to_string(coupler.CouplingFlag) : std::string{"-"}; + return coupler.Connected != nullptr ? coupler.Connected->Name + "/" + std::to_string(coupler.CouplingFlag.Bits()) : std::string{"-"}; }; WriteLog(format("SELFTEST vehicle %s head %.2f %.2f front %.2f %.2f dir %d coupler0 %s coupler1 %s", vehicle->name().c_str(), head.x, head.z, front.x, front.z, vehicle->iDirection, coupler(0).c_str(), coupler(1).c_str())); } diff --git a/physics/mover.h b/physics/mover.h index b254656c8..364c6bb2b 100644 --- a/physics/mover.h +++ b/physics/mover.h @@ -479,13 +479,13 @@ struct TCoupling double FmaxC = 1000.0; double beta = 0.0; TCouplerType CouplerType = TCouplerType::NoCoupler; /*typ sprzegu*/ - int AutomaticCouplingFlag = coupling::coupler; - int AllowedFlag = coupling::coupler | coupling::brakehose; // Ra: maska dostępnych - int PowerFlag = coupling::power110v | coupling::power24v; - int PowerCoupling = coupling::permanent; // type of coupling required for power transfer + CouplingSet AutomaticCouplingFlag{Coupling::coupler}; + CouplingSet AllowedFlag{Coupling::coupler | Coupling::brakeHose}; // Ra: maska dostępnych + CouplingSet PowerFlag{Coupling::power110v | Coupling::power24v}; + CouplingSet PowerCoupling{Coupling::permanent}; // type of coupling required for power transfer /*zmienne*/ bool AutomaticCouplingAllowed{true}; // whether automatic coupling can be currently performed - int CouplingFlag = 0; /*0 - wirtualnie, 1 - sprzegi, 2 - pneumatycznie, 4 - sterowanie, 8 - kabel mocy*/ + CouplingSet CouplingFlag; // what the coupling joins; none: the vehicles only see each other class TMoverParameters *Connected = nullptr; /*co jest podlaczone*/ int ConnectedNr = 0; // Ra: od której strony podłączony do (Connected): 0=przód, 1=tył double CForce = 0.0; /*sila z jaka dzialal*/ @@ -502,29 +502,29 @@ struct TCoupling power_coupling power_110v; power_coupling power_24v; // the circuit of the power coupling given, nullptr for a coupling which isn't one - power_coupling *power(coupling const Coupling) + power_coupling *power(Coupling const kind) { - switch (Coupling) + switch (kind) { - case coupling::highvoltage: + case Coupling::highVoltage: return &power_high; - case coupling::power110v: + case Coupling::power110v: return &power_110v; - case coupling::power24v: + case Coupling::power24v: return &power_24v; default: return nullptr; } } - power_coupling const *power(coupling const Coupling) const + power_coupling const *power(Coupling const kind) const { - switch (Coupling) + switch (kind) { - case coupling::highvoltage: + case Coupling::highVoltage: return &power_high; - case coupling::power110v: + case Coupling::power110v: return &power_110v; - case coupling::power24v: + case Coupling::power24v: return &power_24v; default: return nullptr; @@ -1768,7 +1768,7 @@ class TMoverParameters // obsługa sprzęgów static double CouplerDist(TMoverParameters const *Left, TMoverParameters const *Right); static double Distance(const TLocation &Loc1, const TLocation &Loc2, const TDimension &Dim1, const TDimension &Dim2); - bool Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Enforce = false, bool Audible = true); + bool Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, CouplingSet CouplingType, bool Enforce = false, bool Audible = true); int DettachStatus(int ConnectNo); bool Dettach(int ConnectNo); void damage_coupler(int const End); @@ -1859,7 +1859,7 @@ class TMoverParameters double ShowEngineRotation(int VehN) const; // Q ******************************************************************************************* - double GetTrainsetVoltage(int const Coupling = coupling::heating | coupling::highvoltage) const; + double GetTrainsetVoltage(CouplingSet const couplings = Coupling::heating | Coupling::highVoltage) const; double GetTrainsetHighVoltage() const; // what turns the physics on, counted for the debug panel (Timer::switching_counter) enum class wake_cause @@ -1893,20 +1893,20 @@ class TMoverParameters double EngineMaxRPM() const; /*! przesylanie komend sterujacych*/ - bool SendCtrlToNext(VehicleCommand const CtrlCommand, double const ctrlvalue, double const dir, int const Couplertype = coupling::control); - bool SetInternalCommand(VehicleCommand const NewCommand, double NewValue1, double NewValue2, int const Couplertype = coupling::control); - bool RunCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype = coupling::control, std::string_view Argument = {}); + bool SendCtrlToNext(VehicleCommand const CtrlCommand, double const ctrlvalue, double const dir, CouplingSet const Couplertype = Coupling::control); + bool SetInternalCommand(VehicleCommand const NewCommand, double NewValue1, double NewValue2, CouplingSet const Couplertype = Coupling::control); + bool RunCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype = Coupling::control, std::string_view Argument = {}); // the parts of RunCommand(), by the area of the commands - bool RunControllerCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunRelaysCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunCabCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunBrakeCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunBrakeEquipmentCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunAuxiliariesCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunPumpsCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunBlowersCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunPowerCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); - bool RunDoorsCommand(VehicleCommand const Command, double CValue1, double CValue2, int Couplertype, bool &OK); + bool RunControllerCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunRelaysCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunCabCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunBrakeCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunBrakeEquipmentCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunAuxiliariesCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunPumpsCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunBlowersCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunPowerCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); + bool RunDoorsCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet Couplertype, bool &OK); void DoorPermitCommand(double CValue1, double CValue2); void DoorRemoteCommand(bool Open, double CValue1, double CValue2); bool RunLoadCommand(VehicleCommand const Command, double CValue1, double CValue2, std::string_view Argument, bool &OK); @@ -2111,7 +2111,7 @@ class TMoverParameters bool ControlCouplingAllowed(int const End, TMoverParameters const &Other, int const OtherEnd) const; // the CouplingType to join the End of this vehicle and the OtherEnd of the other one with, without the control coupling // when ControlCouplingAllowed() rules it out. a permanent coupling (of the vehicles of one unit) is kept whole - int CompatibleCoupling(int const End, TMoverParameters const &Other, int const OtherEnd, int const CouplingType) const; + CouplingSet CompatibleCoupling(int const End, TMoverParameters const &Other, int const OtherEnd, CouplingSet const CouplingType) const; // the horns of the Signal (WarningSignal bits) which have the air or the voltage they need to sound int SoundingHorns(int const Signal) const; // whether the signal lamps of the main circuit (line contactors, ground relay, motor overload relays) can light: @@ -2225,12 +2225,12 @@ class TMoverParameters /*-funkcje typowe dla lokomotywy elektrycznej*/ void LowVoltagePowerCheck(double const Deltatime); void MainsCheck(double const Deltatime); - void PowerCouplersCheck(double const Deltatime, coupling const Coupling); + void PowerCouplersCheck(double const Deltatime, Coupling const kind); // the parts of PowerCouplersCheck() - double LocalPowerVoltage(coupling Coupling); - void PowerCouplersVoltage(coupling Coupling, double abslocalvoltage, bool localpowersource); - void PowerCouplersCurrent(coupling Coupling, bool localpowersource); - double *PowerCircuitCurrent(coupling Coupling); + double LocalPowerVoltage(Coupling kind); + void PowerCouplersVoltage(Coupling kind, double abslocalvoltage, bool localpowersource); + void PowerCouplersCurrent(Coupling kind, bool localpowersource); + double *PowerCircuitCurrent(Coupling kind); void ConverterCheck(double const Timestep); // przetwornica void HeatingCheck(double const Timestep); void WaterPumpCheck(double const Timestep); diff --git a/physics/mover/cab.cpp b/physics/mover/cab.cpp index 14df59d94..760327cdb 100644 --- a/physics/mover/cab.cpp +++ b/physics/mover/cab.cpp @@ -82,7 +82,7 @@ int TMoverParameters::SoundingHorns(int const Signal) const } // a vehicle without a main reservoir of its own takes the air from the main pipe, a vehicle without either // (a road vehicle, say) has no air to check - auto const mainpipe{((Couplers[end::front].AllowedFlag | Couplers[end::rear].AllowedFlag) & coupling::mainhose) != 0}; + auto const mainpipe{(Couplers[end::front].AllowedFlag | Couplers[end::rear].AllowedFlag).HasAny(Coupling::mainHose)}; return false == mainpipe || ScndPipePress >= HornMinPressure; }}; auto horns{0}; diff --git a/physics/mover/collisions.cpp b/physics/mover/collisions.cpp index a890e1bbb..a696bba8b 100644 --- a/physics/mover/collisions.cpp +++ b/physics/mover/collisions.cpp @@ -57,7 +57,7 @@ namespace // a derailed vehicle tears its brake hoses: the brake pipe vents and the rest of the train brakes in emergency void tear_brake_hoses(TMoverParameters &Vehicle) { - if (std::any_of(std::begin(Vehicle.Couplers), std::end(Vehicle.Couplers), [](auto const &Coupler) { return (Coupler.CouplingFlag & coupling::brakehose) == coupling::brakehose; })) + if (std::any_of(std::begin(Vehicle.Couplers), std::end(Vehicle.Couplers), [](auto const &Coupler) { return Coupler.CouplingFlag.HasAll(Coupling::brakeHose); })) { Vehicle.AlarmChainFlag = true; } @@ -109,7 +109,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) auto velocity{V}; auto othervehiclevelocity{othervehicle->V * otherdirection}; // calculate collision force and new velocities for involved vehicles - auto const VirtualCoupling{(thiscoupler.CouplingFlag == coupling::faux)}; + auto const VirtualCoupling{(thiscoupler.CouplingFlag == Coupling::none)}; auto CCF{0.0}; switch (End) @@ -141,7 +141,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) } // HACK: limit excessive speed derailment checks to vehicles which aren't part of the same consist - auto const outsideconsist{thiscoupler.CouplingFlag == coupling::faux || true == TestFlag(othervehicle->DamageFlag, dtrain_out)}; + auto const outsideconsist{thiscoupler.CouplingFlag == Coupling::none || true == TestFlag(othervehicle->DamageFlag, dtrain_out)}; auto const velocitydifference{outsideconsist ? CollisionVelocity(End, *othervehicle, otherend) : 0.0}; if (velocitydifference > SafeCollisionVelocity) @@ -169,7 +169,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) auto const accelerationspike{physical ? 0.0 : 1.0}; // derailed the legacy way a vehicle is a wall, off the rails by the new criteria it slides on and takes the hit. with // the crush, the vehicles coupled to the wall push it on (crush_hit()) - auto const coupled{thiscoupler.CouplingFlag != coupling::faux}; + auto const coupled{thiscoupler.CouplingFlag != Coupling::none}; auto const wall = [crushing, coupled](TMoverParameters const &Vehicle) { return TestFlag(Vehicle.DamageFlag, dtrain_out) && (false == crushing || (Vehicle.Derailed == derailment::outcome::none && false == coupled)); }; @@ -201,14 +201,14 @@ void TMoverParameters::damage_coupler(int const End) if (SetFlag(DamageFlag, dtrain_coupling)) EventFlag = true; - auto const hosetorn{(thiscoupler.CouplingFlag & coupling::brakehose) == coupling::brakehose}; + auto const hosetorn{thiscoupler.CouplingFlag.HasAll(Coupling::brakeHose)}; if (hosetorn) { // hamowanie nagle - zerwanie przewodow hamulcowych AlarmChainFlag = true; } - thiscoupler.CouplingFlag = 0; + thiscoupler.CouplingFlag = {}; thiscoupler.broken = true; if (thiscoupler.Connected != nullptr) @@ -216,7 +216,7 @@ void TMoverParameters::damage_coupler(int const End) // break connection with other vehicle, if there's any: on the end it's coupled with, which is the front one too // for vehicles facing each other auto &othercoupler{thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr]}; - othercoupler.CouplingFlag = coupling::faux; + othercoupler.CouplingFlag = Coupling::none; // the coupling broke between the two, either end can be repaired othercoupler.broken = true; if (hosetorn && coupler_physics_at(End)) @@ -377,7 +377,7 @@ bool TMoverParameters::crush_hit(int const End, double const dt) // a vehicle derailed the legacy way (the end of the track, say) stays where it is, whatever hits it from outside its // train. the vehicles coupled to it push it on, as the train behind a derailed vehicle does: a wall to them, it // stopped the whole train at once, and the vehicles behind it crushed by the energy of the train - auto const coupled{thiscoupler.CouplingFlag != coupling::faux}; + auto const coupled{thiscoupler.CouplingFlag != Coupling::none}; auto const wall{false == coupled && TestFlag(DamageFlag, dtrain_out) && Derailed == derailment::outcome::none}; auto const otherwall{false == coupled && TestFlag(othervehicle->DamageFlag, dtrain_out) && othervehicle->Derailed == derailment::outcome::none}; if (wall && otherwall) @@ -506,16 +506,16 @@ bool TMoverParameters::crush_hit(int const End, double const dt) // the crushed headstock tears off the draw gear, with the brake hose: both parts of the train brake in emergency. // the coupler of an end not coupled is gone as well, it doesn't couple any more - if (thiscoupler.CouplingFlag != coupling::faux && std::max(thiscoupler.crush, othercoupler.crush) >= collision::draw_gear_crush) + if (thiscoupler.CouplingFlag != Coupling::none && std::max(thiscoupler.crush, othercoupler.crush) >= collision::draw_gear_crush) { - auto const hose{(thiscoupler.CouplingFlag & coupling::brakehose) == coupling::brakehose}; + auto const hose{thiscoupler.CouplingFlag.HasAll(Coupling::brakeHose)}; damage_coupler(End); if (hose) { othervehicle->AlarmChainFlag = true; } } - else if (thiscoupler.CouplingFlag == coupling::faux) + else if (thiscoupler.CouplingFlag == Coupling::none) { if (thiscoupler.crush >= collision::draw_gear_crush && false == thiscoupler.broken) { diff --git a/physics/mover/commands.cpp b/physics/mover/commands.cpp index 499ba62fc..2fc63a698 100644 --- a/physics/mover/commands.cpp +++ b/physics/mover/commands.cpp @@ -50,10 +50,10 @@ void TMoverParameters::PutCommand(std::string const &NewCommand, double NewValue // Q: 20160714 // Ustawienie komendy wraz z parametrami // ************************************************************************************************* -bool TMoverParameters::SetInternalCommand(VehicleCommand const NewCommand, double NewValue1, double NewValue2, int const Couplertype) +bool TMoverParameters::SetInternalCommand(VehicleCommand const NewCommand, double NewValue1, double NewValue2, CouplingSet const Couplertype) { bool SIC; - if (CommandIn.Command == NewCommand && CommandIn.Argument.empty() && CommandIn.Value1 == NewValue1 && CommandIn.Value2 == NewValue2 && CommandIn.Coupling == Couplertype) + if (CommandIn.Command == NewCommand && CommandIn.Argument.empty() && CommandIn.Value1 == NewValue1 && CommandIn.Value2 == NewValue2 && CommandIn.couplings == Couplertype) SIC = false; else { @@ -62,7 +62,7 @@ bool TMoverParameters::SetInternalCommand(VehicleCommand const NewCommand, doubl CommandIn.Argument.clear(); CommandIn.Value1 = NewValue1; CommandIn.Value2 = NewValue2; - CommandIn.Coupling = Couplertype; + CommandIn.couplings = Couplertype; SIC = true; LastLoadChangeTime = 0; // zerowanie czasu (roz)ładowania } @@ -74,7 +74,7 @@ bool TMoverParameters::SetInternalCommand(VehicleCommand const NewCommand, doubl // Q: 20160714 // wysyłanie komendy w kierunku dir (1=przód, -1=tył) do kolejnego pojazdu (jednego) // ************************************************************************************************* -bool TMoverParameters::SendCtrlToNext(VehicleCommand const CtrlCommand, double const ctrlvalue, double const dir, int const Couplertype) +bool TMoverParameters::SendCtrlToNext(VehicleCommand const CtrlCommand, double const ctrlvalue, double const dir, CouplingSet const Couplertype) { bool OK; int d; // numer sprzęgu w kierunku którego wysyłamy @@ -84,7 +84,7 @@ bool TMoverParameters::SendCtrlToNext(VehicleCommand const CtrlCommand, double c OK = true; // ( dir != 0 ); // experimentally disabled d = (1 + static_cast(Sign(dir))) / 2; // dir=-1=>d=0, dir=1=>d=1 - wysyłanie tylko w tył // musi być wybrana niezerowa kabina - if (OK && Couplers[d].Connected != nullptr && TestFlag(Couplers[d].CouplingFlag, Couplertype)) + if (OK && Couplers[d].Connected != nullptr && Couplers[d].CouplingFlag.HasAll(Couplertype)) { if (Couplers[d].ConnectedNr != d) @@ -114,7 +114,7 @@ bool TMoverParameters::SendCtrlToNext(VehicleCommand const CtrlCommand, double c // Komenda musi być zdefiniowana tutaj, a jeśli się wywołuje funkcję, to ona nie może // sama przesyłać do kolejnych pojazdów. Należy też się zastanowić, czy dla uzyskania // jakiejś zmiany (np. IncMainCtrl) lepiej wywołać funkcję, czy od razu wysłać komendę. -bool TMoverParameters::RunCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, std::string_view const Argument) +bool TMoverParameters::RunCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, std::string_view const Argument) { // the group of the command sets OK; a command none of them knows isn't done if (bool OK{false}; RunControllerCommand(Command, CValue1, CValue2, Couplertype, OK) || RunRelaysCommand(Command, CValue1, CValue2, Couplertype, OK) || @@ -134,7 +134,7 @@ bool TMoverParameters::RunCommand(VehicleCommand const Command, double CValue1, } // RunCommand() for the controllers; returns whether the command is one of them -bool TMoverParameters::RunControllerCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunControllerCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::mainController) { @@ -183,7 +183,7 @@ bool TMoverParameters::RunControllerCommand(VehicleCommand const Command, double } // RunCommand() for the direction, the automatic start and the current relays; returns whether the command is one of them -bool TMoverParameters::RunRelaysCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunRelaysCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::direction) { @@ -217,7 +217,7 @@ bool TMoverParameters::RunRelaysCommand(VehicleCommand const Command, double CVa } // RunCommand() for the cab and the speed control; returns whether the command is one of them -bool TMoverParameters::RunCabCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunCabCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::cabActivation) { @@ -268,7 +268,7 @@ bool TMoverParameters::RunCabCommand(VehicleCommand const Command, double CValue } // RunCommand() for the train brake, the releaser and the emergency brake; returns whether the command is one of them -bool TMoverParameters::RunBrakeCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunBrakeCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::brake) // youBy - jak sie EP hamuje, to trza sygnal wyslac... { @@ -308,7 +308,7 @@ bool TMoverParameters::RunBrakeCommand(VehicleCommand const Command, double CVal } // RunCommand() for the brake delays, the spring brake, the sand and the cab signalling; returns whether the command is one of them -bool TMoverParameters::RunBrakeEquipmentCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunBrakeEquipmentCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::brakeDelay) { @@ -355,7 +355,7 @@ bool TMoverParameters::RunBrakeEquipmentCommand(VehicleCommand const Command, do } // RunCommand() for the heating, the converter, the battery and the compressor; returns whether the command is one of them -bool TMoverParameters::RunAuxiliariesCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunAuxiliariesCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::heatingSwitch) { @@ -403,7 +403,7 @@ bool TMoverParameters::RunAuxiliariesCommand(VehicleCommand const Command, doubl } // RunCommand() for the water, fuel and oil pumps and the water heater; returns whether the command is one of them -bool TMoverParameters::RunPumpsCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunPumpsCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::waterPumpBreakerSwitch) { @@ -514,7 +514,7 @@ bool TMoverParameters::RunPumpsCommand(VehicleCommand const Command, double CVal } // RunCommand() for the motor blowers and the compartment lights; returns whether the command is one of them -bool TMoverParameters::RunBlowersCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunBlowersCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::motorBlowersFrontSwitch) { @@ -580,7 +580,7 @@ bool TMoverParameters::RunBlowersCommand(VehicleCommand const Command, double CV } // RunCommand() for the line breaker, the relays and the pantographs; returns whether the command is one of them -bool TMoverParameters::RunPowerCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunPowerCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::mainSwitch) { @@ -598,7 +598,7 @@ bool TMoverParameters::RunPowerCommand(VehicleCommand const Command, double CVal auto const inputcab{(static_cast(CValue1) & 0x40) != 0 ? 1 : 0}; auto const inputoperation{static_cast(CValue1) & ~(0x80 | 0x40)}; auto const noswap{TrainType == train_type::emu || TrainType == train_type::et41}; - auto swap{false == noswap && TestFlag(Couplers[CValue2 == -1 ? end::rear : end::front].CouplingFlag, coupling::control)}; + auto swap{false == noswap && Couplers[CValue2 == -1 ? end::rear : end::front].CouplingFlag.HasAll(Coupling::control)}; if (auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; reversed) { swap = !swap; @@ -634,7 +634,7 @@ bool TMoverParameters::RunPowerCommand(VehicleCommand const Command, double CVal } // RunCommand() for the doors and the departure signal; returns whether the command is one of them -bool TMoverParameters::RunDoorsCommand(VehicleCommand const Command, double CValue1, double CValue2, int const Couplertype, bool &OK) +bool TMoverParameters::RunDoorsCommand(VehicleCommand const Command, double CValue1, double CValue2, CouplingSet const Couplertype, bool &OK) { if (Command == VehicleCommand::doorPermit) { @@ -780,7 +780,7 @@ bool TMoverParameters::RunInternalCommand() if (CommandIn.Command != VehicleCommand::none) { - OK = RunCommand(CommandIn.Command, CommandIn.Value1, CommandIn.Value2, CommandIn.Coupling, CommandIn.Argument); + OK = RunCommand(CommandIn.Command, CommandIn.Value1, CommandIn.Value2, CommandIn.couplings, CommandIn.Argument); if (OK) { @@ -789,7 +789,7 @@ bool TMoverParameters::RunInternalCommand() CommandIn.Argument.clear(); CommandIn.Value1 = 0; CommandIn.Value2 = 0; - CommandIn.Coupling = 0; + CommandIn.couplings = {}; CommandIn.Location.X = 0; CommandIn.Location.Y = 0; CommandIn.Location.Z = 0; diff --git a/physics/mover/couplers.cpp b/physics/mover/couplers.cpp index 06bf30481..6acf3f233 100644 --- a/physics/mover/couplers.cpp +++ b/physics/mover/couplers.cpp @@ -45,12 +45,12 @@ double TMoverParameters::CouplerDist(TMoverParameters const *Left, TMoverParamet return Distance(Left->Loc, Right->Loc, Left->Dim, Right->Dim); // odległość pomiędzy sprzęgami (kula!) }; -bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Enforce, bool Audible) +bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, CouplingSet CouplingType, bool Enforce, bool Audible) { // łączenie do swojego sprzęgu (ConnectNo) pojazdu (ConnectTo) stroną (ConnectToNr) // Ra: zwykle wykonywane dwukrotnie, dla każdego pojazdu oddzielnie // Ra: trzeba by odróżnić wymóg dociśnięcia od uszkodzenia sprzęgu przy podczepianiu AI do składu - if (ConnectTo == nullptr || CouplingType == coupling::faux) + if (ConnectTo == nullptr || CouplingType == Coupling::none) { return false; } @@ -72,14 +72,14 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters * { WriteLog(std::format("Vehicles \"{}\" and \"{}\" can't share their control, coupled without the control connection", Name, ConnectTo->Name)); CouplingType = compatible; - if (CouplingType == coupling::faux) + if (CouplingType == Coupling::none) { return false; } } // stykaja sie zderzaki i kompatybilne typy sprzegow, chyba że łączenie na starcie - if (thiscoupler.CouplingFlag == coupling::faux) + if (thiscoupler.CouplingFlag == Coupling::none) { // a new coupling: the play of the coupling as set up anew, without the stretch of the one before thiscoupler.physics_state.couple(); @@ -99,16 +99,16 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters * othercoupler.CouplingFlag = CouplingType; othercoupler.ConnectedNr = ConnectNo; - if (true == Audible && couplingchange != 0) + if (true == Audible && false == couplingchange.Empty()) { // set sound event flag int soundflag{sound::none}; - std::vector> const soundmappings = {{coupling::coupler, sound::attachcoupler}, {coupling::brakehose, sound::attachbrakehose}, - {coupling::mainhose, sound::attachmainhose}, {coupling::control, sound::attachcontrol}, - {coupling::gangway, sound::attachgangway}, {coupling::heating, sound::attachheating}}; + std::vector> const soundmappings = {{Coupling::coupler, sound::attachcoupler}, {Coupling::brakeHose, sound::attachbrakehose}, + {Coupling::mainHose, sound::attachmainhose}, {Coupling::control, sound::attachcontrol}, + {Coupling::gangway, sound::attachgangway}, {Coupling::heating, sound::attachheating}}; for (auto const &[mappingcoupling, mappingsound] : soundmappings) { - if ((couplingchange & mappingcoupling) != 0) + if (couplingchange.HasAny(mappingcoupling)) { soundflag |= mappingsound; } @@ -124,14 +124,14 @@ int TMoverParameters::DettachStatus(int ConnectNo) // powinny być 3 informacje: =0 sprzęg już rozłączony, <0 da się rozłączyć. >0 nie da się rozłączyć if (!Couplers[ConnectNo].Connected) return 0; // nie ma nic, to rozłączanie jest OK - if ((Couplers[ConnectNo].CouplingFlag & ctrain_coupler) == 0) - return -Couplers[ConnectNo].CouplingFlag; // hak nie połączony - rozłączanie jest OK + if (false == Couplers[ConnectNo].CouplingFlag.HasAny(Coupling::coupler)) + return -Couplers[ConnectNo].CouplingFlag.Bits(); // hak nie połączony - rozłączanie jest OK if (TestFlag(DamageFlag, dtrain_coupling)) - return -Couplers[ConnectNo].CouplingFlag; // hak urwany - rozłączanie jest OK + return -Couplers[ConnectNo].CouplingFlag.Bits(); // hak urwany - rozłączanie jest OK // CouplerDist(ConnectNo); if (Couplers[ConnectNo].type() != TCouplerType::Screw || Neighbours[ConnectNo].distance < 0.01) - return -Couplers[ConnectNo].CouplingFlag; // można rozłączać, jeśli dociśnięty - return Neighbours[ConnectNo].distance > 0.2 ? -Couplers[ConnectNo].CouplingFlag : Couplers[ConnectNo].CouplingFlag; + return -Couplers[ConnectNo].CouplingFlag.Bits(); // można rozłączać, jeśli dociśnięty + return Neighbours[ConnectNo].distance > 0.2 ? -Couplers[ConnectNo].CouplingFlag.Bits() : Couplers[ConnectNo].CouplingFlag.Bits(); }; bool TMoverParameters::Dettach(int ConnectNo) @@ -151,25 +151,25 @@ bool TMoverParameters::Dettach(int ConnectNo) if (couplingstate < 0) { // gdy scisniete zderzaki, chyba ze zerwany sprzeg (wirtualnego nie odpinamy z drugiej strony) - std::tie(othercoupler.Connected, othercoupler.ConnectedNr, othercoupler.CouplingFlag) = std::make_tuple(nullptr, -1, coupling::faux); - std::tie(thiscoupler.Connected, thiscoupler.ConnectedNr, thiscoupler.CouplingFlag) = std::make_tuple(nullptr, -1, coupling::faux); + std::tie(othercoupler.Connected, othercoupler.ConnectedNr, othercoupler.CouplingFlag) = std::make_tuple(nullptr, -1, Coupling::none); + std::tie(thiscoupler.Connected, thiscoupler.ConnectedNr, thiscoupler.CouplingFlag) = std::make_tuple(nullptr, -1, Coupling::none); } else if (couplingstate > 0) { // odłączamy węże i resztę, pozostaje sprzęg fizyczny, który wymaga dociśnięcia (z wirtualnym nic) - thiscoupler.CouplingFlag &= coupling::coupler; - othercoupler.CouplingFlag &= coupling::coupler; + thiscoupler.CouplingFlag &= Coupling::coupler; + othercoupler.CouplingFlag &= Coupling::coupler; } // set sound event flag couplingchange ^= thiscoupler.CouplingFlag; // remaining bits were removed from coupling - if (couplingchange != 0) + if (false == couplingchange.Empty()) { int soundflag{sound::detach}; // HACK: use detach flag to indicate removal of listed coupling - std::vector> const soundmappings = {{coupling::coupler, sound::attachcoupler}, {coupling::brakehose, sound::attachbrakehose}, - {coupling::mainhose, sound::attachmainhose}, {coupling::control, sound::attachcontrol}, - {coupling::gangway, sound::attachgangway}, {coupling::heating, sound::attachheating}}; + std::vector> const soundmappings = {{Coupling::coupler, sound::attachcoupler}, {Coupling::brakeHose, sound::attachbrakehose}, + {Coupling::mainHose, sound::attachmainhose}, {Coupling::control, sound::attachcontrol}, + {Coupling::gangway, sound::attachgangway}, {Coupling::heating, sound::attachheating}}; for (auto const &[mappingcoupling, mappingsound] : soundmappings) { - if ((couplingchange & mappingcoupling) != 0) + if (couplingchange.HasAny(mappingcoupling)) { soundflag |= mappingsound; } @@ -246,13 +246,13 @@ bool TMoverParameters::ControlCouplingAllowed(int const End, TMoverParameters co return traction == traction_kind::none || othertraction == traction_kind::none || traction == othertraction; } -int TMoverParameters::CompatibleCoupling(int const End, TMoverParameters const &Other, int const OtherEnd, int const CouplingType) const +CouplingSet TMoverParameters::CompatibleCoupling(int const End, TMoverParameters const &Other, int const OtherEnd, CouplingSet const CouplingType) const { - if ((CouplingType & coupling::control) == 0 || (CouplingType & coupling::permanent) != 0 || ControlCouplingAllowed(End, Other, OtherEnd)) + if (false == CouplingType.HasAny(Coupling::control) || CouplingType.HasAny(Coupling::permanent) || ControlCouplingAllowed(End, Other, OtherEnd)) { return CouplingType; } - return CouplingType & ~coupling::control; + return CouplingType.Without(Coupling::control); } // ************************************************************************************************* @@ -289,7 +289,7 @@ double TMoverParameters::CouplerForce(int const End, double dt) // 090503: dzwieki pracy zderzakow SetFlag(thiscoupler.sounds, absdV > 5.0 ? sound::bufferclash | sound::loud : sound::bufferclash); } - else if (thiscoupler.CouplingFlag != coupling::faux && newdistance > 0.001 && thiscoupler.Dist <= 0.001 && absdV > 0.005 && Vel > 1.0) + else if (thiscoupler.CouplingFlag != Coupling::none && newdistance > 0.001 && thiscoupler.Dist <= 0.001 && absdV > 0.005 && Vel > 1.0) { // 090503: dzwieki pracy sprzegu SetFlag(thiscoupler.sounds, absdV > 0.035 ? sound::couplerstretch | sound::loud : sound::couplerstretch); @@ -300,13 +300,13 @@ double TMoverParameters::CouplerForce(int const End, double dt) double CF{0.0}; - if (thiscoupler.CouplingFlag == coupling::faux && initialdistance > 0.05) + if (thiscoupler.CouplingFlag == Coupling::none && initialdistance > 0.05) { // arbitrary distance // potentially reset auto coupling lock thiscoupler.AutomaticCouplingAllowed = true; } - if (thiscoupler.CouplingFlag != coupling::faux || initialdistance < 0) + if (thiscoupler.CouplingFlag != Coupling::none || initialdistance < 0) { thiscoupler.Dist = safe_clamp(newdistance, thiscoupler.has_adapter() ? 0 : -thiscoupler.DmaxB, thiscoupler.DmaxC); @@ -314,7 +314,7 @@ double TMoverParameters::CouplerForce(int const End, double dt) double BetaAvg = 0; double Fmax = 0; - if (thiscoupler.CouplingFlag == coupling::faux) + if (thiscoupler.CouplingFlag == Coupling::none) { BetaAvg = thiscoupler.beta; @@ -374,7 +374,7 @@ double TMoverParameters::CouplerForce(int const End, double dt) } } - if (thiscoupler.CouplingFlag != coupling::faux) + if (thiscoupler.CouplingFlag != Coupling::none) { // uzgadnianie prawa Newtona, on the coupler of the other vehicle this one is coupled with, along that vehicle's // axis: turned around once more when the vehicles face each other @@ -425,7 +425,7 @@ void TMoverParameters::automatic_coupling(int const End, TMoverParameters &Other auto &thiscoupler{Couplers[End]}; auto &othercoupler{Other.Couplers[OtherEnd]}; - if (thiscoupler.type() != TCouplerType::Automatic || thiscoupler.type() != othercoupler.type() || thiscoupler.CouplingFlag != coupling::faux || false == thiscoupler.AutomaticCouplingAllowed || + if (thiscoupler.type() != TCouplerType::Automatic || thiscoupler.type() != othercoupler.type() || thiscoupler.CouplingFlag != Coupling::none || false == thiscoupler.AutomaticCouplingAllowed || false == othercoupler.AutomaticCouplingAllowed) { return; @@ -440,7 +440,7 @@ void TMoverParameters::automatic_coupling(int const End, TMoverParameters &Other // potentially exclude incompatible control coupling if (thiscoupler.control_type != othercoupler.control_type) { - couplingtype &= ~coupling::control; + couplingtype = couplingtype.Without(Coupling::control); } couplingtype = CompatibleCoupling(End, Other, OtherEnd, couplingtype); @@ -503,7 +503,7 @@ double TMoverParameters::coupler_force_physical(int const End, double const dt) auto const gap{Neighbours[End].distance + (End == end::front ? othervehiclemove - dMoveLen : dMoveLen - othervehiclemove)}; // the gap opens up when the front end falls behind the vehicle ahead of it, or the rear end runs ahead of the one behind auto const gaprate{CouplerVelocityDifference(End, *othervehicle, otherend) * DirF(End)}; - auto const coupled{thiscoupler.CouplingFlag != coupling::faux}; + auto const coupled{thiscoupler.CouplingFlag != Coupling::none}; auto const adapter{thiscoupler.has_adapter() || othercoupler.has_adapter()}; if (false == coupled && Neighbours[End].distance > 0.05) @@ -539,7 +539,7 @@ double TMoverParameters::coupler_force_physical(int const End, double const dt) // tension pulls this vehicle towards the other one auto const force{result.force * -DirF(End)}; - if (thiscoupler.CouplingFlag != coupling::faux) + if (thiscoupler.CouplingFlag != Coupling::none) { // uzgadnianie prawa Newtona, as in CouplerForce() othercoupler.CForce = -force * DirPatch(End, otherend); diff --git a/physics/mover/diesel.cpp b/physics/mover/diesel.cpp index 1548f8885..e2e95959f 100644 --- a/physics/mover/diesel.cpp +++ b/physics/mover/diesel.cpp @@ -124,7 +124,7 @@ bool TMoverParameters::WaterPumpBreakerSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::waterPumpBreakerSwitch, WaterPump.breaker ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::waterPumpBreakerSwitch, WaterPump.breaker ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return WaterPump.breaker != initialstate; @@ -146,7 +146,7 @@ bool TMoverParameters::WaterPumpSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::waterPumpSwitch, WaterPump.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::waterPumpSwitch, WaterPump.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return WaterPump.is_enabled != initialstate; @@ -168,7 +168,7 @@ bool TMoverParameters::WaterPumpSwitchOff(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::waterPumpSwitchOff, WaterPump.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::waterPumpSwitchOff, WaterPump.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return WaterPump.is_disabled != initialstate; @@ -189,7 +189,7 @@ bool TMoverParameters::WaterHeaterBreakerSwitch(bool State, range_t const Notify if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::waterHeaterBreakerSwitch, WaterHeater.breaker ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::waterHeaterBreakerSwitch, WaterHeater.breaker ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return WaterHeater.breaker != initialstate; @@ -210,7 +210,7 @@ bool TMoverParameters::WaterHeaterSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::waterHeaterSwitch, WaterHeater.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::waterHeaterSwitch, WaterHeater.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return WaterHeater.is_enabled != initialstate; @@ -232,7 +232,7 @@ bool TMoverParameters::WaterCircuitsLinkSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::waterCircuitsLinkSwitch, WaterCircuitsLink ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::waterCircuitsLinkSwitch, WaterCircuitsLink ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return WaterCircuitsLink != initialstate; @@ -254,7 +254,7 @@ bool TMoverParameters::FuelPumpSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::fuelPumpSwitch, FuelPump.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::fuelPumpSwitch, FuelPump.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return FuelPump.is_enabled != initialstate; @@ -275,7 +275,7 @@ bool TMoverParameters::FuelPumpSwitchOff(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::fuelPumpSwitchOff, FuelPump.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::fuelPumpSwitchOff, FuelPump.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return FuelPump.is_disabled != initialstate; @@ -297,7 +297,7 @@ bool TMoverParameters::OilPumpSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::oilPumpSwitch, OilPump.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::oilPumpSwitch, OilPump.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return OilPump.is_enabled != initialstate; @@ -318,7 +318,7 @@ bool TMoverParameters::OilPumpSwitchOff(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::oilPumpSwitchOff, OilPump.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::oilPumpSwitchOff, OilPump.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return OilPump.is_disabled != initialstate; diff --git a/physics/mover/doors.cpp b/physics/mover/doors.cpp index 28b2e379a..923496d4d 100644 --- a/physics/mover/doors.cpp +++ b/physics/mover/doors.cpp @@ -199,7 +199,7 @@ bool TMoverParameters::PermitDoorStep(bool const State, range_t const Notify) if (Notify != range_t::local) { // wysłanie wyłączenia do pozostałych? - SendCtrlToNext(VehicleCommand::doorStep, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::doorStep, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return Doors.step_enabled != initialstate; @@ -220,7 +220,7 @@ bool TMoverParameters::PermitDoors(side const Door, bool const State, range_t co * (Door == (CabActive > 0 ? side::left : side::right) ? // 1=lewe, 2=prawe (swap if reversed) 1 : 2), - CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return Doors.instances[Door].open_permit != initialstate; @@ -245,7 +245,7 @@ bool TMoverParameters::ChangeDoorControlMode(bool const State, range_t const Not if (Notify != range_t::local) { // wysłanie wyłączenia do pozostałych? - SendCtrlToNext(VehicleCommand::doorMode, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::doorMode, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } if (true == State) @@ -296,7 +296,7 @@ bool TMoverParameters::OperateDoors(side const Door, bool const State, range_t c Door == (CabActive > 0 ? side::left : side::right) ? // 1=lewe, 2=prawe (swap if reversed) 1 : 2, - CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return result; @@ -312,7 +312,7 @@ bool TMoverParameters::LockDoors(bool const State, range_t const Notify) if (Notify != range_t::local) { // wysłanie wyłączenia do pozostałych? - SendCtrlToNext(VehicleCommand::doorLock, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::doorLock, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return Doors.lock_enabled != initialstate; @@ -332,7 +332,7 @@ bool TMoverParameters::signal_departure(bool const State, range_t const Notify) if (Notify != range_t::local) { // wysłanie wyłączenia do pozostałych? - SendCtrlToNext(VehicleCommand::departureSignal, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::departureSignal, State == true ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return true; diff --git a/physics/mover/electrics.cpp b/physics/mover/electrics.cpp index 9127e00cb..ada624e72 100644 --- a/physics/mover/electrics.cpp +++ b/physics/mover/electrics.cpp @@ -344,36 +344,36 @@ void TMoverParameters::LowVoltagePowerCheck(double const /*Deltatime*/) } } -void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, coupling const Coupling) +void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, Coupling const kind) { - if (Coupling != coupling::highvoltage && Coupling != coupling::power110v && Coupling != coupling::power24v) + if (kind != Coupling::highVoltage && kind != Coupling::power110v && kind != Coupling::power24v) { // only power couplings carry voltage return; } - auto const localvoltage{LocalPowerVoltage(Coupling)}; + auto const localvoltage{LocalPowerVoltage(kind)}; auto const abslocalvoltage{std::abs(localvoltage)}; auto const localpowersource{(abslocalvoltage > 1.0)}; // przekazywanie napiec - PowerCouplersVoltage(Coupling, abslocalvoltage, localpowersource); + PowerCouplersVoltage(kind, abslocalvoltage, localpowersource); // przekazywanie pradow - PowerCouplersCurrent(Coupling, localpowersource); + PowerCouplersCurrent(kind, localpowersource); } // the current the vehicle draws from the circuit of the power coupling given -double *TMoverParameters::PowerCircuitCurrent(coupling const Coupling) +double *TMoverParameters::PowerCircuitCurrent(Coupling const kind) { - switch (Coupling) + switch (kind) { - case coupling::highvoltage: + case Coupling::highVoltage: return &TotalCurrent; - case coupling::power110v: + case Coupling::power110v: return &PowerCircuits[1].second; - case coupling::power24v: + case Coupling::power24v: return &PowerCircuits[0].second; default: return nullptr; @@ -381,16 +381,16 @@ double *TMoverParameters::PowerCircuitCurrent(coupling const Coupling) } // the voltage of the vehicle's own source for the coupling given; notes the low voltage circuits' too -double TMoverParameters::LocalPowerVoltage(coupling const Coupling) +double TMoverParameters::LocalPowerVoltage(Coupling const kind) { auto localvoltage{0.0}; // local power sources // the results could be kept in the PowerCircuit fields - switch (Coupling) + switch (kind) { - case coupling::highvoltage: + case Coupling::highVoltage: { // heating power sources if (Heating) @@ -428,7 +428,7 @@ double TMoverParameters::LocalPowerVoltage(coupling const Coupling) break; } - case coupling::power110v: + case Coupling::power110v: { if (ConverterFlag) { @@ -439,7 +439,7 @@ double TMoverParameters::LocalPowerVoltage(coupling const Coupling) break; } - case coupling::power24v: + case Coupling::power24v: { if (Battery) { @@ -460,9 +460,9 @@ double TMoverParameters::LocalPowerVoltage(coupling const Coupling) } // the voltage passed through the vehicle to the coupler at its other end, from the coupled vehicle or its own source -void TMoverParameters::PowerCouplersVoltage(coupling const Coupling, double const abslocalvoltage, bool const localpowersource) +void TMoverParameters::PowerCouplersVoltage(Coupling const kind, double const abslocalvoltage, bool const localpowersource) { - if (Couplers[end::front].power(Coupling) == nullptr) + if (Couplers[end::front].power(kind) == nullptr) { // not a power coupling, there's no voltage to pass return; @@ -477,29 +477,29 @@ void TMoverParameters::PowerCouplersVoltage(coupling const Coupling, double cons bool oppositecouplingispresent; bool localpowerexportisenabled; - switch (Coupling) + switch (kind) { - case coupling::highvoltage: + case Coupling::highVoltage: { - auto const oppositehighvoltagecoupling{(oppositecoupler.CouplingFlag & coupling::highvoltage) != 0}; - auto const oppositeheatingcoupling{(oppositecoupler.CouplingFlag & coupling::heating) != 0}; + auto const oppositehighvoltagecoupling{oppositecoupler.CouplingFlag.HasAny(Coupling::highVoltage)}; + auto const oppositeheatingcoupling{oppositecoupler.CouplingFlag.HasAny(Coupling::heating)}; oppositecouplingispresent = oppositehighvoltagecoupling || oppositeheatingcoupling; localpowerexportisenabled = oppositehighvoltagecoupling || (oppositeheatingcoupling && localpowersource && Heating); break; } - case coupling::power110v: + case Coupling::power110v: { - oppositecouplingispresent = TestFlag(oppositecoupler.CouplingFlag, oppositecoupler.PowerCoupling) && (oppositecoupler.PowerFlag & coupling::power110v) != 0; + oppositecouplingispresent = oppositecoupler.CouplingFlag.HasAll(oppositecoupler.PowerCoupling) && oppositecoupler.PowerFlag.HasAny(Coupling::power110v); localpowerexportisenabled = oppositecouplingispresent; break; } - case coupling::power24v: + case Coupling::power24v: { - oppositecouplingispresent = TestFlag(oppositecoupler.CouplingFlag, oppositecoupler.PowerCoupling) && (oppositecoupler.PowerFlag & coupling::power24v) != 0; + oppositecouplingispresent = oppositecoupler.CouplingFlag.HasAll(oppositecoupler.PowerCoupling) && oppositecoupler.PowerFlag.HasAny(Coupling::power24v); localpowerexportisenabled = oppositecouplingispresent; break; } @@ -510,8 +510,8 @@ void TMoverParameters::PowerCouplersVoltage(coupling const Coupling, double cons } } - auto const *coupling = thiscoupler.power(Coupling); - auto *oppositecoupling = oppositecoupler.power(Coupling); + auto const *coupling = thiscoupler.power(kind); + auto *oppositecoupling = oppositecoupler.power(kind); // start with base voltage oppositecoupling->voltage = abslocalvoltage; @@ -521,7 +521,7 @@ void TMoverParameters::PowerCouplersVoltage(coupling const Coupling, double cons if (thiscoupler.Connected != nullptr) { auto const &connectedcoupler{thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr]}; - auto const *connectedcoupling = connectedcoupler.power(Coupling); + auto const *connectedcoupling = connectedcoupler.power(kind); auto const connectedvoltage{(connectedcoupling->is_live ? connectedcoupling->voltage : 0.0)}; oppositecoupling->voltage = std::max(oppositecoupling->voltage, connectedvoltage - coupling->current * 0.02); oppositecoupling->is_live = connectedvoltage > 0.1 && oppositecouplingispresent; @@ -536,11 +536,11 @@ void TMoverParameters::PowerCouplersVoltage(coupling const Coupling, double cons } // the current drawn through the couplers, shared by their voltages, or added to the vehicle's own -void TMoverParameters::PowerCouplersCurrent(coupling const Coupling, bool const localpowersource) +void TMoverParameters::PowerCouplersCurrent(Coupling const kind, bool const localpowersource) { - auto const *frontcoupling{Couplers[end::front].power(Coupling)}; - auto const *rearcoupling{Couplers[end::rear].power(Coupling)}; - auto *totalcurrent{PowerCircuitCurrent(Coupling)}; + auto const *frontcoupling{Couplers[end::front].power(kind)}; + auto const *rearcoupling{Couplers[end::rear].power(kind)}; + auto *totalcurrent{PowerCircuitCurrent(kind)}; if (frontcoupling == nullptr || rearcoupling == nullptr || totalcurrent == nullptr) { // not a power coupling, there's no current to share @@ -550,7 +550,7 @@ void TMoverParameters::PowerCouplersCurrent(coupling const Coupling, bool const for (auto &thiscoupler : Couplers) { - auto *coupling = thiscoupler.power(Coupling); + auto *coupling = thiscoupler.power(kind); coupling->current = 0.0; @@ -560,8 +560,8 @@ void TMoverParameters::PowerCouplersCurrent(coupling const Coupling, bool const } auto const &connectedothercoupler{thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr == end::front ? end::rear : end::front]}; - auto const *connectedothercoupling = connectedothercoupler.power(Coupling); - auto const extracurrent = Coupling == coupling::highvoltage ? std::abs(Itot) * IsVehicleEIMBrakingFactor() : 0.0; + auto const *connectedothercoupling = connectedothercoupler.power(kind); + auto const extracurrent = kind == Coupling::highVoltage ? std::abs(Itot) * IsVehicleEIMBrakingFactor() : 0.0; if (false == localpowersource) { @@ -862,8 +862,8 @@ bool TMoverParameters::BatterySwitch(bool State, range_t const Notify) // switching batteries does not require activation if (Notify != local) { - SendCtrlToNext(VehicleCommand::batterySwitch, State ? 1 : 0, 1, Notify == unit ? coupling::control | coupling::permanent : coupling::control); - SendCtrlToNext(VehicleCommand::batterySwitch, State ? 1 : 0, -1, Notify == unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::batterySwitch, State ? 1 : 0, 1, Notify == unit ? Coupling::control | Coupling::permanent : Coupling::control); + SendCtrlToNext(VehicleCommand::batterySwitch, State ? 1 : 0, -1, Notify == unit ? Coupling::control | Coupling::permanent : Coupling::control); } return Battery != initialstate; @@ -884,7 +884,7 @@ bool TMoverParameters::CompartmentLightsSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::compartmentLightsSwitch, CompartmentLights.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::compartmentLightsSwitch, CompartmentLights.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return CompartmentLights.is_enabled != initialstate; @@ -906,7 +906,7 @@ bool TMoverParameters::CompartmentLightsSwitchOff(bool State, range_t const Noti if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::compartmentLightsSwitchOff, CompartmentLights.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::compartmentLightsSwitchOff, CompartmentLights.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return CompartmentLights.is_disabled != initialstate; @@ -927,7 +927,7 @@ bool TMoverParameters::MainSwitch(bool const State, range_t const Notify) { // pass the command to other vehicles // TBD: pass the requested state, or the actual state? - SendCtrlToNext(VehicleCommand::mainSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::mainSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return (Mains || dizel_startup) != initialstate; @@ -1038,7 +1038,7 @@ bool TMoverParameters::ConverterSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::converterSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::converterSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return ConverterAllow != initialstate; @@ -1055,7 +1055,7 @@ bool TMoverParameters::HeatingSwitch(bool const State, range_t const Notify) { // pass the command to other vehicles // TBD: pass the requested state, or the actual state? - SendCtrlToNext(VehicleCommand::heatingSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::heatingSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return HeatingAllow != initialstate; @@ -1081,7 +1081,7 @@ bool TMoverParameters::GensetSwitch(bool const State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::gensetSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::gensetSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return Genset.is_enabled != initialstate; @@ -1207,7 +1207,7 @@ bool TMoverParameters::OperatePantographsValve(operation_t const State, range_t if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::pantographsValve, static_cast(State), CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::pantographsValve, static_cast(State), CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return true; @@ -1271,7 +1271,7 @@ bool TMoverParameters::OperatePantographValve(end const End, operation_t const S // HACK: pack the state, pantograph index and sender cab into 8-bit value // with high bit storing front/rear pantograph, and 7th bit storing sender cab static_cast(0x80 * (End == end::front ? 0 : 1) + 0x40 * (CabActive != -1 ? 1 : 0) + static_cast(State)), CabActive, - Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return true; @@ -1286,7 +1286,7 @@ bool TMoverParameters::DropAllPantographs(bool const State, range_t const Notify if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::pantographsAllDown, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::pantographsAllDown, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return State != initialstate; @@ -1296,7 +1296,7 @@ bool TMoverParameters::DropAllPantographs(bool const State, range_t const Notify // Q: 20160709 // Funkcja zwracajaca napiecie dla calego skladu, przydatna dla EZT // ************************************************************************************************* -double TMoverParameters::GetTrainsetVoltage(int const Coupling) const +double TMoverParameters::GetTrainsetVoltage(CouplingSet const couplings) const { // ABu: funkcja zwracajaca napiecie dla calego skladu, przydatna dla EZT // TBD, TODO: call once per vehicle update, return cached results? std::array voltages{0.0, 0.0}; @@ -1307,13 +1307,13 @@ double TMoverParameters::GetTrainsetVoltage(int const Coupling) const continue; } auto const &thiscoupler{Couplers[end]}; - if (auto const fullcoupling{thiscoupler.CouplingFlag | (TestFlag(thiscoupler.CouplingFlag, thiscoupler.PowerCoupling) ? thiscoupler.PowerFlag : 0)}; (fullcoupling & Coupling) == 0) + if (auto const fullcoupling{thiscoupler.CouplingFlag | (thiscoupler.CouplingFlag.HasAll(thiscoupler.PowerCoupling) ? thiscoupler.PowerFlag : CouplingSet{})}; false == fullcoupling.HasAny(couplings)) { continue; } - auto const *connectedpowercoupling = (Coupling & (coupling::highvoltage | coupling::heating)) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_high : - (Coupling & coupling::power110v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_110v : - (Coupling & coupling::power24v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_24v : + auto const *connectedpowercoupling = couplings.HasAny(Coupling::highVoltage | Coupling::heating) ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_high : + couplings.HasAny(Coupling::power110v) ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_110v : + couplings.HasAny(Coupling::power24v) ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_24v : nullptr; if (connectedpowercoupling != nullptr && connectedpowercoupling->is_live) { @@ -1326,7 +1326,7 @@ double TMoverParameters::GetTrainsetVoltage(int const Coupling) const double TMoverParameters::GetTrainsetHighVoltage() const { - return std::max(GetTrainsetVoltage(coupling::highvoltage), HeatingAllow ? GetTrainsetVoltage(coupling::heating) : 0.0); + return std::max(GetTrainsetVoltage(Coupling::highVoltage), HeatingAllow ? GetTrainsetVoltage(Coupling::heating) : 0.0); } int TMoverParameters::clampDimmerPosition(int const Position) const diff --git a/physics/mover/fizsections.cpp b/physics/mover/fizsections.cpp index 193356ab1..8bf7673c6 100644 --- a/physics/mover/fizsections.cpp +++ b/physics/mover/fizsections.cpp @@ -578,14 +578,20 @@ void TMoverParameters::LoadFIZ_BuffCoupl(std::string const &line, int const Inde extract_value(thiscoupler->DmaxB, "DmaxB", line, ""); extract_value(thiscoupler->FmaxB, "FmaxB", line, ""); extract_value(thiscoupler->beta, "beta", line, ""); - extract_value(thiscoupler->AutomaticCouplingFlag, "AutomaticFlag", line, ""); - extract_value(thiscoupler->AllowedFlag, "AllowedFlag", line, ""); - if (thiscoupler->AllowedFlag < 0) - { - thiscoupler->AllowedFlag = -thiscoupler->AllowedFlag | coupling::permanent; - } - extract_value(thiscoupler->PowerCoupling, "PowerCoupling", line, ""); - extract_value(thiscoupler->PowerFlag, "PowerFlag", line, ""); + // the sets are numbers in the definition, the sums of the numbers of the kinds of coupling + auto automaticflag{thiscoupler->AutomaticCouplingFlag.Bits()}; + extract_value(automaticflag, "AutomaticFlag", line, ""); + thiscoupler->AutomaticCouplingFlag = CouplingSet::FromBits(automaticflag); + auto allowedflag{thiscoupler->AllowedFlag.Bits()}; + extract_value(allowedflag, "AllowedFlag", line, ""); + // negative: the coupling is permanent besides + thiscoupler->AllowedFlag = allowedflag < 0 ? CouplingSet::FromBits(-allowedflag) | Coupling::permanent : CouplingSet::FromBits(allowedflag); + auto powercoupling{thiscoupler->PowerCoupling.Bits()}; + extract_value(powercoupling, "PowerCoupling", line, ""); + thiscoupler->PowerCoupling = CouplingSet::FromBits(powercoupling); + auto powerflag{thiscoupler->PowerFlag.Bits()}; + extract_value(powerflag, "PowerFlag", line, ""); + thiscoupler->PowerFlag = CouplingSet::FromBits(powerflag); extract_value(thiscoupler->control_type, "ControlType", line, ""); if (thiscoupler->CouplerType != TCouplerType::NoCoupler && thiscoupler->CouplerType != TCouplerType::Bare && thiscoupler->CouplerType != TCouplerType::Articulated) diff --git a/physics/mover/mover.cpp b/physics/mover/mover.cpp index 5a86a41ac..fa6f20c1e 100644 --- a/physics/mover/mover.cpp +++ b/physics/mover/mover.cpp @@ -144,8 +144,8 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string const &TypeNam for (auto &couplerentry : Couplers) { - couplerentry.AllowedFlag = 3; // domyślnie hak i hamulec, inne trzeba włączyć jawnie w FIZ - couplerentry.CouplingFlag = 0; + couplerentry.AllowedFlag = Coupling::coupler | Coupling::brakeHose; // domyślnie hak i hamulec, inne trzeba włączyć jawnie w FIZ + couplerentry.CouplingFlag = {}; couplerentry.Connected = nullptr; couplerentry.ConnectedNr = 0; // Ra: to nie ma znaczenia jak nie podłączony couplerentry.Render = false; @@ -193,7 +193,7 @@ void TMoverParameters::change_train_velocity(double const Change) { auto const &coupler{vehicle->Couplers[end]}; auto *other{coupler.Connected}; - if (other == nullptr || coupler.CouplingFlag == coupling::faux || std::any_of(train.begin(), train.end(), [other](auto const &Entry) { return Entry.first == other; })) + if (other == nullptr || coupler.CouplingFlag == Coupling::none || std::any_of(train.begin(), train.end(), [other](auto const &Entry) { return Entry.first == other; })) { continue; } @@ -522,11 +522,11 @@ void TMoverParameters::compute_movement_(double const Deltatime) UpdateBatteryVoltage(Deltatime); UpdateScndPipePressure(Deltatime); // druga rurka, youBy - if ((DCEMUED_CC & 1) != 0 && (Couplers[end::front].CouplingFlag & coupling::control) != 0) + if ((DCEMUED_CC & 1) != 0 && Couplers[end::front].CouplingFlag.HasAny(Coupling::control)) { DynamicBrakeEMUStatus &= Couplers[end::front].Connected->DynamicBrakeEMUStatus; } - if ((DCEMUED_CC & 2) != 0 && (Couplers[end::rear].CouplingFlag & coupling::control) != 0) + if ((DCEMUED_CC & 2) != 0 && Couplers[end::rear].CouplingFlag.HasAny(Coupling::control)) { DynamicBrakeEMUStatus &= Couplers[end::rear].Connected->DynamicBrakeEMUStatus; } @@ -542,13 +542,13 @@ void TMoverParameters::compute_movement_(double const Deltatime) m_plc.update(Deltatime); - PowerCouplersCheck(Deltatime, coupling::highvoltage); - PowerCouplersCheck(Deltatime, coupling::power110v); - PowerCouplersCheck(Deltatime, coupling::power24v); + PowerCouplersCheck(Deltatime, Coupling::highVoltage); + PowerCouplersCheck(Deltatime, Coupling::power110v); + PowerCouplersCheck(Deltatime, Coupling::power24v); - Power24vVoltage = std::max(PowerCircuits[0].first, GetTrainsetVoltage(coupling::power24v)); + Power24vVoltage = std::max(PowerCircuits[0].first, GetTrainsetVoltage(Coupling::power24v)); Power24vIsAvailable = Power24vVoltage > 0; - Power110vIsAvailable = PowerCircuits[1].first > 0 || GetTrainsetVoltage(coupling::power110v) > 0; + Power110vIsAvailable = PowerCircuits[1].first > 0 || GetTrainsetVoltage(Coupling::power110v) > 0; } // ************************************************************************************************* @@ -671,7 +671,7 @@ bool TMoverParameters::Sandbox(bool const State, range_t const Notify) if (Notify != range_t::local) { // if requested pass the command on - auto const couplingtype = Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control; + auto const couplingtype = Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control; if (State == true) { @@ -694,7 +694,7 @@ bool TMoverParameters::Sandbox(bool const State, range_t const Notify) // ************************************************************************************************* bool TMoverParameters::SandboxAutoAllow(bool State) { - // SendCtrlToNext(VehicleCommand::sandboxAutoAllow, int(State), CabActive, ctrain_controll); + // SendCtrlToNext(VehicleCommand::sandboxAutoAllow, int(State), CabActive, Coupling::control); if (SandDoseAutoAllow != State) { diff --git a/physics/mover/pneumatics.cpp b/physics/mover/pneumatics.cpp index 5ed05fbd5..c4519d5fb 100644 --- a/physics/mover/pneumatics.cpp +++ b/physics/mover/pneumatics.cpp @@ -248,7 +248,7 @@ bool TMoverParameters::SpringBrakeActivate(bool State) { if (Power24vIsAvailable || Power110vIsAvailable) { - SendCtrlToNext(VehicleCommand::springBrakeActivate, int(State), CabActive, SpringBrake.MultiTractionCoupler); + SendCtrlToNext(VehicleCommand::springBrakeActivate, int(State), CabActive, CouplingSet::FromBits(SpringBrake.MultiTractionCoupler)); if (SpringBrake.Activate != State) { @@ -323,7 +323,7 @@ bool TMoverParameters::CompressorSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::compressorSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::compressorSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return CompressorAllow != initialstate; @@ -338,7 +338,7 @@ bool TMoverParameters::ChangeCompressorPreset(int const State, range_t const Not if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::compressorPreset, State, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::compressorPreset, State, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return CompressorListPos != initialstate; @@ -828,8 +828,8 @@ void TMoverParameters::CompressorCheck(double dt) // NOTE: this is crude implementation, limited only to adjacent vehicles // TODO: re-implement when a more elegant/flexible system is in place auto const coupledgovernorlock{ - (Couplers[end::rear].Connected != nullptr && true == TestFlag(Couplers[end::rear].CouplingFlag, coupling::permanent) && Couplers[end::rear].Connected->CompressorGovernorLock) || - (Couplers[end::front].Connected != nullptr && true == TestFlag(Couplers[end::front].CouplingFlag, coupling::permanent) && Couplers[end::front].Connected->CompressorGovernorLock)}; + (Couplers[end::rear].Connected != nullptr && true == Couplers[end::rear].CouplingFlag.HasAll(Coupling::permanent) && Couplers[end::rear].Connected->CompressorGovernorLock) || + (Couplers[end::front].Connected != nullptr && true == Couplers[end::front].CouplingFlag.HasAll(Coupling::permanent) && Couplers[end::front].Connected->CompressorGovernorLock)}; auto const governorlock{CompressorGovernorLock || coupledgovernorlock}; auto const compressorflag{CompressorFlag}; @@ -1141,7 +1141,7 @@ void TMoverParameters::UpdateDistributorSettings() for (auto const &couplerentry : Couplers) // nie podoba mi się to rozwiązanie, chyba trzeba // dodać jakiś wpis do fizyki na to - if (et41or42(TrainType) && couplerentry.Connected != nullptr && et41or42(couplerentry.Connected->TrainType) && (couplerentry.CouplingFlag & 36) == 36) + if (et41or42(TrainType) && couplerentry.Connected != nullptr && et41or42(couplerentry.Connected->TrainType) && couplerentry.CouplingFlag.HasAll(Coupling::control | Coupling::mainHose)) LocBrakePress = std::max(couplerentry.Connected->LocHandle->GetCP(), LocBrakePress); // if ((DynamicBrakeFlag) && (EngineType == ElectricInductionMotor)) @@ -1349,7 +1349,7 @@ double TMoverParameters::GetDVc(double dt) dv1 = 0; dv2 = 0; // sprzeg 1 - if (Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_pneumatic)) + if (Couplers[0].Connected != nullptr && Couplers[0].CouplingFlag.HasAll(Coupling::brakeHose)) { //*0.85 c = Couplers[0].Connected; // skrot //0.08 //e/D * L/D = e/D^2 * L dv1 = 0.5 * dt * PF(PipePress, neighbour_pipe_pressure(*c, c->PipePress, *c->Pipe), Spg / (1.0 + 0.015 / Spg * Dim.L)); @@ -1358,7 +1358,7 @@ double TMoverParameters::GetDVc(double dt) c->switch_physics(true, wake_cause::mainpipe); } // sprzeg 2 - if (Couplers[1].Connected != nullptr && TestFlag(Couplers[1].CouplingFlag, ctrain_pneumatic)) + if (Couplers[1].Connected != nullptr && Couplers[1].CouplingFlag.HasAll(Coupling::brakeHose)) { c = Couplers[1].Connected; // skrot dv2 = 0.5 * dt * PF(PipePress, neighbour_pipe_pressure(*c, c->PipePress, *c->Pipe), Spg / (1.0 + 0.015 / Spg * Dim.L)); @@ -1367,8 +1367,8 @@ double TMoverParameters::GetDVc(double dt) c->switch_physics(true, wake_cause::mainpipe); } // if ((Couplers[1].Connected != NULL) && (Couplers[0].Connected != NULL)) - // if ((TestFlag(Couplers[0].CouplingFlag, ctrain_pneumatic)) && - // (TestFlag(Couplers[1].CouplingFlag, ctrain_pneumatic))) + // if ((Couplers[0].CouplingFlag.HasAll(Coupling::brakeHose)) && + // (Couplers[1].CouplingFlag.HasAll(Coupling::brakeHose))) // { // dV = 0.05 * dt * PF(Couplers[0].Connected->PipePress, Couplers[1].Connected->PipePress, // (Spg * 0.85) / (1 + 0.03 * Dim.L)) * @@ -1392,7 +1392,7 @@ double TMoverParameters::GetScndDVc(double dt) double dv2 = 0; // sprzeg 1 - if (Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic)) + if (Couplers[0].Connected != nullptr && Couplers[0].CouplingFlag.HasAll(Coupling::mainHose)) { c = Couplers[0].Connected; // skrot dv1 = 0.5 * dt * PF(ScndPipePress, neighbour_pipe_pressure(*c, c->ScndPipePress, *c->Pipe2), Spz * 0.75); @@ -1401,7 +1401,7 @@ double TMoverParameters::GetScndDVc(double dt) c->switch_physics(true, wake_cause::scndpipe); } // sprzeg 2 - if (Couplers[1].Connected != nullptr && TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic)) + if (Couplers[1].Connected != nullptr && Couplers[1].CouplingFlag.HasAll(Coupling::mainHose)) { c = Couplers[1].Connected; // skrot dv2 = 0.5 * dt * PF(ScndPipePress, neighbour_pipe_pressure(*c, c->ScndPipePress, *c->Pipe2), Spz * 0.75); @@ -1409,7 +1409,7 @@ double TMoverParameters::GetScndDVc(double dt) if (pipe_wakes(dv2, ScndPipePress, *c->Pipe2)) c->switch_physics(true, wake_cause::scndpipe); } - if (Couplers[1].Connected != nullptr && Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic) && TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic)) + if (Couplers[1].Connected != nullptr && Couplers[0].Connected != nullptr && Couplers[0].CouplingFlag.HasAll(Coupling::mainHose) && Couplers[1].CouplingFlag.HasAll(Coupling::mainHose)) { double const dV = 0.00025 * dt * PF(Couplers[0].Connected->ScndPipePress, Couplers[1].Connected->ScndPipePress, Spz * 0.25); Couplers[0].Connected->Pipe2->Flow(+dV); @@ -1427,7 +1427,7 @@ struct train_pipe std::shared_ptr TMoverParameters::*reservoir; double TMoverParameters::*pressure; bool TMoverParameters::*pending; // the vehicle stepped the pipe, the exchange through its hoses is yet to come - int hose; // the coupling flag of the pipe's hose + CouplingSet hose; // the coupling of the pipe's hose double (TMoverParameters::*exchange)(double); // the air the hoses carry in a step, the neighbours' share sent to them double (*area)(TMoverParameters const &); // the cross-section of the hose, as the exchange takes it }; @@ -1436,14 +1436,14 @@ struct train_pipe train_pipe const brake_pipe{&TMoverParameters::Pipe, &TMoverParameters::PipePress, &TMoverParameters::PipeCouplersPending, - ctrain_pneumatic, + Coupling::brakeHose, &TMoverParameters::GetDVc, [](TMoverParameters const &Vehicle) { return Vehicle.Spg / (1.0 + 0.015 / Vehicle.Spg * Vehicle.Dim.L); }}; // the main reservoir pipe, GetScndDVc() train_pipe const main_reservoir_pipe{&TMoverParameters::Pipe2, &TMoverParameters::ScndPipePress, &TMoverParameters::ScndPipeCouplersPending, - ctrain_scndpneumatic, + Coupling::mainHose, &TMoverParameters::GetScndDVc, [](TMoverParameters const &) { return 0.5067 * 0.75; }}; @@ -1456,7 +1456,7 @@ int hose_substeps(TMoverParameters const &Vehicle, train_pipe const &Pipe, doubl auto const capacity{(Vehicle.*Pipe.reservoir)->GetCap()}; for (auto const &hose : Vehicle.Couplers) { - if (hose.Connected == nullptr || false == TestFlag(hose.CouplingFlag, Pipe.hose)) + if (hose.Connected == nullptr || false == hose.CouplingFlag.HasAll(Pipe.hose)) { continue; } @@ -1509,7 +1509,7 @@ std::vector hose_trains(std::vector const &Vehi stack.pop_back(); for (auto const &hose : vehicle.Couplers) { - if (hose.Connected == nullptr || false == TestFlag(hose.CouplingFlag, Pipe.hose)) + if (hose.Connected == nullptr || false == hose.CouplingFlag.HasAll(Pipe.hose)) { continue; } diff --git a/physics/mover/setup.cpp b/physics/mover/setup.cpp index 18a3abcea..29db46d97 100644 --- a/physics/mover/setup.cpp +++ b/physics/mover/setup.cpp @@ -410,7 +410,7 @@ double TMoverParameters::InitialScndPipePress(double const HosePressure) const { return CompressedVolume / VeselVolume; } - if ((Couplers[end::front].AllowedFlag & coupling::mainhose) != 0 || (Couplers[end::rear].AllowedFlag & coupling::mainhose) != 0) + if (Couplers[end::front].AllowedFlag.HasAny(Coupling::mainHose) || Couplers[end::rear].AllowedFlag.HasAny(Coupling::mainHose)) { return HosePressure; } diff --git a/physics/mover/traction.cpp b/physics/mover/traction.cpp index 745b51d0e..05b52bbc3 100644 --- a/physics/mover/traction.cpp +++ b/physics/mover/traction.cpp @@ -303,12 +303,12 @@ double TMoverParameters::ShowEngineRotation(int VehN) const return std::abs(enrot); case 2: for (b = 0; b <= 1; ++b) - if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01) + if (Couplers[b].CouplingFlag.HasAll(Coupling::control) && Couplers[b].Connected->Power > 0.01) return fabs(Couplers[b].Connected->enrot); break; case 3: // to nie uwzględnia ewentualnego odwrócenia pojazdu w środku for (b = 0; b <= 1; ++b) - if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01 && TestFlag(Couplers[b].Connected->Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Couplers[b].Connected->Power > 0.01) + if (Couplers[b].CouplingFlag.HasAll(Coupling::control) && Couplers[b].Connected->Power > 0.01 && Couplers[b].Connected->Couplers[b].CouplingFlag.HasAll(Coupling::control) && Couplers[b].Connected->Couplers[b].Connected->Power > 0.01) return fabs(Couplers[b].Connected->Couplers[b].Connected->enrot); break; default: @@ -412,7 +412,7 @@ bool TMoverParameters::MotorBlowersSwitch(bool State, end const Side, range_t co if (Notify != range_t::local) { SendCtrlToNext(Side == end::front ? VehicleCommand::motorBlowersFrontSwitch : VehicleCommand::motorBlowersRearSwitch, fan.is_enabled ? 1 : 0, CabActive, - Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return fan.is_enabled != initialstate; @@ -436,7 +436,7 @@ bool TMoverParameters::MotorBlowersSwitchOff(bool State, end const Side, range_t if (Notify != range_t::local) { SendCtrlToNext(Side == end::front ? VehicleCommand::motorBlowersFrontSwitchOff : VehicleCommand::motorBlowersRearSwitchOff, fan.is_disabled ? 1 : 0, CabActive, - Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return fan.is_disabled != initialstate; @@ -456,7 +456,7 @@ bool TMoverParameters::TractionModeSwitch(traction_mode const Mode, range_t cons if (Notify != range_t::local && accepted) { - SendCtrlToNext(VehicleCommand::tractionMode, Mode == traction_mode::genset ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::tractionMode, Mode == traction_mode::genset ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return TractionMode != initialstate; @@ -548,7 +548,7 @@ bool TMoverParameters::DynamicBrakeSwitch(bool Switch) DBS = true; for (auto &thiscoupler : Couplers) // with Couplers[b] do - if (TestFlag(thiscoupler.CouplingFlag, coupling::control)) + if (thiscoupler.CouplingFlag.HasAll(Coupling::control)) thiscoupler.Connected->DynamicBrakeFlag = Switch; // end; // if (DynamicBrakeType=dbrake_passive) and (TrainType=train_type::et42) then @@ -1454,7 +1454,7 @@ bool TMoverParameters::FuseFlagCheck(void) const FFC = FuseFlag; else // pobor pradu jezeli niema mocy for (auto &thiscoupler : Couplers) - if (TestFlag(thiscoupler.CouplingFlag, coupling::control) && thiscoupler.Connected->Power > 0.01) + if (thiscoupler.CouplingFlag.HasAll(Coupling::control) && thiscoupler.Connected->Power > 0.01) FFC = thiscoupler.Connected->FuseFlagCheck(); return FFC; @@ -1549,7 +1549,7 @@ bool TMoverParameters::RelayReset(int const Relays, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::relayReset, Relays, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::relayReset, Relays, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return reset; @@ -1637,7 +1637,7 @@ bool TMoverParameters::MaxCurrentSwitch(bool State, range_t const Notify) if (Notify != range_t::local) { - SendCtrlToNext(VehicleCommand::maxCurrentSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control); + SendCtrlToNext(VehicleCommand::maxCurrentSwitch, State ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return State != initialstate; @@ -1684,7 +1684,7 @@ bool TMoverParameters::ResistorsFlagCheck(void) const else // pobor pradu jezeli niema mocy { for (auto &thiscoupler : Couplers) - if (TestFlag(thiscoupler.CouplingFlag, coupling::control) && thiscoupler.Connected->Power > 0.01) + if (thiscoupler.CouplingFlag.HasAll(Coupling::control) && thiscoupler.Connected->Power > 0.01) RFC = thiscoupler.Connected->ResistorsFlagCheck(); } return RFC; @@ -1722,7 +1722,7 @@ double TMoverParameters::ShowCurrentP(int AmpN) const int current = 0; for (int b = 0; b < 2; b++) // with Couplers[b] do - if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01) + if (Couplers[b].CouplingFlag.HasAll(Coupling::control) && Couplers[b].Connected->Power > 0.01) current = static_cast(Couplers[b].Connected->ShowCurrent(AmpN)); return current; } diff --git a/physics/vehicletypes.h b/physics/vehicletypes.h index 077e94cb0..4cd26d21b 100644 --- a/physics/vehicletypes.h +++ b/physics/vehicletypes.h @@ -128,25 +128,6 @@ enum DerailReason /// Fuzzy-logic probability weight: damage caused by wheel slip. #define p_slippdmg (1e-03) -/*typ sprzegu*/ -/// Coupling type: virtual — vehicles share a track and are aware of each other. -static int const ctrain_virtual = 0; // gdy pojazdy na tym samym torze się widzą wzajemnie -/// Coupling type: physical coupler. -static int const ctrain_coupler = 1; // sprzeg fizyczny -/// Coupling type: pneumatic brake hose. -static int const ctrain_pneumatic = 2; // przewody hamulcowe -/// Coupling type: control cable (multiple-unit). -static int const ctrain_controll = 4; // przewody sterujące (ukrotnienie) -/// Coupling type: high-voltage power cable. -static int const ctrain_power = 8; // przewody zasilające (WN) -/// Coupling type: passenger gangway. -static int const ctrain_passenger = 16; // mostek przejściowy -/// Coupling type: secondary 8 atm pneumatic line (yellow, main air). -static int const ctrain_scndpneumatic = 32; // przewody 8 atm (żółte; zasilanie powietrzem) -/// Coupling type: high-voltage train heating cable. -static int const ctrain_heating = 64; // przewody ogrzewania WN -/// Coupling type: permanent (inter-section) — not separable during ordinary shunting; encoded as negative in config files. -static int const ctrain_depot = 128; // nie rozłączalny podczas zwykłych manewrów (międzyczłonowy), we wpisie wartość ujemna /// Vehicle ends — front or rear (mutually exclusive). enum end { @@ -165,35 +146,130 @@ enum side left = 1 }; -/// Bit flags representing the kind of physical/logical connections in a coupling. Combinable. -enum coupling +/// The kinds of connection a coupling between two vehicles makes. The numbers are the ones of the scenery +/// files and the vehicle definitions (AllowedFlag, the coupling of a vehicle in a train), where they add up. +enum class Coupling : unsigned { - /// No coupling (virtual / not connected). - faux = 0x0, - /// Mechanical coupler. - coupler = 0x1, - /// Pneumatic brake hose (PG). - brakehose = 0x2, - /// Control cable (multiple-unit). - control = 0x4, - /// High-voltage cable (traction supply). - highvoltage = 0x8, - /// Passenger gangway. - gangway = 0x10, - /// Main air (8 atm) line — secondary pneumatic supply. - mainhose = 0x20, - /// Train heating cable. - heating = 0x40, - /// Permanent (non-separable) coupling. - permanent = 0x80, - /// 24 V auxiliary power cable. - power24v = 0x100, - /// 110 V auxiliary power cable. - power110v = 0x200, - /// 3-phase 400 V auxiliary power cable. - power3x400v = 0x400, - // uic = 0x1000, + none = 0x0, // the vehicles only see each other (virtual) + coupler = 0x1, // the mechanical coupler + brakeHose = 0x2, // the brake pipe + control = 0x4, // the control cable of the multiple unit + highVoltage = 0x8, // the high voltage cable of the traction supply + gangway = 0x10, // the gangway for the passengers + mainHose = 0x20, // the main reservoir pipe (8 bar, yellow) + heating = 0x40, // the high voltage cable of the train heating + permanent = 0x80, // not parted by usual shunting (between the sections of a unit); negative in a definition + power24v = 0x100, // the 24 V cable + power110v = 0x200, // the 110 V cable + power3x400v = 0x400, // the 3x400 V cable }; + +/// A set of the kinds of connection of a coupling: what a coupling joins, what a vehicle allows, what a +/// command needs to pass. Read from and written to the numbers of the files only through FromBits() and Bits(). +class CouplingSet +{ +public: + constexpr CouplingSet() = default; + constexpr CouplingSet(Coupling const kind) : bits{static_cast(kind)} {} // NOSONAR: a kind is a set of one + // the set the number of a file gives (the sum of the numbers of the kinds) + static constexpr CouplingSet FromBits(int const number) + { + CouplingSet set; + set.bits = static_cast(number); + return set; + } + // every kind of coupling: a coupling of any kind has one of them + static constexpr CouplingSet All() + { + return FromBits(-1); + } + // any kind at all: as the old number was true when it wasn't zero + constexpr explicit operator bool() const + { + return bits != 0; + } + // the number of the set, for the files and the log + constexpr int Bits() const + { + return static_cast(bits); + } + constexpr bool Empty() const + { + return bits == 0; + } + // all the kinds of the other set are in this one + constexpr bool HasAll(CouplingSet const other) const + { + return (bits & other.bits) == other.bits; + } + // any of the kinds of the other set is in this one + constexpr bool HasAny(CouplingSet const other) const + { + return (bits & other.bits) != 0; + } + // adds the kinds; returns whether any of them was missing + constexpr bool Set(CouplingSet const other) + { + if (HasAll(other)) + { + return false; + } + bits |= other.bits; + return true; + } + // takes the kinds away, where all of them are there; returns whether it did + constexpr bool Clear(CouplingSet const other) + { + if (false == HasAll(other)) + { + return false; + } + bits &= ~other.bits; + return true; + } + // this set without the kinds of the other + constexpr CouplingSet Without(CouplingSet const other) const + { + return FromBits(static_cast(bits & ~other.bits)); + } + constexpr CouplingSet &operator|=(CouplingSet const other) + { + bits |= other.bits; + return *this; + } + constexpr CouplingSet &operator&=(CouplingSet const other) + { + bits &= other.bits; + return *this; + } + friend constexpr CouplingSet operator|(CouplingSet left, CouplingSet const right) + { + return left |= right; + } + friend constexpr CouplingSet operator&(CouplingSet left, CouplingSet const right) + { + return left &= right; + } + // the kinds in one of the sets and not in the other: what changed between them + constexpr CouplingSet &operator^=(CouplingSet const other) + { + bits ^= other.bits; + return *this; + } + friend constexpr CouplingSet operator^(CouplingSet left, CouplingSet const right) + { + return left ^= right; + } + friend constexpr bool operator==(CouplingSet const &left, CouplingSet const &right) = default; + +private: + unsigned bits{0}; +}; + +constexpr CouplingSet operator|(Coupling const left, Coupling const right) +{ + return CouplingSet{left} | CouplingSet{right}; +} /// Range of effect for a control command (mutually exclusive). enum class range_t { @@ -616,7 +692,7 @@ struct TCommand /// Second numeric argument. double Value2 = 0.0; /// Coupling flag controlling how the command propagates between vehicles. - int Coupling{coupling::control}; // coupler flag used to determine command propagation + CouplingSet couplings{Coupling::control}; // the couplings the command passes through /// World-space location associated with the command. TLocation Location; }; diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp index 1a91a1f5c..ebceae0ff 100644 --- a/rendering/common/scenewalk.cpp +++ b/rendering/common/scenewalk.cpp @@ -186,16 +186,16 @@ bool scene_walk::Render_interior( bool const Alpha ) { glm::dvec3 const originoffset { dynamic->vPosition - m_renderpass.pass_camera.position() }; float const squaredistance{ glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) }; dynamics.emplace_back( squaredistance, dynamic ); - dynamic = dynamic->Next( coupling::permanent ); + dynamic = dynamic->Next( Coupling::permanent ); } // draw also interiors of permanently coupled vehicles in front, if there's any - dynamic = simulation::Train->Dynamic()->Prev( coupling::permanent ); + dynamic = simulation::Train->Dynamic()->Prev( Coupling::permanent ); while( dynamic != nullptr ) { glm::dvec3 const originoffset { dynamic->vPosition - m_renderpass.pass_camera.position() }; float const squaredistance{ glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) }; dynamics.emplace_back( squaredistance, dynamic ); - dynamic = dynamic->Prev( coupling::permanent ); + dynamic = dynamic->Prev( Coupling::permanent ); } if( Alpha ) { std::sort( diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 3599bb1bb..e53e77dfa 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -208,7 +208,7 @@ bool coupled(TDynamicObject const *From, TDynamicObject const *To) { for (int step = 0; step < 1000 && vehicle != nullptr; ++step) { auto const *mover{vehicle->MoverParameters}; auto const &neighbour{mover->Neighbours[side]}; - if (mover->Couplers[side].CouplingFlag == 0 || neighbour.vehicle == nullptr) + if (mover->Couplers[side].CouplingFlag.Empty() || neighbour.vehicle == nullptr) break; if (neighbour.vehicle == To) return true; @@ -621,8 +621,8 @@ void blackbox_recorder::look_at_couplers() { for (int side = 0; side < 2; ++side) { auto const flags{mover->Couplers[side].CouplingFlag}; // a neighbour not coupled is only seen on the same track - auto const *other{flags != 0 ? mover->Neighbours[side].vehicle : nullptr}; - coupler_entry const now{other, other != nullptr ? mover->Neighbours[side].vehicle_end : 0, other != nullptr ? flags : 0}; + auto const *other{false == flags.Empty() ? mover->Neighbours[side].vehicle : nullptr}; + coupler_entry const now{other, other != nullptr ? mover->Neighbours[side].vehicle_end : 0, other != nullptr ? flags.Bits() : 0}; auto &last{entry.couplers[side]}; auto const changed{now.other != last.other || now.other_side != last.other_side || now.flags != last.flags}; auto const before{last}; diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp index 69fc726b9..7c4644868 100644 --- a/simulation/simulationstateserializer.cpp +++ b/simulation/simulationstateserializer.cpp @@ -1478,7 +1478,7 @@ state_serializer::deserialize_endtrainset( cParser &Input, scene::scratch_data & 0, nullptr ); } - if( Scratchpad.trainset.couplings.back() == coupling::faux ) { + if( Scratchpad.trainset.couplings.back() == 0 ) { // no coupling // jeśli ostatni pojazd ma sprzęg 0 to założymy mu końcówki blaszane (jak AI się odpali, to sobie poprawi) // place end signals only on trains without a driver, activate markers otherwise Scratchpad.trainset.vehicles.back()->RaLightsSet( @@ -1625,12 +1625,12 @@ state_serializer::deserialize_dynamic( cParser &Input, scene::scratch_data &Scra auto coupling = couplingdatawithparams != std::string::npos ? std::atoi(couplingdata.substr(0, couplingdatawithparams).c_str()) : std::atoi(couplingdata.c_str()); if( coupling < 0 ) { // sprzęg zablokowany (pojazdy nierozłączalne przy manewrach) - coupling = -coupling | coupling::permanent; + coupling = ( CouplingSet::FromBits( -coupling ) | Coupling::permanent ).Bits(); } if( offset != -1.0 && std::abs(offset) > 0.5 ) { // maksymalna odległość między sprzęgami - do przemyślenia // likwidacja sprzęgu, jeśli odległość zbyt duża - to powinno być uwzględniane w fizyce sprzęgów... - coupling = coupling::faux; + coupling = 0; // no coupling } auto const params = couplingdatawithparams != std::string::npos ? couplingdata.substr(couplingdatawithparams + 1) : ""; // load amount and type @@ -1692,8 +1692,8 @@ state_serializer::deserialize_dynamic( cParser &Input, scene::scratch_data &Scra } // automatically establish permanent connections for couplers which specify them in their definitions if( coupling != 0 - && vehicle->MoverParameters->Couplers[(offset == -1.0 ? end::front : end::rear)].AllowedFlag & coupling::permanent ) { - coupling |= coupling::permanent; + && vehicle->MoverParameters->Couplers[(offset == -1.0 ? end::front : end::rear)].AllowedFlag & Coupling::permanent ) { + coupling = ( CouplingSet::FromBits( coupling ) | Coupling::permanent ).Bits(); } if( true == Scratchpad.trainset.is_open ) { Scratchpad.trainset.vehicles.emplace_back( vehicle ); diff --git a/simulation/simulationtest.cpp b/simulation/simulationtest.cpp index f6e2a4a39..a247918aa 100644 --- a/simulation/simulationtest.cpp +++ b/simulation/simulationtest.cpp @@ -188,7 +188,7 @@ bool test_manager::tested_trains_at_rest() const // the consists as they are now: a train the tested one couples to joins it, one it leaves behind doesn't return std::ranges::none_of(Global.test.vehicles, [](std::string const &Name) { auto *vehicle { simulation::Vehicles.find(Name) }; - return vehicle != nullptr && vehicle->find_vehicle(coupling::coupler, is_moving) != nullptr; + return vehicle != nullptr && vehicle->find_vehicle(Coupling::coupler, is_moving) != nullptr; }); } diff --git a/tests/unit/consist.cpp b/tests/unit/consist.cpp index 1f22632e6..141abe5af 100644 --- a/tests/unit/consist.cpp +++ b/tests/unit/consist.cpp @@ -8,7 +8,7 @@ namespace test { consist::consist() = default; consist::~consist() = default; -vehicle &consist::add(definition const &Definition, int Cab, int Coupling, double Velocity, double Gap) { +vehicle &consist::add(definition const &Definition, int Cab, CouplingSet const couplings, double Velocity, double Gap) { auto added{std::make_unique(Definition, Velocity, std::format("test{}", m_vehicles.size()), Cab)}; auto &mover{added->mover()}; @@ -20,9 +20,9 @@ vehicle &consist::add(definition const &Definition, int Cab, int Coupling, doubl auto &last{m_vehicles.back()->mover()}; position = m_positions.back() - 0.5 * (last.Dim.L + mover.Dim.L) - Gap; mover.Loc = TLocation{position, 0.0, 0.0}; - if (Coupling != coupling::faux) { - last.Attach(end::rear, end::front, &mover, Coupling, true, false); - mover.Attach(end::front, end::rear, &last, Coupling, true, false); + if (false == couplings.Empty()) { + last.Attach(end::rear, end::front, &mover, couplings, true, false); + mover.Attach(end::front, end::rear, &last, couplings, true, false); } } else { diff --git a/tests/unit/consist.h b/tests/unit/consist.h index 2c982e446..eb330e787 100644 --- a/tests/unit/consist.h +++ b/tests/unit/consist.h @@ -21,8 +21,8 @@ namespace test { class consist { public: // everything a coupler can join, as two vehicles of a train coupled by a crew - static constexpr int full_coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control | coupling::gangway | coupling::heating | - coupling::permanent | coupling::power110v | coupling::power24v | coupling::highvoltage}; + static constexpr CouplingSet full_coupling{Coupling::coupler | Coupling::brakeHose | Coupling::mainHose | Coupling::control | Coupling::gangway | Coupling::heating | + Coupling::permanent | Coupling::power110v | Coupling::power24v | Coupling::highVoltage}; consist(); ~consist(); @@ -31,8 +31,8 @@ public: // a vehicle at the back of the train, its front coupler joined to the rear one of the last vehicle with // the given coupling (coupling flags), Gap [m] between their buffers. Cab as for a vehicle. a vehicle - // with no coupling (coupling::faux) is free on the same track, as one about to be coupled or hit - vehicle &add(definition const &Definition, int Cab = 0, int Coupling = full_coupling, double Velocity = 0.0, double Gap = 0.0); + // with no coupling (Coupling::none) is free on the same track, as one about to be coupled or hit + vehicle &add(definition const &Definition, int Cab = 0, CouplingSet couplings = full_coupling, double Velocity = 0.0, double Gap = 0.0); vehicle &operator[](std::size_t Index) { return *m_vehicles[Index]; } std::size_t size() const { return m_vehicles.size(); } diff --git a/tests/unit/drive.cpp b/tests/unit/drive.cpp index 6c0356ad5..7663d8363 100644 --- a/tests/unit/drive.cpp +++ b/tests/unit/drive.cpp @@ -74,7 +74,7 @@ void release_brakes(TMoverParameters &Cab) { auto const *vehicle{pending.back()}; pending.pop_back(); for (auto const &thiscoupler : vehicle->Couplers) { - if (thiscoupler.Connected != nullptr && thiscoupler.CouplingFlag != coupling::faux && std::ranges::find(train, thiscoupler.Connected) == train.end()) { + if (thiscoupler.Connected != nullptr && thiscoupler.CouplingFlag != Coupling::none && std::ranges::find(train, thiscoupler.Connected) == train.end()) { thiscoupler.Connected->DecManualBrakeLevel(ManualBrakePosNo); thiscoupler.Connected->SpringBrake.Activate = false; train.push_back(thiscoupler.Connected); diff --git a/tests/unit/scenario.cpp b/tests/unit/scenario.cpp index ebb5ae0c3..9dfee124f 100644 --- a/tests/unit/scenario.cpp +++ b/tests/unit/scenario.cpp @@ -24,8 +24,8 @@ scenario::scenario(std::string Name, std::vector Channels, track const reseed_random(); } -scenario &scenario::add(std::string const &Path, int Cab, int Coupling, double Velocity, double Gap) { - m_train.add(definition::fiz(Path), Cab, Coupling, Velocity, Gap); +scenario &scenario::add(std::string const &Path, int Cab, CouplingSet const couplings, double Velocity, double Gap) { + m_train.add(definition::fiz(Path), Cab, couplings, Velocity, Gap); return *this; } diff --git a/tests/unit/scenario.h b/tests/unit/scenario.h index fff4d9619..54678af5d 100644 --- a/tests/unit/scenario.h +++ b/tests/unit/scenario.h @@ -25,7 +25,7 @@ public: scenario(std::string Name, std::vector Channels, track const &Track = {0.15, 0.0, catenary_3kv}); // adds a real vehicle at the back, see consist::add() - scenario &add(std::string const &Path, int Cab = 0, int Coupling = consist::full_coupling, double Velocity = 0.0, double Gap = 0.0); + scenario &add(std::string const &Path, int Cab = 0, CouplingSet couplings = consist::full_coupling, double Velocity = 0.0, double Gap = 0.0); consist &train() { return m_train; } TMoverParameters &vehicle(std::size_t Index) { return m_train[Index].mover(); } diff --git a/tests/unit/test_brakes.cpp b/tests/unit/test_brakes.cpp index cd2a95a3c..5c5246798 100644 --- a/tests/unit/test_brakes.cpp +++ b/tests/unit/test_brakes.cpp @@ -102,7 +102,7 @@ TEST_CASE("brakes: service braking stops a heavier wagon too") { TEST_CASE("brakes: a dead EN57 hauled with the brake hose alone charges from the brake pipe and brakes") { test::consist train; auto &locomotive{train.add(definition::fiz("sm42_v1/6d1"))}; - train.add(definition::fiz("en57_v1/5bgb"), 0, coupling::coupler | coupling::brakehose); + train.add(definition::fiz("en57_v1/5bgb"), 0, Coupling::coupler | Coupling::brakeHose); train.add(definition::fiz("en57_v1/6ba_840")); train.add(definition::fiz("en57_v1/5bgaiii_led_spot")); // a unit standing dead: no air anywhere, nothing in its main reservoir pipe diff --git a/tests/unit/test_cab.cpp b/tests/unit/test_cab.cpp index eab6e87ca..40a94d552 100644 --- a/tests/unit/test_cab.cpp +++ b/tests/unit/test_cab.cpp @@ -38,7 +38,7 @@ TEST_CASE("cab: the engine rotation of up to three vehicles in multiple, on the // no control cable, no reading consist apart; auto const &alone{apart.add(definition::fiz("sn61_v2/sn61"), 1).mover()}; - apart.add(definition::fiz("sn61_v2/sn61"), 0, coupling::coupler | coupling::brakehose); + apart.add(definition::fiz("sn61_v2/sn61"), 0, Coupling::coupler | Coupling::brakeHose); CHECK(alone.ShowEngineRotation(2) == doctest::Approx(0.0)); } diff --git a/tests/unit/test_collisions.cpp b/tests/unit/test_collisions.cpp index bafa01a82..be5910011 100644 --- a/tests/unit/test_collisions.cpp +++ b/tests/unit/test_collisions.cpp @@ -125,8 +125,8 @@ definition mixed_wagon(int const Index) { return definition::fiz(Index % 3 == 1 ? "3wl_v2/3wl" : "430w_v2/430w"); } -vehicle &add_mixed(consist &Train, int const Index, int const Coupling, double const Velocity, double const Gap) { - auto &wagon{Train.add(mixed_wagon(Index), 0, Coupling, Velocity, Gap)}; +vehicle &add_mixed(consist &Train, int const Index, CouplingSet const couplings, double const Velocity, double const Gap) { + auto &wagon{Train.add(mixed_wagon(Index), 0, couplings, Velocity, Gap)}; if (Index % 3 != 1) { wagon->AssignLoad("coal", 59.5f); wagon->ComputeMass(); @@ -162,7 +162,7 @@ crash_outcome freight_crash(double const Speed, double const Radius, double cons } train.run(30.0, track); // the train running into it, its locomotive leading, a metre short of the hit - train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, Speed, 1.0); + train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, Speed, 1.0); for (int i = 0; i < 12; ++i) { add_mixed(train, i, consist::full_coupling, Speed, 0.0); } @@ -202,7 +202,7 @@ double locomotive_into_wagon(double const Speed, double const Dt) { wagon->AssignLoad("coal", 59.5f); wagon->ComputeMass(); // behind the wagon, running forwards into its rear end - auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, Speed, 0.5)}; + auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, Speed, 0.5)}; train.run(3.0, {}, Dt); return wagon->Couplers[end::rear].crush + locomotive->Couplers[end::front].crush; } @@ -235,7 +235,7 @@ struct contact_outcome { contact_outcome contact(definition const &Front, definition const &Back, double const Speed, double const Gap, double const Seconds = 5.0, double const Dt = 0.01) { consist train; auto &front{train.add(Front)}; - auto &back{train.add(Back, 0, coupling::faux, Speed, Gap)}; + auto &back{train.add(Back, 0, Coupling::none, Speed, Gap)}; train.run(Seconds, {}, Dt); contact_outcome result; result.crush = front->Couplers[end::rear].crush + back->Couplers[end::front].crush; @@ -266,8 +266,8 @@ double pushed_ratio_of(TMoverParameters const &Vehicle, int const End, double co } // a loaded 430W coal wagon -vehicle &add_loaded(consist &Train, int const Coupling, double const Velocity, double const Gap) { - auto &wagon{Train.add(definition::fiz("430w_v2/430w"), 0, Coupling, Velocity, Gap)}; +vehicle &add_loaded(consist &Train, CouplingSet const couplings, double const Velocity, double const Gap) { + auto &wagon{Train.add(definition::fiz("430w_v2/430w"), 0, couplings, Velocity, Gap)}; wagon->AssignLoad("coal", 59.5f); wagon->ComputeMass(); return wagon; @@ -579,7 +579,7 @@ TEST_CASE("collisions: a locomotive at its starting effort against a braked trai train[i].hold_brake_pipe(0.0); } train.run(30.0, line); - auto &locomotive{train.add(definition::fiz("st44_v2/m62-1151"), 1, coupling::faux, 0.0, 0.0)}; + auto &locomotive{train.add(definition::fiz("st44_v2/m62-1151"), 1, Coupling::none, 0.0, 0.0)}; test::driven const driver{locomotive.mover(), locomotive.mover(), locomotive.mover(), [&train](double const Seconds, test::track const &Track) { train.run(Seconds, Track); }}; REQUIRE(test::start_up(driver, line)); test::release_brakes(locomotive.mover()); @@ -625,7 +625,7 @@ TEST_CASE("collisions: a locomotive running onto an empty wagon at 9 km/h doesn' curve.radius = 150.0; consist train; auto &empty{train.add(definition::fiz("3wl_v2/3wl"))}; - auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, 9.0, 0.5)}; + auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 9.0, 0.5)}; auto pushed{0.0}; auto worst{0.0}; auto over{0}; // steps past the climbing limit @@ -661,7 +661,7 @@ TEST_CASE("collisions: a train propelling an empty wagon into a braked one in a train[i].hold_brake_pipe(0.0); } train.run(30.0, curve); - auto &empty{train.add(definition::fiz("3wl_v2/3wl"), 0, coupling::faux, 15.0, 1.0)}; + auto &empty{train.add(definition::fiz("3wl_v2/3wl"), 0, Coupling::none, 15.0, 1.0)}; train.add(definition::fiz("4e_v1/4e"), 0, consist::full_coupling, 15.0, 0.0); for (int i = 0; i < 6; ++i) { add_loaded(train, consist::full_coupling, 15.0, 0.0); @@ -681,8 +681,8 @@ TEST_CASE("collisions: a repaired vehicle has its ends rebuilt and is back on th model_setting const physical{global_settings::collision_model::physical}; flag_setting const crashdamage{Global.crash_damage, true}; consist train; - auto &wagon{add_loaded(train, coupling::faux, 0.0, 0.0)}; - auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, 30.0, 0.5)}; + auto &wagon{add_loaded(train, Coupling::none, 0.0, 0.0)}; + auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 30.0, 0.5)}; train.run(3.0); REQUIRE(wagon->Couplers[end::rear].crush + locomotive->Couplers[end::front].crush > cl::override_crush); REQUIRE((derailed(wagon.mover()) || derailed(locomotive.mover()))); @@ -764,7 +764,7 @@ TEST_CASE("collisions: the legacy rule with physics.collisions old, the crush wi model_setting const setting{model}; consist train; train.add(definition::fiz(front)); - train.add(definition::fiz(back), 0, coupling::faux, speed, 20.0); + train.add(definition::fiz(back), 0, Coupling::none, speed, 20.0); train.run(10.0); CHECK(derailed(train[0].mover()) == (physical ? frontout_new : frontout_old)); CHECK(derailed(train[1].mover()) == (physical ? backout_new : backout_old)); @@ -805,7 +805,7 @@ TEST_CASE("collisions: the model of the collisions goes apart from the one of th model_setting const setting{collisions}; consist train; train.add(definition::fiz("4e_v1/4e")); - train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, 25.0, 20.0); + train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 25.0, 20.0); train.run(10.0); Global.derailment = previous; auto const crush{train[0]->Couplers[end::rear].crush + train[1]->Couplers[end::front].crush}; @@ -844,7 +844,7 @@ TEST_CASE("collisions: the crush of a locomotive hitting a wagon doesn't depend TEST_CASE("collisions: automatic couplers hit too fast don't catch, the ends crush; torn off, they don't couple again") { model_setting const physical{global_settings::collision_model::physical}; flag_setting const crashdamage{Global.crash_damage, true}; - auto const automatic{definition::load("wagon").set("BuffCoupl", "CType", "Automatic").set("BuffCoupl", "AutomaticFlag", coupling::coupler | coupling::brakehose)}; + auto const automatic{definition::load("wagon").set("BuffCoupl", "CType", "Automatic").set("BuffCoupl", "AutomaticFlag", Coupling::coupler | Coupling::brakeHose)}; for (auto const speed : {20.0, 30.0, 45.0}) { CAPTURE(speed); vehicle moving{automatic, speed, "moving"}; @@ -882,7 +882,7 @@ TEST_CASE("collisions: road vehicles keep the legacy rule") { model_setting const setting{model}; consist road; road.add(definition::fiz("road/man/nl293")); - road.add(definition::fiz("road/man/nl293"), 0, coupling::faux, 40.0, 5.0); + road.add(definition::fiz("road/man/nl293"), 0, Coupling::none, 40.0, 5.0); road.run(5.0); CHECK(derailed(road[0].mover())); CHECK(derailed(road[1].mover())); @@ -897,7 +897,7 @@ TEST_CASE("collisions: a vehicle off the rails by the new model stays in the cha flag_setting const crashdamage{Global.crash_damage, true}; consist train; auto &wagon{train.add(definition::fiz("430w_v2/430w"))}; - auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, 10.0, 0.5)}; + auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 10.0, 0.5)}; wagon->derail_in_collision(COLLISION_PUSHED_OFF, "for the test"); REQUIRE(derailed(wagon.mover())); auto const before{wagon->TotalMass * wagon->V + locomotive->TotalMass * locomotive->V}; @@ -946,7 +946,7 @@ TEST_CASE("collisions: identical units built to EN 15227 at 36 km/h") { consist train; train.add(unit(Anticlimbers, 1.040)); train.add(unit(Anticlimbers, 1.040)); - train.add(unit(Anticlimbers, 1.040 + Offset), 0, coupling::faux, Speed, 1.0); + train.add(unit(Anticlimbers, 1.040 + Offset), 0, Coupling::none, Speed, 1.0); train.add(unit(Anticlimbers, 1.040 + Offset), 0, consist::full_coupling, Speed); train.run(6.0); struct { @@ -1205,7 +1205,7 @@ TEST_CASE("collisions: two coaches (36 t and 41.6 t) at 8 km/h don't crush, nor auto &wall{train.add(light)}; wall->Derail(END_OF_TRACK); REQUIRE(derailed(wall.mover())); - auto &running{train.add(heavy, 0, coupling::faux, 5.0, gap)}; + auto &running{train.add(heavy, 0, Coupling::none, 5.0, gap)}; train.run(5.0); CHECK(wall->Couplers[end::rear].crush + running->Couplers[end::front].crush == 0.0); CHECK(running->CollisionDerail == NONE); @@ -1231,7 +1231,7 @@ TEST_CASE("collisions: a locomotive pushing a standing braked train at full powe } train.run(30.0, line); // the locomotive behind them, touching, driven forwards into them at full power - auto &locomotive{train.add(definition::fiz(path), 1, coupling::faux, 0.0, 0.0)}; + auto &locomotive{train.add(definition::fiz(path), 1, Coupling::none, 0.0, 0.0)}; test::driven const driver{locomotive.mover(), locomotive.mover(), locomotive.mover(), [&train](double const Seconds, test::track const &Track) { train.run(Seconds, Track); }}; REQUIRE(test::start_up(driver, line)); test::release_brakes(locomotive.mover()); @@ -1298,14 +1298,14 @@ TEST_CASE("collisions: the monitor goes by the energy of the hit as well") { CAPTURE(gap); consist train; train.add(definition::fiz("sm42_v1/6d1")); - train.add(definition::fiz("su45_v2/301d"), 0, coupling::faux, 5.8, gap); + train.add(definition::fiz("su45_v2/301d"), 0, Coupling::none, 5.8, gap); train.run(5.0); CHECK(train[0]->crush_reports + train[1]->crush_reports == 0); } // one past them it does consist train; train.add(definition::fiz("4e_v1/4e")); - train.add(definition::fiz("4e_v1/4e"), 0, coupling::faux, 25.0, 20.0); + train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 25.0, 20.0); train.run(10.0); CHECK(train[0]->crush_reports + train[1]->crush_reports == 1); } @@ -1370,7 +1370,7 @@ TEST_CASE("collisions: the cut of the speed of the legacy derailment is no hit i for (auto const reason : {TOO_HIGH_SPEED, END_OF_TRACK}) { CAPTURE(reason); consist train; - auto &locomotive{train.add(definition::fiz(path), 0, coupling::faux, speed)}; + auto &locomotive{train.add(definition::fiz(path), 0, Coupling::none, speed)}; for (int i = 0; i < 3; ++i) { train.add(coach(41.0e3), 0, consist::full_coupling, speed); } @@ -1415,7 +1415,7 @@ TEST_CASE("collisions: the train behind a vehicle that ran off the end of the tr auto const speed{pushed ? 33.0 : 30.0}; consist train; if (false == pushed) { - train.add(definition::fiz("st44_v2/m62-1151"), 0, coupling::faux, speed); + train.add(definition::fiz("st44_v2/m62-1151"), 0, Coupling::none, speed); } constexpr int wagons{6}; for (int i = 0; i < wagons; ++i) { @@ -1477,7 +1477,7 @@ TEST_CASE("collisions: a pair parting at the start of the step isn't crushed (l0 consist train; auto &front{train.add(definition::fiz("430w_v2/430w"))}; // behind it with the buffers pressed to their stop, moving back away from it, or standing - auto &back{train.add(definition::fiz("430w_v2/430w"), 0, coupling::faux, parting ? -3.0 : 0.0, -0.3)}; + auto &back{train.add(definition::fiz("430w_v2/430w"), 0, Coupling::none, parting ? -3.0 : 0.0, -0.3)}; // one step, the way the consist steps it, with the vehicle behind knocked forwards onto the front one between // the forces and the movement, as a hit of another vehicle in the step does constexpr double dt{0.01}; diff --git a/tests/unit/test_commands.cpp b/tests/unit/test_commands.cpp index a0b6569db..bd06bb26b 100644 --- a/tests/unit/test_commands.cpp +++ b/tests/unit/test_commands.cpp @@ -249,7 +249,7 @@ TEST_CASE("commands: every command run on every real vehicle") { auto const &command{commands[i]}; trace.mark(std::format("{} {} {}", command.name, command.value1, command.value2)); auto const parsed{ParseVehicleCommand(command.name)}; - done = real->RunCommand(parsed.command, command.value1, command.value2, coupling::control, parsed.argument); + done = real->RunCommand(parsed.command, command.value1, command.value2, Coupling::control, parsed.argument); trace.sample(static_cast(i + 1), real.mover()); } trace.check(); @@ -448,9 +448,9 @@ struct train { vehicle middle{definition::fiz("4e_v1/4e"), 0.0, "middle"}; vehicle last{definition::fiz("4e_v1/4e"), 0.0, "last"}; - explicit train(int Coupling) { - head->Attach(end::rear, end::rear, &middle.mover(), Coupling, true, false); - middle->Attach(end::front, end::front, &last.mover(), Coupling, true, false); + explicit train(CouplingSet const couplings) { + head->Attach(end::rear, end::rear, &middle.mover(), couplings, true, false); + middle->Attach(end::front, end::front, &last.mover(), couplings, true, false); } }; @@ -485,24 +485,24 @@ TEST_CASE("commands: travel along the train, turned round for a vehicle facing b CHECK(consist.last->Pantographs[end::rear].valve.is_enabled); } SUBCASE("sent backwards, it goes no further than the sender: nothing is coupled at its front") { - consist.head->RunCommand(VehicleCommand::doorLock, 0, -1, coupling::control); + consist.head->RunCommand(VehicleCommand::doorLock, 0, -1, Coupling::control); CHECK_FALSE(consist.head->Doors.lock_enabled); CHECK(consist.middle->Doors.lock_enabled); } SUBCASE("the same command again isn't taken by the next vehicle a second time") { - CHECK(consist.middle->SetInternalCommand(VehicleCommand::doorStep, 0, 1, coupling::control)); - CHECK_FALSE(consist.middle->SetInternalCommand(VehicleCommand::doorStep, 0, 1, coupling::control)); + CHECK(consist.middle->SetInternalCommand(VehicleCommand::doorStep, 0, 1, Coupling::control)); + CHECK_FALSE(consist.middle->SetInternalCommand(VehicleCommand::doorStep, 0, 1, Coupling::control)); CHECK_FALSE(consist.head->RunInternalCommand()); // nothing to run } } TEST_CASE("commands: don't pass a coupling without the control cable") { - train consist{coupling::coupler | coupling::brakehose}; - consist.head->RunCommand(VehicleCommand::doorLock, 0, 1, coupling::control); + train consist{Coupling::coupler | Coupling::brakeHose}; + consist.head->RunCommand(VehicleCommand::doorLock, 0, 1, Coupling::control); CHECK_FALSE(consist.head->Doors.lock_enabled); CHECK(consist.middle->Doors.lock_enabled); // a command of another coupling goes through it - consist.head->RunCommand(VehicleCommand::doorStep, 0, 1, coupling::brakehose); + consist.head->RunCommand(VehicleCommand::doorStep, 0, 1, Coupling::brakeHose); CHECK_FALSE(consist.middle->Doors.step_enabled); } diff --git a/tests/unit/test_controls.cpp b/tests/unit/test_controls.cpp index 251bb18a6..47b852f2d 100644 --- a/tests/unit/test_controls.cpp +++ b/tests/unit/test_controls.cpp @@ -508,7 +508,7 @@ TEST_CASE("controls: a locomotive running into a standing wagon") { CAPTURE(speed); scenario scenario{std::format("controls/collision/{} kmh", static_cast(speed)), motion()}; // the wagon stands in front, the locomotive comes from behind it - scenario.add("bdhpumn_v3/bdhpumn").add("4e_v1/4e", 0, coupling::faux, speed, 30.0); + scenario.add("bdhpumn_v3/bdhpumn").add("4e_v1/4e", 0, Coupling::none, speed, 30.0); auto const &wagon{scenario.vehicle(0)}; scenario.wait(30.0); // slow, the locomotive pushes the wagon off, the buffers only touching, and both roll to a stop; fast, diff --git a/tests/unit/test_coupler_physics.cpp b/tests/unit/test_coupler_physics.cpp index ebffa8e80..31b46a165 100644 --- a/tests/unit/test_coupler_physics.cpp +++ b/tests/unit/test_coupler_physics.cpp @@ -268,9 +268,9 @@ TEST_CASE("coupler physics: a jerk on the solid draw gear breaks the coupling by namespace { // couples the facing ends of the two vehicles, as the scenery does -void join(vehicle &First, int FirstEnd, vehicle &Second, int SecondEnd, int Coupling = coupling::coupler) { - REQUIRE(First->Attach(FirstEnd, SecondEnd, &Second.mover(), Coupling, true, false)); - REQUIRE(Second->Attach(SecondEnd, FirstEnd, &First.mover(), Coupling, true, false)); +void join(vehicle &First, int FirstEnd, vehicle &Second, int SecondEnd, CouplingSet const couplings = Coupling::coupler) { + REQUIRE(First->Attach(FirstEnd, SecondEnd, &Second.mover(), couplings, true, false)); + REQUIRE(Second->Attach(SecondEnd, FirstEnd, &First.mover(), couplings, true, false)); } // the wagon of data/wagon.json with the given play of its screw couplings @@ -391,7 +391,7 @@ TEST_CASE("coupler physics: a jerk on a coupling with play breaks it, the brake flag_setting const everywhere{Global.coupler_physics_all, true}; auto front{loose_wagon(0.05, 20.0, "front")}; auto rear{loose_wagon(0.05, 0.1, "rear")}; - join(rear, end::front, front, end::rear, coupling::coupler | coupling::brakehose); + join(rear, end::front, front, end::rear, Coupling::coupler | Coupling::brakeHose); test::pair pair{rear, end::front, front, end::rear, 0.0}; front.hold_brake_pipe(5.0); rear.hold_brake_pipe(5.0); @@ -439,7 +439,7 @@ TEST_CASE("coupler physics: automatic couplers still catch a wagon rolling into flag_setting const physics{Global.coupler_physics, true}; flag_setting const everywhere{Global.coupler_physics_all, true}; flag_setting const crashdamage{Global.crash_damage, true}; - auto automatic{definition::load("wagon").set("BuffCoupl", "CType", "Automatic").set("BuffCoupl", "AutomaticFlag", coupling::coupler | coupling::brakehose)}; + auto automatic{definition::load("wagon").set("BuffCoupl", "CType", "Automatic").set("BuffCoupl", "AutomaticFlag", Coupling::coupler | Coupling::brakeHose)}; auto moving{vehicle{automatic, 5.0, "moving"}}; auto standing{vehicle{automatic, 0.0, "standing"}}; test::pair pair{moving, end::front, standing, end::rear, 1.0}; @@ -460,18 +460,18 @@ TEST_CASE("couplers: a broken coupling of vehicles facing each other uncouples t join(second, end::rear, third, end::front); first->damage_coupler(end::front); - CHECK(first->Couplers[end::front].CouplingFlag == coupling::faux); - CHECK(second->Couplers[end::front].CouplingFlag == coupling::faux); + CHECK(first->Couplers[end::front].CouplingFlag == Coupling::none); + CHECK(second->Couplers[end::front].CouplingFlag == Coupling::none); // the other coupling of the second vehicle stays - CHECK(second->Couplers[end::rear].CouplingFlag == coupling::coupler); + CHECK(second->Couplers[end::rear].CouplingFlag == Coupling::coupler); } TEST_CASE("couplers: a broken coupler is repaired alone, with the one of the vehicle it was coupled with") { auto first{vehicle{definition::load("wagon"), 0.0, "first"}}; auto second{vehicle{definition::load("wagon"), 0.0, "second"}}; auto third{vehicle{definition::load("wagon"), 0.0, "third"}}; - join(first, end::rear, second, end::front, coupling::coupler | coupling::brakehose); - join(second, end::rear, third, end::front, coupling::coupler | coupling::brakehose); + join(first, end::rear, second, end::front, Coupling::coupler | Coupling::brakeHose); + join(second, end::rear, third, end::front, Coupling::coupler | Coupling::brakeHose); // both couplings of the second wagon break second->damage_coupler(end::front); @@ -499,8 +499,8 @@ TEST_CASE("couplers: a broken coupler is repaired alone, with the one of the veh CHECK_FALSE(TestFlag(second->DamageFlag, dtrain_coupling)); CHECK_FALSE(second->AlarmChainFlag); // repaired, not coupled: the vehicles are coupled again as usual - CHECK(second->Couplers[end::rear].CouplingFlag == coupling::faux); - CHECK(second->Attach(end::rear, end::front, &third.mover(), coupling::coupler, true, false)); + CHECK(second->Couplers[end::rear].CouplingFlag == Coupling::none); + CHECK(second->Attach(end::rear, end::front, &third.mover(), Coupling::coupler, true, false)); } TEST_CASE("coupler physics: with couplerphysics yes, only the pairs with a vehicle covered take the physical model") { @@ -543,7 +543,7 @@ TEST_CASE("coupler physics: a hit on a braked train runs through it as a wave, w train.add(definition::load("wagon")); } // a wagon rolling at 15 km/h into the rear of the standing train, its brakes applied - train.add(definition::load("wagon"), 0, coupling::faux, 15.0, 0.3); + train.add(definition::load("wagon"), 0, Coupling::none, 15.0, 0.3); std::vector peak(wagons, 0.0); std::vector started(wagons, -1.0); diff --git a/tests/unit/test_couplers.cpp b/tests/unit/test_couplers.cpp index 19421c52b..44b3ad663 100644 --- a/tests/unit/test_couplers.cpp +++ b/tests/unit/test_couplers.cpp @@ -9,7 +9,7 @@ using test::vehicle; namespace { // the wagon from data/wagon.json with automatic couplers at both ends, which couple the given connections -definition automatic_definition(int Flag = coupling::coupler | coupling::brakehose) { +definition automatic_definition(CouplingSet const Flag = Coupling::coupler | Coupling::brakeHose) { return definition::load("wagon").set("BuffCoupl", "CType", "Automatic").set("BuffCoupl", "AutomaticFlag", Flag); } @@ -202,8 +202,8 @@ TEST_CASE("couplers: a wagon rolling slowly into a standing one couples with it" pair.run(3.0); REQUIRE(pair.coupled()); - CHECK(moving->Couplers[end::front].CouplingFlag == (coupling::coupler | coupling::brakehose)); - CHECK(standing->Couplers[end::rear].CouplingFlag == (coupling::coupler | coupling::brakehose)); + CHECK(moving->Couplers[end::front].CouplingFlag == (Coupling::coupler | Coupling::brakeHose)); + CHECK(standing->Couplers[end::rear].CouplingFlag == (Coupling::coupler | Coupling::brakeHose)); CHECK(moving->Couplers[end::front].Connected == &standing.mover()); CHECK_FALSE(derailed(moving)); CHECK_FALSE(derailed(standing)); @@ -423,7 +423,7 @@ TEST_CASE("couplers: an automatic coupler doesn't catch a coupler of another typ TEST_CASE("couplers: automatic couplers of different control systems couple without the control connection") { crash_damage_setting const crashdamage{true}; - auto const flag{coupling::coupler | coupling::brakehose | coupling::control}; + auto const flag{Coupling::coupler | Coupling::brakeHose | Coupling::control}; auto moving{vehicle{automatic_definition(flag).set("BuffCoupl", "ControlType", "first"), 5.0, "moving"}}; SUBCASE("the same control system") { @@ -438,7 +438,7 @@ TEST_CASE("couplers: automatic couplers of different control systems couple with REQUIRE(standing->Couplers[end::rear].control_type == "second"); test::pair pair{moving, end::front, standing, end::rear, 1.0}; REQUIRE(couple_during(pair, 3.0)); - CHECK(pair.coupling() == (coupling::coupler | coupling::brakehose)); + CHECK(pair.coupling() == (Coupling::coupler | Coupling::brakeHose)); } } @@ -488,8 +488,8 @@ vehicle articulated_wagon(double Velocity, std::string const &Name) { // couples the facing ends of the two vehicles for good, as the scenery does for an articulated set void join(vehicle &First, int FirstEnd, vehicle &Second, int SecondEnd) { - REQUIRE(First->Attach(FirstEnd, SecondEnd, &Second.mover(), coupling::coupler, true, false)); - REQUIRE(Second->Attach(SecondEnd, FirstEnd, &First.mover(), coupling::coupler, true, false)); + REQUIRE(First->Attach(FirstEnd, SecondEnd, &Second.mover(), Coupling::coupler, true, false)); + REQUIRE(Second->Attach(SecondEnd, FirstEnd, &First.mover(), Coupling::coupler, true, false)); } } // namespace @@ -560,12 +560,12 @@ private: bool m_previous{Global.control_coupling_engine_check}; }; -constexpr int scenario_coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; +constexpr CouplingSet scenario_coupling{Coupling::coupler | Coupling::brakeHose | Coupling::mainHose | Coupling::control}; // couples the rear of the first vehicle to the front of the second one the way the scenery does (forced, from the // first one only), returns the coupling the pair got -int scenario_couple(vehicle &First, vehicle &Second, int Coupling = scenario_coupling) { - REQUIRE(First->Attach(end::rear, end::front, &Second.mover(), Coupling, true, false)); +CouplingSet scenario_couple(vehicle &First, vehicle &Second, CouplingSet const couplings = scenario_coupling) { + REQUIRE(First->Attach(end::rear, end::front, &Second.mover(), couplings, true, false)); CHECK(Second->Couplers[end::front].CouplingFlag == First->Couplers[end::rear].CouplingFlag); return First->Couplers[end::rear].CouplingFlag; } @@ -582,13 +582,13 @@ TEST_CASE("couplers: an electric and a diesel locomotive don't share their contr auto diesel{vehicle{definition::fiz("sm42_v1/6d1"), 0.0, "diesel"}}; REQUIRE(diesel->EngineType == TEngineType::DieselElectric); CHECK_FALSE(electric->ControlCouplingAllowed(end::rear, diesel.mover(), end::front)); - CHECK(scenario_couple(electric, diesel) == (scenario_coupling & ~coupling::control)); + CHECK(scenario_couple(electric, diesel) == scenario_coupling.Without(Coupling::control)); } SUBCASE("a diesel-mechanical one without a control system named, either") { auto diesel{vehicle{definition::fiz("sm03_v1/sm03"), 0.0, "diesel"}}; REQUIRE(diesel->EngineType == TEngineType::DieselEngine); CHECK_FALSE(diesel->ControlCouplingAllowed(end::front, electric.mover(), end::rear)); - CHECK(scenario_couple(diesel, electric) == (scenario_coupling & ~coupling::control)); + CHECK(scenario_couple(diesel, electric) == scenario_coupling.Without(Coupling::control)); } SUBCASE("unless both name the same control system") { auto diesel{vehicle{definition::fiz("sm03_v1/sm03").set("BuffCoupl", "ControlType", "shared"), 0.0, "diesel"}}; @@ -597,7 +597,7 @@ TEST_CASE("couplers: an electric and a diesel locomotive don't share their contr } SUBCASE("unless the vehicles make one unit, coupled for good") { auto diesel{vehicle{definition::fiz("sm03_v1/sm03"), 0.0, "diesel"}}; - auto const forgood{scenario_coupling | coupling::permanent}; + auto const forgood{scenario_coupling | Coupling::permanent}; CHECK(scenario_couple(electric, diesel, forgood) == forgood); } SUBCASE("unless the check is turned off") { @@ -638,7 +638,7 @@ TEST_CASE("couplers: locomotives of the same traction and the cars keep their co TEST_CASE("couplers: automatic couplers of an electric and a diesel locomotive couple without the control connection") { crash_damage_setting const crashdamage{true}; control_coupling_check_setting const check{true}; - auto const flag{coupling::coupler | coupling::brakehose | coupling::control}; + auto const flag{Coupling::coupler | Coupling::brakeHose | Coupling::control}; auto automatic = [flag](std::string const &Path) { return definition::fiz(Path).set("BuffCoupl", "CType", "Automatic").set("BuffCoupl", "AutomaticFlag", flag); }; @@ -648,7 +648,7 @@ TEST_CASE("couplers: automatic couplers of an electric and a diesel locomotive c auto standing{vehicle{automatic("sm03_v1/sm03"), 0.0, "standing"}}; test::pair pair{moving, end::front, standing, end::rear, 1.0}; REQUIRE(couple_during(pair, 3.0)); - CHECK(pair.coupling() == (coupling::coupler | coupling::brakehose)); + CHECK(pair.coupling() == (Coupling::coupler | Coupling::brakeHose)); } SUBCASE("an electric one") { auto standing{vehicle{automatic("ep09_v2/104e"), 0.0, "standing"}}; @@ -664,8 +664,8 @@ TEST_CASE("couplers: the AI and the player get the coupling the vehicles can tak auto diesel{vehicle{definition::fiz("sm42_v1/6d1"), 0.0, "diesel"}}; auto other{vehicle{definition::fiz("ep09_v2/104e"), 0.0, "other"}}; - CHECK(electric->CompatibleCoupling(end::rear, diesel.mover(), end::front, scenario_coupling) == (scenario_coupling & ~coupling::control)); + CHECK(electric->CompatibleCoupling(end::rear, diesel.mover(), end::front, scenario_coupling) == scenario_coupling.Without(Coupling::control)); CHECK(electric->CompatibleCoupling(end::rear, other.mover(), end::front, scenario_coupling) == scenario_coupling); // nothing to take away without the control connection asked for - CHECK(electric->CompatibleCoupling(end::rear, diesel.mover(), end::front, coupling::coupler) == coupling::coupler); + CHECK(electric->CompatibleCoupling(end::rear, diesel.mover(), end::front, Coupling::coupler) == Coupling::coupler); } diff --git a/tests/unit/test_couplers_trains.cpp b/tests/unit/test_couplers_trains.cpp index cbe002bb1..cf4dc58b8 100644 --- a/tests/unit/test_couplers_trains.cpp +++ b/tests/unit/test_couplers_trains.cpp @@ -35,27 +35,27 @@ TEST_CASE("couplers: coupled by hand, touching or apart, of the same kind or not consist train; auto &locomotive{train.add(definition::fiz("4e_v1/4e")).mover()}; // the wagon's buffers touch the locomotive's, the unit's car stands a metre away - auto &wagon{train.add(definition::fiz("3wl_v2/3wl"), 0, coupling::faux).mover()}; + auto &wagon{train.add(definition::fiz("3wl_v2/3wl"), 0, Coupling::none).mover()}; train.step(); // nothing to couple to, or nothing to couple - CHECK_FALSE(locomotive.Attach(end::rear, end::front, nullptr, coupling::coupler)); - CHECK_FALSE(locomotive.Attach(end::rear, end::front, &wagon, coupling::faux)); + CHECK_FALSE(locomotive.Attach(end::rear, end::front, nullptr, Coupling::coupler)); + CHECK_FALSE(locomotive.Attach(end::rear, end::front, &wagon, Coupling::none)); // the hook first: the coupler alone, which sounds locomotive.Couplers[end::rear].sounds = 0; - REQUIRE(locomotive.Attach(end::rear, end::front, &wagon, coupling::coupler)); + REQUIRE(locomotive.Attach(end::rear, end::front, &wagon, Coupling::coupler)); CHECK(locomotive.Couplers[end::rear].Connected == &wagon); CHECK(wagon.Couplers[end::front].Connected == &locomotive); - CHECK(wagon.Couplers[end::front].CouplingFlag == coupling::coupler); + CHECK(wagon.Couplers[end::front].CouplingFlag == Coupling::coupler); CHECK(locomotive.Couplers[end::rear].sounds == sound::attachcoupler); // then the hoses: only what changes sounds locomotive.Couplers[end::rear].sounds = 0; - REQUIRE(locomotive.Attach(end::rear, end::front, &wagon, coupling::coupler | coupling::brakehose | coupling::mainhose)); + REQUIRE(locomotive.Attach(end::rear, end::front, &wagon, Coupling::coupler | Coupling::brakeHose | Coupling::mainHose)); CHECK(locomotive.Couplers[end::rear].sounds == (sound::attachbrakehose | sound::attachmainhose)); // and again, quietly, the other side naming the coupler by the one it's connected to (2) locomotive.Couplers[end::rear].sounds = 0; - REQUIRE(wagon.Attach(end::front, 2, &locomotive, coupling::coupler | coupling::brakehose, false, false)); - CHECK(locomotive.Couplers[end::rear].CouplingFlag == (coupling::coupler | coupling::brakehose)); + REQUIRE(wagon.Attach(end::front, 2, &locomotive, Coupling::coupler | Coupling::brakeHose, false, false)); + CHECK(locomotive.Couplers[end::rear].CouplingFlag == (Coupling::coupler | Coupling::brakeHose)); CHECK(locomotive.Couplers[end::rear].sounds == 0); // a screw coupler with the buffers pressed together comes apart whole @@ -74,20 +74,20 @@ TEST_CASE("couplers: a screw coupler uncoupled with the buffers apart, or with t struct state { char const *name; double gap; // between the buffers, the coupler stretched - int coupling; + CouplingSet coupling; bool damaged; bool apart; // whether it comes apart whole }; for (auto const &[name, gap, couplingtype, damaged, apart] : { - state{"stretched a little", 0.1, coupling::coupler | coupling::brakehose, false, false}, - state{"stretched far", 0.3, coupling::coupler | coupling::brakehose, false, true}, - state{"hoses alone", 0.1, coupling::brakehose, false, true}, - state{"broken", 0.1, coupling::coupler | coupling::brakehose, true, true}, + state{"stretched a little", 0.1, Coupling::coupler | Coupling::brakeHose, false, false}, + state{"stretched far", 0.3, Coupling::coupler | Coupling::brakeHose, false, true}, + state{"hoses alone", 0.1, Coupling::brakeHose, false, true}, + state{"broken", 0.1, Coupling::coupler | Coupling::brakeHose, true, true}, }) { CAPTURE(name); consist train; auto &locomotive{train.add(definition::fiz("4e_v1/4e")).mover()}; - auto &wagon{train.add(definition::fiz("3wl_v2/3wl"), 0, coupling::faux, 0.0, gap).mover()}; + auto &wagon{train.add(definition::fiz("3wl_v2/3wl"), 0, Coupling::none, 0.0, gap).mover()}; REQUIRE(locomotive.Attach(end::rear, end::front, &wagon, couplingtype, true)); if (damaged) { SetFlag(locomotive.DamageFlag, dtrain_coupling); @@ -96,16 +96,16 @@ TEST_CASE("couplers: a screw coupler uncoupled with the buffers apart, or with t CHECK((locomotive.DettachStatus(end::rear) < 0) == apart); CHECK(locomotive.Dettach(end::rear) == apart); // what's left when it doesn't come apart is the coupler, the hoses taken off - CHECK(locomotive.Couplers[end::rear].CouplingFlag == (apart ? coupling::faux : coupling::coupler)); - CHECK(wagon.Couplers[end::front].CouplingFlag == (apart ? coupling::faux : coupling::coupler)); + CHECK(locomotive.Couplers[end::rear].CouplingFlag == (apart ? Coupling::none : Coupling::coupler)); + CHECK(wagon.Couplers[end::front].CouplingFlag == (apart ? Coupling::none : Coupling::coupler)); } // couplers of different kinds don't couple, unless forced consist train; auto &locomotive{train.add(definition::fiz("4e_v1/4e")).mover()}; - auto &unit{train.add(definition::fiz("en57_v1/5bgb"), 0, coupling::faux).mover()}; + auto &unit{train.add(definition::fiz("en57_v1/5bgb"), 0, Coupling::none).mover()}; train.step(); - CHECK_FALSE(locomotive.Attach(end::rear, end::front, &unit, coupling::coupler)); - CHECK(locomotive.Attach(end::rear, end::front, &unit, coupling::coupler, true)); + CHECK_FALSE(locomotive.Attach(end::rear, end::front, &unit, Coupling::coupler)); + CHECK(locomotive.Attach(end::rear, end::front, &unit, Coupling::coupler, true)); } TEST_CASE("couplers: automatic couplers coupling on contact") { @@ -115,17 +115,17 @@ TEST_CASE("couplers: automatic couplers coupling on contact") { char const *name; char const *standing; // its rear coupler met char const *running; // its front coupler meets - int coupling; // what they couple: what both flags allow, the control cable only of one kind + CouplingSet coupling; // what they couple: what both flags allow, the control cable only of one kind }; for (auto const &[name, standing, running, couplingtype] : { - meeting{"en57 to en57", "en57_v1/5bgb", "en57_v1/5bgaiii_led_spot", 39}, - meeting{"impuls to en57", "en57_v1/5bgb", "impuls_v1/31we-a_pr", 39 & ~coupling::control}, - meeting{"en57 without the flag", "en57_v1/5bgaiii_led_spot", "en57_v1/6ba_840", coupling::coupler}, + meeting{"en57 to en57", "en57_v1/5bgb", "en57_v1/5bgaiii_led_spot", CouplingSet::FromBits(39)}, + meeting{"impuls to en57", "en57_v1/5bgb", "impuls_v1/31we-a_pr", CouplingSet::FromBits(39).Without(Coupling::control)}, + meeting{"en57 without the flag", "en57_v1/5bgaiii_led_spot", "en57_v1/6ba_840", Coupling::coupler}, }) { CAPTURE(name); scenario scenario{std::string{"couplers/automatic/"} + name, motion(), test::track{}}; scenario.add(standing, 0, consist::full_coupling); - scenario.add(running, 0, coupling::faux, 3.0, 0.2); + scenario.add(running, 0, Coupling::none, 3.0, 0.2); scenario.wait(10.0); auto &first{scenario.vehicle(0)}; auto &second{scenario.vehicle(1)}; @@ -147,8 +147,8 @@ TEST_CASE("couplers: a coupler broken, with its brake hose torn off") { locomotive.damage_coupler(end::rear); CHECK(TestFlag(locomotive.DamageFlag, dtrain_coupling)); CHECK(locomotive.AlarmChainFlag); - CHECK(locomotive.Couplers[end::rear].CouplingFlag == coupling::faux); - CHECK(wagon.Couplers[end::front].CouplingFlag == coupling::faux); + CHECK(locomotive.Couplers[end::rear].CouplingFlag == Coupling::none); + CHECK(wagon.Couplers[end::front].CouplingFlag == Coupling::none); // the front coupler of the wagon, broken on its own: no hose to tear wagon.damage_coupler(end::front); CHECK(TestFlag(wagon.DamageFlag, dtrain_coupling)); @@ -159,7 +159,7 @@ TEST_CASE("couplers: a coupler broken, with its brake hose torn off") { articulated.add(definition::fiz("impuls_v1/31we-b_pr")); unit.damage_coupler(end::rear); CHECK_FALSE(TestFlag(unit.DamageFlag, dtrain_coupling)); - CHECK(unit.Couplers[end::rear].CouplingFlag != coupling::faux); + CHECK(unit.Couplers[end::rear].CouplingFlag != Coupling::none); } TEST_CASE("couplers: collisions fast enough to derail") { @@ -184,7 +184,7 @@ TEST_CASE("couplers: collisions fast enough to derail") { CAPTURE(name); scenario scenario{std::string{"couplers/collision/"} + name, motion(), test::track{}}; scenario.add(frontpath, 0, consist::full_coupling, frontspeed); - scenario.add(back, 0, coupling::faux, backspeed, 20.0); + scenario.add(back, 0, Coupling::none, backspeed, 20.0); scenario.wait(10.0); CHECK(TestFlag(scenario.vehicle(0).DamageFlag, dtrain_out) == frontout); CHECK(TestFlag(scenario.vehicle(1).DamageFlag, dtrain_out) == backout); diff --git a/tests/unit/test_derailment_vehicle.cpp b/tests/unit/test_derailment_vehicle.cpp index 4a3a8efa7..8fee07d9a 100644 --- a/tests/unit/test_derailment_vehicle.cpp +++ b/tests/unit/test_derailment_vehicle.cpp @@ -134,7 +134,7 @@ TEST_CASE("derailment: the model of eu07.ini") { TEST_CASE("derailment: the brake hoses tear") { model_setting const physical{global_settings::derailment_model::physical}; vehicle eu07vehicle{definition::fiz("4e_v1/4e"), 150.0}; - eu07vehicle->Couplers[end::rear].CouplingFlag = coupling::coupler | coupling::brakehose; + eu07vehicle->Couplers[end::rear].CouplingFlag = Coupling::coupler | Coupling::brakeHose; test::track curve; curve.radius = 300.0; for (int step = 0; step < 20; ++step) { diff --git a/tests/unit/test_engine_start.cpp b/tests/unit/test_engine_start.cpp index c721e5a1a..59bb6af0e 100644 --- a/tests/unit/test_engine_start.cpp +++ b/tests/unit/test_engine_start.cpp @@ -111,7 +111,7 @@ TEST_CASE("engine start: only the vehicles with an engine and under control thro // coupled without the control cable, the other railcar isn't under the cab's control consist apart; auto &alone{apart.add(sn61(), 1).mover()}; - apart.add(sn61(), 0, coupling::coupler | coupling::brakehose); + apart.add(sn61(), 0, Coupling::coupler | Coupling::brakeHose); CHECK(engine_start::engine(alone, alone, 2) == nullptr); } diff --git a/tests/unit/test_genset.cpp b/tests/unit/test_genset.cpp index cadd39d28..33af24480 100644 --- a/tests/unit/test_genset.cpp +++ b/tests/unit/test_genset.cpp @@ -527,7 +527,7 @@ TEST_CASE("genset: one genset feeds the next car through the high voltage coupli consist train; auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 1).mover()}; auto &second{train.add(dragon().set("BuffCoupl", "AllowedFlag", 47)).mover()}; - REQUIRE((first.Couplers[end::rear].CouplingFlag & coupling::highvoltage) != 0); + REQUIRE(first.Couplers[end::rear].CouplingFlag.HasAny(Coupling::highVoltage)); wake(first); REQUIRE(first.TractionModeSwitch(traction_mode::genset)); first.GensetSwitch(true); @@ -553,11 +553,11 @@ TEST_CASE("genset: one genset feeds the next car through the high voltage coupli TEST_CASE("genset: the selector command travels along the train") { // two locomotives in multiple: the control line, no permanent coupling - auto const coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; + auto const coupling{Coupling::coupler | Coupling::brakeHose | Coupling::mainHose | Coupling::control}; consist train; auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 1).mover()}; auto &second{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 0, coupling).mover()}; - REQUIRE((first.Couplers[end::rear].CouplingFlag & coupling::control) != 0); + REQUIRE(first.Couplers[end::rear].CouplingFlag.HasAny(Coupling::control)); wake(first); train.run(1.0, no_wire); CHECK(first.TractionModeSwitch(traction_mode::genset, range_t::consist)); @@ -575,7 +575,7 @@ TEST_CASE("genset: the selector command travels along the train") { } TEST_CASE("genset: a selector command refused with the line breaker closed isn't passed on") { - auto const coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; + auto const coupling{Coupling::coupler | Coupling::brakeHose | Coupling::mainHose | Coupling::control}; consist train; auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 1).mover()}; auto &second{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 0, coupling).mover()}; @@ -595,7 +595,7 @@ TEST_CASE("genset: a selector command refused with the line breaker closed isn't } TEST_CASE("genset: a lead which starts its genset on its own passes the start switch on") { - auto const coupling{coupling::coupler | coupling::brakehose | coupling::mainhose | coupling::control}; + auto const coupling{Coupling::coupler | Coupling::brakeHose | Coupling::mainHose | Coupling::control}; consist train; auto &first{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47).set("Cntrl", "GensetStart", "Automatic"), 1).mover()}; auto &second{train.add(dragon_genset().set("BuffCoupl", "AllowedFlag", 47), 0, coupling).mover()}; diff --git a/tests/unit/test_pullee.cpp b/tests/unit/test_pullee.cpp index 7e2742f7a..41a3b69e2 100644 --- a/tests/unit/test_pullee.cpp +++ b/tests/unit/test_pullee.cpp @@ -18,7 +18,7 @@ using test::vehicle; namespace { -constexpr int hook_and_brake_hose{coupling::coupler | coupling::brakehose}; +constexpr CouplingSet hook_and_brake_hose{Coupling::coupler | Coupling::brakeHose}; // an EU07 with nobody in it, its brake pipe held by the test the way a driver's valve would hold it, and the // vehicle it hauls. Velocity as of a trainset of a scenery [km/h]: not 0, the vehicles are ready to depart, diff --git a/tests/unit/test_queries.cpp b/tests/unit/test_queries.cpp index d42232c2e..797e40534 100644 --- a/tests/unit/test_queries.cpp +++ b/tests/unit/test_queries.cpp @@ -51,7 +51,7 @@ TEST_CASE("queries: the damage of a vehicle as the driver's panel describes it") TEST_CASE("queries: the ammeters of a vehicle without power show the current of the ones it controls") { vehicle unpowered{definition::fiz("en57_v1/6ba_840")}; vehicle powered{definition::fiz("en57_v1/5bgb")}; - unpowered->Attach(end::rear, end::front, &powered.mover(), coupling::control, true, false); + unpowered->Attach(end::rear, end::front, &powered.mover(), Coupling::control, true, false); powered->Power = 600.0; powered->Itot = 321.7; unpowered->Power = 0.0; diff --git a/tests/unit/vehicle.cpp b/tests/unit/vehicle.cpp index afbac8680..7946d3d84 100644 --- a/tests/unit/vehicle.cpp +++ b/tests/unit/vehicle.cpp @@ -355,7 +355,7 @@ double pair::gap() const { return std::abs(m_vehicles[1].position - m_vehicles[0].position) - 0.5 * (first.Dim.L + second.Dim.L); } -int pair::coupling() const { +CouplingSet pair::coupling() const { return m_vehicles[0].owner->mover().Couplers[m_vehicles[0].end].CouplingFlag; } diff --git a/tests/unit/vehicle.h b/tests/unit/vehicle.h index 601ece1c5..97c4cf6a1 100644 --- a/tests/unit/vehicle.h +++ b/tests/unit/vehicle.h @@ -39,6 +39,10 @@ public: // sets the key of the section, adding either one when it's missing definition &set(std::string const &Section, std::string const &Key, nlohmann::ordered_json const &Value); + // a set of couplings, as the number the definition writes + definition &set(std::string const &Section, std::string const &Key, CouplingSet const Value) { + return set(Section, Key, Value.Bits()); + } // drops the whole section, with its rows, or one key of it definition &remove(std::string const &Section); definition &remove(std::string const &Section, std::string const &Key); @@ -148,9 +152,9 @@ public: void run(double Seconds, track const &Track = {}, double Dt = 0.01); // distance between the facing couplers [m], negative while the buffers are pressed in double gap() const; - // type of the coupling between the vehicles, coupling::faux when they aren't coupled - int coupling() const; - bool coupled() const { return coupling() != coupling::faux; } + // type of the coupling between the vehicles, Coupling::none when they aren't coupled + CouplingSet coupling() const; + bool coupled() const { return false == coupling().Empty(); } private: struct placement { diff --git a/utilities/translation.cpp b/utilities/translation.cpp index 24c1946bc..ec695b05b 100644 --- a/utilities/translation.cpp +++ b/utilities/translation.cpp @@ -419,25 +419,25 @@ std::string locale::label_cab_control(std::string const &Label) const std::string& locale::coupling_name(int c) { - static std::unordered_map coupling_names = + static std::unordered_map coupling_names = { - { coupling::faux, STRN("faux") }, - { coupling::coupler, STRN("coupler") }, - { coupling::brakehose, STRN("brake hose") }, - { coupling::control, STRN("control") }, - { coupling::highvoltage, STRN("high voltage") }, - { coupling::gangway, STRN("gangway") }, - { coupling::mainhose, STRN("main hose") }, - { coupling::heating, STRN("heating") }, - { coupling::permanent, STRN("permanent") }, - { coupling::power24v, STRN("power 24V") }, - { coupling::power110v, STRN("power 110V") }, - { coupling::power3x400v, STRN("power 3x400V") }, + { Coupling::none, STRN("faux") }, + { Coupling::coupler, STRN("coupler") }, + { Coupling::brakeHose, STRN("brake hose") }, + { Coupling::control, STRN("control") }, + { Coupling::highVoltage, STRN("high voltage") }, + { Coupling::gangway, STRN("gangway") }, + { Coupling::mainHose, STRN("main hose") }, + { Coupling::heating, STRN("heating") }, + { Coupling::permanent, STRN("permanent") }, + { Coupling::power24v, STRN("power 24V") }, + { Coupling::power110v, STRN("power 110V") }, + { Coupling::power3x400v, STRN("power 3x400V") }, }; static std::string unknown(STRN("unknown")); - auto it = coupling_names.find(static_cast(c)); + auto it = coupling_names.find(static_cast(c)); if (it != coupling_names.end()) return lookup_s(it->second); else diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 9ad82244d..a35244fc6 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -2504,7 +2504,7 @@ void TController::Activation() ZeroDirection(); mvOccupied->CabOccupied = mvOccupied->CabActive; // użytkownik moze zmienić CabOccupied wychodząc mvOccupied->CabDeactivisation(); // tak jest w Train.cpp - if (TestFlag(pVehicle->MoverParameters->Couplers[iDirectionOrder < 0 ? end::rear : end::front].CouplingFlag, coupling::control)) { + if (pVehicle->MoverParameters->Couplers[iDirectionOrder < 0 ? end::rear : end::front].CouplingFlag.HasAll(Coupling::control)) { ZeroLocalBrake(); if( initialspringbrakestate ) { mvOccupied->SpringBrakeActivate( false ); @@ -2517,7 +2517,7 @@ void TController::Activation() // TODO: clean this up, there's lot of redundancy with TMoverParameters::ChangeCab() and TTrain::MoveToVehicle() { int movedirection { ( iDirection < 0 ? end::rear : end::front ) }; - auto *targetvehicle { pVehicle->FirstFind( movedirection, coupling::control ) }; + auto *targetvehicle { pVehicle->FirstFind( movedirection, Coupling::control ) }; if( pVehicle != targetvehicle ) { auto *targetvehicledriver { targetvehicle->Mechanik }; // zapamiętanie tego, co ewentualnie tam siedzi, żeby w razie dwóch zamienić miejscami // move to the new vehicle @@ -2854,7 +2854,7 @@ bool TController::CheckVehicles(TOrders user) while (p) { if( p != pVehicle ) { - if( false == p->is_connected( pVehicle, coupling::control ) ) { + if( false == p->is_connected( pVehicle, Coupling::control ) ) { // NOTE: don't set battery in controllable vehicles, let the user/ai do it explicitly // HACK: wagony muszą mieć baterię załączoną do otwarcia drzwi... p->MoverParameters->BatterySwitch( true ); @@ -2883,8 +2883,8 @@ bool TController::CheckVehicles(TOrders user) if( user == Connect && true == main ) { // HACK: with additional vehicles in the consist ensure all linked vehicles are set to move in the same direction - if( pVehicle->Prev(coupling::control) != nullptr - || pVehicle->Next(coupling::control) != nullptr ) { + if( pVehicle->Prev(Coupling::control) != nullptr + || pVehicle->Next(Coupling::control) != nullptr ) { sync_consist_reversers(); } // potentially sync compartment lighting state for the newly connected vehicles @@ -2912,7 +2912,7 @@ bool TController::CheckVehicles(TOrders user) /* if( ( true == drivingFlags.connect ) && ( true == TestFlag( OrderCurrentGet(), Connect ) ) ) { - iCoupler = 0; // dalsza jazda manewrowa już bez łączenia + iCoupler = {}; // dalsza jazda manewrowa już bez łączenia drivingFlags.connect = false; // zdjęcie flagi doczepiania SetVelocity( 0, 0, stopJoin ); // wyłączyć przyspieszanie JumpToNextOrder(); // wykonanie następnej komendy @@ -2921,7 +2921,7 @@ bool TController::CheckVehicles(TOrders user) } // detect push-pull train configurations and mark them accordingly - if( frontvehicle->is_connected( pVehicles[ end::rear ], coupling::control ) ) { + if( frontvehicle->is_connected( pVehicles[ end::rear ], Coupling::control ) ) { // zmiana czoła przez zmianę kabiny drivingFlags.pushPull = true; } @@ -2957,7 +2957,7 @@ bool TController::CheckVehicles(TOrders user) // TODO: replace connection test with connection check between last engine and first car, specifically auto const isheatingcouplingactive { ( ControlledEnginesCount == 1 ? - frontvehicle->is_connected( pVehicles[ end::rear ], coupling::heating ) : + frontvehicle->is_connected( pVehicles[ end::rear ], Coupling::heating ) : true ) }; auto const isheatingneeded { (is_emu() || is_dmu() ? true : @@ -3023,9 +3023,9 @@ TBrakeSystem TController::consist_brake_system() const { // NOTE: we could simplify this by doing only check of the rear coupler, but this can be quite tricky in itself // TODO: add easier ways to access front/rear coupler taking into account vehicle's direction isepcapable = (vehicle->MoverParameters->Couplers[end::front].Connected == nullptr || - (vehicle->MoverParameters->Couplers[end::front].CouplingFlag & coupling::control && vehicle->MoverParameters->Couplers[end::front].Connected->Power > -1)) && + (vehicle->MoverParameters->Couplers[end::front].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[end::front].Connected->Power > -1)) && (vehicle->MoverParameters->Couplers[end::rear].Connected == nullptr || - (vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & coupling::control && vehicle->MoverParameters->Couplers[end::rear].Connected->Power > -1)); + (vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[end::rear].Connected->Power > -1)); vehicle = vehicle->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła) } } @@ -3634,11 +3634,11 @@ bool TController::IncBrake() || mvOccupied->TrainType == train_type::et42 ) { // NOTE: we're doing simplified checks full of presuptions here. // they'll break if someone does strange thing like turning around the second unit - if( mvOccupied->Couplers[end::rear].CouplingFlag & coupling::permanent + if( mvOccupied->Couplers[end::rear].CouplingFlag & Coupling::permanent && mvOccupied->Couplers[end::rear].Connected->Couplers[end::rear].Connected != nullptr ) { standalone = false; } - if( mvOccupied->Couplers[end::front].CouplingFlag & coupling::permanent + if( mvOccupied->Couplers[end::front].CouplingFlag & Coupling::permanent && mvOccupied->Couplers[end::front].Connected->Couplers[end::front].Connected != nullptr ) { standalone = false; } @@ -3655,8 +3655,8 @@ bool TController::IncBrake() else { /* standalone = - ( ( mvOccupied->Couplers[ 0 ].CouplingFlag == 0 ) - && ( mvOccupied->Couplers[ 1 ].CouplingFlag == 0 ) ); + ( ( mvOccupied->Couplers[ 0 ].CouplingFlag.Empty() ) + && ( mvOccupied->Couplers[ 1 ].CouplingFlag.Empty() ) ); */ if( pVehicles[ end::front ] != pVehicles[ end::rear ] ) { // more detailed version, will use manual braking also for coupled sets of controlled vehicles @@ -3667,9 +3667,9 @@ bool TController::IncBrake() // TODO: add easier ways to access front/rear coupler taking into account vehicle's direction standalone = (vehicle->MoverParameters->Couplers[end::front].Connected == nullptr || - (vehicle->MoverParameters->Couplers[end::front].CouplingFlag & coupling::control && vehicle->MoverParameters->Couplers[end::front].Connected->Power > 1)) && + (vehicle->MoverParameters->Couplers[end::front].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[end::front].Connected->Power > 1)) && (vehicle->MoverParameters->Couplers[end::rear].Connected == nullptr || - (vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & coupling::control && vehicle->MoverParameters->Couplers[end::rear].Connected->Power > 1)); + (vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[end::rear].Connected->Power > 1)); vehicle = vehicle->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła) } } @@ -5327,7 +5327,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N } if (NewValue2 != 0) // jeśli podany jest sprzęg { - iCoupler = std::floor( std::abs( NewValue2 ) ); // jakim sprzęgiem + iCoupler = CouplingSet::FromBits( static_cast( std::floor( std::abs( NewValue2 ) ) ) ); // jakim sprzęgiem OrderNext(Connect); // najpierw połącz pojazdy if (NewValue1 >= 0.0) // jeśli ilość wagonów inna niż wszystkie { // to po podpięciu należy się odczepić @@ -6764,7 +6764,7 @@ TController::determine_consist_state() { auto islocalconverterswitchoff { false }; pVehicle->for_each( - coupling::control, + Coupling::control, [this, &islocalconverterswitchoff]( TDynamicObject * Vehicle ) { auto const *vehicle { Vehicle->MoverParameters }; islocalconverterswitchoff |= vehicle->LineContactorsHeldByLocalConverterSwitch(); @@ -6982,7 +6982,7 @@ TController::control_pantographs() { // raise/lower pantographs as needed auto const useregularpantographlayout { - pVehicle->Next(coupling::control) == nullptr // standalone + pVehicle->Next(Coupling::control) == nullptr // standalone || is_emu() // special case || mvControlling->TrainType == train_type::et41 }; // special case @@ -7642,7 +7642,7 @@ TController::check_departure() { } } } - else if( VelSignal == 0.0 && VelNext > 0.0 && mvOccupied->Vel < 1.0 && (iCoupler > 0 || ( false == drivingFlags.stopHere )) ) { + else if( VelSignal == 0.0 && VelNext > 0.0 && mvOccupied->Vel < 1.0 && (false == iCoupler.Empty() || ( false == drivingFlags.stopHere )) ) { // Ra: tu jest coś nie tak, bo bez tego warunku ruszało w manewrowym !!!! SetVelocity(VelNext, VelNext, stopSem); // omijanie SBL } @@ -7823,7 +7823,7 @@ TController::UpdateConnect() { // jeżeli został podłączony CheckVehicles( Connect ); // sprawdzić światła nowego składu - iCoupler = 0; // dalsza jazda manewrowa już bez łączenia + iCoupler = {}; // dalsza jazda manewrowa już bez łączenia iCouplingVehicle.reset(); drivingFlags.connect = false; // zdjęcie flagi doczepiania JumpToNextOrder( true ); // wykonanie następnej komendy @@ -7873,11 +7873,11 @@ TController::unit_count( int const Threshold ) const { end::rear : end::front ) }; auto const coupling { vehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag }; - if( coupling == coupling::faux ) { + if( coupling == Coupling::none ) { break; } // jeżeli sprzęg zablokowany to liczymy człony jako jeden - if( ( coupling & coupling::permanent ) == 0 ) { + if( false == coupling.HasAny( Coupling::permanent ) ) { ++unitcount; } vehicle = vehicle->Next(); @@ -7920,7 +7920,7 @@ TController::UpdateDisconnect() { end::front : end::rear; // jeżeli sprzęg zablokowany to liczymy człony jako jeden - if( decoupledvehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag & coupling::permanent ) { + if( decoupledvehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag & Coupling::permanent ) { ++vehiclecount; } if( decoupledvehicle != pVehicle ) { @@ -7943,7 +7943,7 @@ TController::UpdateDisconnect() { decoupledvehicle->Dettach( decoupledend ); } // tylko jeśli odepnie - if( decoupledvehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag == coupling::faux ) { + if( decoupledvehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag == Coupling::none ) { WriteLog( "Uncoupling [" + mvOccupied->Name + "]: uncoupled" ); iVehicleCount = -2; // update trainset state @@ -9589,7 +9589,7 @@ TController::check_route_ahead( double const Range ) { if( ( OrderCurrentGet() & ~( Shunt | Loose_shunt | Obey_train | Bank ) ) == 0 ) { // jedzie w dowolnym trybie albo Wait_for_orders PutCommand( "ShuntVelocity", VelSignal, VelNext, nullptr ); } - else if( iCoupler ) { // jeśli jedzie w celu połączenia + else if( false == iCoupler.Empty() ) { // jeśli jedzie w celu połączenia SetVelocity( VelSignal, VelNext ); } break; diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 8cf80ddcf..7592e6eac 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -477,7 +477,7 @@ private: std::optional iDirectionBackup; // consist direction to be restored after coupling/uncoupling and similar direction-changing operations std::optional> iCouplingVehicle; // to be coupled with another consist in current coupling operation int iVehicleCount = -2; // wartość neutralna // ilość pojazdów do odłączenia albo zabrania ze składu (-1=wszystkie) - int iCoupler = 0; // maska sprzęgu, jaką należy użyć przy łączeniu (po osiągnięciu trybu Connect), 0 gdy jazda bez łączenia + CouplingSet iCoupler; // maska sprzęgu, jaką należy użyć przy łączeniu (po osiągnięciu trybu Connect), 0 gdy jazda bez łączenia int iDriverFailCount = 0; // licznik błędów AI bool Need_TryAgain = false; // true, jeśli druga pozycja w elektryku nie załapała // bool Need_BrakeRelease = true; diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index b2f6a268e..951e614fb 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -299,7 +299,7 @@ bool TDynamicObject::destination_data::deserialize_mapping( cParser &Input ) { //--------------------------------------------------------------------------- -TDynamicObject * TDynamicObject::FirstFind(int &coupler_nr, int cf) +TDynamicObject * TDynamicObject::FirstFind(int &coupler_nr, CouplingSet const cf) { // szukanie skrajnego połączonego pojazdu w pociagu // od strony sprzegu (coupler_nr) obiektu (start) TDynamicObject *temp = this; @@ -307,7 +307,7 @@ TDynamicObject * TDynamicObject::FirstFind(int &coupler_nr, int cf) { if (!temp) return nullptr; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów - if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & cf) != cf) + if (false == temp->MoverParameters->Couplers[coupler_nr].CouplingFlag.HasAll(cf)) return temp; // nic nie ma już dalej podłączone sprzęgiem cf if (coupler_nr == end::front) { // jeżeli szukamy od sprzęgu 0 @@ -350,7 +350,7 @@ float TDynamicObject::GetEPP() break; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów eq += temp->MoverParameters->PipePress * temp->MoverParameters->Dim.L; am += temp->MoverParameters->Dim.L; - if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & coupling::brakehose) != coupling::brakehose) + if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & Coupling::brakeHose) != Coupling::brakeHose) break; // nic nie ma już dalej podłączone if (coupler_nr == 0) { // jeżeli szukamy od sprzęgu 0 @@ -384,7 +384,7 @@ float TDynamicObject::GetEPP() break; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów eq += temp->MoverParameters->PipePress * temp->MoverParameters->Dim.L; am += temp->MoverParameters->Dim.L; - if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & coupling::brakehose) != coupling::brakehose) + if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & Coupling::brakeHose) != Coupling::brakeHose) break; // nic nie ma już dalej podłączone if (coupler_nr == 0) { // jeżeli szukamy od sprzęgu 0 @@ -415,7 +415,7 @@ float TDynamicObject::GetEPP() }; //--------------------------------------------------------------------------- -TDynamicObject * TDynamicObject::GetFirstDynamic(int cpl_type, int cf) +TDynamicObject * TDynamicObject::GetFirstDynamic(int cpl_type, CouplingSet const cf) { // Szukanie skrajnego połączonego pojazdu w pociagu // od strony sprzegu (cpl_type) obiektu szukajacego // Ra: wystarczy jedna funkcja do szukania w obu kierunkach @@ -930,7 +930,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) // display _xon if connected with another vehicle and not the coupling owner // display _xon if not connected, but equipped with coupling adapter // display _off if not connected, not equipped with coupling adapter or if _xon model is missing - if( TestFlag( MoverParameters->Couplers[ end::front ].CouplingFlag, coupling::coupler ) ) { + if( MoverParameters->Couplers[ end::front ].CouplingFlag.HasAll(Coupling::coupler) ) { if( MoverParameters->Couplers[ end::front ].Render ) { btCoupler1.TurnOn(); } @@ -945,7 +945,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } } - if( TestFlag( MoverParameters->Couplers[ end::rear ].CouplingFlag, coupling::coupler ) ) { + if( MoverParameters->Couplers[ end::rear ].CouplingFlag.HasAll(Coupling::coupler) ) { if( MoverParameters->Couplers[ end::rear ].Render ) { btCoupler2.TurnOn(); } @@ -972,7 +972,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) SetPneumatic(true, true); // ktore z nich nalezy SetPneumatic(false, true); // wyswietlic w tej klatce - if (TestFlag(MoverParameters->Couplers[end::front].CouplingFlag, ctrain_pneumatic)) + if (MoverParameters->Couplers[end::front].CouplingFlag.HasAll(Coupling::brakeHose)) { switch (cp1) { @@ -992,7 +992,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } - if (TestFlag(MoverParameters->Couplers[end::rear].CouplingFlag, ctrain_pneumatic)) + if (MoverParameters->Couplers[end::rear].CouplingFlag.HasAll(Coupling::brakeHose)) { switch (cp2) { @@ -1013,7 +1013,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } // przewody zasilajace, j.w. (yB) - if (TestFlag(MoverParameters->Couplers[end::front].CouplingFlag, ctrain_scndpneumatic)) + if (MoverParameters->Couplers[end::front].CouplingFlag.HasAll(Coupling::mainHose)) { switch (sp1) { @@ -1033,7 +1033,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } - if (TestFlag(MoverParameters->Couplers[end::rear].CouplingFlag, ctrain_scndpneumatic)) + if (MoverParameters->Couplers[end::rear].CouplingFlag.HasAll(Coupling::mainHose)) { switch (sp2) { @@ -1058,7 +1058,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) { // przewody powietrzne j.w., ABu: decyzja czy rysowac tylko na podstawie // 'render' - if (TestFlag(MoverParameters->Couplers[end::front].CouplingFlag, ctrain_pneumatic)) + if (MoverParameters->Couplers[end::front].CouplingFlag.HasAll(Coupling::brakeHose)) { if (MoverParameters->Couplers[end::front].Render) btCPneumatic1.TurnOn(); @@ -1067,7 +1067,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } - if (TestFlag(MoverParameters->Couplers[end::rear].CouplingFlag, ctrain_pneumatic)) + if (MoverParameters->Couplers[end::rear].CouplingFlag.HasAll(Coupling::brakeHose)) { if (MoverParameters->Couplers[end::rear].Render) btCPneumatic2.TurnOn(); @@ -1079,7 +1079,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) // przewody powietrzne j.w., ABu: decyzja czy rysowac tylko na podstawie // 'render' // //yB - zasilajace - if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_scndpneumatic)) + if (MoverParameters->Couplers[0].CouplingFlag.HasAll(Coupling::mainHose)) { if (MoverParameters->Couplers[0].Render) btPneumatic1.TurnOn(); @@ -1088,7 +1088,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } - if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_scndpneumatic)) + if (MoverParameters->Couplers[1].CouplingFlag.HasAll(Coupling::mainHose)) { if (MoverParameters->Couplers[1].Render) btPneumatic2.TurnOn(); @@ -1124,26 +1124,26 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) // Winger 160204 - podnoszenie pantografow // przewody sterowania ukrotnionego - if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, coupling::control)) + if (MoverParameters->Couplers[0].CouplingFlag.HasAll(Coupling::control)) { btCCtrl1.Turn( true ); btnOn = true; } // else btCCtrl1.TurnOff(); - if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, coupling::control)) + if (MoverParameters->Couplers[1].CouplingFlag.HasAll(Coupling::control)) { btCCtrl2.Turn( true ); btnOn = true; } // else btCCtrl2.TurnOff(); // McZapkie-181103: mostki przejsciowe - if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_passenger)) + if (MoverParameters->Couplers[0].CouplingFlag.HasAll(Coupling::gangway)) { btCPass1.Turn( true ); btnOn = true; } // else btCPass1.TurnOff(); - if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_passenger)) + if (MoverParameters->Couplers[1].CouplingFlag.HasAll(Coupling::gangway)) { btCPass2.Turn( true ); btnOn = true; @@ -1625,8 +1625,8 @@ TDynamicObject::ABuFindObject( int &Foundcoupler, double &Distance, TTrack const continue; } /* - if( ( ( dynamic == PrevConnected ) && ( MoverParameters->Couplers[ TMoverParameters::side::front ].CouplingFlag != coupling::faux ) ) - || ( ( dynamic == NextConnected ) && ( MoverParameters->Couplers[ TMoverParameters::side::rear ].CouplingFlag != coupling::faux ) ) ){ + if( ( ( dynamic == PrevConnected ) && ( MoverParameters->Couplers[ TMoverParameters::side::front ].CouplingFlag != Coupling::none ) ) + || ( ( dynamic == NextConnected ) && ( MoverParameters->Couplers[ TMoverParameters::side::rear ].CouplingFlag != Coupling::none ) ) ){ // stop-gap check to prevent 'detection' of attached vehicles // which seems to be a side-effect of inaccurate location calculation in 'simple' mode? // TODO: investigate actual cause @@ -1686,7 +1686,7 @@ int TDynamicObject::DettachStatus(int dir) // rzeczywistych od strony (dir): // 0=przód,1=tył // Ra: dziwne, że ta funkcja nie jest używana - if( MoverParameters->Couplers[ dir ].CouplingFlag == coupling::faux ) { + if( MoverParameters->Couplers[ dir ].CouplingFlag == Coupling::none ) { return 0; // jeśli nic nie podłączone, to jest OK } return MoverParameters->DettachStatus(dir); // czy jest w odpowiedniej odległości? @@ -1725,7 +1725,7 @@ int TDynamicObject::Dettach(int dir) */ } // sprzęg po rozłączaniu (czego się nie da odpiąć - return MoverParameters->Couplers[dir].CouplingFlag; + return MoverParameters->Couplers[dir].CouplingFlag.Bits(); } void @@ -1740,15 +1740,15 @@ TDynamicObject::couple( int const Side ) { auto *othervehicleparams{ othervehicle->MoverParameters }; auto const &othercoupler { othervehicleparams->Couplers[ neighbour.vehicle_end ] }; - if( coupler.CouplingFlag == coupling::faux ) { + if( coupler.CouplingFlag == Coupling::none ) { // najpierw hak if( ( coupler.AllowedFlag & othercoupler.AllowedFlag - & coupling::coupler ) == coupling::coupler ) { + & Coupling::coupler ) == Coupling::coupler ) { if( MoverParameters->Attach( Side, neighbour.vehicle_end, othervehicleparams, - coupling::coupler ) ) { + Coupling::coupler ) ) { // one coupling type per key press return; } @@ -1757,15 +1757,15 @@ TDynamicObject::couple( int const Side ) { } } } - if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::brakehose ) ) { + if( false == MoverParameters->Couplers[ Side ].CouplingFlag.HasAll(Coupling::brakeHose) ) { // pneumatyka if( ( coupler.AllowedFlag & othercoupler.AllowedFlag - & coupling::brakehose ) == coupling::brakehose ) { + & Coupling::brakeHose ) == Coupling::brakeHose ) { if( MoverParameters->Attach( Side, neighbour.vehicle_end, othervehicleparams, - coupler.CouplingFlag | coupling::brakehose ) ) { + coupler.CouplingFlag | Coupling::brakeHose ) ) { SetPneumatic( Side != 0, true ); othervehicle->SetPneumatic( Side != 0, true ); // one coupling type per key press @@ -1773,15 +1773,15 @@ TDynamicObject::couple( int const Side ) { } } } - if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::mainhose ) ) { + if( false == MoverParameters->Couplers[ Side ].CouplingFlag.HasAll(Coupling::mainHose) ) { // zasilajacy if( ( coupler.AllowedFlag & othercoupler.AllowedFlag - & coupling::mainhose ) == coupling::mainhose ) { + & Coupling::mainHose ) == Coupling::mainHose ) { if( MoverParameters->Attach( Side, neighbour.vehicle_end, othervehicleparams, - coupler.CouplingFlag | coupling::mainhose ) ) { + coupler.CouplingFlag | Coupling::mainHose ) ) { SetPneumatic( Side != 0, false ); othervehicle->SetPneumatic( Side != 0, false ); // one coupling type per key press @@ -1789,43 +1789,43 @@ TDynamicObject::couple( int const Side ) { } } } - if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::control ) ) { + if( false == MoverParameters->Couplers[ Side ].CouplingFlag.HasAll(Coupling::control) ) { // ukrotnionko - if( (coupler.AllowedFlag & othercoupler.AllowedFlag & coupling::control) == coupling::control + if( (coupler.AllowedFlag & othercoupler.AllowedFlag & Coupling::control) == Coupling::control && coupler.control_type == othercoupler.control_type - && ( MoverParameters->CompatibleCoupling( Side, *othervehicleparams, neighbour.vehicle_end, coupler.CouplingFlag | coupling::control ) & coupling::control ) != 0 ) { + && MoverParameters->CompatibleCoupling( Side, *othervehicleparams, neighbour.vehicle_end, coupler.CouplingFlag | Coupling::control ).HasAny( Coupling::control ) ) { if( MoverParameters->Attach( Side, neighbour.vehicle_end, othervehicleparams, - coupler.CouplingFlag | coupling::control ) ) { + coupler.CouplingFlag | Coupling::control ) ) { // one coupling type per key press return; } } } - if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::gangway ) ) { + if( false == MoverParameters->Couplers[ Side ].CouplingFlag.HasAll(Coupling::gangway) ) { // mostek if( ( coupler.AllowedFlag & othercoupler.AllowedFlag - & coupling::gangway ) == coupling::gangway ) { + & Coupling::gangway ) == Coupling::gangway ) { if( MoverParameters->Attach( Side, neighbour.vehicle_end, othervehicleparams, - coupler.CouplingFlag | coupling::gangway ) ) { + coupler.CouplingFlag | Coupling::gangway ) ) { // one coupling type per key press return; } } } - if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::heating ) ) { + if( false == MoverParameters->Couplers[ Side ].CouplingFlag.HasAll(Coupling::heating) ) { // heating if( ( coupler.AllowedFlag & othercoupler.AllowedFlag - & coupling::heating ) == coupling::heating ) { + & Coupling::heating ) == Coupling::heating ) { if( MoverParameters->Attach( Side, neighbour.vehicle_end, othervehicleparams, - coupler.CouplingFlag | coupling::heating ) ) { + coupler.CouplingFlag | Coupling::heating ) ) { // one coupling type per key press return; } @@ -1838,9 +1838,9 @@ int TDynamicObject::uncouple( int const Side ) { if( DettachStatus(Side) >= 0 - || true == TestFlag(MoverParameters->Couplers[Side].CouplingFlag, coupling::permanent) ) { + || true == MoverParameters->Couplers[Side].CouplingFlag.HasAll(Coupling::permanent) ) { // can't uncouple, return existing coupling state - return MoverParameters->Couplers[ Side ].CouplingFlag; + return MoverParameters->Couplers[ Side ].CouplingFlag.Bits(); } // jeżeli sprzęg niezablokowany, jest co odczepić i się da auto const couplingflag { Dettach( Side ) }; @@ -3278,7 +3278,7 @@ void TDynamicObject::pull_neighbours( double const Distance ) { for( int end = end::front; end <= end::rear; ++end ) { auto const &coupler { MoverParameters->Couplers[ end ] }; auto *neighbour { MoverParameters->Neighbours[ end ].vehicle }; - if( coupler.CouplingFlag == coupling::faux || neighbour == nullptr || neighbour->MoverParameters->OffTrack.active() + if( coupler.CouplingFlag == Coupling::none || neighbour == nullptr || neighbour->MoverParameters->OffTrack.active() || TestFlag( neighbour->MoverParameters->DamageFlag, dtrain_out ) ) { m_pulledoff[ end ].reset(); continue; @@ -3337,7 +3337,7 @@ void TDynamicObject::AttachNext(TDynamicObject *Object, int iType) auto const vehicleend { iDirection }; auto const othervehicleend { Object->iDirection ^ 1 }; - MoverParameters->Attach( vehicleend, othervehicleend, Object->MoverParameters, iType, true, false ); + MoverParameters->Attach( vehicleend, othervehicleend, Object->MoverParameters, CouplingSet::FromBits( iType ), true, false ); // update neighbour data for both affected vehicles update_neighbours(); Object->update_neighbours(); @@ -3779,8 +3779,8 @@ bool TDynamicObject::Update(double dt, double dt1) tp.Name = &MyTrack->name(); // couplers - if( MoverParameters->Couplers[0].CouplingFlag != coupling::faux - && MoverParameters->Couplers[1].CouplingFlag != coupling::faux ) { + if( MoverParameters->Couplers[0].CouplingFlag != Coupling::none + && MoverParameters->Couplers[1].CouplingFlag != Coupling::none ) { MoverParameters->InsideConsist = true; } else { @@ -3895,8 +3895,8 @@ bool TDynamicObject::Update(double dt, double dt1) // 2. ustal mozliwa do realizacji sile hamowania ED // - w szczegolnosci powinien brac pod uwage rozne sily hamowania - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p; - kier ? p = p->Next(4) : p = p->Prev(4)) + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { ++np; masamax += @@ -4047,8 +4047,8 @@ bool TDynamicObject::Update(double dt, double dt1) ////ALGORYTM 2 - KAZDEMU PO ROWNO, ale nie wiecej niz eped * masa // 1. najpierw daj kazdemu tyle samo int i = 0; - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p; - p = kier == true ? p->Next(4) : p->Prev(4) ) + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + p = kier == true ? p->Next(Coupling::control) : p->Prev(Coupling::control) ) { auto const Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] - p->MoverParameters->BrakeCylSpring) * @@ -4075,8 +4075,8 @@ bool TDynamicObject::Update(double dt, double dt1) test = false; i = 0; float przek = 0; - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p; - p = kier == true ? p->Next(4) : p->Prev(4) ) + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + p = kier == true ? p->Next(Coupling::control) : p->Prev(Coupling::control) ) { if (FzEP[i] > 0.01 && FzEP[i] > p->MoverParameters->TotalMass * p->MoverParameters->eimc[eimc_p_eped] + std::min(p->MoverParameters->eimv[eimv_Fmax], 0.) * 1000 && @@ -4099,8 +4099,8 @@ bool TDynamicObject::Update(double dt, double dt1) } i = 0; przek = przek / (np - nPrzekrF); - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p; - true == kier ? p = p->Next(4) : p = p->Prev(4)) + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + true == kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { if (!PrzekrF[i]) { @@ -4110,8 +4110,8 @@ bool TDynamicObject::Update(double dt, double dt1) } } i = 0; - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p; - true == kier ? p = p->Next(4) : p = p->Prev(4)) + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + true == kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { float Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] - p->MoverParameters->BrakeCylSpring) * @@ -4163,8 +4163,8 @@ bool TDynamicObject::Update(double dt, double dt1) { MEDLogFile << MEDLogTime << "\t" << MoverParameters->Vel << "\t" << masa*0.001 << "\t" << osie << "\t" << FmaxPN*0.001 << "\t" << FmaxED*0.001 << "\t" << FfulED*0.001 << "\t" << FrED*0.001 << "\t" << Fzad*0.001 << "\t" << FzadED*0.001 << "\t" << FzadPN*0.001; - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p; - true == kier ? p = p->Next(4) : p = p->Prev(4)) + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + true == kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { MEDLogFile << "\t" << p->MoverParameters->BrakePress; } @@ -4857,15 +4857,15 @@ void TDynamicObject::pants_up() { isAnyPantUp |= item.is_active; } - d = d->Next(4); // pozostałe też + d = d->Next(Coupling::control); // pozostałe też } - d = Prev(4); + d = Prev(Coupling::control); while (d) { for (auto &item : d->MoverParameters->Pantographs) { isAnyPantUp |= item.is_active; } - d = d->Prev(4); // w drugą stronę też + d = d->Prev(Coupling::control); // w drugą stronę też } if (isAnyPantUp) { @@ -4873,13 +4873,13 @@ void TDynamicObject::pants_up() while (d) { d->MoverParameters->OperatePantographValve(end::front, operation_t::enable, range_t::local); d->MoverParameters->OperatePantographValve(end::rear, operation_t::enable, range_t::local); - d = d->Next(4); // pozostałe też + d = d->Next(Coupling::control); // pozostałe też } - d = Prev(4); + d = Prev(Coupling::control); while (d) { d->MoverParameters->OperatePantographValve(end::front, operation_t::enable, range_t::local); d->MoverParameters->OperatePantographValve(end::rear, operation_t::enable, range_t::local); - d = d->Prev(4); // w drugą stronę też + d = d->Prev(Coupling::control); // w drugą stronę też } } } @@ -8012,17 +8012,17 @@ void TDynamicObject::SetLights() { automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::rear ][ lightpos ] }; // the custom position keeps the lights lit at coupled ends as well auto const ignorecouplings { MoverParameters->LightsPos == 18 }; - auto *vehicle { GetFirstDynamic( MoverParameters->CabOccupied >= 0 ? end::front : end::rear, coupling::control ) }; + auto *vehicle { GetFirstDynamic( MoverParameters->CabOccupied >= 0 ? end::front : end::rear, Coupling::control ) }; while( vehicle != nullptr ) { // set lights on given side if there's no coupling with another vehicle, turn them off otherwise auto const iscoupled { [ vehicle, ignorecouplings ]( end const Side ) { return false == ignorecouplings - && ( vehicle->MoverParameters->Couplers[ Side ].CouplingFlag & coupling::coupler ) != 0 + && vehicle->MoverParameters->Couplers[ Side ].CouplingFlag.HasAny(Coupling::coupler) && vehicle->MoverParameters->Neighbours[ Side ].vehicle != nullptr; } }; auto const lights { lights_programmer::vehicle_lights( cablights, isfrontcaboccupied, vehicle->iDirection, { iscoupled( end::front ), iscoupled( end::rear ) } ) }; vehicle->RaLightsSet( lights.head, lights.rear ); - vehicle = isfrontcaboccupied ? vehicle->Next(coupling::control) : vehicle->Prev(coupling::control); + vehicle = isfrontcaboccupied ? vehicle->Next(Coupling::control) : vehicle->Prev(Coupling::control); } }; @@ -8252,16 +8252,16 @@ int TDynamicObject::DirectionSet(int d) TDynamicObject * TDynamicObject::PrevAny() const { return MoverParameters->Neighbours[ iDirection ^ 1 ].vehicle; } -TDynamicObject * TDynamicObject::Prev(int C) const { - return MoverParameters->Couplers[iDirection ^ 1].CouplingFlag & C ? MoverParameters->Neighbours[iDirection ^ 1].vehicle : nullptr;// gdy sprzęg wirtualny, to jakby nic nie było +TDynamicObject * TDynamicObject::Prev(CouplingSet const couplings) const { + return MoverParameters->Couplers[iDirection ^ 1].CouplingFlag.HasAny(couplings) ? MoverParameters->Neighbours[iDirection ^ 1].vehicle : nullptr;// gdy sprzęg wirtualny, to jakby nic nie było } -TDynamicObject * TDynamicObject::Next(int C) const { - return MoverParameters->Couplers[iDirection].CouplingFlag & C ? MoverParameters->Neighbours[iDirection].vehicle : nullptr;// gdy sprzęg wirtualny, to jakby nic nie było +TDynamicObject * TDynamicObject::Next(CouplingSet const couplings) const { + return MoverParameters->Couplers[iDirection].CouplingFlag.HasAny(couplings) ? MoverParameters->Neighbours[iDirection].vehicle : nullptr;// gdy sprzęg wirtualny, to jakby nic nie było } // checks whether there's unbroken connection of specified type to specified vehicle bool -TDynamicObject::is_connected( TDynamicObject const *Vehicle, coupling const Coupling ) const { +TDynamicObject::is_connected( TDynamicObject const *Vehicle, CouplingSet const couplings ) const { auto *vehicle { this }; if( vehicle == Vehicle ) { @@ -8269,7 +8269,7 @@ TDynamicObject::is_connected( TDynamicObject const *Vehicle, coupling const Coup return true; } // check ahead, it's more likely the "owner" using this method is located there - while( ( vehicle = vehicle->Prev( Coupling ) ) != nullptr ) { + while( ( vehicle = vehicle->Prev( couplings ) ) != nullptr ) { if( vehicle == Vehicle ) { return true; } @@ -8280,7 +8280,7 @@ TDynamicObject::is_connected( TDynamicObject const *Vehicle, coupling const Coup } // start anew in the other direction vehicle = this; - while( ( vehicle = vehicle->Next( Coupling ) ) != nullptr ) { + while( ( vehicle = vehicle->Next( couplings ) ) != nullptr ) { if( vehicle == Vehicle ) { return true; } @@ -8294,7 +8294,7 @@ TDynamicObject * TDynamicObject::Neighbour(int &dir) { auto *neighbour { ( - MoverParameters->Couplers[ dir ].CouplingFlag != coupling::faux ? + MoverParameters->Couplers[ dir ].CouplingFlag != Coupling::none ? MoverParameters->Neighbours[ dir ].vehicle : nullptr ) }; // nowa wartość @@ -8470,8 +8470,8 @@ TDynamicObject * TDynamicObject::FindPowered() // jeśli silnikowy będzie zapięty odwrotnie (tzn. -1), to i tak powinno jeździć dobrze // również hamowanie wykonuje się zaworem w członie, a nie w silnikowym... auto const coupling { MoverParameters->is_multiple_unit() ? - coupling::permanent : - coupling::control }; + Coupling::permanent : + Coupling::control }; auto *lookup { find_vehicle( @@ -8486,7 +8486,7 @@ TDynamicObject * TDynamicObject::FindPantographCarrier() { // try first within a single unit, broaden to all vehicles under our control if first attempt fails - std::array const couplings = { coupling::permanent, coupling::control }; + std::array const couplings = { Coupling::permanent, Coupling::control }; for( auto const coupling : couplings ) { auto *result = @@ -9538,7 +9538,7 @@ coupled_train( TDynamicObject *Vehicle ) { auto const &mover { *vehicle->MoverParameters }; auto *next { mover.Neighbours[ side ].vehicle }; if( next == nullptr - || ( mover.Couplers[ side ].CouplingFlag & coupling::coupler ) == 0 + || false == mover.Couplers[ side ].CouplingFlag.HasAny(Coupling::coupler) || std::ranges::find( train, next ) != train.end() ) { break; } @@ -9561,7 +9561,7 @@ trains_closing_in( std::vector const &Train ) { auto const &mover { *vehicle->MoverParameters }; auto const &neighbour { mover.Neighbours[ side ] }; if( neighbour.vehicle == nullptr - || ( mover.Couplers[ side ].CouplingFlag & coupling::coupler ) != 0 + || mover.Couplers[ side ].CouplingFlag.HasAny(Coupling::coupler) || neighbour.distance > coupler_physics_reach || std::ranges::find( Train, neighbour.vehicle ) != Train.end() ) { continue; @@ -9856,7 +9856,7 @@ std::string_view overlap_kind( TDynamicObject const &First, TDynamicObject const auto const offtrack { First.MoverParameters->OffTrack.active() && Second.MoverParameters->OffTrack.active() }; for( int end = end::front; end <= end::rear; ++end ) { if( First.MoverParameters->Couplers[ end ].Connected == Second.MoverParameters - && First.MoverParameters->Couplers[ end ].CouplingFlag != coupling::faux ) { + && First.MoverParameters->Couplers[ end ].CouplingFlag != Coupling::none ) { return offtrack ? "coupled, both off the track" : "coupled, one on the rails"; } if( First.MoverParameters->Neighbours[ end ].vehicle == &Second ) { diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index 1923e8889..afe730d07 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -660,10 +660,10 @@ private: bool HeadlightsAoff{false}; // wygaszone swiatelki A bool HeadlightsBoff{false}; // wygaszone swiatelki B // checks whether there's unbroken connection of specified type to specified vehicle - bool is_connected( TDynamicObject const *Vehicle, coupling const Coupling = coupling::coupler ) const; + bool is_connected( TDynamicObject const *Vehicle, CouplingSet const couplings = Coupling::coupler ) const; TDynamicObject * PrevAny() const; - TDynamicObject * Prev(int C = -1) const; - TDynamicObject * Next(int C = -1) const; + TDynamicObject * Prev(CouplingSet couplings = CouplingSet::All()) const; // the vehicle coupled with any of the couplings given + TDynamicObject * Next(CouplingSet couplings = CouplingSet::All()) const; void SetdMoveLen(double dMoveLen); void ResetdMoveLen(); double GetdMoveLen(); @@ -687,7 +687,7 @@ private: TDynamicObject * ABuScanNearestObject(glm::vec3 pos, TTrack *Track, double ScanDir, double ScanDist, int &CouplNr); - TDynamicObject * GetFirstDynamic(int cpl_type, int cf = 1); + TDynamicObject * GetFirstDynamic(int cpl_type, CouplingSet cf = Coupling::coupler); void ABuSetModelShake(glm::dvec3 mShake); // place in vehicle_table::m_items, set by its update for the groups of the physics steps on many threads @@ -886,7 +886,7 @@ public: bool has_signal_pc5_on() const; bool has_signal_on( int const Side, int const Pattern ) const; void set_cab_lights( int const Cab, float const Level ); - TDynamicObject * FirstFind(int &coupler_nr, int cf = 1); + TDynamicObject * FirstFind(int &coupler_nr, CouplingSet cf = Coupling::coupler); float GetEPP(); // wyliczanie sredniego cisnienia w PG int DirectionSet(int d); // ustawienie kierunku w składzie // odczyt kierunku w składzie; returns 1 if true, -1 otherwise @@ -905,11 +905,11 @@ public: auto find_vehicle( int const Direction, double const Range, bool const InLine = false ) const -> std::tuple; // locates potential vehicle connected with specific coupling type and satisfying supplied predicate template - auto find_vehicle( coupling const Coupling, Predicate_ const Predicate ) -> TDynamicObject *; + auto find_vehicle( CouplingSet const couplings, Predicate_ const Predicate ) -> TDynamicObject *; TDynamicObject * FindPowered(); TDynamicObject * FindPantographCarrier(); template - void for_each( coupling const Coupling, UnaryFunction_ const Function ); + void for_each( CouplingSet const couplings, UnaryFunction_ const Function ); void ParamSet(int what, int into); // zapytanie do AI, po którym segmencie skrzyżowania jechać int RouteWish(TTrack *tr); @@ -1050,18 +1050,18 @@ private: template auto -TDynamicObject::find_vehicle( coupling const Coupling, Predicate_ const Predicate ) -> TDynamicObject * { +TDynamicObject::find_vehicle( CouplingSet const couplings, Predicate_ const Predicate ) -> TDynamicObject * { if( Predicate( this ) ) { return this; } // try first to look towards the rear auto *vehicle { this }; - while( ( vehicle = vehicle->Next( Coupling ) ) != nullptr ) { + while( ( vehicle = vehicle->Next( couplings ) ) != nullptr ) { if( Predicate( vehicle ) ) { return vehicle; } } // if we didn't yet find a suitable vehicle try in the other direction vehicle = this; - while( ( vehicle = vehicle->Prev( Coupling ) ) != nullptr ) { + while( ( vehicle = vehicle->Prev( couplings ) ) != nullptr ) { if( Predicate( vehicle ) ) { return vehicle; } } // if we still don't have a match give up @@ -1070,16 +1070,16 @@ TDynamicObject::find_vehicle( coupling const Coupling, Predicate_ const Predicat template void -TDynamicObject::for_each( coupling const Coupling, UnaryFunction_ const Function ) { +TDynamicObject::for_each( CouplingSet const couplings, UnaryFunction_ const Function ) { Function( this ); // walk first towards the rear auto *vehicle { this }; - while( ( vehicle = vehicle->Next( Coupling ) ) != nullptr ) { + while( ( vehicle = vehicle->Next( couplings ) ) != nullptr ) { Function( vehicle ); } // then towards the front vehicle = this; - while( ( vehicle = vehicle->Prev( Coupling ) ) != nullptr ) { + while( ( vehicle = vehicle->Prev( couplings ) ) != nullptr ) { Function( vehicle ); } } diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index e736bafdf..076e01fde 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -913,7 +913,7 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const } bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0; - TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, 4); + TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, Coupling::control); int in = 0; while (p && in < 8) { @@ -928,7 +928,7 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const dict->insert("eimp_c" + std::to_string(in) + "_inv" + std::to_string(j + 1) + "_allow", p->MoverParameters->Inverters[j].Activate); } } - p = kier ? p->Next(4) : p->Prev(4); + p = kier ? p->Next(Coupling::control) : p->Prev(Coupling::control); } for (int i = 0; i < 20; ++i) { @@ -1117,11 +1117,11 @@ void TTrain::set_paired_open_motor_connectors_button(bool const State) { // crude implementation of the button affecting entire unit for multi-unit engines // TODO: rework it into part of standard command propagation system - if (mvControlled->Couplers[end::front].Connected != nullptr && true == TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::permanent)) + if (mvControlled->Couplers[end::front].Connected != nullptr && true == mvControlled->Couplers[end::front].CouplingFlag.HasAll(Coupling::permanent)) { mvControlled->Couplers[end::front].Connected->StLinSwitchOff = State; } - if (mvControlled->Couplers[end::rear].Connected != nullptr && true == TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::permanent)) + if (mvControlled->Couplers[end::rear].Connected != nullptr && true == mvControlled->Couplers[end::rear].CouplingFlag.HasAll(Coupling::permanent)) { mvControlled->Couplers[end::rear].Connected->StLinSwitchOff = State; } @@ -7401,7 +7401,7 @@ void TTrain::OnCommand_inverterenable(TTrain *Train, command_data const &Command { // only reacting to press, so the switch doesn't flip back and forth if key is held down bool kier = Train->DynamicObject->DirectionGet() * Train->mvOccupied->CabOccupied > 0; - int flag = Train->DynamicObject->MoverParameters->InverterControlCouplerFlag; + auto const flag{CouplingSet::FromBits(Train->DynamicObject->MoverParameters->InverterControlCouplerFlag)}; TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); while (p) { @@ -7440,7 +7440,7 @@ void TTrain::OnCommand_inverterdisable(TTrain *Train, command_data const &Comman { // only reacting to press, so the switch doesn't flip back and forth if key is held down bool kier = Train->DynamicObject->DirectionGet() * Train->mvOccupied->CabOccupied > 0; - int flag = Train->DynamicObject->MoverParameters->InverterControlCouplerFlag; + auto const flag{CouplingSet::FromBits(Train->DynamicObject->MoverParameters->InverterControlCouplerFlag)}; TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); while (p) { @@ -7479,7 +7479,7 @@ void TTrain::OnCommand_invertertoggle(TTrain *Train, command_data const &Command { // only reacting to press, so the switch doesn't flip back and forth if key is held down bool kier = Train->DynamicObject->DirectionGet() * Train->mvOccupied->CabOccupied > 0; - int flag = Train->DynamicObject->MoverParameters->InverterControlCouplerFlag; + auto const flag{CouplingSet::FromBits(Train->DynamicObject->MoverParameters->InverterControlCouplerFlag)}; TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); while (p) { @@ -8807,7 +8807,7 @@ void TTrain::OnCommand_cabchangeforward(TTrain *Train, command_data const &Comma if (auto const movedirection{1}; false == Train->CabChange(movedirection)) { auto const exitdirection{(movedirection > 0 ? end::front : end::rear)}; - if (TestFlag(Train->mvOccupied->Couplers[exitdirection].CouplingFlag, coupling::gangway)) + if (Train->mvOccupied->Couplers[exitdirection].CouplingFlag.HasAll(Coupling::gangway)) { // przejscie do nastepnego pojazdu auto *targetvehicle = exitdirection == end::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected(); @@ -8837,7 +8837,7 @@ void TTrain::OnCommand_cabchangebackward(TTrain *Train, command_data const &Comm { // current vehicle doesn't extend any farther in this direction, check if we there's one connected we can move to auto const exitdirection{(movedirection > 0 ? end::front : end::rear)}; - if (TestFlag(Train->mvOccupied->Couplers[exitdirection].CouplingFlag, coupling::gangway)) + if (Train->mvOccupied->Couplers[exitdirection].CouplingFlag.HasAll(Coupling::gangway)) { // przejscie do nastepnego pojazdu auto *targetvehicle = exitdirection == end::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected(); @@ -9153,7 +9153,7 @@ bool TTrain::Update(double const Deltatime) } bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0; - TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, 4); + TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, Coupling::control); int in = 0; fEIMParams[0][6] = 0; iCarNo = 0; @@ -9262,9 +9262,9 @@ bool TTrain::Update(double const Deltatime) in++; iPowerNo = in; } - if ((kier ? p->Next(coupling::permanent) : p->Prev(coupling::permanent)) != (kier ? p->Next(coupling::control) : p->Prev(coupling::control))) + if ((kier ? p->Next(Coupling::permanent) : p->Prev(Coupling::permanent)) != (kier ? p->Next(Coupling::control) : p->Prev(Coupling::control))) iUnitNo++; - p = kier ? p->Next(coupling::control) : p->Prev(coupling::control); + p = kier ? p->Next(Coupling::control) : p->Prev(Coupling::control); iCarNo = i + 1; } else @@ -9363,9 +9363,9 @@ bool TTrain::Update(double const Deltatime) // youBy - prad w drugim czlonie: galaz lub calosc { TDynamicObject const *tmp{nullptr}; - if (DynamicObject->NextConnected() && TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == 1) + if (DynamicObject->NextConnected() && mvControlled->Couplers[end::rear].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied == 1) tmp = DynamicObject->NextConnected(); - if (DynamicObject->PrevConnected() && TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == -1) + if (DynamicObject->PrevConnected() && mvControlled->Couplers[end::front].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied == -1) tmp = DynamicObject->PrevConnected(); if (tmp && tmp->MoverParameters->Power > 0) { @@ -9565,7 +9565,7 @@ bool TTrain::Update(double const Deltatime) btLampkaStyczn.Turn(mvControlled->LineContactorsLampLit()); // mozna prowadzic rozruch btLampkaPrzekRozn.Turn(!mvControlled->GroundRelay && mvControlled->MainCircuitLampsEnabled()); // relay is off and needs a reset btLampkaNadmSil.Turn(mvControlled->FuseFlagCheck() && mvControlled->MainCircuitLampsEnabled()); // relay is off and needs a reset - btLampkaUkrotnienie.Turn(TestFlag(mvControlled->Couplers[mvControlled->CabOccupied == 1 ? rear : front].CouplingFlag, control)); + btLampkaUkrotnienie.Turn(mvControlled->Couplers[mvControlled->CabOccupied == 1 ? rear : front].CouplingFlag.HasAll(Coupling::control)); btLampkaHamPosp.Turn(TestFlag(mvOccupied->Hamulec->GetBrakeStatus(), 1)); // lampka drugiego stopnia hamowania // TODO: youBy wyciągnąć flagę wysokiego stopnia btLampkaNadmWent.Turn(mvControlled->RventRot < 5.0 && mvControlled->ResistorsFlagCheck()); // hunter-121211: lampka zanikowo-pradowego wentylatorow @@ -9806,9 +9806,9 @@ bool TTrain::Update(double const Deltatime) { // yB - wskazniki drugiego czlonu TDynamicObject const *tmp{nullptr}; //=mvControlled->mvSecond; //Ra 2014-07: trzeba to jeszcze wyjąć z kabiny... // Ra 2014-07: no nie ma potrzeby szukać tego w każdej klatce - if (TestFlag(mvControlled->Couplers[1].CouplingFlag, coupling::control) && mvOccupied->CabOccupied > 0) + if (mvControlled->Couplers[1].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied > 0) tmp = DynamicObject->NextConnected(); - if (TestFlag(mvControlled->Couplers[0].CouplingFlag, coupling::control) && mvOccupied->CabOccupied < 0) + if (mvControlled->Couplers[0].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied < 0) tmp = DynamicObject->PrevConnected(); if (tmp) @@ -11560,13 +11560,13 @@ void TTrain::DynamicSet(TDynamicObject *d) mvSecond = nullptr; // gdyby się nic nie znalazło if (mvOccupied->Power > 1.0) // dwuczłonowe lub ukrotnienia, żeby nie szukać każdorazowo { - if (mvOccupied->Couplers[1].Connected ? mvOccupied->Couplers[1].AllowedFlag & coupling::control : false) + if (mvOccupied->Couplers[1].Connected != nullptr && mvOccupied->Couplers[1].AllowedFlag.HasAny(Coupling::control)) { // gdy jest człon od sprzęgu 1, a sprzęg łączony // warsztatowo (powiedzmy) if (mvOccupied->Couplers[1].Connected->Power > 1.0) // ten drugi ma moc mvSecond = mvOccupied->Couplers[1].Connected; // wskaźnik na drugiego } - else if (mvOccupied->Couplers[0].Connected ? mvOccupied->Couplers[0].AllowedFlag & coupling::control : false) + else if (mvOccupied->Couplers[0].Connected != nullptr && mvOccupied->Couplers[0].AllowedFlag.HasAny(Coupling::control)) { // gdy jest człon od sprzęgu 0, a sprzęg łączony // warsztatowo (powiedzmy) if (mvOccupied->Couplers[0].Connected->Power > 1.0) // ale ten drugi ma moc @@ -12355,7 +12355,7 @@ void TTrain::set_cab_controls(int const Cab) // finding each inverter - not so optimal, but action ins performed only during changing cabin bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0; - int flag = DynamicObject->MoverParameters->InverterControlCouplerFlag; + auto const flag{CouplingSet::FromBits(DynamicObject->MoverParameters->InverterControlCouplerFlag)}; int itemstart = 0; for ([[maybe_unused]] auto const &item : ggInverterToggleButtons) // for each button { diff --git a/vehicle/enginestart.cpp b/vehicle/enginestart.cpp index a826bb19c..ca276b73c 100644 --- a/vehicle/enginestart.cpp +++ b/vehicle/enginestart.cpp @@ -30,7 +30,7 @@ TMoverParameters *find_along(TMoverParameters const &Start, int const Side, TMov // a train can't loop back on itself, the limit only guards against a broken chain of couplers for (auto steps = 0; steps < 1000; ++steps) { auto const &coupler{vehicle->Couplers[side]}; - if (coupler.Connected == nullptr || false == TestFlag(coupler.CouplingFlag, coupling::control)) { + if (coupler.Connected == nullptr || false == coupler.CouplingFlag.HasAll(Coupling::control)) { return nullptr; } // onwards through the other end of the next vehicle, whichever way round it stands