From fbb9dc1e89e34ced198e2f78e0ef772a97ef33a7 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Sat, 28 Nov 2026 18:32:58 +0100 Subject: [PATCH] refactor(physics): the ends and the sides of a vehicle as scoped enums end and side were unscoped enums: front, rear, left and right sat in the global namespace (the test PCH had to leave mover.h out for it), and an end went into any int, a side into an end, without a word from the compiler. They become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the names follow the rule for types, and leave "end" and "side" to the many locals of that name. The numbers stay: front 0, rear 1, right 0, left 1. - ByEnd / BySide: two values indexed by the enum, and by a number where a loop or a format counts them. The arrays of the ends and the sides are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights, iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler, m_couplersounds, m_mirrormotion, iInventory, and the voltages of the couplers - VehicleEnds / VehicleSides to go through them, Opposite() in place of 1 - end, NumberOf() where a number is needed - the couplers and the collisions take the ends they work on as VehicleEnd: CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit, CompatibleCoupling and the rest of their family, DirF, DirPatch, and of the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on; Attach, Dettach and DettachStatus have overloads by the ends - neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1 and 2 for "none" in places The walks along the consist (FirstFind, Neighbour, the AI's coupling and uncoupling) still carry the ends as numbers; where one of them meets a typed end, NumberOf() and EndOf() say so, and keep the number as it was. Kept as it was, and worth a look: TDynamicObject::SetLights() switches the headlights A/B off by CabActive with the cases end::front and end::rear, that is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are NumberOf(VehicleEnd::front / rear) now, the same numbers. No change in behaviour: 1144/1144 tests, golden traces exact against staging 62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed. --- application/consistviews.cpp | 32 +-- application/consistviews.h | 3 +- application/driverhints.cpp | 94 ++++----- application/drivermode.cpp | 6 +- application/driveruipanels.cpp | 62 +++--- application/driveruipanels.h | 7 +- input/messaging.cpp | 4 +- physics/components/body.cpp | 38 ++-- physics/components/cab.cpp | 6 +- physics/components/collisions.cpp | 54 ++--- physics/components/commands.cpp | 32 +-- physics/components/controllers.cpp | 2 +- physics/components/couplers.cpp | 34 ++-- physics/components/doors.cpp | 30 +-- physics/components/electrics.cpp | 24 +-- physics/components/fizsections.cpp | 18 +- physics/components/internal.h | 6 +- physics/components/pneumatics.cpp | 4 +- physics/components/setup.cpp | 2 +- physics/components/traction.cpp | 12 +- physics/mover.h | 80 +++++--- physics/vehicletypes.h | 77 ++++++- rendering/common/scenewalk.cpp | 18 +- rendering/common/scenewalk.h | 3 +- rendering/lightarray.cpp | 10 +- simulation/blackboxrecorder.cpp | 32 +-- simulation/simulation.cpp | 2 +- simulation/simulationstateserializer.cpp | 6 +- tests/unit/consist.cpp | 12 +- tests/unit/drive.cpp | 4 +- tests/unit/golden.cpp | 4 +- tests/unit/scenario.h | 2 +- tests/unit/test_auxiliaries.cpp | 4 +- tests/unit/test_collisions.cpp | 72 +++---- tests/unit/test_commands.cpp | 82 ++++---- tests/unit/test_controls.cpp | 86 ++++---- tests/unit/test_coupler_physics.cpp | 102 +++++----- tests/unit/test_couplers.cpp | 192 +++++++++--------- tests/unit/test_couplers_trains.cpp | 82 ++++---- tests/unit/test_definition.cpp | 2 +- tests/unit/test_derailment_vehicle.cpp | 2 +- tests/unit/test_door_closure.cpp | 20 +- tests/unit/test_genset.cpp | 4 +- tests/unit/test_handover.cpp | 14 +- tests/unit/test_lights_preset_cablight.cpp | 12 +- tests/unit/test_lights_programmer.cpp | 36 ++-- tests/unit/test_line_contactors_interlock.cpp | 20 +- tests/unit/test_loads.cpp | 4 +- tests/unit/test_mains_before_pantographs.cpp | 36 ++-- tests/unit/test_pressure_switch.cpp | 30 +-- tests/unit/test_pullee.cpp | 2 +- tests/unit/test_queries.cpp | 2 +- tests/unit/vehicle.cpp | 14 +- tests/unit/vehicle.h | 6 +- vehicle/Driver.h | 18 +- vehicle/DynObj.h | 38 ++-- vehicle/Train.h | 10 +- vehicle/ai/consist.cpp | 50 ++--- vehicle/ai/controls.cpp | 20 +- vehicle/ai/doors.cpp | 20 +- vehicle/ai/driver.cpp | 28 +-- vehicle/ai/engine.cpp | 12 +- vehicle/ai/force.cpp | 8 +- vehicle/ai/obstacles.cpp | 20 +- vehicle/ai/orders.cpp | 44 ++-- vehicle/ai/routescan.cpp | 8 +- vehicle/ai/situation.cpp | 26 +-- vehicle/ai/speed.cpp | 2 +- vehicle/ai/speedtable.cpp | 20 +- vehicle/cab/auxiliarycommands.cpp | 44 ++-- vehicle/cab/cabcommands.cpp | 8 +- vehicle/cab/couplingcommands.cpp | 10 +- vehicle/cab/doorcommands.cpp | 28 +-- vehicle/cab/equipmentcommands.cpp | 6 +- vehicle/cab/lightcommands.cpp | 36 ++-- vehicle/cab/pantographcommands.cpp | 26 +-- vehicle/cab/setup.cpp | 32 +-- vehicle/cab/train.cpp | 40 ++-- vehicle/cab/update.cpp | 66 +++--- vehicle/crewchange.cpp | 2 +- vehicle/dynamic/animations.cpp | 22 +- vehicle/dynamic/consist.cpp | 43 ++-- vehicle/dynamic/couplers.cpp | 38 ++-- vehicle/dynamic/lifecycle.cpp | 44 ++-- vehicle/dynamic/lights.cpp | 46 ++--- vehicle/dynamic/load.cpp | 20 +- vehicle/dynamic/mmd.cpp | 92 ++++----- vehicle/dynamic/movement.cpp | 4 +- vehicle/dynamic/offtrack.cpp | 26 +-- vehicle/dynamic/sounds.cpp | 10 +- vehicle/dynamic/update.cpp | 58 +++--- vehicle/dynamic/vehicletable.cpp | 12 +- vehicle/dynamic/visual.cpp | 72 +++---- vehicle/enginestart.cpp | 2 +- vehicle/lightsprogrammer.h | 16 +- widgets/vehicleparams.cpp | 28 +-- 96 files changed, 1395 insertions(+), 1304 deletions(-) diff --git a/application/consistviews.cpp b/application/consistviews.cpp index 8c7847386..42cd41257 100644 --- a/application/consistviews.cpp +++ b/application/consistviews.cpp @@ -37,9 +37,9 @@ cameraviews::vehicle_pose pose_of(TDynamicObject const *Vehicle) { // the end of the Vehicle the Other vehicle is beyond, -1 when it's beyond neither int end_towards(TDynamicObject const *Vehicle, TDynamicObject const *Other) { - for (auto const side : {end::front, end::rear}) { + for (auto const side : VehicleEnds) { if (Vehicle->MoverParameters->Neighbours[side].vehicle == Other) { - return side; + return NumberOf(side); } } return -1; @@ -54,10 +54,10 @@ int outer_end(TDynamicObject const *Vehicle, TDynamicObject const *Inner, int co return inner < 0 ? Alone : 1 - inner; } -cameraviews::coupler coupler_of(TDynamicObject const *Vehicle, int const End) { +cameraviews::coupler coupler_of(TDynamicObject const *Vehicle, VehicleEnd const End) { cameraviews::coupler coupler; - coupler.position = Vehicle->CouplerPosition(static_cast(End)); - coupler.outward = Vehicle->VectorFront() * (End == end::front ? 1.0 : -1.0); + coupler.position = Vehicle->CouplerPosition(End); + coupler.outward = Vehicle->VectorFront() * (End == VehicleEnd::front ? 1.0 : -1.0); coupler.width = Vehicle->MoverParameters->Dim.W; return coupler; } @@ -71,8 +71,8 @@ int driven_way(TDynamicObject const *Driven) { // the coupler of the Vehicle furthest along the Way (or furthest back, with a negative Way) glm::dvec3 end_along(TDynamicObject const *Vehicle, glm::dvec3 const &Way) { - auto const front{Vehicle->CouplerPosition(end::front)}; - auto const rear{Vehicle->CouplerPosition(end::rear)}; + auto const front{Vehicle->CouplerPosition(VehicleEnd::front)}; + auto const rear{Vehicle->CouplerPosition(VehicleEnd::rear)}; return glm::dot(front - rear, Way) >= 0.0 ? front : rear; } @@ -103,7 +103,7 @@ std::vector consist_views::train_of(TDynamicObject *Driven) { return train; } auto const *controller{Driven->Mechanik != nullptr ? Driven->Mechanik : Driven->ctOwner}; - auto *first{controller != nullptr ? controller->Vehicle(end::front) : nullptr}; + auto *first{controller != nullptr ? controller->Vehicle(VehicleEnd::front) : nullptr}; if (first == nullptr) { first = Driven; } @@ -142,7 +142,7 @@ TDynamicObject *consist_views::pick(std::vector const &Train, return m_vehicle; } -double consist_views::gap_beyond(TDynamicObject const *Vehicle, int const End) { +double consist_views::gap_beyond(TDynamicObject const *Vehicle, VehicleEnd const End) { auto const &neighbour{Vehicle->MoverParameters->Neighbours[End]}; if (neighbour.vehicle == nullptr || false == Vehicle->MoverParameters->Couplers[End].CouplingFlag.Empty()) { return -1.0; @@ -163,23 +163,23 @@ consist_views::coupling_place consist_views::coupling_at(std::vectorCouplerPosition(static_cast(behindend < 0 ? end::front : behindend)); + place.otherposition = behind->CouplerPosition(behindend < 0 ? VehicleEnd::front : EndOf(behindend)); return place; } // an end of the train, perhaps with another vehicle coming closer to it auto const front{Index <= 0}; auto *vehicle{front ? Train.front() : Train.back()}; auto const *inner{count > 1 ? Train[front ? 1 : count - 2] : nullptr}; - auto const outer{outer_end(vehicle, inner, front ? end::front : end::rear)}; + auto const outer{outer_end(vehicle, inner, NumberOf(front ? VehicleEnd::front : VehicleEnd::rear))}; place.vehicle = vehicle; - place.coupler = coupler_of(vehicle, outer); + place.coupler = coupler_of(vehicle, EndOf(outer)); auto const &neighbour{vehicle->MoverParameters->Neighbours[outer]}; - place.gap = gap_beyond(vehicle, outer); - if (place.gap >= 0.0 && (neighbour.vehicle_end == end::front || neighbour.vehicle_end == end::rear)) { + place.gap = gap_beyond(vehicle, EndOf(outer)); + if (place.gap >= 0.0 && (neighbour.FacingEnd() == VehicleEnd::front || neighbour.FacingEnd() == VehicleEnd::rear)) { place.other = true; - place.otherposition = neighbour.vehicle->CouplerPosition(static_cast(neighbour.vehicle_end)); + place.otherposition = neighbour.vehicle->CouplerPosition(neighbour.FacingEnd()); } return place; } diff --git a/application/consistviews.h b/application/consistviews.h index 1c86345c0..d5bf6641e 100644 --- a/application/consistviews.h +++ b/application/consistviews.h @@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/. #pragma once #include +#include "physics/vehicletypes.h" #include "vehicle/cameraviews.h" @@ -51,7 +52,7 @@ private: // the Index coupling of the Train, 0 its front end, Train.size() its rear end static coupling_place coupling_at(std::vector const &Train, int Index); // the distance to a vehicle not coupled beyond the End of the Vehicle, negative for none - static double gap_beyond(TDynamicObject const *Vehicle, int End); + static double gap_beyond(TDynamicObject const *Vehicle, VehicleEnd End); // keeps up the way the train goes and works out where its ends are, for the trackside view cameraviews::train_motion motion_of(std::vector const &Train, TDynamicObject const *Driven); diff --git a/application/driverhints.cpp b/application/driverhints.cpp index e00158bc0..93e2735fd 100644 --- a/application/driverhints.cpp +++ b/application/driverhints.cpp @@ -279,48 +279,48 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) } case driver_hint::frontpantographvalveon: { if( AIControllFlag ) { - mvOccupied->OperatePantographValve( end::front, operation_t::enable ); + mvOccupied->OperatePantographValve( VehicleEnd::front, operation_t::enable ); } remove_hint( driver_hint::frontpantographvalveoff ); hint( Action, [ this ]( float const Parameter ) { - return mvPantographUnit->Pantographs[end::front].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); }, + return mvPantographUnit->Pantographs[VehicleEnd::front].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); }, Actionparameter ); break; } case driver_hint::frontpantographvalveoff: { if( AIControllFlag ) { - mvOccupied->OperatePantographValve( end::front, operation_t::disable ); + mvOccupied->OperatePantographValve( VehicleEnd::front, operation_t::disable ); } remove_hint( driver_hint::frontpantographvalveon ); hint( Action, [this](float const /*Parameter*/) { - return mvPantographUnit->Pantographs[end::front].valve.is_active == false; } ); + return mvPantographUnit->Pantographs[VehicleEnd::front].valve.is_active == false; } ); break; } case driver_hint::rearpantographvalveon: { if( AIControllFlag ) { - mvOccupied->OperatePantographValve( end::rear, operation_t::enable ); + mvOccupied->OperatePantographValve( VehicleEnd::rear, operation_t::enable ); } remove_hint( driver_hint::rearpantographvalveoff ); hint( Action, [ this ]( float const Parameter ) { - return mvPantographUnit->Pantographs[end::rear].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); }, + return mvPantographUnit->Pantographs[VehicleEnd::rear].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); }, Actionparameter ); break; } case driver_hint::rearpantographvalveoff: { if( AIControllFlag ) { - mvOccupied->OperatePantographValve( end::rear, operation_t::disable ); + mvOccupied->OperatePantographValve( VehicleEnd::rear, operation_t::disable ); } remove_hint( driver_hint::rearpantographvalveon ); hint( Action, [this](float const /*Parameter*/) { - return mvPantographUnit->Pantographs[end::rear].valve.is_active == false; } ); + return mvPantographUnit->Pantographs[VehicleEnd::rear].valve.is_active == false; } ); break; } // converter @@ -434,27 +434,27 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) } case driver_hint::frontmotorblowerson: { if( AIControllFlag ) { - mvOccupied->MotorBlowersSwitchOff( false, end::front ); - mvOccupied->MotorBlowersSwitch( true, end::front ); + mvOccupied->MotorBlowersSwitchOff( false, VehicleEnd::front ); + mvOccupied->MotorBlowersSwitch( true, VehicleEnd::front ); } remove_hint( driver_hint::frontmotorblowersoff ); hint( Action, [this]( float const /*Parameter*/ ) { - auto const &device { mvOccupied->MotorBlowers[ end::front ] }; + auto const &device { mvOccupied->MotorBlowers[ VehicleEnd::front ] }; return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false); } ); break; } case driver_hint::rearmotorblowerson: { if( AIControllFlag ) { - mvOccupied->MotorBlowersSwitchOff( false, end::rear ); - mvOccupied->MotorBlowersSwitch( true, end::rear ); + mvOccupied->MotorBlowersSwitchOff( false, VehicleEnd::rear ); + mvOccupied->MotorBlowersSwitch( true, VehicleEnd::rear ); } remove_hint( driver_hint::rearmotorblowersoff ); hint( Action, [this]( float const /*Parameter*/ ) { - auto const &device { mvOccupied->MotorBlowers[ end::rear ] }; + auto const &device { mvOccupied->MotorBlowers[ VehicleEnd::rear ] }; return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false); } ); break; } @@ -1070,93 +1070,93 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) case driver_hint::doorrightopen: { if( AIControllFlag || pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) { - pVehicle->MoverParameters->OperateDoors( side::right, true ); + pVehicle->MoverParameters->OperateDoors( VehicleSide::right, true ); } remove_hint( driver_hint::doorrightclose ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorOpen[side::right] == true; } ); + return IsAnyDoorOpen[VehicleSide::right] == true; } ); break; } case driver_hint::doorrightclose: { if( AIControllFlag || pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) { - pVehicle->MoverParameters->OperateDoors( side::right, false ); + pVehicle->MoverParameters->OperateDoors( VehicleSide::right, false ); } remove_hint( driver_hint::doorrightopen ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorOpen[side::right] == false; } ); + return IsAnyDoorOpen[VehicleSide::right] == false; } ); break; } case driver_hint::doorleftopen: { if( AIControllFlag || pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) { - pVehicle->MoverParameters->OperateDoors( side::left, true ); + pVehicle->MoverParameters->OperateDoors( VehicleSide::left, true ); } remove_hint( driver_hint::doorleftclose ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorOpen[side::left] == true; } ); + return IsAnyDoorOpen[VehicleSide::left] == true; } ); break; } case driver_hint::doorleftclose: { if( AIControllFlag || pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) { - pVehicle->MoverParameters->OperateDoors( side::left, false ); + pVehicle->MoverParameters->OperateDoors( VehicleSide::left, false ); } remove_hint( driver_hint::doorleftopen ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorOpen[side::left] == false; } ); + return IsAnyDoorOpen[VehicleSide::left] == false; } ); break; } case driver_hint::doorrightpermiton: { if( AIControllFlag ) { - pVehicle->MoverParameters->PermitDoors( side::right, true ); + pVehicle->MoverParameters->PermitDoors( VehicleSide::right, true ); } remove_hint( driver_hint::doorrightpermitoff ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorPermitActive[side::right] == true; } ); + return IsAnyDoorPermitActive[VehicleSide::right] == true; } ); break; } case driver_hint::doorrightpermitoff: { if( AIControllFlag ) { - pVehicle->MoverParameters->PermitDoors( side::right, false ); + pVehicle->MoverParameters->PermitDoors( VehicleSide::right, false ); } remove_hint( driver_hint::doorrightpermiton ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorPermitActive[side::right] == false; } ); + return IsAnyDoorPermitActive[VehicleSide::right] == false; } ); break; } case driver_hint::doorleftpermiton: { if( AIControllFlag ) { - pVehicle->MoverParameters->PermitDoors( side::left, true ); + pVehicle->MoverParameters->PermitDoors( VehicleSide::left, true ); } remove_hint( driver_hint::doorleftpermitoff ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorPermitActive[side::left] == true; } ); + return IsAnyDoorPermitActive[VehicleSide::left] == true; } ); break; } case driver_hint::doorleftpermitoff: { if( AIControllFlag ) { - pVehicle->MoverParameters->PermitDoors( side::left, false ); + pVehicle->MoverParameters->PermitDoors( VehicleSide::left, false ); } remove_hint( driver_hint::doorleftpermiton ); hint( Action, [this](float const /*Parameter*/) { - return IsAnyDoorPermitActive[side::left] == false; } ); + return IsAnyDoorPermitActive[VehicleSide::left] == false; } ); break; } // doorsteps, as the timetable asks (eu07/maszyna#95) @@ -1254,30 +1254,30 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) case driver_hint::couplingadapterattach: { // TODO: run also for potential settings-based virtual assistant if( AIControllFlag ) { - pVehicles[ end::front ]->attach_coupler_adapter( static_cast(Actionparameter) ); + pVehicles[ VehicleEnd::front ]->attach_coupler_adapter( EndOf( static_cast(Actionparameter) ) ); } hint( Action, [this](float const Parameter) { - auto const &device { pVehicles[ end::front ]->MoverParameters->Couplers[ static_cast( Parameter ) ] }; + auto const &device { pVehicles[ VehicleEnd::front ]->MoverParameters->Couplers[ static_cast( Parameter ) ] }; return device.type() == TCouplerType::Automatic; } ); break; } case driver_hint::couplingadapterremove: { if( AIControllFlag || Global.AITrainman ) { - pVehicles[ end::front ]->remove_coupler_adapter( static_cast(Actionparameter) ); + pVehicles[ VehicleEnd::front ]->remove_coupler_adapter( EndOf( static_cast(Actionparameter) ) ); } hint( Action, [this](float const Parameter) { - auto const &device { pVehicles[ end::front ]->MoverParameters->Couplers[ static_cast( Parameter ) ] }; + auto const &device { pVehicles[ VehicleEnd::front ]->MoverParameters->Couplers[ static_cast( Parameter ) ] }; return false == device.has_adapter(); } ); break; } // lights case driver_hint::headcodepc1: { if( AIControllFlag ) { - pVehicles[ end::front ]->RaLightsSet( light::headlight_left | light::headlight_right | light::headlight_upper, -1 ); + pVehicles[ VehicleEnd::front ]->RaLightsSet( light::headlight_left | light::headlight_right | light::headlight_upper, -1 ); } remove_hint( driver_hint::headcodepc2 ); remove_hint( driver_hint::headcodetb1 ); @@ -1285,12 +1285,12 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - return pVehicles[end::front]->has_signal_pc1_on(); } ); + return pVehicles[VehicleEnd::front]->has_signal_pc1_on(); } ); break; } case driver_hint::headcodepc2: { if( AIControllFlag ) { - pVehicles[ end::front ]->RaLightsSet( light::redmarker_left | light::headlight_right | light::headlight_upper, -1 ); + pVehicles[ VehicleEnd::front ]->RaLightsSet( light::redmarker_left | light::headlight_right | light::headlight_upper, -1 ); } remove_hint( driver_hint::headcodepc1 ); remove_hint( driver_hint::headcodetb1 ); @@ -1298,7 +1298,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - return pVehicles[end::front]->has_signal_pc2_on(); } ); + return pVehicles[VehicleEnd::front]->has_signal_pc2_on(); } ); break; } case driver_hint::headcodetb1: { @@ -1315,22 +1315,22 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - auto const activeend { mvOccupied->CabActive >= 0 ? end::front : end::rear }; - auto const consistfront { mvOccupied->DirActive >= 0 ? end::front : end::rear }; - return pVehicles[consistfront]->has_signal_on(activeend, light::headlight_right) && pVehicles[1 - consistfront]->has_signal_on(1 - activeend, light::headlight_left); } ); + auto const activeend { mvOccupied->CabActive >= 0 ? VehicleEnd::front : VehicleEnd::rear }; + auto const consistfront { mvOccupied->DirActive >= 0 ? VehicleEnd::front : VehicleEnd::rear }; + return pVehicles[consistfront]->has_signal_on(activeend, light::headlight_right) && pVehicles[Opposite(consistfront)]->has_signal_on(Opposite(activeend), light::headlight_left); } ); break; } case driver_hint::headcodepc5: { if( AIControllFlag - || ( Global.AITrainman && false == pVehicles[end::rear]->is_connected(pVehicle, Coupling::control) ) ) { - pVehicles[ end::rear ]->RaLightsSet( -1, light::redmarker_left | light::redmarker_right | light::rearendsignals ); + || ( Global.AITrainman && false == pVehicles[VehicleEnd::rear]->is_connected(pVehicle, Coupling::control) ) ) { + pVehicles[ VehicleEnd::rear ]->RaLightsSet( -1, light::redmarker_left | light::redmarker_right | light::rearendsignals ); } remove_hint( driver_hint::headcodetb1 ); remove_hint( driver_hint::lightsoff ); hint( Action, [this](float const /*Parameter*/) { - return pVehicles[end::rear]->has_signal_pc5_on(); } ); + return pVehicles[VehicleEnd::rear]->has_signal_pc5_on(); } ); break; } case driver_hint::lightsoff: { @@ -1344,9 +1344,9 @@ TController::cue_action( driver_hint const Action, float const Actionparameter ) hint( Action, [this](float const /*Parameter*/) { - auto const activeend { mvOccupied->CabActive >= 0 ? end::front : end::rear }; - auto const consistfront { mvOccupied->DirActive >= 0 ? end::front : end::rear }; - return pVehicles[consistfront]->has_signal_on(activeend, 0) && pVehicles[1 - consistfront]->has_signal_on(1 - activeend, 0); } ); + auto const activeend { mvOccupied->CabActive >= 0 ? VehicleEnd::front : VehicleEnd::rear }; + auto const consistfront { mvOccupied->DirActive >= 0 ? VehicleEnd::front : VehicleEnd::rear }; + return pVehicles[consistfront]->has_signal_on(activeend, 0) && pVehicles[Opposite(consistfront)]->has_signal_on(Opposite(activeend), 0); } ); break; } // releaser diff --git a/application/drivermode.cpp b/application/drivermode.cpp index 20df43a3b..b121d7250 100644 --- a/application/drivermode.cpp +++ b/application/drivermode.cpp @@ -1242,7 +1242,7 @@ void driver_mode::ExternalView() case view::consistfront: { // bind camera with the vehicle - auto *owner{vehicle->Mechanik->Vehicle(end::front)}; + auto *owner{vehicle->Mechanik->Vehicle(VehicleEnd::front)}; Camera.m_owner = owner; @@ -1272,7 +1272,7 @@ void driver_mode::ExternalView() case view::consistrear: { // bind camera with the vehicle - auto *owner{vehicle->Mechanik->Vehicle(end::rear)}; + auto *owner{vehicle->Mechanik->Vehicle(VehicleEnd::rear)}; Camera.m_owner = owner; @@ -1300,7 +1300,7 @@ void driver_mode::ExternalView() } case view::bogie: { - auto *owner{vehicle->Mechanik->Vehicle(end::front)}; + auto *owner{vehicle->Mechanik->Vehicle(VehicleEnd::front)}; Camera.m_owner = owner; diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 304cf5d1a..53d988a29 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -55,13 +55,13 @@ namespace { constexpr float coupler_repair_radius { 5.f }; // the broken coupler nearest to the camera, within reach: the vehicle and its end, or no vehicle -std::pair broken_coupler_nearby( glm::dvec3 const &Camera ) { +std::pair broken_coupler_nearby( glm::dvec3 const &Camera ) { auto const *vehicle { std::get( simulation::Region->find_vehicle( Camera, coupler_repair_radius, false, true ) ) }; - if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) { return { nullptr, end::front }; } - auto const front { glm::distance( vehicle->CouplerPosition( end::front ), Camera ) }; - auto const rear { glm::distance( vehicle->CouplerPosition( end::rear ), Camera ) }; - auto const nearest { front <= rear ? end::front : end::rear }; - if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->MoverParameters->Couplers[ nearest ].broken ) { return { nullptr, end::front }; } + if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) { return { nullptr, VehicleEnd::front }; } + auto const front { glm::distance( vehicle->CouplerPosition( VehicleEnd::front ), Camera ) }; + auto const rear { glm::distance( vehicle->CouplerPosition( VehicleEnd::rear ), Camera ) }; + auto const nearest { front <= rear ? VehicleEnd::front : VehicleEnd::rear }; + if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->MoverParameters->Couplers[ nearest ].broken ) { return { nullptr, VehicleEnd::front }; } return { vehicle, nearest }; } @@ -232,7 +232,7 @@ drivingaid_panel::render_contents() { // only the coupler the camera is next to, and the one of the vehicle it was coupled with if( m_brokenvehicle != nullptr && ImGui::Button( STR_C( "Repair coupler" ) ) ) { command_relay commandrelay; - commandrelay.post( user_command::repaircoupler, m_brokenend, 0.0, GLFW_PRESS, 0, glm::vec3( 0.0f ), &m_brokenvehicle->name() ); + commandrelay.post( user_command::repaircoupler, NumberOf( m_brokenend ), 0.0, GLFW_PRESS, 0, glm::vec3( 0.0f ), &m_brokenvehicle->name() ); } ui_panel::render_contents(); @@ -807,8 +807,8 @@ debug_panel::update_section_vehicle( std::vector &Output ) { mover.EngineDescription( 0 ).c_str(), // TODO: put wheel flat reporting in the enginedescription() std::string( mover.WheelFlat > 0.01 ? " Flat: " + to_string( mover.WheelFlat, 1 ) + " mm" : "" ).c_str(), - update_vehicle_coupler( end::front ).c_str(), - update_vehicle_coupler( end::rear ).c_str() ); + update_vehicle_coupler( VehicleEnd::front ).c_str(), + update_vehicle_coupler( VehicleEnd::rear ).c_str() ); Output.emplace_back( std::string{ m_buffer.data() }, Global.UITextColor ); @@ -818,11 +818,11 @@ debug_panel::update_section_vehicle( std::vector &Output ) { // devices mover.Battery ? 'B' : '.', mover.PantsValve.is_active ? '+' : '.', - mover.Pantographs[end::rear].valve.is_active ? 'O' : - mover.Pantographs[end::rear].valve.is_enabled ? 'o' : + mover.Pantographs[VehicleEnd::rear].valve.is_active ? 'O' : + mover.Pantographs[VehicleEnd::rear].valve.is_enabled ? 'o' : '.', - mover.Pantographs[end::front].valve.is_active ? 'P' : - mover.Pantographs[end::front].valve.is_enabled ? 'p' : + mover.Pantographs[VehicleEnd::front].valve.is_active ? 'P' : + mover.Pantographs[VehicleEnd::front].valve.is_enabled ? 'p' : '.', mover.PantPressLockActive ? '!' : mover.PantPressSwitchActive ? '*' : @@ -866,21 +866,21 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::string( isdieselenginepowered ? STR(" oil pressure: ") + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(), // power transfers // 3000v - mover.Couplers[ end::front ].power_high.voltage, - mover.Couplers[ end::front ].power_high.current, - std::string( mover.Couplers[ end::front ].power_high.is_local ? ":" : ":=" ).c_str(), + mover.Couplers[ VehicleEnd::front ].power_high.voltage, + mover.Couplers[ VehicleEnd::front ].power_high.current, + std::string( mover.Couplers[ VehicleEnd::front ].power_high.is_local ? ":" : ":=" ).c_str(), mover.EngineVoltage, - std::string( mover.Couplers[ end::rear ].power_high.is_local ? ":" : "=:" ).c_str(), - mover.Couplers[ end::rear ].power_high.voltage, - mover.Couplers[ end::rear ].power_high.current, + std::string( mover.Couplers[ VehicleEnd::rear ].power_high.is_local ? ":" : "=:" ).c_str(), + mover.Couplers[ VehicleEnd::rear ].power_high.voltage, + mover.Couplers[ VehicleEnd::rear ].power_high.current, // 110v - mover.Couplers[ end::front ].power_110v.voltage, - mover.Couplers[ end::front ].power_110v.current, - std::string( mover.Couplers[ end::front ].power_110v.is_local ? ":" : ":=" ).c_str(), + mover.Couplers[ VehicleEnd::front ].power_110v.voltage, + mover.Couplers[ VehicleEnd::front ].power_110v.current, + std::string( mover.Couplers[ VehicleEnd::front ].power_110v.is_local ? ":" : ":=" ).c_str(), mover.PowerCircuits[ 1 ].first, - std::string( mover.Couplers[ end::rear ].power_110v.is_local ? ":" : "=:" ).c_str(), - mover.Couplers[ end::rear ].power_110v.voltage, - mover.Couplers[ end::rear ].power_110v.current ); + std::string( mover.Couplers[ VehicleEnd::rear ].power_110v.is_local ? ":" : "=:" ).c_str(), + mover.Couplers[ VehicleEnd::rear ].power_110v.voltage, + mover.Couplers[ VehicleEnd::rear ].power_110v.current ); Output.emplace_back( m_buffer.data(), Global.UITextColor ); @@ -898,8 +898,8 @@ debug_panel::update_section_vehicle( std::vector &Output ) { std::abs( mover.enrot ) * 60, std::abs( mover.nrot ) * mover.Transmision.Ratio * 60, mover.RventRot * 60, - std::abs( mover.MotorBlowers[end::front].revolutions ), - std::abs( mover.MotorBlowers[end::rear].revolutions ), + std::abs( mover.MotorBlowers[VehicleEnd::front].revolutions ), + std::abs( mover.MotorBlowers[VehicleEnd::rear].revolutions ), mover.diesel.heat.rpmw, mover.diesel.heat.rpmw2 ); @@ -1033,7 +1033,7 @@ void debug_panel::graph_data::render() { } std::string -debug_panel::update_vehicle_coupler( int const Side ) { +debug_panel::update_vehicle_coupler( VehicleEnd const Side ) { // NOTE: mover and vehicle are guaranteed to be valid by the caller auto const &mover { *m_input.mover }; @@ -1613,8 +1613,8 @@ debug_panel::update_section_coupler( std::vector &Output ) { Output.emplace_back( std::format( "No coupler within {:.0f} m of the camera", coupler_pick_radius ), Global.UITextColor ); return; } - auto const nearerfront { glm::distance( vehicle->CouplerPosition( end::front ), camera ) <= glm::distance( vehicle->CouplerPosition( end::rear ), camera ) }; - m_coupler = { vehicle, nearerfront ? end::front : end::rear }; + auto const nearerfront { glm::distance( vehicle->CouplerPosition( VehicleEnd::front ), camera ) <= glm::distance( vehicle->CouplerPosition( VehicleEnd::rear ), camera ) }; + m_coupler = { vehicle, nearerfront ? VehicleEnd::front : VehicleEnd::rear }; auto const &mover { *vehicle->MoverParameters }; auto const &coupler { mover.Couplers[ m_coupler.end ] }; @@ -1634,7 +1634,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.Bits(), neighbour.distance * 1000.0 ), + std::format( "Neighbour: {} ({} end), coupling [{}], gap {:.1f} mm", neighbour.vehicle->name(), neighbour.FacingEnd() == VehicleEnd::front ? "front" : "rear", coupler.CouplingFlag.Bits(), neighbour.distance * 1000.0 ), Global.UITextColor ); } else { diff --git a/application/driveruipanels.h b/application/driveruipanels.h index 0e8b6917e..c35ff12d6 100644 --- a/application/driveruipanels.h +++ b/application/driveruipanels.h @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include "application/uilayer.h" #include "utilities/Classes.h" +#include "physics/vehicletypes.h" #include "rendering/renderer.h" class drivingaid_panel : public ui_expandable_panel { @@ -28,7 +29,7 @@ private: std::array m_buffer; // the broken coupler next to the camera, which the panel offers to repair: the vehicle and its end TDynamicObject const *m_brokenvehicle { nullptr }; - int m_brokenend { 0 }; + VehicleEnd m_brokenend { VehicleEnd::front }; }; class timetable_panel : public ui_expandable_panel { @@ -99,7 +100,7 @@ private: void update_section_uart( std::vector &Output ) const; #endif // section update helpers - std::string update_vehicle_coupler( int const Side ); + std::string update_vehicle_coupler( VehicleEnd const Side ); std::string update_vehicle_brake() const; // renders provided lines, under specified collapsing header bool render_section( std::string const &Header, std::vector const &Lines ); @@ -130,7 +131,7 @@ private: // the coupler nearest to the camera struct coupler_pick { TDynamicObject const *vehicle { nullptr }; - int end { 0 }; + VehicleEnd end { VehicleEnd::front }; }; coupler_pick m_coupler; bool m_couplerbothends { true }; // changes to the parameters apply to the end of the other vehicle of the pair too diff --git a/input/messaging.cpp b/input/messaging.cpp index f91da91bd..0f1530199 100644 --- a/input/messaging.cpp +++ b/input/messaging.cpp @@ -302,8 +302,8 @@ WyslijNamiary([[maybe_unused]] TDynamicObject const *Vehicle) + Vehicle->MoverParameters->DoorLeftOpened * 16 + Vehicle->MoverParameters->DoorRightOpened * 32 #else - + ( false == Vehicle->MoverParameters->Doors.instances[side::left].is_closed ) * 16 - + ( false == Vehicle->MoverParameters->Doors.instances[side::right].is_closed ) * 32 + + ( false == Vehicle->MoverParameters->Doors.instances[VehicleSide::left].is_closed ) * 16 + + ( false == Vehicle->MoverParameters->Doors.instances[VehicleSide::right].is_closed ) * 32 #endif + Vehicle->MoverParameters->FuseFlag * 64 + Vehicle->MoverParameters->DepartureSignal * 128; diff --git a/physics/components/body.cpp b/physics/components/body.cpp index c91910ad2..698f19d98 100644 --- a/physics/components/body.cpp +++ b/physics/components/body.cpp @@ -31,7 +31,7 @@ http://mozilla.org/MPL/2.0/. #include "physics/components/drive.h" -int DirPatch(int Coupler1, int Coupler2) +int DirPatch(VehicleEnd const Coupler1, VehicleEnd const Coupler2) { // poprawka dla liczenia sil przy ustawieniu przeciwnym obiektow return Coupler1 != Coupler2 ? 1 : -1; } @@ -51,13 +51,13 @@ bool legacy_derailed_slides(TMoverParameters const &Vehicle) } // namespace -int DirF(int CouplerN) +int DirF(VehicleEnd CouplerN) { switch (CouplerN) { - case 0: + case VehicleEnd::front: return -1; - case 1: + case VehicleEnd::rear: return 1; default: return 0; @@ -173,7 +173,7 @@ void TMoverParameters::change_train_velocity(double const Change) for (std::size_t i = 0; i < train.size(); ++i) { auto const [vehicle, direction] = train[i]; - for (int end = end::front; end <= end::rear; ++end) + for (auto const end : VehicleEnds) { auto const &coupler{vehicle->Couplers[end]}; auto *other{coupler.Connected}; @@ -181,7 +181,7 @@ void TMoverParameters::change_train_velocity(double const Change) { continue; } - auto const otherdirection{direction * DirPatch(end, coupler.ConnectedNr)}; + auto const otherdirection{direction * DirPatch(end, coupler.ConnectedEnd())}; other->V += Change * otherdirection; train.emplace_back(other, otherdirection); } @@ -308,7 +308,7 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap } derailment_distance = 0.0; // ale jesli jest kolizja (zas. zach. pedu) to...} - for (int b = 0; b < 2; b++) + for (auto const b : VehicleEnds) if (Couplers[b].CheckCollision) CollisionDetect(b, dt); // zmienia niejawnie AccS, V !!! check_pushed_off(dt, std::abs(dL)); @@ -386,7 +386,7 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape & /*Sh // the criteria of derailment go by the distance, checked in the full step which ends the frame derailment_distance += std::abs(dL); // ale jesli jest kolizja (zas. zach. pedu) to... - for (int b = 0; b < 2; b++) + for (auto const b : VehicleEnds) if (Couplers[b].CheckCollision) CollisionDetect(b, dt); // zmienia niejawnie AccS, V !!! check_pushed_off(dt, std::abs(dL)); @@ -501,13 +501,13 @@ void TMoverParameters::compute_movement_(double const Deltatime) UpdateBatteryVoltage(Deltatime); UpdateScndPipePressure(Deltatime); // druga rurka, youBy - if ((DCEMUED_CC & 1) != 0 && Couplers[end::front].CouplingFlag.HasAny(Coupling::control)) + if ((DCEMUED_CC & 1) != 0 && Couplers[VehicleEnd::front].CouplingFlag.HasAny(Coupling::control)) { - DynamicBrakeEMUStatus &= Couplers[end::front].Connected->DynamicBrakeEMUStatus; + DynamicBrakeEMUStatus &= Couplers[VehicleEnd::front].Connected->DynamicBrakeEMUStatus; } - if ((DCEMUED_CC & 2) != 0 && Couplers[end::rear].CouplingFlag.HasAny(Coupling::control)) + if ((DCEMUED_CC & 2) != 0 && Couplers[VehicleEnd::rear].CouplingFlag.HasAny(Coupling::control)) { - DynamicBrakeEMUStatus &= Couplers[end::rear].Connected->DynamicBrakeEMUStatus; + DynamicBrakeEMUStatus &= Couplers[VehicleEnd::rear].Connected->DynamicBrakeEMUStatus; } if (BrakeSlippingTimer > 0.8 && ASBType != 128) @@ -721,7 +721,7 @@ void TMoverParameters::ComputeConstans(void) // drag calculation { // NOTE: draft effect of previous vehicle is simplified and doesn't have much to do with reality - auto const *previousvehicle{Couplers[V >= 0.0 ? end::front : end::rear].Connected}; + auto const *previousvehicle{Couplers[V >= 0.0 ? VehicleEnd::front : VehicleEnd::rear].Connected}; auto dragarea{Dim.W * Dim.H}; if (previousvehicle) { @@ -797,11 +797,11 @@ void TMoverParameters::ComputeTotalForce(double dt) auto const vehicleisactive{CabActive != 0 || Vel > 0.0001 || accelerating() || LastSwitchingTime < 5 || is_multiple_unit()}; - auto const movingvehicleahead{Neighbours[end::front].vehicle != nullptr && - (Neighbours[end::front].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[end::front].vehicle->MoverParameters->accelerating())}; + auto const movingvehicleahead{Neighbours[VehicleEnd::front].vehicle != nullptr && + (Neighbours[VehicleEnd::front].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[VehicleEnd::front].vehicle->MoverParameters->accelerating())}; - auto const movingvehiclebehind{Neighbours[end::rear].vehicle != nullptr && - (Neighbours[end::rear].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[end::rear].vehicle->MoverParameters->accelerating())}; + auto const movingvehiclebehind{Neighbours[VehicleEnd::rear].vehicle != nullptr && + (Neighbours[VehicleEnd::rear].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[VehicleEnd::rear].vehicle->MoverParameters->accelerating())}; auto const calculatephysics{vehicleisactive || movingvehicleahead || movingvehiclebehind}; @@ -914,7 +914,7 @@ void TMoverParameters::ComputeTotalForce(double dt) } nrot_eps = (abs(nrot) - old_nrot) / dt; // doliczenie sił z innych pojazdów - for (int end = end::front; end <= end::rear; ++end) + for (auto const end : VehicleEnds) { // a new step: the hit of the pair not taken by either vehicle yet Couplers[end].hit_handled = false; @@ -924,7 +924,7 @@ void TMoverParameters::ComputeTotalForce(double dt) if (Neighbours[end].vehicle != nullptr) { // the velocities before the step, the forces of all the vehicles come before their movement - Couplers[end].closing = -CouplerVelocityDifference(end, *Neighbours[end].vehicle->MoverParameters, Neighbours[end].vehicle_end) * DirF(end); + Couplers[end].closing = -CouplerVelocityDifference(end, *Neighbours[end].vehicle->MoverParameters, Neighbours[end].FacingEnd()) * DirF(end); Couplers[end].CForce = CouplerForce(end, dt); FTrain += Couplers[end].CForce; // what the buffers of the pair take in, for the budget of the crush (physics.collisions new and monitor) diff --git a/physics/components/cab.cpp b/physics/components/cab.cpp index 02bd95d0e..2accee006 100644 --- a/physics/components/cab.cpp +++ b/physics/components/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).HasAny(Coupling::mainHose)}; + auto const mainpipe{(Couplers[VehicleEnd::front].AllowedFlag | Couplers[VehicleEnd::rear].AllowedFlag).HasAny(Coupling::mainHose)}; return false == mainpipe || ScndPipePress >= HornMinPressure; }}; auto horns{0}; @@ -154,8 +154,8 @@ bool TMoverParameters::CabDeactivisation(bool const Enforce) } if (InactiveCabFlag & activation::doorpermition) { - PermitDoors(side::right, true, range_t::consist); - PermitDoors(side::left, true, range_t::consist); + PermitDoors(VehicleSide::right, true, range_t::consist); + PermitDoors(VehicleSide::left, true, range_t::consist); } if (InactiveCabFlag & activation::neutraldirection) { diff --git a/physics/components/collisions.cpp b/physics/components/collisions.cpp index 12266fed8..db73aa29a 100644 --- a/physics/components/collisions.cpp +++ b/physics/components/collisions.cpp @@ -69,7 +69,7 @@ void tear_brake_hoses(TMoverParameters &Vehicle) // Q: 20160716 // Wykrywanie kolizji // ************************************************************************************************* -void TMoverParameters::CollisionDetect(int const End, double const dt) +void TMoverParameters::CollisionDetect(VehicleEnd const End, double const dt) { if (Neighbours[End].vehicle == nullptr) { @@ -78,7 +78,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) auto const &thiscoupler{Couplers[End]}; auto *othervehicle{Neighbours[End].vehicle->MoverParameters}; - auto const otherend{Neighbours[End].vehicle_end}; + auto const otherend{Neighbours[End].FacingEnd()}; auto const &othercoupler{othervehicle->Couplers[otherend]}; auto const physical{coupler_physics_at(End)}; @@ -114,12 +114,12 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) switch (End) { - case 0: + case VehicleEnd::front: { CCF = ComputeCollision(velocity, othervehiclevelocity, TotalMass, othervehicle->TotalMass, loss, VirtualCoupling) / dt; break; // yB: ej ej ej, a po } - case 1: + case VehicleEnd::rear: { CCF = ComputeCollision(othervehiclevelocity, velocity, othervehicle->TotalMass, TotalMass, loss, VirtualCoupling) / dt; break; @@ -188,7 +188,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) } } -void TMoverParameters::damage_coupler(int const End) +void TMoverParameters::damage_coupler(VehicleEnd const End) { auto &thiscoupler{Couplers[End]}; @@ -241,12 +241,12 @@ collision::vehicle_kind TMoverParameters::collision_kind() const return collision::kind_of(powered, unit || passengers || (false == powered && HeatingPower > 0.0), false); } -collision::crush_curve TMoverParameters::crush_curve_at(int const End) const +collision::crush_curve TMoverParameters::crush_curve_at(VehicleEnd const End) const { return collision::crush_of(Couplers[End].collision, collision_kind()); } -double TMoverParameters::buffer_height_at(int const End) const +double TMoverParameters::buffer_height_at(VehicleEnd const End) const { auto const loadshare{MaxLoad > 0.f ? LoadAmount / MaxLoad : 0.0}; return collision::buffer_height(Couplers[End].collision, collision_kind(), loadshare); @@ -282,9 +282,9 @@ namespace { -char const *end_name(int const End) +char const *end_name(VehicleEnd const End) { - return End == end::front ? "front" : "rear"; + return End == VehicleEnd::front ? "front" : "rear"; } char const *kind_name(collision::vehicle_kind const Kind) @@ -306,9 +306,9 @@ char const *kind_name(collision::vehicle_kind const Kind) } // namespace // the force pressing the end in, of the coupling or of the buffers touching [N]: forwards at the front pulls -double compression_at(TCoupling const &Coupler, int const End) +double compression_at(TCoupling const &Coupler, VehicleEnd const End) { - return std::max(0.0, (End == end::front ? -1.0 : 1.0) * Coupler.CForce); + return std::max(0.0, (End == VehicleEnd::front ? -1.0 : 1.0) * Coupler.CForce); } namespace { @@ -330,11 +330,11 @@ void record_hit(TCoupling &Coupler, double const Force, double const Duration) } // namespace -bool TMoverParameters::crush_hit(int const End, double const dt) +bool TMoverParameters::crush_hit(VehicleEnd const End, double const dt) { auto &thiscoupler{Couplers[End]}; auto *othervehicle{Neighbours[End].vehicle->MoverParameters}; - auto const otherend{Neighbours[End].vehicle_end}; + auto const otherend{Neighbours[End].FacingEnd()}; auto &othercoupler{othervehicle->Couplers[otherend]}; auto const physical{coupler_physics_at(End)}; @@ -465,7 +465,7 @@ bool TMoverParameters::crush_hit(int const End, double const dt) // the hit at the force the weaker end gives at pushes the vehicles apart: the velocities alone change, along this // vehicle's axis as in CollisionDetect() auto const otherdirection{DirPatch(End, otherend)}; - auto const apart{End == end::front ? -1.0 : 1.0}; + auto const apart{End == VehicleEnd::front ? -1.0 : 1.0}; if (false == wall) { V += apart * hit.impulse / mass; @@ -491,10 +491,10 @@ bool TMoverParameters::crush_hit(int const End, double const dt) secondcurve.force(othercoupler.crush) / 1000.0, hit.force / 1000.0, springs / 1000.0, input.start_velocity * 3.6, kinetic / 1000.0, thiscoupler.contact.absorbed() / 1000.0, capacity / 1000.0, thiscoupler.contact.crush_work() / 1000.0); }; - auto const crushed = [&](TMoverParameters const &Vehicle, int const VehicleEnd, double const Before, double const After) { + auto const crushed = [&](TMoverParameters const &Vehicle, VehicleEnd const crushedEnd, double const Before, double const After) { if (Before < collision::crush_mark && After >= collision::crush_mark) { - ErrorLog(std::format("Bad driving: {} and {} collided at {:.0f} km/h, the {} end of {} crushed ({})", Name, othervehicle->Name, closing * 3.6, end_name(VehicleEnd), Vehicle.Name, pair())); + ErrorLog(std::format("Bad driving: {} and {} collided at {:.0f} km/h, the {} end of {} crushed ({})", Name, othervehicle->Name, closing * 3.6, end_name(crushedEnd), Vehicle.Name, pair())); } }; auto const before{thiscoupler.crush}; @@ -566,8 +566,8 @@ void TMoverParameters::check_pushed_off(double const dt, double const Distance) auto duration{0.0}; auto worst{0.0}; auto worstforce{0.0}; - auto worstend{static_cast(end::front)}; - for (int end = end::front; end <= end::rear; ++end) + auto worstend{VehicleEnd::front}; + for (auto const end : VehicleEnds) { auto const *other{Neighbours[end].vehicle}; if (other == nullptr) @@ -612,9 +612,9 @@ void TMoverParameters::check_pushed_off(double const dt, double const Distance) lifted ? std::format("its wheels lifted off the rail for {:.3f} s", pushed_off_monitor.time()) : std::format("the flange climbing over {:.2f} m", pushed_off_monitor.distance()), Vel, std::abs(RunningShape.R), std::min(worst, 99.0), - vehicle.mass / 1000.0, kind_name(collision_kind()), vehicle.axles, compression_at(Couplers[end::front], end::front) / 1000.0, - compression_at(Couplers[end::rear], end::rear) / 1000.0, Couplers[end::front].hit_force / 1000.0, Couplers[end::rear].hit_force / 1000.0, - Couplers[end::front].crush, Couplers[end::rear].crush)); + vehicle.mass / 1000.0, kind_name(collision_kind()), vehicle.axles, compression_at(Couplers[VehicleEnd::front], VehicleEnd::front) / 1000.0, + compression_at(Couplers[VehicleEnd::rear], VehicleEnd::rear) / 1000.0, Couplers[VehicleEnd::front].hit_force / 1000.0, Couplers[VehicleEnd::rear].hit_force / 1000.0, + Couplers[VehicleEnd::front].crush, Couplers[VehicleEnd::rear].crush)); } } namespace @@ -641,7 +641,7 @@ void repair(TMoverParameters &Vehicle, TCoupling &Coupler) Coupler.stretch_duration = 0.f; Coupler.physics_state.couple(); restore_end(Coupler); - if (Vehicle.Couplers[end::front].broken || Vehicle.Couplers[end::rear].broken) + if (Vehicle.Couplers[VehicleEnd::front].broken || Vehicle.Couplers[VehicleEnd::rear].broken) { return; } @@ -652,7 +652,7 @@ void repair(TMoverParameters &Vehicle, TCoupling &Coupler) } // namespace -bool TMoverParameters::repair_coupler(int const End) +bool TMoverParameters::repair_coupler(VehicleEnd const End) { auto &thiscoupler{Couplers[End]}; if (false == thiscoupler.broken) @@ -665,7 +665,7 @@ bool TMoverParameters::repair_coupler(int const End) { repair(*other, other->Couplers[thiscoupler.ConnectedNr]); } - WriteLog(std::format("Coupler of {} repaired, at its {} end", Name, End == end::front ? "front" : "rear")); + WriteLog(std::format("Coupler of {} repaired, at its {} end", Name, End == VehicleEnd::front ? "front" : "rear")); return true; } @@ -694,7 +694,7 @@ void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam co vehicle.length = Dim.L; vehicle.axle_base = ADist > 0.0 ? ADist : BDist; vehicle.centre_of_gravity = centre_of_gravity(); - for (int end = end::front; end <= end::rear; ++end) + for (auto const end : VehicleEnds) { auto const *other{Neighbours[end].vehicle}; if (other == nullptr) @@ -702,8 +702,8 @@ void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam co continue; } // the force of the coupling, or of the buffers touching, along this vehicle: forwards at the front pulls - vehicle.ends[end].compression = (end == end::front ? -1.0 : 1.0) * Couplers[end].CForce; - vehicle.ends[end].other_length = other->MoverParameters->Dim.L; + vehicle.ends[NumberOf(end)].compression = (end == VehicleEnd::front ? -1.0 : 1.0) * Couplers[end].CForce; + vehicle.ends[NumberOf(end)].other_length = other->MoverParameters->Dim.L; } derailment::track_state track; track.radius = Shape.R; diff --git a/physics/components/commands.cpp b/physics/components/commands.cpp index 8a1ca64c5..1477b3c37 100644 --- a/physics/components/commands.cpp +++ b/physics/components/commands.cpp @@ -518,37 +518,37 @@ bool TMoverParameters::RunBlowersCommand(VehicleCommand const Command, double CV { if (Command == VehicleCommand::motorBlowersFrontSwitch) { - if (MotorBlowers[end::front].start_type != start_t::manual && MotorBlowers[end::front].start_type != start_t::manualwithautofallback) + if (MotorBlowers[VehicleEnd::front].start_type != start_t::manual && MotorBlowers[VehicleEnd::front].start_type != start_t::manualwithautofallback) { // automatic device ignores 'manual' state commands - MotorBlowers[end::front].is_enabled = CValue1 == 1; + MotorBlowers[VehicleEnd::front].is_enabled = CValue1 == 1; } OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } else if (Command == VehicleCommand::motorBlowersFrontSwitchOff) { - if (MotorBlowers[end::front].start_type != start_t::manual && MotorBlowers[end::front].start_type != start_t::manualwithautofallback) + if (MotorBlowers[VehicleEnd::front].start_type != start_t::manual && MotorBlowers[VehicleEnd::front].start_type != start_t::manualwithautofallback) { // automatic device ignores 'manual' state commands - MotorBlowers[end::front].is_disabled = CValue1 == 1; + MotorBlowers[VehicleEnd::front].is_disabled = CValue1 == 1; } OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } else if (Command == VehicleCommand::motorBlowersRearSwitch) { - if (MotorBlowers[end::rear].start_type != start_t::manual && MotorBlowers[end::rear].start_type != start_t::manualwithautofallback) + if (MotorBlowers[VehicleEnd::rear].start_type != start_t::manual && MotorBlowers[VehicleEnd::rear].start_type != start_t::manualwithautofallback) { // automatic device ignores 'manual' state commands - MotorBlowers[end::rear].is_enabled = CValue1 == 1; + MotorBlowers[VehicleEnd::rear].is_enabled = CValue1 == 1; } OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } else if (Command == VehicleCommand::motorBlowersRearSwitchOff) { - if (MotorBlowers[end::rear].start_type != start_t::manual && MotorBlowers[end::rear].start_type != start_t::manualwithautofallback) + if (MotorBlowers[VehicleEnd::rear].start_type != start_t::manual && MotorBlowers[VehicleEnd::rear].start_type != start_t::manualwithautofallback) { // automatic device ignores 'manual' state commands - MotorBlowers[end::rear].is_disabled = CValue1 == 1; + MotorBlowers[VehicleEnd::rear].is_disabled = CValue1 == 1; } OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } @@ -598,12 +598,12 @@ 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 && Couplers[CValue2 == -1 ? end::rear : end::front].CouplingFlag.HasAll(Coupling::control)}; + auto swap{false == noswap && Couplers[CValue2 == -1 ? VehicleEnd::rear : VehicleEnd::front].CouplingFlag.HasAll(Coupling::control)}; if (auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; reversed) { swap = !swap; } // TODO: check whether this part has RL equivalent - OperatePantographValve(static_cast(swap ? 1 - inputend : inputend), static_cast(inputoperation), range_t::local); + OperatePantographValve(static_cast(swap ? 1 - inputend : inputend), static_cast(inputoperation), range_t::local); OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } else if (Command == VehicleCommand::pantographsValve) @@ -680,11 +680,11 @@ void TMoverParameters::DoorPermitCommand(double const CValue1, double const CVal auto const leftside{CValue2 > 0 ? 1 : 2}; if (auto const rightside{3 - leftside}; std::abs(static_cast(CValue1)) & rightside) { - PermitDoors_(side::right, CValue1 > 0); + PermitDoors_(VehicleSide::right, CValue1 > 0); } if (std::abs(static_cast(CValue1)) & leftside) { - PermitDoors_(side::left, CValue1 > 0); + PermitDoors_(VehicleSide::left, CValue1 > 0); } } @@ -700,13 +700,13 @@ void TMoverParameters::DoorRemoteCommand(bool const Open, double const CValue1, auto const leftside{CValue2 > 0 ? 1 : 2}; if (auto const rightside{3 - leftside}; static_cast(CValue1) & rightside) { - Doors.instances[side::right].remote_open = Open; - Doors.instances[side::right].remote_close = false == Open; + Doors.instances[VehicleSide::right].remote_open = Open; + Doors.instances[VehicleSide::right].remote_close = false == Open; } if (static_cast(CValue1) & leftside) { - Doors.instances[side::left].remote_open = Open; - Doors.instances[side::left].remote_close = false == Open; + Doors.instances[VehicleSide::left].remote_open = Open; + Doors.instances[VehicleSide::left].remote_close = false == Open; } } diff --git a/physics/components/controllers.cpp b/physics/components/controllers.cpp index fc0e5e1ee..d5e41b2c3 100644 --- a/physics/components/controllers.cpp +++ b/physics/components/controllers.cpp @@ -1215,7 +1215,7 @@ void TMoverParameters::EIMICLimit() auto const eimicpowerenabled{(MainCircuitPowered() || Power == 0.0) && (!SpringBrake.IsActive || !SpringBrakeCutsOffDrive) && !LockPipe && DirAbsolute != 0}; auto const eimicdoorenabled{(SpringBrake.IsActive && ReleaseParkingBySpringBrakeWhenDoorIsOpen)}; double eimic_max = 0.0; - if (Doors.instances[side::left].open_permit == false && Doors.instances[side::right].open_permit == false) + if (Doors.instances[VehicleSide::left].open_permit == false && Doors.instances[VehicleSide::right].open_permit == false) { if (eimicpowerenabled) { diff --git a/physics/components/couplers.cpp b/physics/components/couplers.cpp index b6f750e86..7bf797524 100644 --- a/physics/components/couplers.cpp +++ b/physics/components/couplers.cpp @@ -68,7 +68,7 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters * // no multiple-unit control between an electric and a diesel locomotive, whoever asks for it: the scenario, the AI // or the player (eu07/maszyna#520) - if (auto const compatible{CompatibleCoupling(ConnectNo, *ConnectTo, otherend, CouplingType)}; compatible != CouplingType) + if (auto const compatible{CompatibleCoupling(static_cast(ConnectNo), *ConnectTo, static_cast(otherend), CouplingType)}; compatible != CouplingType) { WriteLog(std::format("Vehicles \"{}\" and \"{}\" can't share their control, coupled without the control connection", Name, ConnectTo->Name)); CouplingType = compatible; @@ -183,21 +183,21 @@ bool TMoverParameters::Dettach(int ConnectNo) // ************************************************************************************************* // prędkość zbliżania się stykających się końców pojazdów przy zderzeniu, w km/h // ************************************************************************************************* -double TMoverParameters::CollisionVelocity(int const End, TMoverParameters const &Other, int const OtherEnd) const +double TMoverParameters::CollisionVelocity(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const { auto const velocitydifference{CouplerVelocityDifference(End, Other, OtherEnd)}; // the front end closes in on the other vehicle when this one moves forward faster, the rear end when it's slower - return (End == end::front ? velocitydifference : -velocitydifference) * 3.6; // m/s -> km/h + return (End == VehicleEnd::front ? velocitydifference : -velocitydifference) * 3.6; // m/s -> km/h } -double TMoverParameters::CouplerVelocityDifference(int const End, TMoverParameters const &Other, int const OtherEnd) const +double TMoverParameters::CouplerVelocityDifference(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const { // V runs along the vehicle's own axis, towards its front; the other vehicle's velocity is turned around when the // vehicles face each other (touch with the same ends) return V - Other.V * DirPatch(End, OtherEnd); } -bool TMoverParameters::AutomaticCouplingSafe(int const End, TMoverParameters const &Other, int const OtherEnd) const +bool TMoverParameters::AutomaticCouplingSafe(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const { return false == Global.crash_damage || CollisionVelocity(End, Other, OtherEnd) <= SafeCollisionVelocity; } @@ -230,7 +230,7 @@ traction_kind traction_of(TEngineType const Engine) } // namespace -bool TMoverParameters::ControlCouplingAllowed(int const End, TMoverParameters const &Other, int const OtherEnd) const +bool TMoverParameters::ControlCouplingAllowed(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const { if (false == Global.control_coupling_engine_check) { @@ -246,7 +246,7 @@ bool TMoverParameters::ControlCouplingAllowed(int const End, TMoverParameters co return traction == traction_kind::none || othertraction == traction_kind::none || traction == othertraction; } -CouplingSet TMoverParameters::CompatibleCoupling(int const End, TMoverParameters const &Other, int const OtherEnd, CouplingSet const CouplingType) const +CouplingSet TMoverParameters::CompatibleCoupling(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd, CouplingSet const CouplingType) const { if (false == CouplingType.HasAny(Coupling::control) || CouplingType.HasAny(Coupling::permanent) || ControlCouplingAllowed(End, Other, OtherEnd)) { @@ -259,7 +259,7 @@ CouplingSet TMoverParameters::CompatibleCoupling(int const End, TMoverParameters // Q: 20160713 // Obliczanie sił dzialających na sprzęgach // ************************************************************************************************* -double TMoverParameters::CouplerForce(int const End, double dt) +double TMoverParameters::CouplerForce(VehicleEnd const End, double dt) { if (coupler_physics_at(End)) { @@ -268,12 +268,12 @@ double TMoverParameters::CouplerForce(int const End, double dt) auto &thiscoupler{Couplers[End]}; auto *othervehicle{Neighbours[End].vehicle->MoverParameters}; - auto const otherend{Neighbours[End].vehicle_end}; + auto const otherend{Neighbours[End].FacingEnd()}; auto const &othercoupler{othervehicle->Couplers[otherend]}; auto const othervehiclemove{(othervehicle->dMoveLen * DirPatch(End, otherend))}; auto const initialdistance{Neighbours[End].distance}; // odległość od sprzęgu sąsiada - auto const distancedelta{(End == end::front ? othervehiclemove - dMoveLen : dMoveLen - othervehiclemove)}; + auto const distancedelta{(End == VehicleEnd::front ? othervehiclemove - dMoveLen : dMoveLen - othervehiclemove)}; // the ends crushed for good (physics.collisions new, see collision.h) let the buffers meet that much closer auto const crushed{thiscoupler.crush + othercoupler.crush}; @@ -385,7 +385,7 @@ double TMoverParameters::CouplerForce(int const End, double dt) } // a coupler stretched with more than its strength for over a second breaks, the more likely the longer, with crash damage on -void TMoverParameters::CouplerStretchCheck(int const End, double const CF, double dt) +void TMoverParameters::CouplerStretchCheck(VehicleEnd const End, double const CF, double dt) { auto &thiscoupler{Couplers[End]}; if (std::abs(CF) > thiscoupler.FmaxC) @@ -405,7 +405,7 @@ void TMoverParameters::CouplerStretchCheck(int const End, double const CF, doubl } } -bool TMoverParameters::coupler_physics_at(int const End) const +bool TMoverParameters::coupler_physics_at(VehicleEnd const End) const { if (false == Global.coupler_physics) { @@ -420,7 +420,7 @@ bool TMoverParameters::coupler_physics_at(int const End) const return other != nullptr && other->MoverParameters->CouplerPhysics; } -void TMoverParameters::automatic_coupling(int const End, TMoverParameters &Other, int const OtherEnd) +void TMoverParameters::automatic_coupling(VehicleEnd const End, TMoverParameters &Other, VehicleEnd const OtherEnd) { auto &thiscoupler{Couplers[End]}; auto &othercoupler{Other.Couplers[OtherEnd]}; @@ -490,17 +490,17 @@ int coupler_sounds(coupler_sound_input const &Input) } // namespace -double TMoverParameters::coupler_force_physical(int const End, double const dt) +double TMoverParameters::coupler_force_physical(VehicleEnd const End, double const dt) { auto &thiscoupler{Couplers[End]}; auto *othervehicle{Neighbours[End].vehicle->MoverParameters}; - auto const otherend{Neighbours[End].vehicle_end}; + auto const otherend{Neighbours[End].FacingEnd()}; auto &othercoupler{othervehicle->Couplers[otherend]}; auto &state{thiscoupler.physics_state}; // the gap as it is now: the distance found at the start of the frame, and the movement of both vehicles since auto const othervehiclemove{othervehicle->dMoveLen * DirPatch(End, otherend)}; - auto const gap{Neighbours[End].distance + (End == end::front ? othervehiclemove - dMoveLen : dMoveLen - othervehiclemove)}; + auto const gap{Neighbours[End].distance + (End == VehicleEnd::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::none}; @@ -547,7 +547,7 @@ double TMoverParameters::coupler_force_physical(int const End, double const dt) return force; } -bool TMoverParameters::coupler_stop_hit(int const End, TMoverParameters &Other, int const OtherEnd) +bool TMoverParameters::coupler_stop_hit(VehicleEnd const End, TMoverParameters &Other, VehicleEnd const OtherEnd) { auto &thiscoupler{Couplers[End]}; auto &othercoupler{Other.Couplers[OtherEnd]}; diff --git a/physics/components/doors.cpp b/physics/components/doors.cpp index c9334a56e..216279bef 100644 --- a/physics/components/doors.cpp +++ b/physics/components/doors.cpp @@ -47,22 +47,22 @@ bool TMoverParameters::AssignLoad(std::string const &Loadname, float const Amoun { if (DoubleTr == 1) { - OperatePantographValve(end::front, operation_t::enable, range_t::local); + OperatePantographValve(VehicleEnd::front, operation_t::enable, range_t::local); } else { - OperatePantographValve(end::rear, operation_t::enable, range_t::local); + OperatePantographValve(VehicleEnd::rear, operation_t::enable, range_t::local); } } if (pantographsetup & 1 << 1) { if (DoubleTr == 1) { - OperatePantographValve(end::rear, operation_t::enable, range_t::local); + OperatePantographValve(VehicleEnd::rear, operation_t::enable, range_t::local); } else { - OperatePantographValve(end::front, operation_t::enable, range_t::local); + OperatePantographValve(VehicleEnd::front, operation_t::enable, range_t::local); } } return true; @@ -183,8 +183,8 @@ bool TMoverParameters::ChangeDoorPermitPreset(int const Change, range_t const No auto const permitleft{((doors & 1) != 0)}; auto const permitright{((doors & 2) != 0)}; - PermitDoors(CabActive > 0 ? side::left : side::right, permitleft, Notify); - PermitDoors(CabActive > 0 ? side::right : side::left, permitright, Notify); + PermitDoors(CabActive > 0 ? VehicleSide::left : VehicleSide::right, permitleft, Notify); + PermitDoors(CabActive > 0 ? VehicleSide::right : VehicleSide::left, permitright, Notify); } return Doors.permit_preset != initialstate; @@ -205,7 +205,7 @@ bool TMoverParameters::PermitDoorStep(bool const State, range_t const Notify) return Doors.step_enabled != initialstate; } -bool TMoverParameters::PermitDoors(side const Door, bool const State, range_t const Notify) +bool TMoverParameters::PermitDoors(VehicleSide const Door, bool const State, range_t const Notify) { bool const initialstate{Doors.instances[Door].open_permit}; @@ -217,7 +217,7 @@ bool TMoverParameters::PermitDoors(side const Door, bool const State, range_t co SendCtrlToNext(VehicleCommand::doorPermit, (State ? 1 : -1) // positive: grant, negative: revoke - * (Door == (CabActive > 0 ? side::left : side::right) ? // 1=lewe, 2=prawe (swap if reversed) + * (Door == (CabActive > 0 ? VehicleSide::left : VehicleSide::right) ? // 1=lewe, 2=prawe (swap if reversed) 1 : 2), CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); @@ -226,7 +226,7 @@ bool TMoverParameters::PermitDoors(side const Door, bool const State, range_t co return Doors.instances[Door].open_permit != initialstate; } -void TMoverParameters::PermitDoors_(side const Door, bool const State) +void TMoverParameters::PermitDoors_(VehicleSide const Door, bool const State) { if (State && State != Doors.instances[Door].open_permit) @@ -252,14 +252,14 @@ bool TMoverParameters::ChangeDoorControlMode(bool const State, range_t const Not { // when door are put in remote control mode they're automatically open // TBD, TODO: make it dependant on config switch? - OperateDoors(side::left, true); - OperateDoors(side::right, true); + OperateDoors(VehicleSide::left, true); + OperateDoors(VehicleSide::right, true); } return Doors.remote_only != initialstate; } -bool TMoverParameters::OperateDoors(side const Door, bool const State, range_t const Notify) +bool TMoverParameters::OperateDoors(VehicleSide const Door, bool const State, range_t const Notify) { auto &door{Doors.instances[Door]}; @@ -293,7 +293,7 @@ bool TMoverParameters::OperateDoors(side const Door, bool const State, range_t c { SendCtrlToNext(State == true ? VehicleCommand::doorOpen : VehicleCommand::doorClose, - Door == (CabActive > 0 ? side::left : side::right) ? // 1=lewe, 2=prawe (swap if reversed) + Door == (CabActive > 0 ? VehicleSide::left : VehicleSide::right) ? // 1=lewe, 2=prawe (swap if reversed) 1 : 2, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); @@ -403,7 +403,7 @@ void TMoverParameters::update_doors(double const Deltatime) move_door(door, Deltatime); } - if (false == Doors.instances[side::right].is_open && false == Doors.instances[side::left].is_open) + if (false == Doors.instances[VehicleSide::right].is_open && false == Doors.instances[VehicleSide::left].is_open) { return; } @@ -414,7 +414,7 @@ void TMoverParameters::update_doors(double const Deltatime) } /* // the door are closed if their timer goes below 0, or if the vehicle is moving faster than defined threshold - std::array const doorids { side::right, side::left }; + std::array const doorids { VehicleSide::right, VehicleSide::left }; for( auto const doorid : doorids ) { auto const &door { Doors.instances[ doorid ] }; if( true == door.is_open ) { diff --git a/physics/components/electrics.cpp b/physics/components/electrics.cpp index bfb0415db..7cdb75bd1 100644 --- a/physics/components/electrics.cpp +++ b/physics/components/electrics.cpp @@ -37,7 +37,7 @@ void TMoverParameters::UpdatePantVolume(double dt) // check the pantograph compressor while at it // TODO: move the check to a separate method // automatic start if the pressure is too low - PantCompFlag |= PantPress < 4.2 && true == (Pantographs[end::front].is_active | Pantographs[end::rear].is_active) // TODO: any_pantograph_is_active method + PantCompFlag |= PantPress < 4.2 && true == (Pantographs[VehicleEnd::front].is_active | Pantographs[VehicleEnd::rear].is_active) // TODO: any_pantograph_is_active method && (PantographCompressorStart == start_t::automatic || PantographCompressorStart == start_t::manualwithautofallback); auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; @@ -463,17 +463,17 @@ double TMoverParameters::LocalPowerVoltage(Coupling const kind) // 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 kind, double const abslocalvoltage, bool const localpowersource) { - if (Couplers[end::front].power(kind) == nullptr) + if (Couplers[VehicleEnd::front].power(kind) == nullptr) { // not a power coupling, there's no voltage to pass return; } - for (auto side = 0; side < 2; ++side) + for (auto const side : VehicleEnds) { auto const &thiscoupler{Couplers[side]}; // NOTE: in the loop we actually update the state of the coupler on the opposite end of the vehicle - auto &oppositecoupler{Couplers[side == end::front ? end::rear : end::front]}; + auto &oppositecoupler{Couplers[Opposite(side)]}; bool oppositecouplingispresent; bool localpowerexportisenabled; @@ -539,8 +539,8 @@ void TMoverParameters::PowerCouplersVoltage(Coupling const kind, double const ab // the current drawn through the couplers, shared by their voltages, or added to the vehicle's own void TMoverParameters::PowerCouplersCurrent(Coupling const kind, bool const localpowersource) { - auto const *frontcoupling{Couplers[end::front].power(kind)}; - auto const *rearcoupling{Couplers[end::rear].power(kind)}; + auto const *frontcoupling{Couplers[VehicleEnd::front].power(kind)}; + auto const *rearcoupling{Couplers[VehicleEnd::rear].power(kind)}; auto *totalcurrent{PowerCircuitCurrent(kind)}; if (frontcoupling == nullptr || rearcoupling == nullptr || totalcurrent == nullptr) { @@ -560,7 +560,7 @@ void TMoverParameters::PowerCouplersCurrent(Coupling const kind, bool const loca continue; } - auto const &connectedothercoupler{thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr == end::front ? end::rear : end::front]}; + auto const &connectedothercoupler{thiscoupler.Connected->Couplers[Opposite(thiscoupler.ConnectedEnd())]}; auto const *connectedothercoupling = connectedothercoupler.power(kind); auto const extracurrent = kind == Coupling::highVoltage ? std::abs(Itot) * IsVehicleEIMBrakingFactor() : 0.0; @@ -1191,7 +1191,7 @@ bool TMoverParameters::OperatePantographsValve(operation_t const State, range_t return true; } -bool TMoverParameters::OperatePantographValve(end const End, operation_t const State, range_t const Notify) +bool TMoverParameters::OperatePantographValve(VehicleEnd const End, operation_t const State, range_t const Notify) { if (EnginePowerSource.SourceType == TPowerSource::CurrentCollector && EnginePowerSource.CollectorParameters.CollectorsNo > 0) @@ -1248,7 +1248,7 @@ bool TMoverParameters::OperatePantographValve(end const End, operation_t const S SendCtrlToNext(VehicleCommand::pantographValve, // 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, + static_cast(0x80 * (End == VehicleEnd::front ? 0 : 1) + 0x40 * (CabActive != -1 ? 1 : 0) + static_cast(State)), CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } @@ -1277,8 +1277,8 @@ bool TMoverParameters::DropAllPantographs(bool const State, range_t const Notify 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}; - for (int end = end::front; end <= end::rear; ++end) + ByEnd voltages{0.0, 0.0}; + for (auto const end : VehicleEnds) { if (Couplers[end].Connected == nullptr) { @@ -1298,7 +1298,7 @@ double TMoverParameters::GetTrainsetVoltage(CouplingSet const couplings) const voltages[end] = connectedpowercoupling->voltage; } } - return std::max(voltages[end::front], voltages[end::rear]); + return std::max(voltages[VehicleEnd::front], voltages[VehicleEnd::rear]); } double TMoverParameters::GetTrainsetHighVoltage() const diff --git a/physics/components/fizsections.cpp b/physics/components/fizsections.cpp index 7c2d082fc..d3de6cc60 100644 --- a/physics/components/fizsections.cpp +++ b/physics/components/fizsections.cpp @@ -660,11 +660,11 @@ void TMoverParameters::LoadFIZ_BuffCoupl(std::string const &line, int const Inde Couplers[1] = Couplers[0]; } // each coupling as made is a little stronger than its rated force, a different one at each end - for (int end = end::front; end <= end::rear; ++end) + for (auto const end : VehicleEnds) { - if (Index == 0 || end == (Index == 2 ? end::rear : end::front)) + if (Index == 0 || end == (Index == 2 ? VehicleEnd::rear : VehicleEnd::front)) { - scale_strength(Couplers[end].physics.link, coupler_physics::strength_scatter(Name, end)); + scale_strength(Couplers[end].physics.link, coupler_physics::strength_scatter(Name, NumberOf(end))); } } } @@ -986,8 +986,8 @@ void TMoverParameters::LoadFIZ_CntrlStarts(std::string const &line) // traction motor fans { auto lookup = starts.find(extract_value("MotorBlowersStart", line)); - MotorBlowers[end::rear].start_type = lookup != starts.end() ? lookup->second : manual; - MotorBlowers[end::front].start_type = MotorBlowers[end::rear].start_type; + MotorBlowers[VehicleEnd::rear].start_type = lookup != starts.end() ? lookup->second : manual; + MotorBlowers[VehicleEnd::front].start_type = MotorBlowers[VehicleEnd::rear].start_type; } // what else the line contactors need to close { @@ -1256,10 +1256,10 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input) } // traction motors - extract_value(MotorBlowers[end::front].speed, "MotorBlowersSpeed", Input, ""); - extract_value(MotorBlowers[end::front].sustain_time, "MotorBlowersSustainTime", Input, ""); - extract_value(MotorBlowers[end::front].min_start_velocity, "MotorBlowersStartVelocity", Input, ""); - MotorBlowers[end::rear] = MotorBlowers[end::front]; + extract_value(MotorBlowers[VehicleEnd::front].speed, "MotorBlowersSpeed", Input, ""); + extract_value(MotorBlowers[VehicleEnd::front].sustain_time, "MotorBlowersSustainTime", Input, ""); + extract_value(MotorBlowers[VehicleEnd::front].min_start_velocity, "MotorBlowersStartVelocity", Input, ""); + MotorBlowers[VehicleEnd::rear] = MotorBlowers[VehicleEnd::front]; // pressure switch extract_value(HasControlPressureSwitch, "PressureSwitch", Input, TrainType != train_type::emu ? "yes" : "no"); // its brake cylinder half; the brake pipe one stays diff --git a/physics/components/internal.h b/physics/components/internal.h index a43782492..baf916278 100644 --- a/physics/components/internal.h +++ b/physics/components/internal.h @@ -21,13 +21,13 @@ inline double square(double val) // SQR() zle liczylo w current() ... return val * val; } -int DirPatch(int Coupler1, int Coupler2); +int DirPatch(VehicleEnd Coupler1, VehicleEnd Coupler2); -int DirF(int CouplerN); +int DirF(VehicleEnd CouplerN); double TableInterpolation(std::map &Map, double Parameter); -double compression_at(TCoupling const &Coupler, int const End); +double compression_at(TCoupling const &Coupler, VehicleEnd const End); bool issection(std::string_view Name, std::string_view Input); diff --git a/physics/components/pneumatics.cpp b/physics/components/pneumatics.cpp index 1e4e44f2b..8a7f0555a 100644 --- a/physics/components/pneumatics.cpp +++ b/physics/components/pneumatics.cpp @@ -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 == 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)}; + (Couplers[VehicleEnd::rear].Connected != nullptr && true == Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::permanent) && Couplers[VehicleEnd::rear].Connected->CompressorGovernorLock) || + (Couplers[VehicleEnd::front].Connected != nullptr && true == Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::permanent) && Couplers[VehicleEnd::front].Connected->CompressorGovernorLock)}; auto const governorlock{CompressorGovernorLock || coupledgovernorlock}; auto const compressorflag{CompressorFlag}; diff --git a/physics/components/setup.cpp b/physics/components/setup.cpp index d4a8aae70..086e37ddc 100644 --- a/physics/components/setup.cpp +++ b/physics/components/setup.cpp @@ -410,7 +410,7 @@ double TMoverParameters::InitialScndPipePress(double const HosePressure) const { return CompressedVolume / VeselVolume; } - if (Couplers[end::front].AllowedFlag.HasAny(Coupling::mainHose) || Couplers[end::rear].AllowedFlag.HasAny(Coupling::mainHose)) + if (Couplers[VehicleEnd::front].AllowedFlag.HasAny(Coupling::mainHose) || Couplers[VehicleEnd::rear].AllowedFlag.HasAny(Coupling::mainHose)) { return HosePressure; } diff --git a/physics/components/traction.cpp b/physics/components/traction.cpp index 44f2d434d..de089e04b 100644 --- a/physics/components/traction.cpp +++ b/physics/components/traction.cpp @@ -394,7 +394,7 @@ double TMoverParameters::ShowCurrent(int AmpN) const return Drive().ShowCurrent(*this, AmpN); }; -bool TMoverParameters::MotorBlowersSwitch(bool State, end const Side, range_t const Notify) +bool TMoverParameters::MotorBlowersSwitch(bool State, VehicleEnd const Side, range_t const Notify) { auto &fan{MotorBlowers[Side]}; @@ -411,14 +411,14 @@ 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, + SendCtrlToNext(Side == VehicleEnd::front ? VehicleCommand::motorBlowersFrontSwitch : VehicleCommand::motorBlowersRearSwitch, fan.is_enabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } return fan.is_enabled != initialstate; } -bool TMoverParameters::MotorBlowersSwitchOff(bool State, end const Side, range_t const Notify) +bool TMoverParameters::MotorBlowersSwitchOff(bool State, VehicleEnd const Side, range_t const Notify) { auto &fan{MotorBlowers[Side]}; @@ -435,7 +435,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, + SendCtrlToNext(Side == VehicleEnd::front ? VehicleCommand::motorBlowersFrontSwitchOff : VehicleCommand::motorBlowersRearSwitchOff, fan.is_disabled ? 1 : 0, CabActive, Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control); } @@ -1179,8 +1179,8 @@ void TMoverParameters::InductionMotorDynamicBrakeFlag() // zalaczenia hamulca elektrodynamicznego - ED jest sterowany wlasnym nastawnikiem auto const dynbrakectrlactive{SplitEDPneumaticBrake && DynamicBrakeRatio() > 0.01 && DynamicBrakeAvailable()}; auto const localbrakeforED{SplitEDPneumaticBrake ? false : localbrakeactive}; - if (false == Doors.instances[side::left].is_closed || false == Doors.instances[side::right].is_closed || - (Doors.permit_needed && (Doors.instances[side::left].open_permit || Doors.instances[side::right].open_permit))) + if (false == Doors.instances[VehicleSide::left].is_closed || false == Doors.instances[VehicleSide::right].is_closed || + (Doors.permit_needed && (Doors.instances[VehicleSide::left].open_permit || Doors.instances[VehicleSide::right].open_permit))) { DynamicBrakeFlag = true; } diff --git a/physics/mover.h b/physics/mover.h index dba810ef7..439574ce6 100644 --- a/physics/mover.h +++ b/physics/mover.h @@ -490,6 +490,11 @@ struct TCoupling 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ł + // the end of the vehicle connected to, while there is one + VehicleEnd ConnectedEnd() const + { + return static_cast(ConnectedNr); + } double CForce = 0.0; /*sila z jaka dzialal*/ double Dist = 0.0; /*strzalka ugiecia zderzaków*/ bool CheckCollision = false; /*czy sprawdzac sile czy pedy*/ @@ -778,7 +783,7 @@ class TMoverParameters // internal data int permit_preset{-1}; // curent position of preset selection switch // vehicle parts - std::array instances; // door on the right and left side of the vehicle + BySide instances; // door on the right and left side of the vehicle // ld outputs bool is_locked{false}; double doorLockSpeed = 10.0; // predkosc przy ktorej wyzwalana jest blokada drzwi @@ -981,7 +986,7 @@ class TMoverParameters int LightsPosNo = 0; int LightsDefPos = 1; bool LightsWrap = false; - int Lights[2][18]; // pozycje świateł, przód - tył, 1 .. 16 (17 do lightsset) + ByEnd> Lights; // pozycje świateł, przód - tył, 1 .. 16 (17 do lightsset) // the cab interior light each light preset sets, from the optional third column of LightsList (bits of // lights_preset_cablight::flag); -1: the preset leaves the cab light as it is (eu07/maszyna#529) std::array LightsCabLight{[] { @@ -1021,7 +1026,7 @@ class TMoverParameters // 5% steps of the 6Dg), one at once when moved to a raising or lowering position, then one each time its SpeedUp / SpeedDown // covers a step; 0 (the default) changes it continuously double UniCtrlValStep{0.0}; - std::pair> PantsPreset{"0132", {0, 0}}; // pantograph preset switches; .first holds possible setups as chars, .second holds currently selected preset in each cab + std::pair> PantsPreset{"0132", {0, 0}}; // pantograph preset switches; .first holds possible setups as chars, .second holds currently selected preset in each cab /*-sekcja parametrow dla lokomotywy elektrycznej*/ TSchemeTable RList; /*lista rezystorow rozruchowych i polaczen silnikow, dla dizla: napelnienia*/ @@ -1216,11 +1221,11 @@ class TMoverParameters TRotation Rot{0.0, 0.0, 0.0}; glm::vec3 Front{}; std::string Name; /*nazwa wlasna*/ - TCoupling Couplers[2]; // urzadzenia zderzno-sprzegowe, polaczenia miedzy wagonami + ByEnd Couplers; // urzadzenia zderzno-sprzegowe, polaczenia miedzy wagonami // the physical coupler model covers the vehicle: it's in the player's train or in one the player's train closes in on // (vehicle_table::update_coupler_physics()); with couplerphysics all in eu07.ini every vehicle is covered bool CouplerPhysics{false}; - std::array Neighbours; // potential collision sources + ByEnd Neighbours; // potential collision sources bool Power110vIsAvailable = false; // cached availability of 110v power bool Power24vIsAvailable = false; // cached availability of 110v power double Power24vVoltage{0.0}; // cached battery voltage @@ -1294,7 +1299,7 @@ class TMoverParameters start_t CompressorStart{start_t::manual}; // whether the compressor is started manually, or another way start_t PantographCompressorStart{start_t::manual}; basic_valve PantsValve; - std::array Pantographs; + ByEnd Pantographs; bool PantAllDown{false}; double PantFrontVolt = 0.0; // pantograf pod napieciem? 'Winger 160404 double PantRearVolt = 0.0; @@ -1318,7 +1323,7 @@ class TMoverParameters water_pump WaterPump; water_heater WaterHeater; bool WaterCircuitsLink{false}; // optional connection between water circuits - std::array MotorBlowers; + ByEnd MotorBlowers; door_data Doors; float DoorsOpenWithPermitAfter{-1.f}; // remote open if permit button is held for specified time. NOTE: separate from door data as its cab control thing int DoorsPermitLightBlinking{0}; // when the doors permit signal light is blinking @@ -1541,7 +1546,7 @@ class TMoverParameters bool bPantKurek3 = true; // kurek trójdrogowy (pantografu): true=połączenie z ZG, false=połączenie z małą sprężarką // domyślnie zbiornik pantografu połączony jest ze zbiornikiem głównym bool PantAutoValve{false}; // type of installed pantograph compressor valve int iProblem = 0; // flagi problemów z taborem, aby AI nie musiało porównywać; 0=może jechać - int iLights[2]; // bity zapalonych świateł tutaj, żeby dało się liczyć pobór prądu + ByEnd iLights; // bity zapalonych świateł tutaj, żeby dało się liczyć pobór prądu // Status nowszego hebelka od przyciemniania swiatel/swiatel dlugich // 0 - swiatla wylaczone (opcja dziala tylko gdy w fiz zdefiniowano OffState w sekcji Switches; w przeciwnym wypadku pstryk startuje z wartoscia == 1 @@ -1600,12 +1605,25 @@ class TMoverParameters static double Distance(const TLocation &Loc1, const TLocation &Loc2, const TDimension &Dim1, const TDimension &Dim2); bool Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, CouplingSet CouplingType, bool Enforce = false, bool Audible = true); int DettachStatus(int ConnectNo); + int DettachStatus(VehicleEnd const ConnectNo) + { + return DettachStatus(NumberOf(ConnectNo)); + } bool Dettach(int ConnectNo); - void damage_coupler(int const End); + // the same by the ends, where they are known to be ends + bool Attach(VehicleEnd const ConnectNo, VehicleEnd const ConnectToNr, TMoverParameters *ConnectTo, CouplingSet CouplingType, bool Enforce = false, bool Audible = true) + { + return Attach(NumberOf(ConnectNo), NumberOf(ConnectToNr), ConnectTo, CouplingType, Enforce, Audible); + } + bool Dettach(VehicleEnd const ConnectNo) + { + return Dettach(NumberOf(ConnectNo)); + } + void damage_coupler(VehicleEnd const End); // repairs the broken coupler of the end, and the one of the vehicle it was coupled with, so they can be coupled // again; the vehicles clear their coupler damage once neither of their couplers is broken. returns: whether there // was a broken coupler to repair - bool repair_coupler(int const End); + bool repair_coupler(VehicleEnd const End); void Derail(DerailReason Reason); // the velocity of the vehicles coupled to this one changes by the Change along the axis of this one [m/s], as the // legacy derailment changes the velocity of this one (physics.collisions new) @@ -1645,8 +1663,8 @@ class TMoverParameters // physics.collisions new: what the vehicle is for the defaults of its crush and its buffers, the crush curve and the // height of the buffers of an end, and how long the push of its ends held its wheels over the climbing limit collision::vehicle_kind collision_kind() const; - collision::crush_curve crush_curve_at(int End) const; - double buffer_height_at(int End) const; + collision::crush_curve crush_curve_at(VehicleEnd End) const; + double buffer_height_at(VehicleEnd End) const; collision::pushed_monitor pushed_off_monitor; // how the vehicle left the rails in a collision (physics.collisions new): overriding or pushed off, NONE otherwise DerailReason CollisionDerail{NONE}; @@ -1656,7 +1674,7 @@ class TMoverParameters // weaker end and may let one vehicle climb onto the other one, see collision.h. returns: whether it did, and the // velocities took the hit; the legacy collision takes the rest. physics.collisions monitor: the log tells what the // crush of the whole hit would be, once for a hit, nothing changes, and it returns false - bool crush_hit(int End, double dt); + bool crush_hit(VehicleEnd End, double dt); // the force pressing the ends pushes the vehicle off the track (physics.collisions new), the step travelled the // Distance [m]: the flange climbs while the wheels roll on void check_pushed_off(double dt, double Distance); @@ -1909,39 +1927,39 @@ class TMoverParameters double BrakeForceR(double ratio, double velocity) const; double BrakeForceP(double press, double velocity) const; double BrakeForce(const TTrackParam &Track); - double CouplerForce(int const End, double dt); - void CouplerStretchCheck(int End, double CF, double dt); + double CouplerForce(VehicleEnd const End, double dt); + void CouplerStretchCheck(VehicleEnd End, double CF, double dt); // whether the coupling at the end is computed by the physical model: couplerphysics set in eu07.ini, and this // vehicle or the one at the end covered by it (CouplerPhysics), or every vehicle with couplerphysics all - bool coupler_physics_at(int const End) const; + bool coupler_physics_at(VehicleEnd const End) const; // the force of the coupling at the end by the physical model (couplerphysics in eu07.ini), see couplerphysics.h - double coupler_force_physical(int const End, double const dt); + double coupler_force_physical(VehicleEnd const End, double const dt); // with the physical model: whether the vehicles at the end hit the stop of their springs at the last update and // still close in on it, so that they collide; a hit hard enough breaks the coupling or crushes the buffers - bool coupler_stop_hit(int const End, TMoverParameters &Other, int const OtherEnd); + bool coupler_stop_hit(VehicleEnd const End, TMoverParameters &Other, VehicleEnd const OtherEnd); // couples the automatic couplers of the end and of the other vehicle pressed against each other, unless the hit // is too fast for them to catch - void automatic_coupling(int const End, TMoverParameters &Other, int const OtherEnd); - void CollisionDetect(int const End, double const dt); + void automatic_coupling(VehicleEnd const End, TMoverParameters &Other, VehicleEnd const OtherEnd); + void CollisionDetect(VehicleEnd const End, double const dt); // closing speed of a collision [km/h] above which the vehicles involved may derail, adjusted for their mass ratio static constexpr double SafeCollisionVelocity{15.0}; // closing speed [km/h] of the End of this vehicle and the OtherEnd of the other vehicle it touches, along the coupler // axis: the sum of the speeds in a head-on collision, the difference in a rear-end one, negative when they part - double CollisionVelocity(int const End, TMoverParameters const &Other, int const OtherEnd) const; + double CollisionVelocity(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const; // velocity [m/s] of this vehicle relative to the other vehicle it touches with its End and the OtherEnd of the // other one, along this vehicle's axis - double CouplerVelocityDifference(int const End, TMoverParameters const &Other, int const OtherEnd) const; + double CouplerVelocityDifference(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const; // whether the automatic couplers at the End of this vehicle and the OtherEnd of the other one can catch each other on // contact, rather than the vehicles colliding (with crash damage enabled, only at a closing speed which doesn't derail them) - bool AutomaticCouplingSafe(int const End, TMoverParameters const &Other, int const OtherEnd) const; + bool AutomaticCouplingSafe(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd const OtherEnd) const; // whether the control coupling (multiple-unit control) can join the End of this vehicle and the OtherEnd of the other // one: not between an electric and a diesel traction vehicle, unless both couplers name the same control system // (ControlType). Vehicles without own traction (cars, control trailers) take any. Global.control_coupling_engine_check // off allows it always (eu07/maszyna#520) - bool ControlCouplingAllowed(int const End, TMoverParameters const &Other, int const OtherEnd) const; + bool ControlCouplingAllowed(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd 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 - CouplingSet CompatibleCoupling(int const End, TMoverParameters const &Other, int const OtherEnd, CouplingSet const CouplingType) const; + CouplingSet CompatibleCoupling(VehicleEnd const End, TMoverParameters const &Other, VehicleEnd 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: @@ -2026,8 +2044,8 @@ class TMoverParameters bool FuelPumpSwitchOff(bool State, range_t const Notify = range_t::consist); // fuel pump state toggle bool OilPumpSwitch(bool State, range_t const Notify = range_t::consist); // oil pump state toggle bool OilPumpSwitchOff(bool State, range_t const Notify = range_t::consist); // oil pump state toggle - bool MotorBlowersSwitch(bool State, end const Side, range_t const Notify = range_t::consist); // traction motor fan state toggle - bool MotorBlowersSwitchOff(bool State, end const Side, range_t const Notify = range_t::consist); // traction motor fan state toggle + bool MotorBlowersSwitch(bool State, VehicleEnd const Side, range_t const Notify = range_t::consist); // traction motor fan state toggle + bool MotorBlowersSwitchOff(bool State, VehicleEnd const Side, range_t const Notify = range_t::consist); // traction motor fan state toggle bool CompartmentLightsSwitch(bool State, range_t const Notify = range_t::consist); // compartment lights state toggle bool CompartmentLightsSwitchOff(bool State, range_t const Notify = range_t::consist); // compartment lights state toggle bool MainSwitch(bool const State, range_t const Notify = range_t::consist); /*! wylacznik glowny*/ @@ -2115,7 +2133,7 @@ class TMoverParameters bool ResistorsFlagCheck(void) const; // sprawdzenie kontrolki oporow rozruchowych NBMX bool OperatePantographsValve(operation_t const State, range_t const Notify = range_t::consist); - bool OperatePantographValve(end const End, operation_t const State, range_t const Notify = range_t::consist); + bool OperatePantographValve(VehicleEnd const End, operation_t const State, range_t const Notify = range_t::consist); bool DropAllPantographs(bool const State, range_t const Notify = range_t::consist); void CheckEIMIC(double dt); // sprawdzenie i zmiana nastawy zintegrowanego nastawnika jazdy/hamowania @@ -2171,12 +2189,12 @@ class TMoverParameters /* funckje dla wagonow*/ bool AssignLoad(std::string const &Name, float const Amount = 0.f); bool LoadingDone(double LSpeed, std::string_view Loadname); - bool PermitDoors(side const Door, bool const State = true, range_t const Notify = range_t::consist); - void PermitDoors_(side const Door, bool const State = true); + bool PermitDoors(VehicleSide const Door, bool const State = true, range_t const Notify = range_t::consist); + void PermitDoors_(VehicleSide const Door, bool const State = true); bool ChangeDoorPermitPreset(int const Change, range_t const Notify = range_t::consist); bool PermitDoorStep(bool const State, range_t const Notify = range_t::consist); bool ChangeDoorControlMode(bool const State, range_t const Notify = range_t::consist); - bool OperateDoors(side const Door, bool const State, range_t const Notify = range_t::consist); + bool OperateDoors(VehicleSide const Door, bool const State, range_t const Notify = range_t::consist); bool LockDoors(bool const State, range_t const Notify = range_t::consist); bool signal_departure(bool const State, range_t const Notify = range_t::consist); // toggles departure warning void update_doors(double const Deltatime); // door controller update diff --git a/physics/vehicletypes.h b/physics/vehicletypes.h index 3e133b0f7..8d0a6bf61 100644 --- a/physics/vehicletypes.h +++ b/physics/vehicletypes.h @@ -12,6 +12,8 @@ http://mozilla.org/MPL/2.0/. #pragma once +#include +#include #include #include @@ -126,8 +128,9 @@ enum DerailReason /// Fuzzy-logic probability weight: damage caused by wheel slip. #define p_slippdmg (1e-03) -/// Vehicle ends — front or rear (mutually exclusive). -enum end +/// Vehicle ends — front or rear (mutually exclusive). The numbers are the ones of the formats (the +/// couplers of the .scn, the network) and the places in a . +enum class VehicleEnd : int { /// Front end. front = 0, @@ -135,8 +138,8 @@ enum end rear = 1 }; -/// Vehicle sides — right or left (mutually exclusive). -enum side +/// Vehicle sides — right or left (mutually exclusive), the places in a . +enum class VehicleSide : int { /// Right side. right = 0, @@ -144,6 +147,66 @@ enum side left = 1 }; +/// Both ends and both sides, to go through them. +constexpr std::array VehicleEnds{VehicleEnd::front, VehicleEnd::rear}; +constexpr std::array VehicleSides{VehicleSide::right, VehicleSide::left}; + +/// The other end of the vehicle. +constexpr VehicleEnd Opposite(VehicleEnd const vehicleEnd) +{ + return vehicleEnd == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front; +} + +/// The other side of the vehicle. +constexpr VehicleSide Opposite(VehicleSide const vehicleSide) +{ + return vehicleSide == VehicleSide::right ? VehicleSide::left : VehicleSide::right; +} + +/// The number of the end or the side, where a format or a count needs it. +constexpr int NumberOf(VehicleEnd const vehicleEnd) +{ + return static_cast(vehicleEnd); +} + +constexpr int NumberOf(VehicleSide const vehicleSide) +{ + return static_cast(vehicleSide); +} + +/// The end of the given number (0 front, 1 rear), as the formats have it; the number is kept as it is. +constexpr VehicleEnd EndOf(int const number) +{ + return static_cast(number); +} + +/// The side of the given number (0 right, 1 left); the number is kept as it is. +constexpr VehicleSide SideOf(int const number) +{ + return static_cast(number); +} + +/// Two values, one for each end or side of a vehicle, indexed by the enum; by a number too, where a loop +/// counts them. +template +struct EnumPair : std::array +{ + using std::array::operator[]; + constexpr Value &operator[](Key const key) + { + return std::array::operator[](static_cast(key)); + } + constexpr Value const &operator[](Key const key) const + { + return std::array::operator[](static_cast(key)); + } +}; + +template +using ByEnd = EnumPair; +template +using BySide = EnumPair; + /// 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 @@ -710,4 +773,10 @@ struct neighbour_data TDynamicObject *vehicle{nullptr}; // detected obstacle int vehicle_end{-1}; // facing end of the obstacle float distance{10000.f}; // distance to the obstacle // NOTE: legacy value. TBD, TODO: use standard -1 instead? + + // the facing end of the obstacle there is + VehicleEnd FacingEnd() const + { + return static_cast(vehicle_end); + } }; diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp index ebceae0ff..cb1b5621f 100644 --- a/rendering/common/scenewalk.cpp +++ b/rendering/common/scenewalk.cpp @@ -288,7 +288,7 @@ bool scene_walk::Render_lowpoly( TDynamicObject *Dynamic, float const Squaredist return true; } -bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Squaredistance, int const End, bool const Alpha ) { +bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Squaredistance, VehicleEnd const End, bool const Alpha ) { if( Dynamic->m_coupleradapters[ End ] == nullptr ) { return false; } gfx::walk_sync::vehicle_hold hold; @@ -296,11 +296,11 @@ bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Sq auto const position { glm::dvec3 { 0.f, Dynamic->MoverParameters->Couplers[ End ].adapter_height, - ( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == end::front ? 1 : -1 ) } }; + ( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == VehicleEnd::front ? 1 : -1 ) } }; auto const angle { glm::vec3{ 0, - ( End == end::front ? 0 : 180 ), + ( End == VehicleEnd::front ? 0 : 180 ), 0 } }; if( Alpha ) { @@ -1931,8 +1931,8 @@ bool scene_walk::Render(TDynamicObject *Dynamic) Render( attachment, Dynamic->Material(), squaredistance ); } // optional coupling adapters - Render_coupler_adapter( Dynamic, squaredistance, end::front ); - Render_coupler_adapter( Dynamic, squaredistance, end::rear ); + Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::front ); + Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::rear ); // post-render cleanup if (gfx::vehicle_shade(Dynamic) > 0.0f) @@ -1957,8 +1957,8 @@ bool scene_walk::Render(TDynamicObject *Dynamic) Render( attachment, Dynamic->Material(), squaredistance ); } // optional coupling adapters - Render_coupler_adapter( Dynamic, squaredistance, end::front ); - Render_coupler_adapter( Dynamic, squaredistance, end::rear ); + Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::front ); + Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::rear ); if( Dynamic->mdLoad ) { // renderowanie nieprzezroczystego ładunku Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} ); @@ -3099,8 +3099,8 @@ bool scene_walk::Render_Alpha(TDynamicObject *Dynamic) Render_Alpha( attachment, Dynamic->Material(), squaredistance ); } // optional coupling adapters - Render_coupler_adapter( Dynamic, squaredistance, end::front, true ); - Render_coupler_adapter( Dynamic, squaredistance, end::rear, true ); + Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::front, true ); + Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::rear, true ); if( Dynamic->mdLoad ) { // renderowanie nieprzezroczystego ładunku Render_Alpha( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} ); diff --git a/rendering/common/scenewalk.h b/rendering/common/scenewalk.h index 37dbb1b7c..0db605644 100644 --- a/rendering/common/scenewalk.h +++ b/rendering/common/scenewalk.h @@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/. #pragma once +#include "physics/vehicletypes.h" #include "rendering/geometrybank.h" #include "rendering/openglcamera.h" #include "scene/scene.h" @@ -178,7 +179,7 @@ class scene_walk bool Render_cab(TDynamicObject const *Dynamic, float const Lightlevel, bool const Alpha = false); bool Render_interior(bool const Alpha = false); bool Render_lowpoly(TDynamicObject *Dynamic, float const Squaredistance, bool const Setup, bool const Alpha = false); - bool Render_coupler_adapter(TDynamicObject *Dynamic, float const Squaredistance, int const End, bool const Alpha = false); + bool Render_coupler_adapter(TDynamicObject *Dynamic, float const Squaredistance, VehicleEnd const End, bool const Alpha = false); void Render(TMemCell *Memcell); void Render_Alpha(scene::basic_region *Region); void Render_Alpha(cell_sequence::reverse_iterator First, cell_sequence::reverse_iterator Last); diff --git a/rendering/lightarray.cpp b/rendering/lightarray.cpp index f34a4d183..eef1c6a2f 100644 --- a/rendering/lightarray.cpp +++ b/rendering/lightarray.cpp @@ -23,8 +23,8 @@ light_array::insert( TDynamicObject const *Owner ) { // we're only storing lights for locos, which have two sets of lights, front and rear // for a more generic role this function would have to be tweaked to add vehicle type-specific light combinations - data.emplace_back( Owner, end::front ); - data.emplace_back( Owner, end::rear ); + data.emplace_back( Owner, NumberOf( VehicleEnd::front ) ); + data.emplace_back( Owner, NumberOf( VehicleEnd::rear ) ); } void @@ -39,7 +39,7 @@ light_array::update() { for( auto &light : data ) { // update light parameters to match current data of the owner - if( light.index == end::front ) { + if( EndOf( light.index ) == VehicleEnd::front ) { // front light set light.position = light.owner->GetPosition() + ( light.owner->VectorFront() * ( std::max( 0.0, light.owner->GetLength() * 0.5 - 2.0 ) ) );// +( light.owner->VectorUp() * 0.25 ); light.direction = glm::make_vec3( glm::value_ptr(light.owner->VectorFront()) ); // TODO: It is needed to get value_ptr and then make_vec3? @@ -56,7 +56,7 @@ light_array::update() { || ( true == light.owner->MoverParameters->Power110vIsAvailable ) ) { // with power on, the intensity depends on the state of activated switches // first we cross-check the list of enabled lights with the lights installed in the vehicle... - auto const lights { light.owner->MoverParameters->iLights[ light.index ] & light.owner->LightList( static_cast( light.index ) ) }; + auto const lights { light.owner->MoverParameters->iLights[ light.index ] & light.owner->LightList( static_cast( light.index ) ) }; // ...then check their individual state light.count = 0 + ( ( lights & light::headlight_left ) ? 1 : 0 ) @@ -67,7 +67,7 @@ light_array::update() { // set intensity if( light.count > 0 ) { - bool isEnabled = light.index == end::front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff; + bool isEnabled = EndOf( light.index ) == VehicleEnd::front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff; light.intensity = std::max(0.0f, std::log((float)light.count + 1.0f)); if (light.owner->DimHeadlights && !light.owner->HighBeamLights && isEnabled) // tylko przyciemnione diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 6b573e1ea..be6fc0000 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -74,19 +74,19 @@ std::uint32_t devices_of(TMoverParameters const &Occupied, TMoverParameters cons namespace device = blackbox::cab_devices; auto const on{[](bool const State, std::uint32_t const Bit) { return State ? Bit : 0u; }}; return on(Occupied.Battery || Controlling.Battery, device::battery) | on(Controlling.Mains, device::main_breaker) | - on(Controlling.Pantographs[end::front].is_active, device::pantograph_front) | on(Controlling.Pantographs[end::rear].is_active, device::pantograph_rear) | + on(Controlling.Pantographs[VehicleEnd::front].is_active, device::pantograph_front) | on(Controlling.Pantographs[VehicleEnd::rear].is_active, device::pantograph_rear) | on(Controlling.ConverterFlag, device::converter) | on(Controlling.CompressorFlag, device::compressor) | on(Controlling.StLinFlag, device::line_contactors) | on(Controlling.FuseFlag, device::overload_relay) | on(Controlling.SandDose, device::sanding) | on(Occupied.WarningSignal != 0, device::horn) | - on(false == Occupied.Doors.instances[side::left].is_closed, device::doors_left) | - on(false == Occupied.Doors.instances[side::right].is_closed, device::doors_right) | on(Occupied.Radio, device::radio) | + on(false == Occupied.Doors.instances[VehicleSide::left].is_closed, device::doors_left) | + on(false == Occupied.Doors.instances[VehicleSide::right].is_closed, device::doors_right) | on(Occupied.Radio, device::radio) | on(Controlling.Heating, device::heating) | on(Occupied.SpringBrake.IsActive, device::spring_brake) | on(Controlling.ShuntMode, device::shunt_mode) | // the doors as the cab works them: the permits, the departure signal, the steps and the lock - on(Occupied.DepartureSignal, device::departure_signal) | on(Occupied.Doors.instances[side::left].open_permit, device::door_permit_left) | - on(Occupied.Doors.instances[side::right].open_permit, device::door_permit_right) | on(Occupied.Doors.step_enabled, device::door_step) | + on(Occupied.DepartureSignal, device::departure_signal) | on(Occupied.Doors.instances[VehicleSide::left].open_permit, device::door_permit_left) | + on(Occupied.Doors.instances[VehicleSide::right].open_permit, device::door_permit_right) | on(Occupied.Doors.step_enabled, device::door_step) | on(Occupied.Doors.lock_enabled, device::door_lock) | on(Occupied.Doors.is_locked, device::doors_locked) | on(Occupied.Hamulec != nullptr && Occupied.Hamulec->Releaser(), device::brake_releaser) | on(Controlling.FuelPump.is_active, device::fuel_pump) | on(Controlling.OilPump.is_active, device::oil_pump) | - on(Controlling.MotorBlowers[end::front].is_active || Controlling.MotorBlowers[end::rear].is_active, device::motor_blowers) | + on(Controlling.MotorBlowers[VehicleEnd::front].is_active || Controlling.MotorBlowers[VehicleEnd::rear].is_active, device::motor_blowers) | on(Controlling.diesel.heat.engine_is_hot, device::engine_hot) | on(Controlling.SpeedCtrl && Controlling.SpeedCtrlUnit.IsActive, device::speed_control); } @@ -112,7 +112,7 @@ std::uint16_t outward_lights(TDynamicObject const *Vehicle, bool const Head) { if (Vehicle == nullptr || Vehicle->MoverParameters == nullptr) return 0; auto const along{Vehicle->iDirection > 0}; - return static_cast(Vehicle->MoverParameters->iLights[Head == along ? end::front : end::rear]); + return static_cast(Vehicle->MoverParameters->iLights[Head == along ? VehicleEnd::front : VehicleEnd::rear]); } // the lamps the vehicle has at that end: the driver checks a pattern against those of it there are @@ -120,7 +120,7 @@ std::uint16_t outward_lamps(TDynamicObject const *Vehicle, bool const Head) { if (Vehicle == nullptr) return 0; auto const along{Vehicle->iDirection > 0}; - return static_cast(Vehicle->LightList(Head == along ? end::front : end::rear)); + return static_cast(Vehicle->LightList(Head == along ? VehicleEnd::front : VehicleEnd::rear)); } // the scenario file without the starter's $, the folders and the extension, safe for a file name @@ -438,8 +438,8 @@ void blackbox_recorder::write_cab() { auto const order{owner->order_current()}; sample.movement = order.HasAny(DriverOrder::obeyTrain) ? blackbox::movements::train : order.HasAny(DriverOrder::shunt | DriverOrder::looseShunt | DriverOrder::connect) ? blackbox::movements::shunting : blackbox::movements::other; - sample.light_hint_head = static_cast(owner->light_hint(end::front)); - sample.light_hint_tail = static_cast(owner->light_hint(end::rear)); + sample.light_hint_head = static_cast(owner->light_hint(VehicleEnd::front)); + sample.light_hint_tail = static_cast(owner->light_hint(VehicleEnd::rear)); } sample.odometer_km = static_cast(occupied->DistCounter); sample.driving = driver_of(*vehicle); @@ -462,10 +462,10 @@ void blackbox_recorder::write_cab() { sample.voltage = static_cast(controlling->EngineVoltage); sample.engine_rpm = static_cast(std::abs(controlling->enrot) * 60.0); // the lights at the ends of the train: of the vehicles at its ends, at their ends turned away from the rest - sample.lights_head = outward_lights(owner != nullptr ? owner->Vehicle(end::front) : vehicle, true); - sample.lights_tail = outward_lights(owner != nullptr ? owner->Vehicle(end::rear) : vehicle, false); - sample.equipped_head = outward_lamps(owner != nullptr ? owner->Vehicle(end::front) : vehicle, true); - sample.equipped_tail = outward_lamps(owner != nullptr ? owner->Vehicle(end::rear) : vehicle, false); + sample.lights_head = outward_lights(owner != nullptr ? owner->Vehicle(VehicleEnd::front) : vehicle, true); + sample.lights_tail = outward_lights(owner != nullptr ? owner->Vehicle(VehicleEnd::rear) : vehicle, false); + sample.equipped_head = outward_lamps(owner != nullptr ? owner->Vehicle(VehicleEnd::front) : vehicle, true); + sample.equipped_tail = outward_lamps(owner != nullptr ? owner->Vehicle(VehicleEnd::rear) : vehicle, false); auto const &security{controlling->SecuritySystem}; namespace flag = blackbox::security_flags; sample.security = static_cast((security.is_vigilance_blinking() ? flag::vigilance : 0) | (security.is_cabsignal_blinking() ? flag::cabsignal : 0) | @@ -493,7 +493,7 @@ void blackbox_recorder::write_cab() { sample.converter_fill = static_cast(controlling->torqueConverter.fill); // the brakes of the whole train: the highest of its cylinders, from the head to the tail auto brakes{occupied->BrakePress}; - for (auto const *each{owner != nullptr ? owner->Vehicle(end::front) : nullptr}; each != nullptr; each = each->Next()) + for (auto const *each{owner != nullptr ? owner->Vehicle(VehicleEnd::front) : nullptr}; each != nullptr; each = each->Next()) if (each->MoverParameters != nullptr) brakes = std::max(brakes, each->MoverParameters->BrakePress); sample.consist_brake_cylinder = static_cast(brakes); @@ -646,7 +646,7 @@ void blackbox_recorder::look_at_couplers() { change.flags = static_cast(now.flags); change.previous_flags = static_cast(entry.couplers_known ? before.flags : 0); change.previous_other = entry.couplers_known ? known_id(before.other) : blackbox::no_vehicle; - change.position = vehicle->CouplerPosition(static_cast(side)); + change.position = vehicle->CouplerPosition(static_cast(side)); m_writer->coupling(change); } entry.couplers_known = true; diff --git a/simulation/simulation.cpp b/simulation/simulation.cpp index 477203061..ab3ec3a56 100644 --- a/simulation/simulation.cpp +++ b/simulation/simulation.cpp @@ -461,7 +461,7 @@ void state_manager::process_commands() { if (commanddata.command == user_command::repaircoupler) { if (auto *vehicle{simulation::Vehicles.find(commanddata.payload)}; vehicle != nullptr) { - vehicle->MoverParameters->repair_coupler(static_cast(commanddata.param1) == end::rear ? end::rear : end::front); + vehicle->MoverParameters->repair_coupler(EndOf(static_cast(commanddata.param1)) == VehicleEnd::rear ? VehicleEnd::rear : VehicleEnd::front); } } diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp index 7c4644868..a12113496 100644 --- a/simulation/simulationstateserializer.cpp +++ b/simulation/simulationstateserializer.cpp @@ -580,8 +580,8 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch } if( vehicle->MoverParameters->CategoryFlag == 1 // trains only - && ( (vehicle->LightList(end::front) & (light::headlight_left | light::headlight_right | light::headlight_upper)) != 0 - || (vehicle->LightList(end::rear) & (light::headlight_left | light::headlight_right | light::headlight_upper)) != 0 ) ) { + && ( (vehicle->LightList(VehicleEnd::front) & (light::headlight_left | light::headlight_right | light::headlight_upper)) != 0 + || (vehicle->LightList(VehicleEnd::rear) & (light::headlight_left | light::headlight_right | light::headlight_upper)) != 0 ) ) { simulation::Lights.insert( vehicle ); } } @@ -1692,7 +1692,7 @@ 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 ) { + && vehicle->MoverParameters->Couplers[(offset == -1.0 ? VehicleEnd::front : VehicleEnd::rear)].AllowedFlag & Coupling::permanent ) { coupling = ( CouplingSet::FromBits( coupling ) | Coupling::permanent ).Bits(); } if( true == Scratchpad.trainset.is_open ) { diff --git a/tests/unit/consist.cpp b/tests/unit/consist.cpp index 141abe5af..2c17ca5b8 100644 --- a/tests/unit/consist.cpp +++ b/tests/unit/consist.cpp @@ -21,8 +21,8 @@ vehicle &consist::add(definition const &Definition, int Cab, CouplingSet const c position = m_positions.back() - 0.5 * (last.Dim.L + mover.Dim.L) - Gap; mover.Loc = TLocation{position, 0.0, 0.0}; if (false == couplings.Empty()) { - last.Attach(end::rear, end::front, &mover, couplings, true, false); - mover.Attach(end::front, end::rear, &last, couplings, true, false); + last.Attach(VehicleEnd::rear, VehicleEnd::front, &mover, couplings, true, false); + mover.Attach(VehicleEnd::front, VehicleEnd::rear, &last, couplings, true, false); } } else { @@ -39,15 +39,15 @@ void consist::update_neighbours() { // TDynamicObject::update_neighbours(), for vehicles coupled in a line for (std::size_t i = 0; i < m_vehicles.size(); ++i) { auto &mover{m_vehicles[i]->mover()}; - for (int end = end::front; end <= end::rear; ++end) { + for (auto const end : VehicleEnds) { auto &neighbour{mover.Neighbours[end]}; - auto const other{end == end::front ? static_cast(i) - 1 : static_cast(i) + 1}; + auto const other{end == VehicleEnd::front ? static_cast(i) - 1 : static_cast(i) + 1}; if (other < 0 || other >= static_cast(m_vehicles.size())) { neighbour = neighbour_data(); continue; } auto const &othermover{m_vehicles[other]->mover()}; - auto const otherend{end == end::front ? end::rear : end::front}; + auto const otherend{Opposite(end)}; auto const distance{TMoverParameters::CouplerDist(&mover, &othermover) - mover.Couplers[end].adapter_length - othermover.Couplers[otherend].adapter_length}; // a vehicle not coupled is a collision source when it's within the range the game scans @@ -56,7 +56,7 @@ void consist::update_neighbours() { continue; } neighbour.vehicle = reinterpret_cast(m_objects[other].data()); // NOSONAR see m_objects - neighbour.vehicle_end = otherend; + neighbour.vehicle_end = NumberOf(otherend); neighbour.distance = static_cast(distance); } } diff --git a/tests/unit/drive.cpp b/tests/unit/drive.cpp index 7663d8363..03785730e 100644 --- a/tests/unit/drive.cpp +++ b/tests/unit/drive.cpp @@ -118,7 +118,7 @@ void raise_pantographs(driven const &Driven) { pantographs.PantCompFlag = false; } Driven.cab.OperatePantographsValve(operation_t::enable); - Driven.cab.OperatePantographValve(end::rear, operation_t::enable); + Driven.cab.OperatePantographValve(VehicleEnd::rear, operation_t::enable); } // the line breaker closed, which it does only with the controller at zero, and after the relays are reset @@ -143,7 +143,7 @@ void close_line_breaker(driven const &Driven) { void switch_auxiliaries_on(TMoverParameters &Cab) { Cab.ConverterSwitch(true); Cab.CompressorSwitch(true); - for (auto const side : {end::front, end::rear}) { + for (auto const side : VehicleEnds) { if (Cab.MotorBlowers[side].speed != 0) { Cab.MotorBlowersSwitchOff(false, side); Cab.MotorBlowersSwitch(true, side); diff --git a/tests/unit/golden.cpp b/tests/unit/golden.cpp index 363d97718..da6a3ce8c 100644 --- a/tests/unit/golden.cpp +++ b/tests/unit/golden.cpp @@ -112,8 +112,8 @@ std::vector doors() { std::vector result{ {"DoorsLocked", [](auto const &M) { return M.Doors.is_locked ? 1.0 : 0.0; }}, }; - for (int side : {side::right, side::left}) { - auto const name{std::string{side == side::right ? "Right" : "Left"}}; + for (auto const side : VehicleSides) { + auto const name{std::string{side == VehicleSide::right ? "Right" : "Left"}}; result.emplace_back(name + "Position", [side](auto const &M) { return M.Doors.instances[side].position; }); result.emplace_back(name + "Step", [side](auto const &M) { return M.Doors.instances[side].step_position; }); result.emplace_back(name + "Open", [side](auto const &M) { return M.Doors.instances[side].is_open ? 1.0 : 0.0; }); diff --git a/tests/unit/scenario.h b/tests/unit/scenario.h index 54678af5d..29a9f5592 100644 --- a/tests/unit/scenario.h +++ b/tests/unit/scenario.h @@ -17,7 +17,7 @@ namespace test { // scenario.add("elf_v1/21we-a", 1).add("elf_v1/21we-b").add("elf_v1/21we-c"); // scenario.start_up(); // scenario.act("open left"); -// scenario.cab().OperateDoors(side::left, true); +// scenario.cab().OperateDoors(VehicleSide::left, true); // scenario.wait(10.0); // scenario.check(); class scenario { diff --git a/tests/unit/test_auxiliaries.cpp b/tests/unit/test_auxiliaries.cpp index bb823a4cf..4da5c1f51 100644 --- a/tests/unit/test_auxiliaries.cpp +++ b/tests/unit/test_auxiliaries.cpp @@ -38,8 +38,8 @@ TEST_CASE("auxiliaries: the battery drained by the lights and the pantographs' c REQUIRE(eu07.BatteryVoltage == doctest::Approx(eu07.NominalBatteryVoltage)); scenario.act("converter off, lights on, small compressor on"); eu07.ConverterSwitch(false); - eu07.iLights[end::front] = 1 | 2 | 4; - eu07.iLights[end::rear] = 16; + eu07.iLights[VehicleEnd::front] = 1 | 2 | 4; + eu07.iLights[VehicleEnd::rear] = 16; eu07.PantCompFlag = true; scenario.wait(30.0); CHECK(eu07.BatteryVoltage < 0.83 * eu07.NominalBatteryVoltage); diff --git a/tests/unit/test_collisions.cpp b/tests/unit/test_collisions.cpp index efc144e69..bb0395df7 100644 --- a/tests/unit/test_collisions.cpp +++ b/tests/unit/test_collisions.cpp @@ -116,7 +116,7 @@ bool derailed(TMoverParameters const &Vehicle) { } double crush_of(TMoverParameters const &Vehicle) { - return std::max(Vehicle.Couplers[end::front].crush, Vehicle.Couplers[end::rear].crush); + return std::max(Vehicle.Couplers[VehicleEnd::front].crush, Vehicle.Couplers[VehicleEnd::rear].crush); } // a mixed freight train as the PoC has it: every third wagon from the given one an empty two-axle 3WL (10.5 t), the @@ -172,7 +172,7 @@ crash_outcome freight_crash(double const Speed, double const Radius, double cons for (std::size_t i = 0; i < train.size(); ++i) { auto const &vehicle{train[i].mover()}; auto const name{i < standing ? std::format("standing {}", standing - 1 - i) : i == standing ? std::string{"locomotive"} : std::format("running {}", i - standing - 1)}; - for (auto const end : {end::front, end::rear}) { + for (auto const end : VehicleEnds) { if (vehicle.Couplers[end].crush >= cl::crush_mark) { ++result.crushed; } @@ -190,7 +190,7 @@ crash_outcome freight_crash(double const Speed, double const Radius, double cons } } for (std::size_t i = 0; i + 1 < train.size(); ++i) { - result.broken += train[i]->Couplers[end::rear].broken; + result.broken += train[i]->Couplers[VehicleEnd::rear].broken; } return result; } @@ -204,16 +204,16 @@ double locomotive_into_wagon(double const Speed, double const Dt) { // behind the wagon, running forwards into its rear end 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; + return wagon->Couplers[VehicleEnd::rear].crush + locomotive->Couplers[VehicleEnd::front].crush; } // the energy the crush of both ends of the pair took, by their curves [J] -double crush_energy(TMoverParameters const &First, int const FirstEnd, TMoverParameters const &Second, int const SecondEnd) { +double crush_energy(TMoverParameters const &First, VehicleEnd const FirstEnd, TMoverParameters const &Second, VehicleEnd const SecondEnd) { return First.crush_curve_at(FirstEnd).energy(0.0, First.Couplers[FirstEnd].crush) + Second.crush_curve_at(SecondEnd).energy(0.0, Second.Couplers[SecondEnd].crush); } // what the buffers of EN 15551 of the two ends take in [J] -double capacity_of(TMoverParameters const &First, int const FirstEnd, TMoverParameters const &Second, int const SecondEnd) { +double capacity_of(TMoverParameters const &First, VehicleEnd const FirstEnd, TMoverParameters const &Second, VehicleEnd const SecondEnd) { return cl::buffer_capacity(First.Couplers[FirstEnd].collision, First.collision_kind()) + cl::buffer_capacity(Second.Couplers[SecondEnd].collision, Second.collision_kind()); } @@ -238,9 +238,9 @@ contact_outcome contact(definition const &Front, definition const &Back, double 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; - result.energy = crush_energy(front.mover(), end::rear, back.mover(), end::front); - result.available = std::max(0.0, relative_energy(front.mover(), back.mover(), Speed * kmh) - capacity_of(front.mover(), end::rear, back.mover(), end::front)); + result.crush = front->Couplers[VehicleEnd::rear].crush + back->Couplers[VehicleEnd::front].crush; + result.energy = crush_energy(front.mover(), VehicleEnd::rear, back.mover(), VehicleEnd::front); + result.available = std::max(0.0, relative_energy(front.mover(), back.mover(), Speed * kmh) - capacity_of(front.mover(), VehicleEnd::rear, back.mover(), VehicleEnd::front)); result.derailed = derailed(front.mover()) || derailed(back.mover()); return result; } @@ -251,7 +251,7 @@ definition coach(double const Mass) { } // Y / Q of the leading wheel of the vehicle at the end pressed in by its coupling, as check_pushed_off() takes it -double pushed_ratio_of(TMoverParameters const &Vehicle, int const End, double const OtherLength, double const Radius) { +double pushed_ratio_of(TMoverParameters const &Vehicle, VehicleEnd const End, double const OtherLength, double const Radius) { cl::pushed_vehicle pushed; pushed.mass = Vehicle.TotalMass - Vehicle.Mred; pushed.axles = Vehicle.NAxles > 0 ? Vehicle.NAxles : 4; @@ -259,7 +259,7 @@ double pushed_ratio_of(TMoverParameters const &Vehicle, int const End, double co pushed.pivots = Vehicle.BDist; pushed.axle_base = Vehicle.ADist > 0.0 ? Vehicle.ADist : Vehicle.BDist; cl::pushed_end end; - end.force = std::max(0.0, (End == end::front ? -1.0 : 1.0) * Vehicle.Couplers[End].CForce); + end.force = std::max(0.0, (End == VehicleEnd::front ? -1.0 : 1.0) * Vehicle.Couplers[End].CForce); end.other_length = OtherLength; end.crush = Vehicle.Couplers[End].crush; return cl::pushed_ratio(pushed, end, Radius); @@ -591,8 +591,8 @@ TEST_CASE("collisions: a locomotive at its starting effort against a braked trai auto pushed{0.0}; auto worst{0.0}; auto const watch = [&]() { - pushed = std::max(pushed, -locomotive->Couplers[end::front].CForce); - worst = std::max(worst, pushed_ratio_of(empty.mover(), end::rear, locomotive->Dim.L, line.radius)); + pushed = std::max(pushed, -locomotive->Couplers[VehicleEnd::front].CForce); + worst = std::max(worst, pushed_ratio_of(empty.mover(), VehicleEnd::rear, locomotive->Dim.L, line.radius)); }; // the line contactors close at the first position, once their delay and the pressure switch let them locomotive->IncMainCtrl(1); @@ -631,8 +631,8 @@ TEST_CASE("collisions: a locomotive running onto an empty wagon at 9 km/h doesn' auto over{0}; // steps past the climbing limit for (int step = 0; step < 500; ++step) { train.step(curve); - pushed = std::max(pushed, empty->Couplers[end::rear].CForce); - auto const ratio{pushed_ratio_of(empty.mover(), end::rear, locomotive->Dim.L, curve.radius)}; + pushed = std::max(pushed, empty->Couplers[VehicleEnd::rear].CForce); + auto const ratio{pushed_ratio_of(empty.mover(), VehicleEnd::rear, locomotive->Dim.L, curve.radius)}; worst = std::max(worst, ratio); over += ratio >= derailment::climbing_limit; } @@ -684,7 +684,7 @@ TEST_CASE("collisions: a repaired vehicle has its ends rebuilt and is back on th 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(wagon->Couplers[VehicleEnd::rear].crush + locomotive->Couplers[VehicleEnd::front].crush > cl::override_crush); REQUIRE((derailed(wagon.mover()) || derailed(locomotive.mover()))); for (auto *vehicle : {&wagon, &locomotive}) { auto &mover{vehicle->mover()}; @@ -708,12 +708,12 @@ TEST_CASE("collisions: a repaired vehicle has its ends rebuilt and is back on th TEST_CASE("collisions: the repair of a coupler torn off by the crush rebuilds its end") { vehicle wagon{definition::fiz("430w_v2/430w")}; - auto &coupler{wagon->Couplers[end::rear]}; + auto &coupler{wagon->Couplers[VehicleEnd::rear]}; coupler.crush = 0.3; coupler.broken = true; coupler.hit_force = 2.0e6; wagon->DamageFlag.Set(VehicleDamage::coupling); - REQUIRE(wagon->repair_coupler(end::rear)); + REQUIRE(wagon->repair_coupler(VehicleEnd::rear)); CHECK(coupler.crush == 0.0); CHECK(coupler.hit_force == 0.0); CHECK_FALSE(coupler.broken); @@ -768,7 +768,7 @@ TEST_CASE("collisions: the legacy rule with physics.collisions old, the crush wi train.run(10.0); CHECK(derailed(train[0].mover()) == (physical ? frontout_new : frontout_old)); CHECK(derailed(train[1].mover()) == (physical ? backout_new : backout_old)); - auto const crush{train[0]->Couplers[end::rear].crush + train[1]->Couplers[end::front].crush}; + auto const crush{train[0]->Couplers[VehicleEnd::rear].crush + train[1]->Couplers[VehicleEnd::front].crush}; if (physical) { MESSAGE(name, ": crush ", crush, " m"); CHECK(crush > 0.05); @@ -808,7 +808,7 @@ TEST_CASE("collisions: the model of the collisions goes apart from the one of th 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}; + auto const crush{train[0]->Couplers[VehicleEnd::rear].crush + train[1]->Couplers[VehicleEnd::front].crush}; CHECK((crush > 0.05) == (collisions == global_settings::collision_model::physical)); } } @@ -849,24 +849,24 @@ TEST_CASE("collisions: automatic couplers hit too fast don't catch, the ends cru CAPTURE(speed); vehicle moving{automatic, speed, "moving"}; vehicle standing{automatic, 0.0, "standing"}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; auto coupled{false}; auto fast{false}; // coupled while closing in faster than the couplers catch for (int i = 0; i < 1000; ++i) { - auto const closing{moving->CollisionVelocity(end::front, standing.mover(), end::rear)}; + auto const closing{moving->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear)}; pair.step(); fast = fast || (pair.coupled() && false == coupled && closing > TMoverParameters::SafeCollisionVelocity); coupled = coupled || pair.coupled(); } - auto const crush{moving->Couplers[end::front].crush + standing->Couplers[end::rear].crush}; + auto const crush{moving->Couplers[VehicleEnd::front].crush + standing->Couplers[VehicleEnd::rear].crush}; MESSAGE(speed, " km/h: crush ", crush, " m, derailed ", derailed(moving.mover()), " ", derailed(standing.mover()), ", coupled later ", coupled); CHECK_FALSE(fast); CHECK(crush > 0.0); // crushed past the draw gear, the coupler is gone; short of it, the wagons may roll together again slowly // after the hit, and couple then - if (std::max(moving->Couplers[end::front].crush, standing->Couplers[end::rear].crush) >= cl::draw_gear_crush) { + if (std::max(moving->Couplers[VehicleEnd::front].crush, standing->Couplers[VehicleEnd::rear].crush) >= cl::draw_gear_crush) { CHECK_FALSE(coupled); - CHECK((moving->Couplers[end::front].broken || standing->Couplers[end::rear].broken)); + CHECK((moving->Couplers[VehicleEnd::front].broken || standing->Couplers[VehicleEnd::rear].broken)); } // the two alike: neither climbs onto the other until the crush is deep enough for both to CHECK(derailed(moving.mover()) == derailed(standing.mover())); @@ -886,7 +886,7 @@ TEST_CASE("collisions: road vehicles keep the legacy rule") { road.run(5.0); CHECK(derailed(road[0].mover())); CHECK(derailed(road[1].mover())); - CHECK(road[0]->Couplers[end::rear].crush == 0.0); + CHECK(road[0]->Couplers[VehicleEnd::rear].crush == 0.0); CHECK(road[1]->CollisionDerail == NONE); CHECK(road[0]->crush_reports + road[1]->crush_reports == 0); } @@ -954,7 +954,7 @@ TEST_CASE("collisions: identical units built to EN 15227 at 36 km/h") { double inner; int derailed; bool higher; - } result{train[1]->Couplers[end::rear].crush + train[2]->Couplers[end::front].crush, std::max(crush_of(train[0].mover()), crush_of(train[3].mover())), 0, + } result{train[1]->Couplers[VehicleEnd::rear].crush + train[2]->Couplers[VehicleEnd::front].crush, std::max(crush_of(train[0].mover()), crush_of(train[3].mover())), 0, derailed(train[2].mover())}; for (std::size_t i = 0; i < train.size(); ++i) { result.derailed += derailed(train[i].mover()); @@ -997,9 +997,9 @@ TEST_CASE("collisions: the buffers of EN 15551 of an end take in their energy, o CHECK(cl::buffer_capacity(category_c, cl::vehicle_kind::wagon) == doctest::Approx(140.0e3)); // the key of the .fiz vehicle wagon{definition::load("wagon").set("BuffCoupl", "BufferCategory", "B")}; - REQUIRE(wagon->Couplers[end::front].collision.buffers.has_value()); - CHECK(*wagon->Couplers[end::front].collision.buffers == cl::buffer_category::B); - CHECK(cl::buffer_capacity(wagon->Couplers[end::rear].collision, wagon->collision_kind()) == doctest::Approx(100.0e3)); + REQUIRE(wagon->Couplers[VehicleEnd::front].collision.buffers.has_value()); + CHECK(*wagon->Couplers[VehicleEnd::front].collision.buffers == cl::buffer_category::B); + CHECK(cl::buffer_capacity(wagon->Couplers[VehicleEnd::rear].collision, wagon->collision_kind()) == doctest::Approx(100.0e3)); } TEST_CASE("collisions: the budget of a contact, by what the hit brings to the buffers") { @@ -1207,7 +1207,7 @@ TEST_CASE("collisions: two coaches (36 t and 41.6 t) at 8 km/h don't crush, nor REQUIRE(derailed(wall.mover())); 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(wall->Couplers[VehicleEnd::rear].crush + running->Couplers[VehicleEnd::front].crush == 0.0); CHECK(running->CollisionDerail == NONE); } } @@ -1242,7 +1242,7 @@ TEST_CASE("collisions: a locomotive pushing a standing braked train at full powe auto pushed{0.0}; auto seconds{0}; // pushing with 100 kN or more auto const push = [&]() { - auto const force{std::max(0.0, -locomotive->Couplers[end::front].CForce)}; + auto const force{std::max(0.0, -locomotive->Couplers[VehicleEnd::front].CForce)}; pushed = std::max(pushed, force); seconds += force >= 100.0e3; }; @@ -1328,12 +1328,12 @@ train_damage damage_of(consist &Train) { for (std::size_t i = 0; i < Train.size(); ++i) { auto const &vehicle{Train[i].mover()}; result.crush = std::max(result.crush, crush_of(vehicle)); - for (auto const end : {end::front, end::rear}) { + for (auto const end : VehicleEnds) { result.energy += vehicle.crush_curve_at(end).energy(0.0, vehicle.Couplers[end].crush); } result.derailed += vehicle.CollisionDerail != NONE; if (i + 1 < Train.size()) { - result.broken += vehicle.Couplers[end::rear].broken; + result.broken += vehicle.Couplers[VehicleEnd::rear].broken; } if (crush_of(vehicle) > 0.0 || vehicle.CollisionDerail != NONE) { result.list += std::format("{} crushed {:.2f} m{}; ", i, crush_of(vehicle), vehicle.CollisionDerail != NONE ? ", derailed" : ""); @@ -1487,12 +1487,12 @@ TEST_CASE("collisions: a pair parting at the start of the step isn't crushed (l0 for (auto *vehicle : {&front, &back}) { vehicle->forces(dt); } - REQUIRE((front->Couplers[end::rear].closing < 0.0) == parting); + REQUIRE((front->Couplers[VehicleEnd::rear].closing < 0.0) == parting); back->V = 25.0 * kmh; for (auto *vehicle : {&front, &back}) { vehicle->move({}, dt, (*vehicle)->Loc, 5.0); } - auto const crush{front->Couplers[end::rear].crush + back->Couplers[end::front].crush}; + auto const crush{front->Couplers[VehicleEnd::rear].crush + back->Couplers[VehicleEnd::front].crush}; if (parting) { CHECK(crush == 0.0); // the legacy collision pushed them apart diff --git a/tests/unit/test_commands.cpp b/tests/unit/test_commands.cpp index ac9d72fee..2304de2d8 100644 --- a/tests/unit/test_commands.cpp +++ b/tests/unit/test_commands.cpp @@ -75,14 +75,14 @@ std::vector state() { {"SpeedCtrlParking", [](auto const &M) { return flag(M.SpeedCtrlUnit.Parking); }}, {"SpringBrakeActivate", [](auto const &M) { return flag(M.SpringBrake.Activate); }}, }; - for (int end : {end::front, end::rear}) { - auto const name{std::string{end == end::front ? "Front" : "Rear"}}; + for (auto const end : VehicleEnds) { + auto const name{std::string{end == VehicleEnd::front ? "Front" : "Rear"}}; result.emplace_back("MotorBlowers" + name + "Enabled", [end](auto const &M) { return flag(M.MotorBlowers[end].is_enabled); }); result.emplace_back("MotorBlowers" + name + "Disabled", [end](auto const &M) { return flag(M.MotorBlowers[end].is_disabled); }); result.emplace_back("Pant" + name + "Valve", [end](auto const &M) { return flag(M.Pantographs[end].valve.is_enabled) + 2 * flag(M.Pantographs[end].valve.is_disabled); }); } - for (int side : {side::right, side::left}) { - auto const name{std::string{side == side::right ? "Right" : "Left"}}; + for (auto const side : VehicleSides) { + auto const name{std::string{side == VehicleSide::right ? "Right" : "Left"}}; result.emplace_back(name + "DoorPermit", [side](auto const &M) { return flag(M.Doors.instances[side].open_permit); }); result.emplace_back(name + "DoorRemoteOpen", [side](auto const &M) { return flag(M.Doors.instances[side].remote_open); }); result.emplace_back(name + "DoorRemoteClose", [side](auto const &M) { return flag(M.Doors.instances[side].remote_close); }); @@ -285,16 +285,16 @@ std::vector const actions{ {"OilPumpSwitch on", [](auto &M) { return M.OilPumpSwitch(true, range_t::consist); }}, {"OilPumpSwitchOff on", [](auto &M) { return M.OilPumpSwitchOff(true, range_t::unit); }}, {"OilPumpSwitchOff off", [](auto &M) { return M.OilPumpSwitchOff(false, range_t::consist); }}, - {"MotorBlowersSwitch front on", [](auto &M) { return M.MotorBlowersSwitch(true, end::front, range_t::consist); }}, - {"MotorBlowersSwitch rear on", [](auto &M) { return M.MotorBlowersSwitch(true, end::rear, range_t::unit); }}, - {"MotorBlowersSwitchOff front on", [](auto &M) { return M.MotorBlowersSwitchOff(true, end::front, range_t::consist); }}, - {"MotorBlowersSwitchOff rear on", [](auto &M) { return M.MotorBlowersSwitchOff(true, end::rear, range_t::unit); }}, - {"MotorBlowersSwitchOff front off", [](auto &M) { return M.MotorBlowersSwitchOff(false, end::front, range_t::consist); }}, - {"MotorBlowersSwitchOff rear off", [](auto &M) { return M.MotorBlowersSwitchOff(false, end::rear, range_t::consist); }}, + {"MotorBlowersSwitch front on", [](auto &M) { return M.MotorBlowersSwitch(true, VehicleEnd::front, range_t::consist); }}, + {"MotorBlowersSwitch rear on", [](auto &M) { return M.MotorBlowersSwitch(true, VehicleEnd::rear, range_t::unit); }}, + {"MotorBlowersSwitchOff front on", [](auto &M) { return M.MotorBlowersSwitchOff(true, VehicleEnd::front, range_t::consist); }}, + {"MotorBlowersSwitchOff rear on", [](auto &M) { return M.MotorBlowersSwitchOff(true, VehicleEnd::rear, range_t::unit); }}, + {"MotorBlowersSwitchOff front off", [](auto &M) { return M.MotorBlowersSwitchOff(false, VehicleEnd::front, range_t::consist); }}, + {"MotorBlowersSwitchOff rear off", [](auto &M) { return M.MotorBlowersSwitchOff(false, VehicleEnd::rear, range_t::consist); }}, {"OperatePantographsValve enable", [](auto &M) { return M.OperatePantographsValve(operation_t::enable, range_t::consist); }}, - {"OperatePantographValve front enable", [](auto &M) { return M.OperatePantographValve(end::front, operation_t::enable, range_t::consist); }}, - {"OperatePantographValve rear enable_on", [](auto &M) { return M.OperatePantographValve(end::rear, operation_t::enable_on, range_t::unit); }}, - {"OperatePantographValve rear enable_off", [](auto &M) { return M.OperatePantographValve(end::rear, operation_t::enable_off, range_t::unit); }}, + {"OperatePantographValve front enable", [](auto &M) { return M.OperatePantographValve(VehicleEnd::front, operation_t::enable, range_t::consist); }}, + {"OperatePantographValve rear enable_on", [](auto &M) { return M.OperatePantographValve(VehicleEnd::rear, operation_t::enable_on, range_t::unit); }}, + {"OperatePantographValve rear enable_off", [](auto &M) { return M.OperatePantographValve(VehicleEnd::rear, operation_t::enable_off, range_t::unit); }}, {"DirectionForward", [](auto &M) { return M.DirectionForward(); }}, {"ConverterSwitch on", [](auto &M) { return M.ConverterSwitch(true, range_t::consist); }}, {"CompressorSwitch on", [](auto &M) { return M.CompressorSwitch(true, range_t::consist); }}, @@ -330,30 +330,30 @@ std::vector const actions{ {"SandboxAuto off", [](auto &M) { return M.SandboxAuto(false, range_t::consist); }}, {"SandboxManual off", [](auto &M) { return M.SandboxManual(false, range_t::consist); }}, {"Sandbox off", [](auto &M) { return M.Sandbox(false, range_t::consist); }}, - {"PermitDoors right", [](auto &M) { return M.PermitDoors(side::right, true, range_t::consist); }}, - {"PermitDoors left", [](auto &M) { return M.PermitDoors(side::left, true, range_t::unit); }}, + {"PermitDoors right", [](auto &M) { return M.PermitDoors(VehicleSide::right, true, range_t::consist); }}, + {"PermitDoors left", [](auto &M) { return M.PermitDoors(VehicleSide::left, true, range_t::unit); }}, {"ChangeDoorPermitPreset +1", [](auto &M) { return M.ChangeDoorPermitPreset(1, range_t::consist); }}, {"ChangeDoorPermitPreset -1", [](auto &M) { return M.ChangeDoorPermitPreset(-1, range_t::consist); }}, {"PermitDoorStep off", [](auto &M) { return M.PermitDoorStep(false, range_t::consist); }}, {"PermitDoorStep on", [](auto &M) { return M.PermitDoorStep(true, range_t::unit); }}, {"LockDoors off", [](auto &M) { return M.LockDoors(false, range_t::consist); }}, - {"OperateDoors right open local", [](auto &M) { return M.OperateDoors(side::right, true, range_t::local); }}, - {"OperateDoors left open", [](auto &M) { return M.OperateDoors(side::left, true, range_t::consist); }}, - {"OperateDoors right close", [](auto &M) { return M.OperateDoors(side::right, false, range_t::unit); }}, + {"OperateDoors right open local", [](auto &M) { return M.OperateDoors(VehicleSide::right, true, range_t::local); }}, + {"OperateDoors left open", [](auto &M) { return M.OperateDoors(VehicleSide::left, true, range_t::consist); }}, + {"OperateDoors right close", [](auto &M) { return M.OperateDoors(VehicleSide::right, false, range_t::unit); }}, {"ChangeDoorControlMode remote", [](auto &M) { return M.ChangeDoorControlMode(true, range_t::consist); }}, {"ChangeDoorControlMode local", [](auto &M) { return M.ChangeDoorControlMode(false, range_t::unit); }}, {"LockDoors on", [](auto &M) { return M.LockDoors(true, range_t::unit); }}, {"signal_departure on", [](auto &M) { return M.signal_departure(true, range_t::consist); }}, {"signal_departure off", [](auto &M) { return M.signal_departure(false, range_t::unit); }}, - {"PermitDoors right off", [](auto &M) { return M.PermitDoors(side::right, false, range_t::consist); }}, + {"PermitDoors right off", [](auto &M) { return M.PermitDoors(VehicleSide::right, false, range_t::consist); }}, {"HeatingSwitch off", [](auto &M) { return M.HeatingSwitch(false, range_t::unit); }}, {"MainSwitch off", [](auto &M) { return M.MainSwitch(false, range_t::consist); }}, {"DropAllPantographs", [](auto &M) { return M.DropAllPantographs(true, range_t::consist); }}, {"DropAllPantographs released", [](auto &M) { return M.DropAllPantographs(false, range_t::unit); }}, {"OperatePantographsValve disable", [](auto &M) { return M.OperatePantographsValve(operation_t::disable, range_t::unit); }}, - {"OperatePantographValve front disable_on", [](auto &M) { return M.OperatePantographValve(end::front, operation_t::disable_on, range_t::consist); }}, - {"OperatePantographValve front disable_off", [](auto &M) { return M.OperatePantographValve(end::front, operation_t::disable_off, range_t::consist); }}, - {"OperatePantographValve front none", [](auto &M) { return M.OperatePantographValve(end::front, operation_t::none, range_t::local); }}, + {"OperatePantographValve front disable_on", [](auto &M) { return M.OperatePantographValve(VehicleEnd::front, operation_t::disable_on, range_t::consist); }}, + {"OperatePantographValve front disable_off", [](auto &M) { return M.OperatePantographValve(VehicleEnd::front, operation_t::disable_off, range_t::consist); }}, + {"OperatePantographValve front none", [](auto &M) { return M.OperatePantographValve(VehicleEnd::front, operation_t::none, range_t::local); }}, {"CompressorSwitch off", [](auto &M) { return M.CompressorSwitch(false, range_t::unit); }}, {"ConverterSwitch off", [](auto &M) { return M.ConverterSwitch(false, range_t::unit); }}, {"WaterCircuitsLinkSwitch off", [](auto &M) { return M.WaterCircuitsLinkSwitch(false, range_t::unit); }}, @@ -363,8 +363,8 @@ std::vector const actions{ {"WaterPumpBreakerSwitch off", [](auto &M) { return M.WaterPumpBreakerSwitch(false, range_t::unit); }}, {"FuelPumpSwitch off", [](auto &M) { return M.FuelPumpSwitch(false, range_t::unit); }}, {"OilPumpSwitch off", [](auto &M) { return M.OilPumpSwitch(false, range_t::unit); }}, - {"MotorBlowersSwitch front off", [](auto &M) { return M.MotorBlowersSwitch(false, end::front, range_t::unit); }}, - {"MotorBlowersSwitch rear off", [](auto &M) { return M.MotorBlowersSwitch(false, end::rear, range_t::consist); }}, + {"MotorBlowersSwitch front off", [](auto &M) { return M.MotorBlowersSwitch(false, VehicleEnd::front, range_t::unit); }}, + {"MotorBlowersSwitch rear off", [](auto &M) { return M.MotorBlowersSwitch(false, VehicleEnd::rear, range_t::consist); }}, {"CompartmentLightsSwitch off", [](auto &M) { return M.CompartmentLightsSwitch(false, range_t::unit); }}, {"BatterySwitch off", [](auto &M) { return M.BatterySwitch(false, range_t::unit); }}, {"CabDeactivisation", [](auto &M) { return M.CabDeactivisation(); }}, @@ -378,7 +378,7 @@ TEST_CASE("commands: every switch of the cab, sent to the next vehicle") { test::reseed_random(); vehicle driven{definition::fiz(path), 0.0, "driven", 1}; vehicle next{definition::fiz(path), 0.0, "next"}; - driven->Attach(end::rear, end::front, &next.mover(), test::consist::full_coupling, true, false); + driven->Attach(VehicleEnd::rear, VehicleEnd::front, &next.mover(), test::consist::full_coupling, true, false); auto done{false}; auto channels{state()}; for (auto const &channel : state()) { @@ -408,8 +408,8 @@ TEST_CASE("commands: every switch of the cab, worked on a pair standing under th auto done{false}; auto channels{state()}; channels.insert(channels.end(), { - {"PantFrontActive", [](auto const &M) { return flag(M.Pantographs[end::front].is_active); }}, - {"PantRearActive", [](auto const &M) { return flag(M.Pantographs[end::rear].is_active); }}, + {"PantFrontActive", [](auto const &M) { return flag(M.Pantographs[VehicleEnd::front].is_active); }}, + {"PantRearActive", [](auto const &M) { return flag(M.Pantographs[VehicleEnd::rear].is_active); }}, {"PantPress", [](auto const &M) { return M.PantPress; }}, {"GroundRelay", [](auto const &M) { return flag(M.GroundRelay); }}, {"ConverterFlag", [](auto const &M) { return flag(M.ConverterFlag); }}, @@ -449,8 +449,8 @@ struct train { vehicle last{definition::fiz("4e_v1/4e"), 0.0, "last"}; 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); + head->Attach(VehicleEnd::rear, VehicleEnd::rear, &middle.mover(), couplings, true, false); + middle->Attach(VehicleEnd::front, VehicleEnd::front, &last.mover(), couplings, true, false); } }; @@ -468,21 +468,21 @@ TEST_CASE("commands: travel along the train, turned round for a vehicle facing b CHECK(consist.last->CommandIn.Command == VehicleCommand::none); SUBCASE("door permits: the right side of the sender is the left one of a vehicle facing backwards") { - consist.head->PermitDoors(side::right, true, range_t::consist); - CHECK(consist.head->Doors.instances[side::right].open_permit); - CHECK(consist.middle->Doors.instances[side::left].open_permit); - CHECK_FALSE(consist.middle->Doors.instances[side::right].open_permit); - CHECK(consist.last->Doors.instances[side::right].open_permit); + consist.head->PermitDoors(VehicleSide::right, true, range_t::consist); + CHECK(consist.head->Doors.instances[VehicleSide::right].open_permit); + CHECK(consist.middle->Doors.instances[VehicleSide::left].open_permit); + CHECK_FALSE(consist.middle->Doors.instances[VehicleSide::right].open_permit); + CHECK(consist.last->Doors.instances[VehicleSide::right].open_permit); // and revoked the same way - consist.head->PermitDoors(side::right, false, range_t::consist); - CHECK_FALSE(consist.middle->Doors.instances[side::left].open_permit); - CHECK_FALSE(consist.last->Doors.instances[side::right].open_permit); + consist.head->PermitDoors(VehicleSide::right, false, range_t::consist); + CHECK_FALSE(consist.middle->Doors.instances[VehicleSide::left].open_permit); + CHECK_FALSE(consist.last->Doors.instances[VehicleSide::right].open_permit); } SUBCASE("a pantograph valve: the vehicles past one coupled by its control cable take the other pantograph") { - consist.head->OperatePantographValve(end::front, operation_t::enable, range_t::consist); - CHECK(consist.head->Pantographs[end::front].valve.is_enabled); - CHECK(consist.middle->Pantographs[end::front].valve.is_enabled); - CHECK(consist.last->Pantographs[end::rear].valve.is_enabled); + consist.head->OperatePantographValve(VehicleEnd::front, operation_t::enable, range_t::consist); + CHECK(consist.head->Pantographs[VehicleEnd::front].valve.is_enabled); + CHECK(consist.middle->Pantographs[VehicleEnd::front].valve.is_enabled); + CHECK(consist.last->Pantographs[VehicleEnd::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); diff --git a/tests/unit/test_controls.cpp b/tests/unit/test_controls.cpp index 133794ccd..55ce1cc0e 100644 --- a/tests/unit/test_controls.cpp +++ b/tests/unit/test_controls.cpp @@ -69,16 +69,16 @@ bool released(scenario &Scenario, double Pressure = 0.1) { return true; } -bool open(TMoverParameters const &Vehicle, int Side) { +bool open(TMoverParameters const &Vehicle, VehicleSide Side) { return Vehicle.Doors.instances[Side].is_open; } // the leaf shut, whatever the step does (closed, is_closed, wants the step folded too) -bool shut(TMoverParameters const &Vehicle, int Side) { +bool shut(TMoverParameters const &Vehicle, VehicleSide Side) { return Vehicle.Doors.instances[Side].position <= 0.f; } -bool closed(TMoverParameters const &Vehicle, int Side) { +bool closed(TMoverParameters const &Vehicle, VehicleSide Side) { return Vehicle.Doors.instances[Side].is_closed; } @@ -100,30 +100,30 @@ TEST_CASE("controls: the doors of an electric unit, opened, locked, permitted an auto &cab{scenario.cab()}; auto const &last{scenario.vehicle(scenario.train().size() - 1)}; scenario.act("permit left"); - cab.PermitDoors(side::left, true); + cab.PermitDoors(VehicleSide::left, true); scenario.wait(2.0); scenario.act("open left"); - cab.OperateDoors(side::left, true); + cab.OperateDoors(VehicleSide::left, true); scenario.wait(10.0); - CHECK(open(cab, side::left)); - CHECK(open(last, side::left)); - CHECK(closed(cab, side::right)); + CHECK(open(cab, VehicleSide::left)); + CHECK(open(last, VehicleSide::left)); + CHECK(closed(cab, VehicleSide::right)); scenario.act("close left"); - cab.OperateDoors(side::left, false); + cab.OperateDoors(VehicleSide::left, false); scenario.wait(10.0); - CHECK(shut(cab, side::left)); - CHECK(shut(last, side::left)); + CHECK(shut(cab, VehicleSide::left)); + CHECK(shut(last, VehicleSide::left)); scenario.act("open right without permit"); - cab.OperateDoors(side::right, true); + cab.OperateDoors(VehicleSide::right, true); scenario.wait(5.0); // the EN57 needs no permit - CHECK(shut(cab, side::right) == cab.Doors.permit_needed); + CHECK(shut(cab, VehicleSide::right) == cab.Doors.permit_needed); scenario.act("permit right, open"); - cab.PermitDoors(side::right, true); - cab.OperateDoors(side::right, true); + cab.PermitDoors(VehicleSide::right, true); + cab.OperateDoors(VehicleSide::right, true); scenario.wait(10.0); - CHECK(open(cab, side::right)); - CHECK(open(last, side::right)); + CHECK(open(cab, VehicleSide::right)); + CHECK(open(last, VehicleSide::right)); scenario.act("lock"); cab.LockDoors(true); scenario.wait(5.0); @@ -136,29 +136,29 @@ TEST_CASE("controls: the doors of an electric unit, opened, locked, permitted an cab.PermitDoorStep(true); cab.ChangeDoorControlMode(false); scenario.act("close all, unlock"); - cab.OperateDoors(side::right, false); - cab.OperateDoors(side::left, false); + cab.OperateDoors(VehicleSide::right, false); + cab.OperateDoors(VehicleSide::left, false); cab.LockDoors(false); scenario.wait(10.0); - CHECK(shut(cab, side::left)); - CHECK(shut(cab, side::right)); + CHECK(shut(cab, VehicleSide::left)); + CHECK(shut(cab, VehicleSide::right)); scenario.act("open both and drive off"); - cab.PermitDoors(side::left, true); - cab.PermitDoors(side::right, true); - cab.OperateDoors(side::left, true); - cab.OperateDoors(side::right, true); + cab.PermitDoors(VehicleSide::left, true); + cab.PermitDoors(VehicleSide::right, true); + cab.OperateDoors(VehicleSide::left, true); + cab.OperateDoors(VehicleSide::right, true); scenario.wait(5.0); - CHECK_FALSE(shut(cab, side::left)); - CHECK_FALSE(shut(cab, side::right)); + CHECK_FALSE(shut(cab, VehicleSide::left)); + CHECK_FALSE(shut(cab, VehicleSide::right)); scenario.get_going(); notch_up(scenario, 4, 2.0); scenario.wait(20.0); // the doors of a train ready to run close as the driver starts off. no CHECK of the speed: the Elf and // the Impuls keep their steps out under the permit, which keeps them from moving (COVERAGE.md) - CHECK(shut(cab, side::left) == ready); - CHECK(shut(cab, side::right) == ready); - CHECK(shut(last, side::left) == ready); - CHECK(shut(last, side::right) == ready); + CHECK(shut(cab, VehicleSide::left) == ready); + CHECK(shut(cab, VehicleSide::right) == ready); + CHECK(shut(last, VehicleSide::left) == ready); + CHECK(shut(last, VehicleSide::right) == ready); notch_down(scenario); brake_to_stop(scenario); scenario.check(); @@ -177,28 +177,28 @@ TEST_CASE("controls: the doors of wagons, worked from the locomotive") { for (auto const range : {range_t::consist, range_t::unit, range_t::local}) { CAPTURE(static_cast(range)); scenario.act(std::format("open right {}", static_cast(range))); - cab.PermitDoors(side::right, true, range); - cab.OperateDoors(side::right, true, range); + cab.PermitDoors(VehicleSide::right, true, range); + cab.OperateDoors(VehicleSide::right, true, range); scenario.wait(10.0); - CHECK(open(coach, side::right) == (range != range_t::local)); - CHECK(shut(coach, side::left)); - CHECK(shut(freight, side::right)); + CHECK(open(coach, VehicleSide::right) == (range != range_t::local)); + CHECK(shut(coach, VehicleSide::left)); + CHECK(shut(freight, VehicleSide::right)); scenario.act("close right"); - cab.OperateDoors(side::right, false, range); + cab.OperateDoors(VehicleSide::right, false, range); scenario.wait(10.0); - CHECK(shut(coach, side::right)); + CHECK(shut(coach, VehicleSide::right)); } scenario.act("wagon opens its own"); - coach.OperateDoors(side::left, true, range_t::local); + coach.OperateDoors(VehicleSide::left, true, range_t::local); // a second at a time, the same run as one wait. the coach's doors close by themselves 5 s after they // opened (DoorStayOpen) scenario.wait(1.0); - CHECK_FALSE(shut(coach, side::left)); + CHECK_FALSE(shut(coach, VehicleSide::left)); scenario.wait(9.0); - CHECK(shut(coach, side::left)); - coach.OperateDoors(side::left, false, range_t::local); + CHECK(shut(coach, VehicleSide::left)); + coach.OperateDoors(VehicleSide::left, false, range_t::local); scenario.wait(10.0); - CHECK(shut(coach, side::left)); + CHECK(shut(coach, VehicleSide::left)); scenario.check(); } diff --git a/tests/unit/test_coupler_physics.cpp b/tests/unit/test_coupler_physics.cpp index bbb935365..60c760fb5 100644 --- a/tests/unit/test_coupler_physics.cpp +++ b/tests/unit/test_coupler_physics.cpp @@ -268,7 +268,7 @@ 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, CouplingSet const couplings = Coupling::coupler) { +void join(vehicle &First, VehicleEnd FirstEnd, vehicle &Second, VehicleEnd 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)); } @@ -286,9 +286,9 @@ bool coupler_damaged(vehicle &Vehicle) { TEST_CASE("coupler physics: the play of the coupling and the parameters of the model come from the vehicle definition") { auto loose{loose_wagon(0.05, 0.0, "loose")}; - auto const &physics{loose->Couplers[end::front].physics}; + auto const &physics{loose->Couplers[VehicleEnd::front].physics}; CHECK(physics.slack == doctest::Approx(0.05)); - CHECK(loose->Couplers[end::rear].physics.slack == doctest::Approx(0.05)); + CHECK(loose->Couplers[VehicleEnd::rear].physics.slack == doctest::Approx(0.05)); CHECK(physics.buffers.stiffness == doctest::Approx(9200e3)); CHECK(physics.buffers.travel == doctest::Approx(0.11)); CHECK(physics.draw_gear.end_force() == doctest::Approx(450e3)); @@ -300,11 +300,11 @@ TEST_CASE("coupler physics: the play of the coupling and the parameters of the m CHECK(physics.link.breakable); auto tight{vehicle{definition::load("wagon"), 0.0, "tight"}}; - CHECK(tight->Couplers[end::front].physics.slack == 0.0); + CHECK(tight->Couplers[VehicleEnd::front].physics.slack == 0.0); auto automatic{vehicle{definition::load("wagon").set("BuffCoupl", "CType", "Automatic"), 0.0, "automatic"}}; - CHECK(automatic->Couplers[end::front].physics.slack == doctest::Approx(0.005)); + CHECK(automatic->Couplers[VehicleEnd::front].physics.slack == doctest::Approx(0.005)); auto articulated{vehicle{definition::load("wagon").set("BuffCoupl", "CType", "Articulated"), 0.0, "articulated"}}; - CHECK_FALSE(articulated->Couplers[end::front].physics.link.breakable); + CHECK_FALSE(articulated->Couplers[VehicleEnd::front].physics.link.breakable); } TEST_CASE("coupler physics: a coupling with play pulls only once the play is taken up") { @@ -313,15 +313,15 @@ TEST_CASE("coupler physics: a coupling with play pulls only once the play is tak flag_setting const crashdamage{Global.crash_damage, true}; auto front{loose_wagon(0.05, 3.0, "front")}; auto rear{loose_wagon(0.05, 0.1, "rear")}; - join(rear, end::front, front, end::rear); - test::pair pair{rear, end::front, front, end::rear, 0.0}; + join(rear, VehicleEnd::front, front, VehicleEnd::rear); + test::pair pair{rear, VehicleEnd::front, front, VehicleEnd::rear, 0.0}; front.hold_brake_pipe(5.0); rear.hold_brake_pipe(5.0); auto pulledwithinplay{false}; for (int i = 0; i < 300 && pair.gap() < 0.09; ++i) { pair.step(); - pulledwithinplay = pulledwithinplay || rear->Couplers[end::front].CForce != 0.0; + pulledwithinplay = pulledwithinplay || rear->Couplers[VehicleEnd::front].CForce != 0.0; } REQUIRE(pair.gap() >= 0.09); CHECK_FALSE(pulledwithinplay); @@ -343,7 +343,7 @@ TEST_CASE("coupler physics: buffers hit at a walking pace give back less than th auto moving{vehicle{definition::load("wagon"), 5.0, "moving"}}; // barely moving, so that its brakes are released auto standing{vehicle{definition::load("wagon"), 0.1, "standing"}}; - test::pair pair{moving, end::front, standing, end::rear, 0.3}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 0.3}; moving.hold_brake_pipe(5.0); standing.hold_brake_pipe(5.0); @@ -352,7 +352,7 @@ TEST_CASE("coupler physics: buffers hit at a walking pace give back less than th for (int i = 0; i < 500; ++i) { pair.step(); touched = touched || pair.gap() < 0.0; - solid = solid || moving->Couplers[end::front].physics_state.stop != 0; + solid = solid || moving->Couplers[VehicleEnd::front].physics_state.stop != 0; if (touched && pair.gap() > 0.3) { break; // parted } @@ -377,8 +377,8 @@ TEST_CASE("coupler physics: coupled vehicles at rest stay at rest") { flag_setting const everywhere{Global.coupler_physics_all, true}; auto first{vehicle{definition::load("wagon"), 0.0, "first"}}; auto second{vehicle{definition::load("wagon"), 0.0, "second"}}; - join(first, end::rear, second, end::front); - test::pair pair{first, end::rear, second, end::front, 0.0}; + join(first, VehicleEnd::rear, second, VehicleEnd::front); + test::pair pair{first, VehicleEnd::rear, second, VehicleEnd::front, 0.0}; pair.run(5.0); CHECK(std::abs(first.speed()) < 0.01); @@ -391,8 +391,8 @@ 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); - test::pair pair{rear, end::front, front, end::rear, 0.0}; + join(rear, VehicleEnd::front, front, VehicleEnd::rear, Coupling::coupler | Coupling::brakeHose); + test::pair pair{rear, VehicleEnd::front, front, VehicleEnd::rear, 0.0}; front.hold_brake_pipe(5.0); rear.hold_brake_pipe(5.0); @@ -424,15 +424,15 @@ TEST_CASE("coupler physics: a gentle pull on a coupling with play doesn't hurt i flag_setting const crashdamage{Global.crash_damage, true}; auto front{loose_wagon(0.05, 3.0, "front")}; auto rear{loose_wagon(0.05, 0.1, "rear")}; - join(rear, end::front, front, end::rear); - test::pair pair{rear, end::front, front, end::rear, 0.0}; + join(rear, VehicleEnd::front, front, VehicleEnd::rear); + test::pair pair{rear, VehicleEnd::front, front, VehicleEnd::rear, 0.0}; front.hold_brake_pipe(5.0); rear.hold_brake_pipe(5.0); pair.run(3.0); CHECK(pair.coupled()); CHECK_FALSE(coupler_damaged(rear)); - CHECK(rear->Couplers[end::front].physics_state.elongation == 0.0); + CHECK(rear->Couplers[VehicleEnd::front].physics_state.elongation == 0.0); } TEST_CASE("coupler physics: automatic couplers still catch a wagon rolling into a standing one") { @@ -442,7 +442,7 @@ TEST_CASE("coupler physics: automatic couplers still catch a wagon rolling into 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}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; pair.run(3.0); REQUIRE(pair.coupled()); @@ -456,51 +456,51 @@ TEST_CASE("couplers: a broken coupling of vehicles facing each other uncouples t 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::front, second, end::front); - join(second, end::rear, third, end::front); + join(first, VehicleEnd::front, second, VehicleEnd::front); + join(second, VehicleEnd::rear, third, VehicleEnd::front); - first->damage_coupler(end::front); - CHECK(first->Couplers[end::front].CouplingFlag == Coupling::none); - CHECK(second->Couplers[end::front].CouplingFlag == Coupling::none); + first->damage_coupler(VehicleEnd::front); + CHECK(first->Couplers[VehicleEnd::front].CouplingFlag == Coupling::none); + CHECK(second->Couplers[VehicleEnd::front].CouplingFlag == Coupling::none); // the other coupling of the second vehicle stays - CHECK(second->Couplers[end::rear].CouplingFlag == Coupling::coupler); + CHECK(second->Couplers[VehicleEnd::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, VehicleEnd::rear, second, VehicleEnd::front, Coupling::coupler | Coupling::brakeHose); + join(second, VehicleEnd::rear, third, VehicleEnd::front, Coupling::coupler | Coupling::brakeHose); // both couplings of the second wagon break - second->damage_coupler(end::front); - second->damage_coupler(end::rear); - REQUIRE(second->Couplers[end::front].broken); - REQUIRE(first->Couplers[end::rear].broken); - REQUIRE(third->Couplers[end::front].broken); + second->damage_coupler(VehicleEnd::front); + second->damage_coupler(VehicleEnd::rear); + REQUIRE(second->Couplers[VehicleEnd::front].broken); + REQUIRE(first->Couplers[VehicleEnd::rear].broken); + REQUIRE(third->Couplers[VehicleEnd::front].broken); REQUIRE(second->DamageFlag.HasAll(VehicleDamage::coupling)); // nothing to repair at the far end of the first wagon - CHECK_FALSE(first->repair_coupler(end::front)); + CHECK_FALSE(first->repair_coupler(VehicleEnd::front)); // repaired from the first wagon: the coupling between the first two, the other one stays broken - CHECK(first->repair_coupler(end::rear)); - CHECK_FALSE(first->Couplers[end::rear].broken); - CHECK_FALSE(second->Couplers[end::front].broken); - CHECK(second->Couplers[end::rear].broken); - CHECK(third->Couplers[end::front].broken); + CHECK(first->repair_coupler(VehicleEnd::rear)); + CHECK_FALSE(first->Couplers[VehicleEnd::rear].broken); + CHECK_FALSE(second->Couplers[VehicleEnd::front].broken); + CHECK(second->Couplers[VehicleEnd::rear].broken); + CHECK(third->Couplers[VehicleEnd::front].broken); // the second wagon keeps its damage, and its emergency braking, while a coupler of it is broken CHECK(second->DamageFlag.HasAll(VehicleDamage::coupling)); CHECK(second->AlarmChainFlag); - CHECK(third->repair_coupler(end::front)); - CHECK_FALSE(second->Couplers[end::rear].broken); + CHECK(third->repair_coupler(VehicleEnd::front)); + CHECK_FALSE(second->Couplers[VehicleEnd::rear].broken); CHECK_FALSE(second->DamageFlag.HasAll(VehicleDamage::coupling)); CHECK_FALSE(second->AlarmChainFlag); // repaired, not coupled: the vehicles are coupled again as usual - CHECK(second->Couplers[end::rear].CouplingFlag == Coupling::none); - CHECK(second->Attach(end::rear, end::front, &third.mover(), Coupling::coupler, true, false)); + CHECK(second->Couplers[VehicleEnd::rear].CouplingFlag == Coupling::none); + CHECK(second->Attach(VehicleEnd::rear, VehicleEnd::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") { @@ -508,28 +508,28 @@ TEST_CASE("coupler physics: with couplerphysics yes, only the pairs with a vehic flag_setting const everywhere{Global.coupler_physics_all, false}; auto moving{vehicle{definition::load("wagon"), 5.0, "moving"}}; auto standing{vehicle{definition::load("wagon"), 0.1, "standing"}}; - test::pair pair{moving, end::front, standing, end::rear, 0.1}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 0.1}; SUBCASE("neither covered: the legacy model") { pair.run(1.0); - CHECK_FALSE(moving->coupler_physics_at(end::front)); - CHECK_FALSE(standing->coupler_physics_at(end::rear)); + CHECK_FALSE(moving->coupler_physics_at(VehicleEnd::front)); + CHECK_FALSE(standing->coupler_physics_at(VehicleEnd::rear)); // the state of the physical model untouched - CHECK(moving->Couplers[end::front].physics_state.gap == 0.0); + CHECK(moving->Couplers[VehicleEnd::front].physics_state.gap == 0.0); } SUBCASE("one covered: both compute the pair physically") { // as the player's train closing in on the other one moving->CouplerPhysics = true; pair.run(1.0); - CHECK(moving->coupler_physics_at(end::front)); - CHECK(standing->coupler_physics_at(end::rear)); - CHECK(moving->Couplers[end::front].physics_state.gap != 0.0); - CHECK(standing->Couplers[end::rear].physics_state.gap == moving->Couplers[end::front].physics_state.gap); + CHECK(moving->coupler_physics_at(VehicleEnd::front)); + CHECK(standing->coupler_physics_at(VehicleEnd::rear)); + CHECK(moving->Couplers[VehicleEnd::front].physics_state.gap != 0.0); + CHECK(standing->Couplers[VehicleEnd::rear].physics_state.gap == moving->Couplers[VehicleEnd::front].physics_state.gap); } SUBCASE("the setting off: the legacy model, covered or not") { flag_setting const off{Global.coupler_physics, false}; moving->CouplerPhysics = true; - CHECK_FALSE(moving->coupler_physics_at(end::front)); + CHECK_FALSE(moving->coupler_physics_at(VehicleEnd::front)); } } diff --git a/tests/unit/test_couplers.cpp b/tests/unit/test_couplers.cpp index 825102f9a..c816bf19b 100644 --- a/tests/unit/test_couplers.cpp +++ b/tests/unit/test_couplers.cpp @@ -70,13 +70,13 @@ TEST_CASE("couplers: automatic couplers catch a standing wagon hit at a walking crash_damage_setting const crashdamage{true}; auto moving{automatic_wagon(10.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; - REQUIRE(moving->Couplers[end::front].type() == TCouplerType::Automatic); + REQUIRE(moving->Couplers[VehicleEnd::front].type() == TCouplerType::Automatic); REQUIRE(moving.speed() == doctest::Approx(10.0)); // the front of the moving wagon runs into the rear of the standing one - CHECK(moving->CollisionVelocity(end::front, standing.mover(), end::rear) == doctest::Approx(10.0)); - CHECK(moving->AutomaticCouplingSafe(end::front, standing.mover(), end::rear)); - CHECK(standing->AutomaticCouplingSafe(end::rear, moving.mover(), end::front)); + CHECK(moving->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear) == doctest::Approx(10.0)); + CHECK(moving->AutomaticCouplingSafe(VehicleEnd::front, standing.mover(), VehicleEnd::rear)); + CHECK(standing->AutomaticCouplingSafe(VehicleEnd::rear, moving.mover(), VehicleEnd::front)); } TEST_CASE("couplers: automatic couplers don't catch a wagon hit too fast, the wagons collide instead") { @@ -85,9 +85,9 @@ TEST_CASE("couplers: automatic couplers don't catch a wagon hit too fast, the wa auto standing{automatic_wagon(0.0, "standing")}; REQUIRE(moving.speed() == doctest::Approx(30.0)); - CHECK(moving->CollisionVelocity(end::front, standing.mover(), end::rear) > TMoverParameters::SafeCollisionVelocity); - CHECK_FALSE(moving->AutomaticCouplingSafe(end::front, standing.mover(), end::rear)); - CHECK_FALSE(standing->AutomaticCouplingSafe(end::rear, moving.mover(), end::front)); + CHECK(moving->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear) > TMoverParameters::SafeCollisionVelocity); + CHECK_FALSE(moving->AutomaticCouplingSafe(VehicleEnd::front, standing.mover(), VehicleEnd::rear)); + CHECK_FALSE(standing->AutomaticCouplingSafe(VehicleEnd::rear, moving.mover(), VehicleEnd::front)); } TEST_CASE("couplers: automatic couplers catch a wagon running ahead only a little slower") { @@ -95,9 +95,9 @@ TEST_CASE("couplers: automatic couplers catch a wagon running ahead only a littl auto faster{automatic_wagon(60.0, "faster")}; auto slower{automatic_wagon(50.0, "slower")}; - CHECK(faster->CollisionVelocity(end::front, slower.mover(), end::rear) == doctest::Approx(10.0)); - CHECK(slower->CollisionVelocity(end::rear, faster.mover(), end::front) == doctest::Approx(10.0)); - CHECK(faster->AutomaticCouplingSafe(end::front, slower.mover(), end::rear)); + CHECK(faster->CollisionVelocity(VehicleEnd::front, slower.mover(), VehicleEnd::rear) == doctest::Approx(10.0)); + CHECK(slower->CollisionVelocity(VehicleEnd::rear, faster.mover(), VehicleEnd::front) == doctest::Approx(10.0)); + CHECK(faster->AutomaticCouplingSafe(VehicleEnd::front, slower.mover(), VehicleEnd::rear)); } TEST_CASE("couplers: without crash damage automatic couplers catch at any speed") { @@ -105,7 +105,7 @@ TEST_CASE("couplers: without crash damage automatic couplers catch at any speed" auto moving{automatic_wagon(30.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; - CHECK(moving->AutomaticCouplingSafe(end::front, standing.mover(), end::rear)); + CHECK(moving->AutomaticCouplingSafe(VehicleEnd::front, standing.mover(), VehicleEnd::rear)); } // the closing speed used to treat the speed of each vehicle as a vector turned by half its heading, so for vehicles @@ -116,16 +116,16 @@ TEST_CASE("couplers: the closing speed of a rear-end collision is the difference auto slower{automatic_wagon(25.0, "slower")}; // running forwards, the front of the faster wagon hits the rear of the slower one - CHECK(faster->CollisionVelocity(end::front, slower.mover(), end::rear) == doctest::Approx(15.0)); - CHECK(slower->CollisionVelocity(end::rear, faster.mover(), end::front) == doctest::Approx(15.0)); + CHECK(faster->CollisionVelocity(VehicleEnd::front, slower.mover(), VehicleEnd::rear) == doctest::Approx(15.0)); + CHECK(slower->CollisionVelocity(VehicleEnd::rear, faster.mover(), VehicleEnd::front) == doctest::Approx(15.0)); // the wagons running ahead of each other are parting - CHECK(slower->CollisionVelocity(end::front, faster.mover(), end::rear) == doctest::Approx(-15.0)); + CHECK(slower->CollisionVelocity(VehicleEnd::front, faster.mover(), VehicleEnd::rear) == doctest::Approx(-15.0)); // backing up, the rear of the faster wagon hits the front of the slower one auto backingfaster{automatic_wagon(-40.0, "backing faster")}; auto backingslower{automatic_wagon(-25.0, "backing slower")}; - CHECK(backingfaster->CollisionVelocity(end::rear, backingslower.mover(), end::front) == doctest::Approx(15.0)); - CHECK(backingslower->CollisionVelocity(end::front, backingfaster.mover(), end::rear) == doctest::Approx(15.0)); + CHECK(backingfaster->CollisionVelocity(VehicleEnd::rear, backingslower.mover(), VehicleEnd::front) == doctest::Approx(15.0)); + CHECK(backingslower->CollisionVelocity(VehicleEnd::front, backingfaster.mover(), VehicleEnd::rear) == doctest::Approx(15.0)); } TEST_CASE("couplers: the closing speed of a head-on collision is the sum of the speeds") { @@ -134,27 +134,27 @@ TEST_CASE("couplers: the closing speed of a head-on collision is the sum of the auto second{automatic_wagon(10.0, "second")}; // both wagons run forwards, their fronts meet - CHECK(first->CollisionVelocity(end::front, second.mover(), end::front) == doctest::Approx(20.0)); - CHECK(second->CollisionVelocity(end::front, first.mover(), end::front) == doctest::Approx(20.0)); + CHECK(first->CollisionVelocity(VehicleEnd::front, second.mover(), VehicleEnd::front) == doctest::Approx(20.0)); + CHECK(second->CollisionVelocity(VehicleEnd::front, first.mover(), VehicleEnd::front) == doctest::Approx(20.0)); // 20 km/h is above the limit, the couplers don't catch (the old formula gave 14.1 km/h and coupled them) - CHECK(first->CollisionVelocity(end::front, second.mover(), end::front) > TMoverParameters::SafeCollisionVelocity); - CHECK_FALSE(first->AutomaticCouplingSafe(end::front, second.mover(), end::front)); - CHECK_FALSE(second->AutomaticCouplingSafe(end::front, first.mover(), end::front)); + CHECK(first->CollisionVelocity(VehicleEnd::front, second.mover(), VehicleEnd::front) > TMoverParameters::SafeCollisionVelocity); + CHECK_FALSE(first->AutomaticCouplingSafe(VehicleEnd::front, second.mover(), VehicleEnd::front)); + CHECK_FALSE(second->AutomaticCouplingSafe(VehicleEnd::front, first.mover(), VehicleEnd::front)); // both wagons back up, their rears meet auto firstbacking{automatic_wagon(-10.0, "first backing")}; auto secondbacking{automatic_wagon(-10.0, "second backing")}; - CHECK(firstbacking->CollisionVelocity(end::rear, secondbacking.mover(), end::rear) == doctest::Approx(20.0)); + CHECK(firstbacking->CollisionVelocity(VehicleEnd::rear, secondbacking.mover(), VehicleEnd::rear) == doctest::Approx(20.0)); // running back to back, the wagons part - CHECK(first->CollisionVelocity(end::rear, second.mover(), end::rear) == doctest::Approx(-20.0)); - CHECK(first->AutomaticCouplingSafe(end::rear, second.mover(), end::rear)); + CHECK(first->CollisionVelocity(VehicleEnd::rear, second.mover(), VehicleEnd::rear) == doctest::Approx(-20.0)); + CHECK(first->AutomaticCouplingSafe(VehicleEnd::rear, second.mover(), VehicleEnd::rear)); // slow enough, the couplers catch auto slowfirst{automatic_wagon(5.0, "slow first")}; auto slowsecond{automatic_wagon(5.0, "slow second")}; - CHECK(slowfirst->CollisionVelocity(end::front, slowsecond.mover(), end::front) == doctest::Approx(10.0)); - CHECK(slowfirst->AutomaticCouplingSafe(end::front, slowsecond.mover(), end::front)); + CHECK(slowfirst->CollisionVelocity(VehicleEnd::front, slowsecond.mover(), VehicleEnd::front) == doctest::Approx(10.0)); + CHECK(slowfirst->AutomaticCouplingSafe(VehicleEnd::front, slowsecond.mover(), VehicleEnd::front)); } TEST_CASE("couplers: the closing speed of a hit on a standing vehicle is the speed of the moving one, whichever way it faces") { @@ -162,17 +162,17 @@ TEST_CASE("couplers: the closing speed of a hit on a standing vehicle is the spe auto standing{automatic_wagon(0.0, "standing")}; // the standing wagon faces away from the moving one - CHECK(moving->CollisionVelocity(end::front, standing.mover(), end::rear) == doctest::Approx(20.0)); - CHECK(standing->CollisionVelocity(end::rear, moving.mover(), end::front) == doctest::Approx(20.0)); + CHECK(moving->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear) == doctest::Approx(20.0)); + CHECK(standing->CollisionVelocity(VehicleEnd::rear, moving.mover(), VehicleEnd::front) == doctest::Approx(20.0)); // the standing wagon faces the moving one - CHECK(moving->CollisionVelocity(end::front, standing.mover(), end::front) == doctest::Approx(20.0)); - CHECK(standing->CollisionVelocity(end::front, moving.mover(), end::front) == doctest::Approx(20.0)); + CHECK(moving->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::front) == doctest::Approx(20.0)); + CHECK(standing->CollisionVelocity(VehicleEnd::front, moving.mover(), VehicleEnd::front) == doctest::Approx(20.0)); // the moving wagon backs up into the standing one auto backing{automatic_wagon(-20.0, "backing")}; - CHECK(backing->CollisionVelocity(end::rear, standing.mover(), end::front) == doctest::Approx(20.0)); - CHECK(backing->CollisionVelocity(end::rear, standing.mover(), end::rear) == doctest::Approx(20.0)); + CHECK(backing->CollisionVelocity(VehicleEnd::rear, standing.mover(), VehicleEnd::front) == doctest::Approx(20.0)); + CHECK(backing->CollisionVelocity(VehicleEnd::rear, standing.mover(), VehicleEnd::rear) == doctest::Approx(20.0)); // the moving wagon runs away from the standing one - CHECK(moving->CollisionVelocity(end::rear, standing.mover(), end::front) == doctest::Approx(-20.0)); + CHECK(moving->CollisionVelocity(VehicleEnd::rear, standing.mover(), VehicleEnd::front) == doctest::Approx(-20.0)); } // the coupling as the simulation runs it: two vehicles on a track, closing in on each other until the couplers (or @@ -183,28 +183,28 @@ TEST_CASE("couplers: automatic couplers catch right up to the safe closing speed auto standing{automatic_wagon(0.0, "standing")}; auto below{automatic_wagon(14.9, "below")}; - CHECK(below->CollisionVelocity(end::front, standing.mover(), end::rear) == doctest::Approx(14.9)); - CHECK(below->AutomaticCouplingSafe(end::front, standing.mover(), end::rear)); + CHECK(below->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear) == doctest::Approx(14.9)); + CHECK(below->AutomaticCouplingSafe(VehicleEnd::front, standing.mover(), VehicleEnd::rear)); auto above{automatic_wagon(15.1, "above")}; - CHECK(above->CollisionVelocity(end::front, standing.mover(), end::rear) == doctest::Approx(15.1)); - CHECK_FALSE(above->AutomaticCouplingSafe(end::front, standing.mover(), end::rear)); + CHECK(above->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear) == doctest::Approx(15.1)); + CHECK_FALSE(above->AutomaticCouplingSafe(VehicleEnd::front, standing.mover(), VehicleEnd::rear)); auto faster{automatic_wagon(15.5, "faster")}; - CHECK_FALSE(faster->AutomaticCouplingSafe(end::front, standing.mover(), end::rear)); + CHECK_FALSE(faster->AutomaticCouplingSafe(VehicleEnd::front, standing.mover(), VehicleEnd::rear)); } TEST_CASE("couplers: a wagon rolling slowly into a standing one couples with it") { crash_damage_setting const crashdamage{true}; auto moving{automatic_wagon(5.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; 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].Connected == &standing.mover()); + CHECK(moving->Couplers[VehicleEnd::front].CouplingFlag == (Coupling::coupler | Coupling::brakeHose)); + CHECK(standing->Couplers[VehicleEnd::rear].CouplingFlag == (Coupling::coupler | Coupling::brakeHose)); + CHECK(moving->Couplers[VehicleEnd::front].Connected == &standing.mover()); CHECK_FALSE(derailed(moving)); CHECK_FALSE(derailed(standing)); // coupled, they run on together @@ -218,7 +218,7 @@ TEST_CASE("couplers: a wagon hitting a standing one too fast doesn't couple, nor legacy_collisions const legacy; auto moving{automatic_wagon(30.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; auto touched{false}; auto parted{false}; @@ -227,12 +227,12 @@ TEST_CASE("couplers: a wagon hitting a standing one too fast doesn't couple, nor for (int i = 0; i < 1000; ++i) { pair.step(); // as far as the couplers know: the distance between them at the start of the step - auto const distance{moving->Neighbours[end::front].distance}; + auto const distance{moving->Neighbours[VehicleEnd::front].distance}; touched = touched || distance < 0.0; parted = parted || (touched && distance > 0.05); coupled = coupled || pair.coupled(); if (touched && false == parted) { - locked = locked && false == moving->Couplers[end::front].AutomaticCouplingAllowed && false == standing->Couplers[end::rear].AutomaticCouplingAllowed; + locked = locked && false == moving->Couplers[VehicleEnd::front].AutomaticCouplingAllowed && false == standing->Couplers[VehicleEnd::rear].AutomaticCouplingAllowed; } } @@ -253,17 +253,17 @@ TEST_CASE("couplers: the automatic coupling locked by a hit is unlocked once the auto moving{automatic_wagon(3.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; // as a hit too fast or manual uncoupling leaves them - moving->Couplers[end::front].AutomaticCouplingAllowed = false; - standing->Couplers[end::rear].AutomaticCouplingAllowed = false; + moving->Couplers[VehicleEnd::front].AutomaticCouplingAllowed = false; + standing->Couplers[VehicleEnd::rear].AutomaticCouplingAllowed = false; SUBCASE("parted by more than 5 cm, they couple on the next approach") { - test::pair pair{moving, end::front, standing, end::rear, 0.5}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 0.5}; pair.step(); - CHECK(moving->Couplers[end::front].AutomaticCouplingAllowed); + CHECK(moving->Couplers[VehicleEnd::front].AutomaticCouplingAllowed); CHECK(couple_during(pair, 3.0)); } SUBCASE("kept together, they don't") { - test::pair pair{moving, end::front, standing, end::rear, 0.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 0.0}; auto coupled{false}; for (int i = 0; i < 300; ++i) { pair.step(); @@ -285,7 +285,7 @@ TEST_CASE("couplers: a hit a little too fast for the couplers bounces the vehicl legacy_collisions const legacy; auto moving{automatic_wagon(20.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; CHECK_FALSE(couple_during(pair, 3.0)); CHECK_FALSE(derailed(moving)); @@ -301,7 +301,7 @@ TEST_CASE("couplers: a hit too fast for the couplers derails the vehicles over t SUBCASE("equal masses: both derail") { auto moving{automatic_wagon(30.0, "moving")}; auto standing{automatic_wagon(0.0, "standing")}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; CHECK_FALSE(couple_during(pair, 5.0)); CHECK(derailed(moving)); CHECK(derailed(standing)); @@ -309,7 +309,7 @@ TEST_CASE("couplers: a hit too fast for the couplers derails the vehicles over t SUBCASE("half the mass: between the safe closing speed and twice that, only the lighter one derails") { auto light{automatic_wagon(27.0, "light")}; auto heavy{heavy_automatic_wagon(0.0, "heavy")}; - test::pair pair{light, end::front, heavy, end::rear, 1.0}; + test::pair pair{light, VehicleEnd::front, heavy, VehicleEnd::rear, 1.0}; CHECK_FALSE(couple_during(pair, 5.0)); CHECK(derailed(light)); CHECK_FALSE(derailed(heavy)); @@ -317,7 +317,7 @@ TEST_CASE("couplers: a hit too fast for the couplers derails the vehicles over t SUBCASE("half the mass: above twice the safe closing speed both derail") { auto light{automatic_wagon(45.0, "light")}; auto heavy{heavy_automatic_wagon(0.0, "heavy")}; - test::pair pair{light, end::front, heavy, end::rear, 1.0}; + test::pair pair{light, VehicleEnd::front, heavy, VehicleEnd::rear, 1.0}; CHECK_FALSE(couple_during(pair, 5.0)); CHECK(derailed(light)); CHECK(derailed(heavy)); @@ -325,7 +325,7 @@ TEST_CASE("couplers: a hit too fast for the couplers derails the vehicles over t SUBCASE("half the mass: below the safe closing speed the couplers catch, nothing derails") { auto light{automatic_wagon(12.0, "light")}; auto heavy{heavy_automatic_wagon(0.0, "heavy")}; - test::pair pair{light, end::front, heavy, end::rear, 1.0}; + test::pair pair{light, VehicleEnd::front, heavy, VehicleEnd::rear, 1.0}; CHECK(couple_during(pair, 5.0)); CHECK_FALSE(derailed(light)); CHECK_FALSE(derailed(heavy)); @@ -339,7 +339,7 @@ TEST_CASE("couplers: wagons running head-on into each other couple only up to th SUBCASE("7 + 7 km/h, the couplers catch") { auto first{automatic_wagon(7.0, "first")}; auto second{automatic_wagon(7.0, "second")}; - test::pair pair{first, end::front, second, end::front, 1.0}; + test::pair pair{first, VehicleEnd::front, second, VehicleEnd::front, 1.0}; CHECK(couple_during(pair, 3.0)); CHECK_FALSE(derailed(first)); CHECK_FALSE(derailed(second)); @@ -347,7 +347,7 @@ TEST_CASE("couplers: wagons running head-on into each other couple only up to th SUBCASE("8 + 8 km/h, the wagons bounce apart") { auto first{automatic_wagon(8.0, "first")}; auto second{automatic_wagon(8.0, "second")}; - test::pair pair{first, end::front, second, end::front, 1.0}; + test::pair pair{first, VehicleEnd::front, second, VehicleEnd::front, 1.0}; CHECK_FALSE(couple_during(pair, 3.0)); CHECK_FALSE(derailed(first)); CHECK_FALSE(derailed(second)); @@ -358,7 +358,7 @@ TEST_CASE("couplers: wagons running head-on into each other couple only up to th SUBCASE("backing up, 8 + 8 km/h, the wagons bounce apart") { auto first{automatic_wagon(-8.0, "first")}; auto second{automatic_wagon(-8.0, "second")}; - test::pair pair{first, end::rear, second, end::rear, 1.0}; + test::pair pair{first, VehicleEnd::rear, second, VehicleEnd::rear, 1.0}; CHECK_FALSE(couple_during(pair, 3.0)); CHECK(first.speed() > 0.0); CHECK(second.speed() > 0.0); @@ -366,7 +366,7 @@ TEST_CASE("couplers: wagons running head-on into each other couple only up to th SUBCASE("15 + 15 km/h, both derail") { auto first{automatic_wagon(15.0, "first")}; auto second{automatic_wagon(15.0, "second")}; - test::pair pair{first, end::front, second, end::front, 1.0}; + test::pair pair{first, VehicleEnd::front, second, VehicleEnd::front, 1.0}; CHECK_FALSE(couple_during(pair, 5.0)); CHECK(derailed(first)); CHECK(derailed(second)); @@ -380,10 +380,10 @@ TEST_CASE("couplers: wagons running head-on into each other couple only up to th TEST_CASE("couplers: a wagon hit head-on runs off the same as one hit from behind") { // without automatic couplers or crash damage, the collision alone crash_damage_setting const crashdamage{false}; - auto speeds_after_hit = [](int StruckEnd) { + auto speeds_after_hit = [](VehicleEnd StruckEnd) { auto moving{vehicle{definition::load("wagon"), 20.0, "moving"}}; auto struck{vehicle{definition::load("wagon"), 0.0, "struck"}}; - test::pair pair{moving, end::front, struck, StruckEnd, 0.5}; + test::pair pair{moving, VehicleEnd::front, struck, StruckEnd, 0.5}; auto touched{false}; for (int i = 0; i < 300; ++i) { pair.step(); @@ -398,8 +398,8 @@ TEST_CASE("couplers: a wagon hit head-on runs off the same as one hit from behin return std::make_pair(moving.speed(), struck.speed()); }; - auto const [hitterfrombehind, struckfrombehind]{speeds_after_hit(end::rear)}; - auto const [hitterheadon, struckheadon]{speeds_after_hit(end::front)}; + auto const [hitterfrombehind, struckfrombehind]{speeds_after_hit(VehicleEnd::rear)}; + auto const [hitterheadon, struckheadon]{speeds_after_hit(VehicleEnd::front)}; // hit from behind, the struck wagon runs off forwards, faster than the hitter CHECK(struckfrombehind > 10.0); @@ -415,8 +415,8 @@ TEST_CASE("couplers: an automatic coupler doesn't catch a coupler of another typ crash_damage_setting const crashdamage{true}; auto moving{automatic_wagon(5.0, "moving")}; auto standing{vehicle{definition::load("wagon"), 0.0, "standing"}}; - REQUIRE(standing->Couplers[end::rear].type() == TCouplerType::Screw); - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + REQUIRE(standing->Couplers[VehicleEnd::rear].type() == TCouplerType::Screw); + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; CHECK_FALSE(couple_during(pair, 3.0)); } @@ -428,15 +428,15 @@ TEST_CASE("couplers: automatic couplers of different control systems couple with SUBCASE("the same control system") { auto standing{vehicle{automatic_definition(flag).set("BuffCoupl", "ControlType", "first"), 0.0, "standing"}}; - REQUIRE(standing->Couplers[end::rear].control_type == "first"); - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + REQUIRE(standing->Couplers[VehicleEnd::rear].control_type == "first"); + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; REQUIRE(couple_during(pair, 3.0)); CHECK(pair.coupling() == flag); } SUBCASE("a different one") { auto standing{vehicle{automatic_definition(flag).set("BuffCoupl", "ControlType", "second"), 0.0, "standing"}}; - REQUIRE(standing->Couplers[end::rear].control_type == "second"); - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + REQUIRE(standing->Couplers[VehicleEnd::rear].control_type == "second"); + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; REQUIRE(couple_during(pair, 3.0)); CHECK(pair.coupling() == (Coupling::coupler | Coupling::brakeHose)); } @@ -451,26 +451,26 @@ TEST_CASE("couplers: the coupler force of vehicles facing each other lands on th auto second{automatic_wagon(0.0, "second")}; SUBCASE("facing each other") { - test::pair pair{first, end::front, second, end::front, 1.0}; + test::pair pair{first, VehicleEnd::front, second, VehicleEnd::front, 1.0}; pair.run(5.0); REQUIRE(pair.coupled()); pair.step(); - REQUIRE(second->Couplers[end::front].CForce != 0.0); - CHECK(first->Couplers[end::front].CForce == doctest::Approx(second->Couplers[end::front].CForce)); - CHECK(first->Couplers[end::rear].CForce == 0.0); // nothing there - CHECK(second->Couplers[end::rear].CForce == 0.0); + REQUIRE(second->Couplers[VehicleEnd::front].CForce != 0.0); + CHECK(first->Couplers[VehicleEnd::front].CForce == doctest::Approx(second->Couplers[VehicleEnd::front].CForce)); + CHECK(first->Couplers[VehicleEnd::rear].CForce == 0.0); // nothing there + CHECK(second->Couplers[VehicleEnd::rear].CForce == 0.0); } SUBCASE("facing the same way") { - test::pair pair{first, end::front, second, end::rear, 1.0}; + test::pair pair{first, VehicleEnd::front, second, VehicleEnd::rear, 1.0}; pair.run(5.0); REQUIRE(pair.coupled()); pair.step(); - REQUIRE(second->Couplers[end::rear].CForce != 0.0); - CHECK(first->Couplers[end::front].CForce == doctest::Approx(-second->Couplers[end::rear].CForce)); - CHECK(first->Couplers[end::rear].CForce == 0.0); - CHECK(second->Couplers[end::front].CForce == 0.0); + REQUIRE(second->Couplers[VehicleEnd::rear].CForce != 0.0); + CHECK(first->Couplers[VehicleEnd::front].CForce == doctest::Approx(-second->Couplers[VehicleEnd::rear].CForce)); + CHECK(first->Couplers[VehicleEnd::rear].CForce == 0.0); + CHECK(second->Couplers[VehicleEnd::front].CForce == 0.0); } } @@ -487,7 +487,7 @@ 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) { +void join(vehicle &First, VehicleEnd FirstEnd, vehicle &Second, VehicleEnd SecondEnd) { REQUIRE(First->Attach(FirstEnd, SecondEnd, &Second.mover(), Coupling::coupler, true, false)); REQUIRE(Second->Attach(SecondEnd, FirstEnd, &First.mover(), Coupling::coupler, true, false)); } @@ -496,7 +496,7 @@ void join(vehicle &First, int FirstEnd, vehicle &Second, int SecondEnd) { TEST_CASE("couplers: an articulated joint takes its full tensile force within its travel") { auto wagon{articulated_wagon(0.0, "wagon")}; - auto const &joint{wagon->Couplers[end::front]}; + auto const &joint{wagon->Couplers[VehicleEnd::front]}; REQUIRE(joint.type() == TCouplerType::Articulated); CHECK(joint.SpringKC * joint.DmaxC >= doctest::Approx(joint.FmaxC)); @@ -511,8 +511,8 @@ TEST_CASE("couplers: an articulated set keeps its momentum when one section jerk // and run on together at half the speed, as the momentum they have between them dictates auto front_section{articulated_wagon(20.0, "front")}; auto rear_section{articulated_wagon(0.1, "rear")}; - join(rear_section, end::front, front_section, end::rear); - test::pair pair{rear_section, end::front, front_section, end::rear, 0.0}; + join(rear_section, VehicleEnd::front, front_section, VehicleEnd::rear); + test::pair pair{rear_section, VehicleEnd::front, front_section, VehicleEnd::rear, 0.0}; REQUIRE(pair.coupled()); // brakes released, as a locomotive keeps them front_section.hold_brake_pipe(5.0); @@ -531,8 +531,8 @@ TEST_CASE("couplers: a collision of coupled vehicles keeps the momentum of the p // the same jerk through screw couplers, which collide when stretched beyond their travel as well auto front_wagon{vehicle{definition::load("wagon"), 30.0, "front"}}; auto rear_wagon{vehicle{definition::load("wagon"), 0.1, "rear"}}; - join(rear_wagon, end::front, front_wagon, end::rear); - test::pair pair{rear_wagon, end::front, front_wagon, end::rear, 0.0}; + join(rear_wagon, VehicleEnd::front, front_wagon, VehicleEnd::rear); + test::pair pair{rear_wagon, VehicleEnd::front, front_wagon, VehicleEnd::rear, 0.0}; REQUIRE(pair.coupled()); front_wagon.hold_brake_pipe(5.0); rear_wagon.hold_brake_pipe(5.0); @@ -565,9 +565,9 @@ constexpr CouplingSet scenario_coupling{Coupling::coupler | Coupling::brakeHose // 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 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; + REQUIRE(First->Attach(VehicleEnd::rear, VehicleEnd::front, &Second.mover(), couplings, true, false)); + CHECK(Second->Couplers[VehicleEnd::front].CouplingFlag == First->Couplers[VehicleEnd::rear].CouplingFlag); + return First->Couplers[VehicleEnd::rear].CouplingFlag; } } // namespace @@ -581,13 +581,13 @@ TEST_CASE("couplers: an electric and a diesel locomotive don't share their contr SUBCASE("a diesel-electric one with its own control system") { 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_FALSE(electric->ControlCouplingAllowed(VehicleEnd::rear, diesel.mover(), VehicleEnd::front)); 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_FALSE(diesel->ControlCouplingAllowed(VehicleEnd::front, electric.mover(), VehicleEnd::rear)); CHECK(scenario_couple(diesel, electric) == scenario_coupling.Without(Coupling::control)); } SUBCASE("unless both name the same control system") { @@ -603,7 +603,7 @@ TEST_CASE("couplers: an electric and a diesel locomotive don't share their contr SUBCASE("unless the check is turned off") { control_coupling_check_setting const off{false}; auto diesel{vehicle{definition::fiz("sm42_v1/6d1"), 0.0, "diesel"}}; - CHECK(electric->ControlCouplingAllowed(end::rear, diesel.mover(), end::front)); + CHECK(electric->ControlCouplingAllowed(VehicleEnd::rear, diesel.mover(), VehicleEnd::front)); CHECK(scenario_couple(electric, diesel) == scenario_coupling); } } @@ -646,13 +646,13 @@ TEST_CASE("couplers: automatic couplers of an electric and a diesel locomotive c SUBCASE("a diesel one") { auto standing{vehicle{automatic("sm03_v1/sm03"), 0.0, "standing"}}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; REQUIRE(couple_during(pair, 3.0)); CHECK(pair.coupling() == (Coupling::coupler | Coupling::brakeHose)); } SUBCASE("an electric one") { auto standing{vehicle{automatic("ep09_v2/104e"), 0.0, "standing"}}; - test::pair pair{moving, end::front, standing, end::rear, 1.0}; + test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; REQUIRE(couple_during(pair, 3.0)); CHECK(pair.coupling() == flag); } @@ -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.Without(Coupling::control)); - CHECK(electric->CompatibleCoupling(end::rear, other.mover(), end::front, scenario_coupling) == scenario_coupling); + CHECK(electric->CompatibleCoupling(VehicleEnd::rear, diesel.mover(), VehicleEnd::front, scenario_coupling) == scenario_coupling.Without(Coupling::control)); + CHECK(electric->CompatibleCoupling(VehicleEnd::rear, other.mover(), VehicleEnd::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(VehicleEnd::rear, diesel.mover(), VehicleEnd::front, Coupling::coupler) == Coupling::coupler); } diff --git a/tests/unit/test_couplers_trains.cpp b/tests/unit/test_couplers_trains.cpp index ccd0ffae4..cdd4cd9a3 100644 --- a/tests/unit/test_couplers_trains.cpp +++ b/tests/unit/test_couplers_trains.cpp @@ -39,35 +39,35 @@ TEST_CASE("couplers: coupled by hand, touching or apart, of the same kind or not 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::none)); + CHECK_FALSE(locomotive.Attach(VehicleEnd::rear, VehicleEnd::front, nullptr, Coupling::coupler)); + CHECK_FALSE(locomotive.Attach(VehicleEnd::rear, VehicleEnd::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)); - CHECK(locomotive.Couplers[end::rear].Connected == &wagon); - CHECK(wagon.Couplers[end::front].Connected == &locomotive); - CHECK(wagon.Couplers[end::front].CouplingFlag == Coupling::coupler); - CHECK(locomotive.Couplers[end::rear].sounds == sound::attachcoupler); + locomotive.Couplers[VehicleEnd::rear].sounds = 0; + REQUIRE(locomotive.Attach(VehicleEnd::rear, VehicleEnd::front, &wagon, Coupling::coupler)); + CHECK(locomotive.Couplers[VehicleEnd::rear].Connected == &wagon); + CHECK(wagon.Couplers[VehicleEnd::front].Connected == &locomotive); + CHECK(wagon.Couplers[VehicleEnd::front].CouplingFlag == Coupling::coupler); + CHECK(locomotive.Couplers[VehicleEnd::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)); - CHECK(locomotive.Couplers[end::rear].sounds == (sound::attachbrakehose | sound::attachmainhose)); + locomotive.Couplers[VehicleEnd::rear].sounds = 0; + REQUIRE(locomotive.Attach(VehicleEnd::rear, VehicleEnd::front, &wagon, Coupling::coupler | Coupling::brakeHose | Coupling::mainHose)); + CHECK(locomotive.Couplers[VehicleEnd::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)); - CHECK(locomotive.Couplers[end::rear].sounds == 0); + locomotive.Couplers[VehicleEnd::rear].sounds = 0; + REQUIRE(wagon.Attach(NumberOf(VehicleEnd::front), 2, &locomotive, Coupling::coupler | Coupling::brakeHose, false, false)); + CHECK(locomotive.Couplers[VehicleEnd::rear].CouplingFlag == (Coupling::coupler | Coupling::brakeHose)); + CHECK(locomotive.Couplers[VehicleEnd::rear].sounds == 0); // a screw coupler with the buffers pressed together comes apart whole train.step(); - CHECK(locomotive.DettachStatus(end::rear) < 0); - locomotive.Couplers[end::rear].sounds = 0; - CHECK(locomotive.Dettach(end::rear)); - CHECK(locomotive.Couplers[end::rear].Connected == nullptr); - CHECK(wagon.Couplers[end::front].Connected == nullptr); - CHECK(locomotive.Couplers[end::rear].sounds == (sound::detach | sound::attachcoupler | sound::attachbrakehose)); - CHECK(locomotive.DettachStatus(end::rear) == 0); - CHECK(locomotive.Dettach(end::rear)); + CHECK(locomotive.DettachStatus(VehicleEnd::rear) < 0); + locomotive.Couplers[VehicleEnd::rear].sounds = 0; + CHECK(locomotive.Dettach(VehicleEnd::rear)); + CHECK(locomotive.Couplers[VehicleEnd::rear].Connected == nullptr); + CHECK(wagon.Couplers[VehicleEnd::front].Connected == nullptr); + CHECK(locomotive.Couplers[VehicleEnd::rear].sounds == (sound::detach | sound::attachcoupler | sound::attachbrakehose)); + CHECK(locomotive.DettachStatus(VehicleEnd::rear) == 0); + CHECK(locomotive.Dettach(VehicleEnd::rear)); } TEST_CASE("couplers: a screw coupler uncoupled with the buffers apart, or with the hoses alone, or broken") { @@ -88,24 +88,24 @@ TEST_CASE("couplers: a screw coupler uncoupled with the buffers apart, or with t consist train; auto &locomotive{train.add(definition::fiz("4e_v1/4e")).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)); + REQUIRE(locomotive.Attach(VehicleEnd::rear, VehicleEnd::front, &wagon, couplingtype, true)); if (damaged) { locomotive.DamageFlag.Set(VehicleDamage::coupling); } train.step(); - CHECK((locomotive.DettachStatus(end::rear) < 0) == apart); - CHECK(locomotive.Dettach(end::rear) == apart); + CHECK((locomotive.DettachStatus(VehicleEnd::rear) < 0) == apart); + CHECK(locomotive.Dettach(VehicleEnd::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::none : Coupling::coupler)); - CHECK(wagon.Couplers[end::front].CouplingFlag == (apart ? Coupling::none : Coupling::coupler)); + CHECK(locomotive.Couplers[VehicleEnd::rear].CouplingFlag == (apart ? Coupling::none : Coupling::coupler)); + CHECK(wagon.Couplers[VehicleEnd::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::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(VehicleEnd::rear, VehicleEnd::front, &unit, Coupling::coupler)); + CHECK(locomotive.Attach(VehicleEnd::rear, VehicleEnd::front, &unit, Coupling::coupler, true)); } TEST_CASE("couplers: automatic couplers coupling on contact") { @@ -129,11 +129,11 @@ TEST_CASE("couplers: automatic couplers coupling on contact") { scenario.wait(10.0); auto &first{scenario.vehicle(0)}; auto &second{scenario.vehicle(1)}; - CHECK(first.Couplers[end::rear].CouplingFlag == couplingtype); - CHECK(second.Couplers[end::front].CouplingFlag == couplingtype); + CHECK(first.Couplers[VehicleEnd::rear].CouplingFlag == couplingtype); + CHECK(second.Couplers[VehicleEnd::front].CouplingFlag == couplingtype); // once coupled, not again until uncoupled; the vehicle which coupled marks it for the AI - CHECK_FALSE(first.Couplers[end::rear].AutomaticCouplingAllowed); - CHECK_FALSE(second.Couplers[end::front].AutomaticCouplingAllowed); + CHECK_FALSE(first.Couplers[VehicleEnd::rear].AutomaticCouplingAllowed); + CHECK_FALSE(second.Couplers[VehicleEnd::front].AutomaticCouplingAllowed); CHECK((TestFlag(first.AIFlag, sound::attachcoupler) || TestFlag(second.AIFlag, sound::attachcoupler))); scenario.check(); } @@ -143,23 +143,23 @@ TEST_CASE("couplers: a coupler broken, with its brake hose torn off") { consist train; auto &locomotive{train.add(definition::fiz("4e_v1/4e")).mover()}; auto &wagon{train.add(definition::fiz("3wl_v2/3wl")).mover()}; - REQUIRE(locomotive.Couplers[end::rear].Connected == &wagon); - locomotive.damage_coupler(end::rear); + REQUIRE(locomotive.Couplers[VehicleEnd::rear].Connected == &wagon); + locomotive.damage_coupler(VehicleEnd::rear); CHECK(locomotive.DamageFlag.HasAll(VehicleDamage::coupling)); CHECK(locomotive.AlarmChainFlag); - CHECK(locomotive.Couplers[end::rear].CouplingFlag == Coupling::none); - CHECK(wagon.Couplers[end::front].CouplingFlag == Coupling::none); + CHECK(locomotive.Couplers[VehicleEnd::rear].CouplingFlag == Coupling::none); + CHECK(wagon.Couplers[VehicleEnd::front].CouplingFlag == Coupling::none); // the front coupler of the wagon, broken on its own: no hose to tear - wagon.damage_coupler(end::front); + wagon.damage_coupler(VehicleEnd::front); CHECK(wagon.DamageFlag.HasAll(VehicleDamage::coupling)); CHECK_FALSE(wagon.AlarmChainFlag); // articulated couplers don't break consist articulated; auto &unit{articulated.add(definition::fiz("impuls_v1/31we-a_pr")).mover()}; articulated.add(definition::fiz("impuls_v1/31we-b_pr")); - unit.damage_coupler(end::rear); + unit.damage_coupler(VehicleEnd::rear); CHECK_FALSE(unit.DamageFlag.HasAll(VehicleDamage::coupling)); - CHECK(unit.Couplers[end::rear].CouplingFlag != Coupling::none); + CHECK(unit.Couplers[VehicleEnd::rear].CouplingFlag != Coupling::none); } TEST_CASE("couplers: collisions fast enough to derail") { diff --git a/tests/unit/test_definition.cpp b/tests/unit/test_definition.cpp index e9a79d9e4..2f87906ae 100644 --- a/tests/unit/test_definition.cpp +++ b/tests/unit/test_definition.cpp @@ -42,7 +42,7 @@ TEST_CASE("definition: rows of a table section reach the vehicle") { CHECK(wagon->LightsPosNo == 2); CHECK(wagon->LightsPos == 1); - CHECK(wagon->Lights[end::front][1] == pc1); + CHECK(wagon->Lights[VehicleEnd::front][1] == pc1); } TEST_CASE("definition: lines the loader skips or trims: comments, a hash anywhere, leading spaces, carriage returns") { diff --git a/tests/unit/test_derailment_vehicle.cpp b/tests/unit/test_derailment_vehicle.cpp index 1c96b4f52..32feec44d 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[VehicleEnd::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_door_closure.cpp b/tests/unit/test_door_closure.cpp index c92d8fef8..4c80670f0 100644 --- a/tests/unit/test_door_closure.cpp +++ b/tests/unit/test_door_closure.cpp @@ -50,13 +50,13 @@ TEST_CASE("door closure: a unit with permits, locked, released by the permit and CHECK(consist_closure(scenario) == door_closure_t::locked); scenario.act("permit left"); - cab.PermitDoors(side::left, true); + cab.PermitDoors(VehicleSide::left, true); scenario.wait(2.0); CHECK(last.door_closure() == door_closure_t::released); CHECK(consist_closure(scenario) == door_closure_t::released); scenario.act("the last car opens its own door"); - last.OperateDoors(side::left, true, range_t::local); + last.OperateDoors(VehicleSide::left, true, range_t::local); scenario.wait(5.0); // the cab's own doors stay closed, the train is open all the same CHECK(cab.door_closure() == door_closure_t::released); @@ -64,15 +64,15 @@ TEST_CASE("door closure: a unit with permits, locked, released by the permit and CHECK(consist_closure(scenario) == door_closure_t::open); scenario.act("close, the steps stay out under the permit"); - last.OperateDoors(side::left, false, range_t::local); - cab.OperateDoors(side::left, false); + last.OperateDoors(VehicleSide::left, false, range_t::local); + cab.OperateDoors(VehicleSide::left, false); scenario.wait(10.0); - CHECK(last.Doors.instances[side::left].position <= 0.f); + CHECK(last.Doors.instances[VehicleSide::left].position <= 0.f); // a step out isn't a closed door CHECK(consist_closure(scenario) == door_closure_t::open); scenario.act("revoke the permit"); - cab.PermitDoors(side::left, false); + cab.PermitDoors(VehicleSide::left, false); scenario.wait(10.0); CHECK(consist_closure(scenario) == door_closure_t::locked); } @@ -90,11 +90,11 @@ TEST_CASE("door closure: the doors of a unit without permits are released at a s CHECK(middle.door_closure() == door_closure_t::locked); CHECK(consist_closure(scenario) == door_closure_t::released); scenario.act("open right"); - cab.OperateDoors(side::right, true); + cab.OperateDoors(VehicleSide::right, true); scenario.wait(10.0); CHECK(consist_closure(scenario) == door_closure_t::open); scenario.act("close right"); - cab.OperateDoors(side::right, false); + cab.OperateDoors(VehicleSide::right, false); scenario.wait(10.0); CHECK(consist_closure(scenario) == door_closure_t::released); } @@ -105,8 +105,8 @@ TEST_CASE("door closure: a locomotive has no doors to signal, its coach does") { scenario.start_up(); CHECK(scenario.cab().door_closure() == door_closure_t::none); scenario.act("open right"); - scenario.cab().PermitDoors(side::right, true); - scenario.cab().OperateDoors(side::right, true); + scenario.cab().PermitDoors(VehicleSide::right, true); + scenario.cab().OperateDoors(VehicleSide::right, true); scenario.wait(10.0); CHECK(scenario.vehicle(1).door_closure() == door_closure_t::open); CHECK(consist_closure(scenario) == door_closure_t::open); diff --git a/tests/unit/test_genset.cpp b/tests/unit/test_genset.cpp index cb39e532d..be52eab9a 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.HasAny(Coupling::highVoltage)); + REQUIRE(first.Couplers[VehicleEnd::rear].CouplingFlag.HasAny(Coupling::highVoltage)); wake(first); REQUIRE(first.TractionModeSwitch(traction_mode::genset)); first.GensetSwitch(true); @@ -557,7 +557,7 @@ TEST_CASE("genset: the selector command travels along the train") { 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.HasAny(Coupling::control)); + REQUIRE(first.Couplers[VehicleEnd::rear].CouplingFlag.HasAny(Coupling::control)); wake(first); train.run(1.0, no_wire); CHECK(first.TractionModeSwitch(traction_mode::genset, range_t::consist)); diff --git a/tests/unit/test_handover.cpp b/tests/unit/test_handover.cpp index ff4a0df82..3cecb9b51 100644 --- a/tests/unit/test_handover.cpp +++ b/tests/unit/test_handover.cpp @@ -95,17 +95,17 @@ TEST_CASE("handover: the light selector moves to the position giving the head li REQUIRE(cab->LightsPos == 1); // untouched selector: lights off SUBCASE("Pc1") { - CHECK(handover::light_selector_position(cab.mover(), end::front, pc1, allheadlights) == 2); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), pc1, allheadlights) == 2); } SUBCASE("lights off") { - CHECK(handover::light_selector_position(cab.mover(), end::front, 0, allheadlights) == 1); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), 0, allheadlights) == 1); } SUBCASE("vehicle without the upper headlight, which the AI's Pc1 can't light") { auto const inventory{allheadlights & ~light::headlight_upper}; - CHECK(handover::light_selector_position(cab.mover(), end::front, pc1 & inventory, inventory) == 2); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), pc1 & inventory, inventory) == 2); } SUBCASE("no position matches: the selector stays") { - CHECK(handover::light_selector_position(cab.mover(), end::front, light::headlight_left, allheadlights) == 1); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), light::headlight_left, allheadlights) == 1); } } @@ -118,8 +118,8 @@ TEST_CASE("handover: the light selector stays within its table") { std::fill(std::begin(table) + cab->LightsPosNo, std::end(table), 0); } cab->LightsPosNo = 100; - CHECK(handover::light_selector_position(cab.mover(), end::front, pc1, allheadlights) == 2); - CHECK(handover::light_selector_position(cab.mover(), end::front, light::headlight_left, allheadlights) == 1); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), pc1, allheadlights) == 2); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), light::headlight_left, allheadlights) == 1); } SUBCASE("table other than the front or rear one: the selector stays") { CHECK(handover::light_selector_position(cab.mover(), -1, pc1, allheadlights) == 1); @@ -131,7 +131,7 @@ TEST_CASE("handover: the light selector already matching the lights stays") { auto cab{cab_vehicle()}; cab->LightsPos = 2; // Pc1 - CHECK(handover::light_selector_position(cab.mover(), end::front, pc1, allheadlights) == 2); + CHECK(handover::light_selector_position(cab.mover(), NumberOf(VehicleEnd::front), pc1, allheadlights) == 2); } TEST_CASE("handover: the headlight dimmer leaves the off position when the head lights are lit") { diff --git a/tests/unit/test_lights_preset_cablight.cpp b/tests/unit/test_lights_preset_cablight.cpp index 7c64c7d5a..fe079bfd4 100644 --- a/tests/unit/test_lights_preset_cablight.cpp +++ b/tests/unit/test_lights_preset_cablight.cpp @@ -21,7 +21,7 @@ TEST_CASE("lights preset cab light: a table without the column sets no position' .set("LightsList", "rows", {{0, 0}, {shunting, shunting}})}; REQUIRE(wagon->LightsPosNo == 2); - CHECK(wagon->Lights[end::front][1] == shunting); + CHECK(wagon->Lights[VehicleEnd::front][1] == shunting); CHECK_FALSE(wagon->LightsPresetCabLight(1).has_value()); CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value()); } @@ -35,9 +35,9 @@ TEST_CASE("lights preset cab light: the third column turns the cab light off, on REQUIRE(wagon->LightsPosNo == 5); // the light columns read as before - CHECK(wagon->Lights[end::front][2] == shunting); - CHECK(wagon->Lights[end::rear][2] == shunting); - CHECK(wagon->Lights[end::rear][4] == 0); + CHECK(wagon->Lights[VehicleEnd::front][2] == shunting); + CHECK(wagon->Lights[VehicleEnd::rear][2] == shunting); + CHECK(wagon->Lights[VehicleEnd::rear][4] == 0); auto const off{wagon->LightsPresetCabLight(1)}; REQUIRE(off.has_value()); @@ -90,7 +90,7 @@ TEST_CASE("lights preset cab light: a stray note after the two columns is not re TMoverParameters wagon(0.0, "wagon", "test", 0); REQUIRE(wagon.LoadFIZ_Text(text)); REQUIRE(wagon.LightsPosNo == 2); - CHECK(wagon.Lights[end::front][1] == 38); - CHECK(wagon.Lights[end::rear][1] == 38); + CHECK(wagon.Lights[VehicleEnd::front][1] == 38); + CHECK(wagon.Lights[VehicleEnd::rear][1] == 38); CHECK_FALSE(wagon.LightsPresetCabLight(2).has_value()); } diff --git a/tests/unit/test_lights_programmer.cpp b/tests/unit/test_lights_programmer.cpp index 8a31563d8..cb6e65103 100644 --- a/tests/unit/test_lights_programmer.cpp +++ b/tests/unit/test_lights_programmer.cpp @@ -11,18 +11,18 @@ namespace { int const pc1{light::headlight_left | light::headlight_upper | light::headlight_right}; int const tailmarkers{light::redmarker_left | light::redmarker_right}; -std::array const cablights{pc1, tailmarkers}; // Lights[end::front], Lights[end::rear] +ByEnd const cablights{pc1, tailmarkers}; // Lights[VehicleEnd::front], Lights[VehicleEnd::rear] // the lights at the vehicle's own end, placed the way TDynamicObject::RaLightsSet() places them -int lights_at(lights_programmer::consist_lights const &Lights, int const Direction, end const Side) { - auto const headend{Direction > 0 ? end::front : end::rear}; +int lights_at(lights_programmer::consist_lights const &Lights, int const Direction, VehicleEnd const Side) { + auto const headend{Direction > 0 ? VehicleEnd::front : VehicleEnd::rear}; return Side == headend ? Lights.head : Lights.rear; } struct setup { int cab; // CabOccupied of the vehicle with the programmer int direction; // its iDirection - std::array coupled; // vehicle coupled at its end::front / end::rear + ByEnd coupled; // vehicle coupled at its VehicleEnd::front / VehicleEnd::rear }; lights_programmer::consist_lights lights_for(setup const &Setup) { @@ -36,14 +36,14 @@ lights_programmer::consist_lights lights_for(setup const &Setup) { TEST_CASE("lights programmer: a lone vehicle gets the cab's front lights ahead of the cab and its back lights behind it") { for (auto const direction : {0, 1}) { CAPTURE(direction); - // cab 1 faces end::front + // cab 1 faces VehicleEnd::front auto const fromcab1{lights_for({1, direction, {false, false}})}; - CHECK(lights_at(fromcab1, direction, end::front) == pc1); - CHECK(lights_at(fromcab1, direction, end::rear) == tailmarkers); - // cab -1 faces end::rear + CHECK(lights_at(fromcab1, direction, VehicleEnd::front) == pc1); + CHECK(lights_at(fromcab1, direction, VehicleEnd::rear) == tailmarkers); + // cab -1 faces VehicleEnd::rear auto const fromcab2{lights_for({-1, direction, {false, false}})}; - CHECK(lights_at(fromcab2, direction, end::rear) == pc1); - CHECK(lights_at(fromcab2, direction, end::front) == tailmarkers); + CHECK(lights_at(fromcab2, direction, VehicleEnd::rear) == pc1); + CHECK(lights_at(fromcab2, direction, VehicleEnd::front) == tailmarkers); } } @@ -52,14 +52,14 @@ TEST_CASE("lights programmer: the end with the train coupled goes dark, not the // the end with the train goes dark, the free end shows the lights meant for it for (auto const direction : {0, 1}) { for (auto const cab : {1, -1}) { - for (auto const trainend : {end::front, end::rear}) { + for (auto const trainend : VehicleEnds) { CAPTURE(direction); CAPTURE(cab); CAPTURE(trainend); - std::array coupled{false, false}; + ByEnd coupled{false, false}; coupled[trainend] = true; - auto const freeend{trainend == end::front ? end::rear : end::front}; - auto const cabfront{cab > 0 ? end::front : end::rear}; + auto const freeend{trainend == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front}; + auto const cabfront{cab > 0 ? VehicleEnd::front : VehicleEnd::rear}; auto const lights{lights_for({cab, direction, coupled})}; @@ -71,13 +71,13 @@ TEST_CASE("lights programmer: the end with the train coupled goes dark, not the } TEST_CASE("lights programmer: 6Dg driven backwards from its second cab position pulls the train with its head lights lit (eu07/maszyna#395)") { - // the reported case: the train coupled behind the driver (end::front, which cab -1 has at its back), the - // locomotive running towards end::rear, the train in tow. the head lights stay lit, the end with the train goes dark; + // the reported case: the train coupled behind the driver (VehicleEnd::front, which cab -1 has at its back), the + // locomotive running towards VehicleEnd::rear, the train in tow. the head lights stay lit, the end with the train goes dark; // before the fix the couplings were looked up at the swapped ends and it was the other way round auto const lights{lights_for({-1, 1, {true, false}})}; - CHECK(lights_at(lights, 1, end::rear) == pc1); - CHECK(lights_at(lights, 1, end::front) == 0); + CHECK(lights_at(lights, 1, VehicleEnd::rear) == pc1); + CHECK(lights_at(lights, 1, VehicleEnd::front) == 0); } TEST_CASE("lights programmer: a vehicle coupled at both ends stays dark") { diff --git a/tests/unit/test_line_contactors_interlock.cpp b/tests/unit/test_line_contactors_interlock.cpp index 28bfee94e..91274ad35 100644 --- a/tests/unit/test_line_contactors_interlock.cpp +++ b/tests/unit/test_line_contactors_interlock.cpp @@ -62,10 +62,10 @@ TEST_CASE("line contactors interlock: on the converter, they close only with the TEST_CASE("line contactors interlock: on the motor blowers, they close only with all of them running") { auto locomotive{ready("MotorBlowers")}; - locomotive->MotorBlowers[end::front].is_active = true; - locomotive->MotorBlowers[end::rear].is_active = false; + locomotive->MotorBlowers[VehicleEnd::front].is_active = true; + locomotive->MotorBlowers[VehicleEnd::rear].is_active = false; CHECK_FALSE(locomotive->MotorConnectorsCheck()); - locomotive->MotorBlowers[end::rear].is_active = true; + locomotive->MotorBlowers[VehicleEnd::rear].is_active = true; CHECK(locomotive->MotorConnectorsCheck()); } @@ -80,10 +80,10 @@ TEST_CASE("line contactors interlock: a blower starting with the speed needs to blower.is_enabled = true; // switched on by the driver blower.is_active = false; // the vehicle stands } - REQUIRE(locomotive->MotorBlowers[end::front].start_type == start_t::manual); + REQUIRE(locomotive->MotorBlowers[VehicleEnd::front].start_type == start_t::manual); CHECK(locomotive->MotorConnectorsCheck()); - auto &rear{locomotive->MotorBlowers[end::rear]}; + auto &rear{locomotive->MotorBlowers[VehicleEnd::rear]}; SUBCASE("switched off, it holds the contactors open") { rear.is_disabled = true; CHECK_FALSE(locomotive->MotorConnectorsCheck()); @@ -118,7 +118,7 @@ TEST_CASE("line contactors interlock: a blower starting with the speed needs to namespace { bool blowers_run(TMoverParameters const &Mover) { - return Mover.MotorBlowers[end::front].is_active && Mover.MotorBlowers[end::rear].is_active; + return Mover.MotorBlowers[VehicleEnd::front].is_active && Mover.MotorBlowers[VehicleEnd::rear].is_active; } // the driver's first power position, held until the line contactors close (their delay, the pressure switch) @@ -155,8 +155,8 @@ TEST_CASE("line contactors interlock: with blowers starting with the speed the v 0.0, "test", 1}; auto &mover{eu07.mover()}; REQUIRE(mover.LineContactorsInterlock == line_contactors_interlock::motor_blowers); - REQUIRE(mover.MotorBlowers[end::front].min_start_velocity == doctest::Approx(5.0)); - REQUIRE(mover.MotorBlowers[end::rear].sustain_time == doctest::Approx(10.0)); + REQUIRE(mover.MotorBlowers[VehicleEnd::front].min_start_velocity == doctest::Approx(5.0)); + REQUIRE(mover.MotorBlowers[VehicleEnd::rear].sustain_time == doctest::Approx(10.0)); auto driven{test::driving(eu07)}; REQUIRE(test::start_up(driven, line)); release(driven); @@ -221,7 +221,7 @@ TEST_CASE("line contactors interlock: a blower starting with the speed, switched REQUIRE(close_line_contactors(driven)); // the switch of the rear blower: off, the contactors open and stay open, standing as well as later - REQUIRE(mover.MotorBlowersSwitchOff(true, end::rear)); + REQUIRE(mover.MotorBlowersSwitchOff(true, VehicleEnd::rear)); test::drive(driven, line, 2.0); CHECK_FALSE(mover.StLinFlag); CHECK(std::abs(mover.Im) < 0.5); @@ -232,7 +232,7 @@ TEST_CASE("line contactors interlock: a blower starting with the speed, switched CHECK_FALSE(close_line_contactors(driven)); // back on, the vehicle starts - REQUIRE(mover.MotorBlowersSwitchOff(false, end::rear)); + REQUIRE(mover.MotorBlowersSwitchOff(false, VehicleEnd::rear)); while (mover.DecMainCtrl(1)) { // down to zero } diff --git a/tests/unit/test_loads.cpp b/tests/unit/test_loads.cpp index b4a9da62a..9440cd450 100644 --- a/tests/unit/test_loads.cpp +++ b/tests/unit/test_loads.cpp @@ -23,8 +23,8 @@ TEST_CASE("loads: the pantographs of an electric vehicle set up by the amount of vehicle et42{definition::fiz("et42_v2/112e-a")}; CHECK(et42->AssignLoad("pantstate", static_cast(amount))); CHECK(et42->DoubleTr == ((amount & 4) != 0 ? -1 : 1)); - CHECK(et42->Pantographs[end::front].valve.is_enabled == frontraised); - CHECK(et42->Pantographs[end::rear].valve.is_enabled == rearraised); + CHECK(et42->Pantographs[VehicleEnd::front].valve.is_enabled == frontraised); + CHECK(et42->Pantographs[VehicleEnd::rear].valve.is_enabled == rearraised); // the load itself stays as it was CHECK(et42->LoadAmount == doctest::Approx(0.0)); } diff --git a/tests/unit/test_mains_before_pantographs.cpp b/tests/unit/test_mains_before_pantographs.cpp index e9c70bb4c..efab5a572 100644 --- a/tests/unit/test_mains_before_pantographs.cpp +++ b/tests/unit/test_mains_before_pantographs.cpp @@ -39,7 +39,7 @@ void prepare(test::vehicle &Loco) { void raise_pantograph(test::vehicle &Loco, test::track const &Track = line) { Loco->OperatePantographsValve(operation_t::enable); - Loco->OperatePantographValve(end::rear, operation_t::enable); + Loco->OperatePantographValve(VehicleEnd::rear, operation_t::enable); Loco.run(5.0, Track); } @@ -93,17 +93,17 @@ TEST_CASE("mains before pantographs: without the flag the line breaker needs the close_line_breaker(loco); CHECK_FALSE(loco->Mains); raise_pantograph(loco); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); close_line_breaker(loco); CHECK(loco->Mains); // the pantographs stay up with the line breaker open, and the line breaker opens without voltage loco->MainSwitch(false); loco.run(2.0, line); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); close_line_breaker(loco); REQUIRE(loco->Mains); - loco->OperatePantographValve(end::rear, operation_t::disable); + loco->OperatePantographValve(VehicleEnd::rear, operation_t::disable); loco.run(2.0, line); CHECK_FALSE(loco->Mains); } @@ -114,28 +114,28 @@ TEST_CASE("mains before pantographs: with the flag the pantographs rise only thr prepare(loco); // the pantographs stay down while the line breaker is open raise_pantograph(loco); - CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == 0.0); // the line breaker closes without voltage, and the pantograph rises through it close_line_breaker(loco); CHECK(loco->Mains); raise_pantograph(loco); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); CHECK(loco->Mains); // opening the line breaker drops the pantograph, which stays down until the line breaker closes again loco->MainSwitch(false); loco.run(2.0, line); CHECK_FALSE(loco->Mains); - CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == 0.0); // a pantograph lowered under the closed line breaker leaves it closed close_line_breaker(loco); raise_pantograph(loco); - REQUIRE(loco->Pantographs[end::rear].is_active); - loco->OperatePantographValve(end::rear, operation_t::disable); + REQUIRE(loco->Pantographs[VehicleEnd::rear].is_active); + loco->OperatePantographValve(VehicleEnd::rear, operation_t::disable); loco.run(5.0, line); - CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->Mains); } @@ -190,14 +190,14 @@ TEST_CASE("mains before pantographs: with the flag the converter and the compres // the voltage gone they stop, behind the line breaker which stays closed auto const *track{&line}; SUBCASE("the pantograph lowered again") { - loco->OperatePantographValve(end::rear, operation_t::disable); + loco->OperatePantographValve(VehicleEnd::rear, operation_t::disable); loco.run(5.0, line); - REQUIRE_FALSE(loco->Pantographs[end::rear].is_active); + REQUIRE_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); } SUBCASE("no voltage in the catenary") { track = &dead; loco.run(5.0, dead); - REQUIRE(loco->Pantographs[end::rear].is_active); + REQUIRE(loco->Pantographs[VehicleEnd::rear].is_active); } SUBCASE("the voltage in the catenary below the one the locomotive works on") { track = &weak; @@ -222,14 +222,14 @@ TEST_CASE("mains before pantographs: with the flag whatever else the main circui close_line_breaker(loco); REQUIRE(loco->Mains); loco->CompressorSwitch(true); - loco->MotorBlowersSwitch(true, end::front); + loco->MotorBlowersSwitch(true, VehicleEnd::front); loco->RVentForceOn = true; loco->HeatingSwitch(true); loco.hold_main_reservoir(-1.0); CHECK(reservoir_gain(loco, 10.0, line) < 0.01); CHECK_FALSE(loco->CompressorFlag); - CHECK_FALSE(loco->MotorBlowers[end::front].is_active); + CHECK_FALSE(loco->MotorBlowers[VehicleEnd::front].is_active); CHECK(loco->RventRot == 0.0); CHECK_FALSE(loco->Heating); @@ -239,7 +239,7 @@ TEST_CASE("mains before pantographs: with the flag whatever else the main circui CHECK(reservoir_gain(loco, 10.0, weak) < 0.01); CHECK(loco->Mains); CHECK_FALSE(loco->CompressorFlag); - CHECK_FALSE(loco->MotorBlowers[end::front].is_active); + CHECK_FALSE(loco->MotorBlowers[VehicleEnd::front].is_active); CHECK(loco->RventRot == 0.0); CHECK_FALSE(loco->Heating); } @@ -248,7 +248,7 @@ TEST_CASE("mains before pantographs: with the flag whatever else the main circui REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); CHECK(reservoir_gain(loco, 10.0, line) > 0.1); CHECK(loco->CompressorFlag); - CHECK(loco->MotorBlowers[end::front].is_active); + CHECK(loco->MotorBlowers[VehicleEnd::front].is_active); CHECK(loco->RventRot > 0.0); CHECK(loco->Heating); } @@ -288,7 +288,7 @@ TEST_CASE("mains before pantographs: with the flag the line contactors open when // the voltage goes: the line breaker holds, the pantograph stays up, the motors are cut off test::drive(driven, dead, 3.0); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK_FALSE(loco->NoVoltRelay); CHECK_FALSE(loco->StLinFlag); CHECK(loco->Im == 0.0); diff --git a/tests/unit/test_pressure_switch.cpp b/tests/unit/test_pressure_switch.cpp index df142574d..bb548ecb4 100644 --- a/tests/unit/test_pressure_switch.cpp +++ b/tests/unit/test_pressure_switch.cpp @@ -50,7 +50,7 @@ void get_ready(test::vehicle &Loco, test::driven const &Driven) { } REQUIRE_FALSE(Loco->ControlPressureSwitch); REQUIRE(Loco->Mains); - REQUIRE(Loco->Pantographs[end::rear].is_active); + REQUIRE(Loco->Pantographs[VehicleEnd::rear].is_active); } // the master controller taken to the given position a notch a second @@ -109,7 +109,7 @@ TEST_CASE("pressure switch: with the brake cylinders at 3.8 bar the EP05 takes n CHECK_FALSE(loco->StLinFlag); CHECK(loco->Im == 0.0); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); } TEST_CASE("pressure switch: without its brake cylinder half the EP05 takes current with the brake cylinders at 3.8 bar") { @@ -149,7 +149,7 @@ TEST_CASE("pressure switch: without its brake cylinder half the brake pipe still CHECK(loco->Im == 0.0); // nothing else lets go without the other key CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); } TEST_CASE("pressure switch: an emergency application with the master controller on a power position opens the line breaker and drops the pantographs") { @@ -167,8 +167,8 @@ TEST_CASE("pressure switch: an emergency application with the master controller REQUIRE(loco->PipePress < emergency_pressure); REQUIRE(loco->MainCtrlPos == 5); CHECK_FALSE(loco->Mains); - CHECK_FALSE(loco->Pantographs[end::front].is_active); - CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::front].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == 0.0); CHECK_FALSE(loco->StLinFlag); CHECK(loco->Im == 0.0); @@ -177,7 +177,7 @@ TEST_CASE("pressure switch: an emergency application with the master controller loco->MainSwitch(true); test::drive(driven, line, 2.0); CHECK_FALSE(loco->Mains); - CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); } TEST_CASE("pressure switch: an emergency application with the master controller at zero leaves the line breaker and the pantographs alone") { @@ -192,7 +192,7 @@ TEST_CASE("pressure switch: an emergency application with the master controller emergency_application(loco, driven); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); CHECK(loco->Im == 0.0); @@ -200,7 +200,7 @@ TEST_CASE("pressure switch: an emergency application with the master controller loco->IncMainCtrl(1); test::drive(driven, line, 2.0); CHECK_FALSE(loco->Mains); - CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); } TEST_CASE("pressure switch: a service application with the master controller on a power position doesn't open the line breaker") { @@ -219,7 +219,7 @@ TEST_CASE("pressure switch: a service application with the master controller on REQUIRE(lowest < 3.0); CHECK(lowest > emergency_pressure); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); // the pressure switch has cut the motors off CHECK_FALSE(loco->StLinFlag); CHECK(loco->Im == 0.0); @@ -233,7 +233,7 @@ TEST_CASE("pressure switch: without the key an emergency application leaves the emergency_application(loco, driven); REQUIRE(loco->MainCtrlPos == 5); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); // the pressure switch cuts the motors off CHECK(loco->ControlPressureSwitch); @@ -249,7 +249,7 @@ TEST_CASE("pressure switch: where the pantographs don't hang on the line breaker emergency_application(loco, driven); CHECK_FALSE(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); CHECK_FALSE(loco->StLinFlag); CHECK(loco->Im == 0.0); @@ -264,20 +264,20 @@ TEST_CASE("pressure switch: after the emergency application the driver's start-u get_under_power(loco, driven, 5); emergency_application(loco, driven); REQUIRE_FALSE(loco->Mains); - REQUIRE_FALSE(loco->Pantographs[end::rear].is_active); - REQUIRE(loco->Pantographs[end::rear].valve.is_enabled); + REQUIRE_FALSE(loco->Pantographs[VehicleEnd::rear].is_active); + REQUIRE(loco->Pantographs[VehicleEnd::rear].valve.is_enabled); // with the brake pipe still empty REQUIRE(test::start_up(driven, line, 60.0)); CHECK(loco->MainCtrlPos == 0); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); REQUIRE(loco->PipePress < emergency_pressure); // and it stays so test::drive(driven, line, 30.0); CHECK(loco->Mains); - CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->Pantographs[VehicleEnd::rear].is_active); // the brakes released (the AI fills an emptied pipe with the releaser held, TController::control_releaser()), // the pressure switch lets the start be made diff --git a/tests/unit/test_pullee.cpp b/tests/unit/test_pullee.cpp index 41a3b69e2..dc5235c08 100644 --- a/tests/unit/test_pullee.cpp +++ b/tests/unit/test_pullee.cpp @@ -49,7 +49,7 @@ void drain_feed_air(TMoverParameters &Vehicle) { // whether the real vehicle can go in a train at all: the road vehicles can't, nor can the draisine, which has no coupler bool can_be_hauled(std::string const &Path) { vehicle probe{definition::fiz(Path)}; - return (probe->CategoryFlag & 1) != 0 && probe->Couplers[end::front].CouplerType != TCouplerType::NoCoupler; + return (probe->CategoryFlag & 1) != 0 && probe->Couplers[VehicleEnd::front].CouplerType != TCouplerType::NoCoupler; } } // namespace diff --git a/tests/unit/test_queries.cpp b/tests/unit/test_queries.cpp index 677b993eb..490c57be4 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(VehicleEnd::rear, VehicleEnd::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 7946d3d84..fa9c99746 100644 --- a/tests/unit/vehicle.cpp +++ b/tests/unit/vehicle.cpp @@ -225,8 +225,8 @@ double vehicle::move(track const &Track, double Dt, TLocation const &Location, d // what TDynamicObject::Update() does before the movement. a raised pantograph touches the wire at once, // the game animates its rise auto &mover{*m_mover}; - mover.PantFrontVolt = mover.Pantographs[end::front].is_active ? Track.voltage : 0.0; - mover.PantRearVolt = mover.Pantographs[end::rear].is_active ? Track.voltage : 0.0; + mover.PantFrontVolt = mover.Pantographs[VehicleEnd::front].is_active ? Track.voltage : 0.0; + mover.PantRearVolt = mover.Pantographs[VehicleEnd::rear].is_active ? Track.voltage : 0.0; TTractionParam traction; traction.TractionVoltage = mover.EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? std::max(std::abs(mover.PantRearVolt), std::abs(mover.PantFrontVolt)) : 0.95 * mover.EnginePowerSource.MaxVoltage; @@ -291,12 +291,12 @@ TDynamicObject *as_neighbour(std::byte *Standin) { } // namespace -pair::pair(vehicle &First, int FirstEnd, vehicle &Second, int SecondEnd, double Gap) { +pair::pair(vehicle &First, VehicleEnd FirstEnd, vehicle &Second, VehicleEnd SecondEnd, double Gap) { auto const &first{First.mover()}; auto const &second{Second.mover()}; // the first vehicle in the middle, its FirstEnd towards the second one - m_vehicles[0] = {&First, FirstEnd, 0.0, FirstEnd == end::front ? 1.0 : -1.0, make_standin(First.mover())}; - m_vehicles[1] = {&Second, SecondEnd, 0.5 * first.Dim.L + Gap + 0.5 * second.Dim.L, SecondEnd == end::front ? -1.0 : 1.0, make_standin(Second.mover())}; + m_vehicles[0] = {&First, FirstEnd, 0.0, FirstEnd == VehicleEnd::front ? 1.0 : -1.0, make_standin(First.mover())}; + m_vehicles[1] = {&Second, SecondEnd, 0.5 * first.Dim.L + Gap + 0.5 * second.Dim.L, SecondEnd == VehicleEnd::front ? -1.0 : 1.0, make_standin(Second.mover())}; } pair::~pair() { @@ -320,10 +320,10 @@ void pair::find_neighbours() { auto const &othermover{other.owner->mover()}; auto &neighbour{mover.Neighbours[self.end]}; neighbour.vehicle = as_neighbour(other.standin.data()); - neighbour.vehicle_end = other.end; + neighbour.vehicle_end = NumberOf(other.end); neighbour.distance = static_cast(TMoverParameters::CouplerDist(&mover, &othermover) - mover.Couplers[self.end].adapter_length - othermover.Couplers[other.end].adapter_length); - mover.Neighbours[1 - self.end] = neighbour_data(); + mover.Neighbours[Opposite(self.end)] = neighbour_data(); } } diff --git a/tests/unit/vehicle.h b/tests/unit/vehicle.h index 97c4cf6a1..f83c50b7e 100644 --- a/tests/unit/vehicle.h +++ b/tests/unit/vehicle.h @@ -133,12 +133,12 @@ private: // vehicles of a scene (vehicle_table::update()): each one finds its neighbour, then both take the forces, the // coupler and buffer ones among them (CouplerForce()), then both move and handle the collisions (CollisionDetect()). // they couple and part on their own, as the couplers let them; the speed of each runs along its own axis -// test::pair pair{moving, end::front, standing, end::rear, 1.0}; // 1 m apart +// test::pair pair{moving, VehicleEnd::front, standing, VehicleEnd::rear, 1.0}; // 1 m apart // pair.run(5.0); // for 5 s // CHECK(pair.coupled()); class pair { public: - pair(vehicle &First, int FirstEnd, vehicle &Second, int SecondEnd, double Gap); + pair(vehicle &First, VehicleEnd FirstEnd, vehicle &Second, VehicleEnd SecondEnd, double Gap); ~pair(); pair(pair const &) = delete; pair &operator=(pair const &) = delete; @@ -159,7 +159,7 @@ public: private: struct placement { vehicle *owner{nullptr}; - int end{0}; // the end facing the other vehicle + VehicleEnd end{VehicleEnd::front}; // the end facing the other vehicle double position{0.0}; // of the middle of the vehicle along the track [m] double heading{1.0}; // +1 when the vehicle runs forwards towards the growing position, -1 otherwise std::vector standin; // what the other vehicle sees as this one, see vehicle.cpp diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 945233f6d..2cde64ee6 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -275,7 +275,7 @@ public: // what the AI would do at this place and speed, worked out also while a human drives, for the black box blackbox::ai_reference ai_reference() const; // the light pattern the timetable or the scenery asks for at an end of the train, -1 the usual one - int light_hint( int const End ) const { return m_lighthints[ End ]; } + int light_hint( VehicleEnd const End ) const { return m_lighthints[ End ]; } // the order the driver goes by now: a train run, shunting and the like DriverOrders order_current() const { return OrderCurrentGet(); } private: @@ -424,7 +424,7 @@ private: TMoverParameters *mvOccupied = nullptr; // jakim pojazdem hamuje TMoverParameters *mvPantographUnit = nullptr; //pantograph equipped vehicle in the occupied/controlled set std::string VehicleName; - std::array m_lighthints = { -1, -1 }; // suggested light patterns + ByEnd m_lighthints = { -1, -1 }; // suggested light patterns double AccPreferred = 0.0; // preferowane przyspieszenie (wg psychiki kierującego, zmniejszana przy wykryciu kolizji) double AccDesired = 0.0; // przyspieszenie, jakie ma utrzymywać (<0:nie przyspieszaj,<-0.1:hamuj) double VelDesired = 0.0; // predkość, z jaką ma jechać, wynikająca z analizy tableki; <=VelSignal @@ -618,8 +618,8 @@ private: int TableDirection() { return iTableDirection; } // Ra: stare funkcje skanujące, używane do szukania sygnalizatora z tyłu bool IsOccupiedByAnotherConsist( TTrack *Track, double const Distance = 0 ); - basic_event *CheckTrackEventBackward( double fDirection, TTrack *Track, TDynamicObject *Vehicle, int const Eventdirection = 1, end const End = end::rear ); - TTrack *BackwardTraceRoute( double &fDistance, double &fDirection, TDynamicObject *Vehicle, basic_event *&Event, int const Eventdirection = 1, end const End = end::rear, bool const Untiloccupied = true ); + basic_event *CheckTrackEventBackward( double fDirection, TTrack *Track, TDynamicObject *Vehicle, int const Eventdirection = 1, VehicleEnd const End = VehicleEnd::rear ); + TTrack *BackwardTraceRoute( double &fDistance, double &fDirection, TDynamicObject *Vehicle, basic_event *&Event, int const Eventdirection = 1, VehicleEnd const End = VehicleEnd::rear, bool const Untiloccupied = true ); void SetProximityVelocity( double dist, double vel, glm::dvec3 const *pos ); TCommandType BackwardScan( double const Range ); std::string TableText( std::size_t const Index ) const; @@ -718,11 +718,11 @@ private: bool Ready = false; // ABu: stan gotowosci do odjazdu - sprawdzenie odhamowania wagonow bool IsConsistBraked { false }; double ConsistShade{ 1.0 }; // averaged amount of sunlight received by the consist - TDynamicObject *pVehicles[ 2 ]; // skrajne pojazdy w składzie (niekoniecznie bezpośrednio sterowane) + ByEnd pVehicles; // skrajne pojazdy w składzie (niekoniecznie bezpośrednio sterowane) bool DoesAnyDoorNeedOpening{ false }; - bool IsAnyDoorOpen[ 2 ]; // state of door in the consist - bool IsAnyDoorOnlyOpen[ 2 ]; // state of door in the consist regardless of step - bool IsAnyDoorPermitActive[ 2 ]; // state of door permit in the consist + BySide IsAnyDoorOpen; // state of door in the consist + BySide IsAnyDoorOnlyOpen; // state of door in the consist regardless of step + BySide IsAnyDoorPermitActive; // state of door permit in the consist door_closure_t DoorClosure{ door_closure_t::none }; // state of the door closure signalling (SOD) of the consist bool IsAnyLineBreakerOpen{ false }; // state of line breaker in all powered vehicles under control bool IsAnyConverterOverloadRelayOpen{ false }; // state of converter overload relays in all vehicles under control @@ -762,7 +762,7 @@ public: return WriteLogFlag || ( WriteTrainLogFlag && is_train() && primary() ); } static std::string_view physicslog_header(); std::string physicslog_line() const; - TDynamicObject *Vehicle( end const Side ) const { + TDynamicObject *Vehicle( VehicleEnd const Side ) const { return pVehicles[ Side ]; } private: std::string OwnerName() const; diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index afe730d07..bd6fba732 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -200,7 +200,7 @@ public: //private: // położenie pojazdu w świecie oraz parametry ruchu glm::dvec3 vPosition; // Ra: pozycja pojazdu liczona zaraz po przesunięciu - glm::dvec3 vCoulpler[2]; // współrzędne sprzęgów do liczenia zderzeń czołowych + ByEnd vCoulpler; // współrzędne sprzęgów do liczenia zderzeń czołowych glm::dvec3 vUp, vFront, vLeft; // wektory jednostkowe ustawienia pojazdu int iDirection; // kierunek pojazdu względem czoła składu (1=zgodny,0=przeciwny) TTrackShape ts; // parametry toru przekazywane do fizyki @@ -415,14 +415,14 @@ private: sound_source step_open { sound_placement::general }; sound_source step_close { sound_placement::general }; sound_source permit_granted { sound_placement::general }; - side placement {}; + VehicleSide placement {}; }; struct mirror_sounds { sound_source unfold { sound_placement::general }; sound_source fold { sound_placement::general }; - side placement {}; - int end {}; // of the vehicle, the mirror moves with the cab at this end occupied + VehicleSide placement {}; + VehicleEnd end {}; // of the vehicle, the mirror moves with the cab at this end occupied }; struct exchange_sounds { @@ -509,7 +509,7 @@ private: // members AirCoupler btCoupler1; // sprzegi AirCoupler btCoupler2; - std::array m_coupleradapters = { nullptr, nullptr }; + ByEnd m_coupleradapters = { nullptr, nullptr }; AirCoupler btCPneumatic1; // sprzegi powietrzne //yB - zmienione z Button na AirCoupler - krzyzyki AirCoupler btCPneumatic2; AirCoupler btCPneumatic1r; // ABu: to zeby nie bylo problemow przy laczeniu wagonow, @@ -598,12 +598,12 @@ private: // moving part and other external sounds sound_source m_startjolt { sound_placement::general }; // movement start jolt, played once on initial acceleration at slow enough speed bool m_startjoltplayed { false }; - std::array m_couplersounds; // always front and rear + ByEnd m_couplersounds; // always front and rear std::vector m_pantographsounds; // typically 2 but can be less (or more?) std::vector m_doorsounds; // can expect symmetrical arrangement, but don't count on it bool m_doorlocks { false }; // sound helper, current state of door locks std::vector m_mirrorsounds; - std::array m_mirrormotion; // indexed by side: right, left + BySide m_mirrormotion; // indexed by side: right, left sound_source sHorn1 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE }; sound_source sHorn2 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE }; sound_source sHorn3 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE }; @@ -636,7 +636,7 @@ private: bool renderme; // yB - czy renderowac float ModCamRot; - int iInventory[ 2 ] { 0, 0 }; // flagi bitowe posiadanych submodeli (np. świateł) + ByEnd iInventory { 0, 0 }; // flagi bitowe posiadanych submodeli (np. świateł) bool btnOn; // ABu: czy byly uzywane buttony, jesli tak, to po renderingu wylacz // bo ten sam model moze byc jeszcze wykorzystany przez inny obiekt! @@ -687,7 +687,7 @@ private: TDynamicObject * ABuScanNearestObject(glm::vec3 pos, TTrack *Track, double ScanDir, double ScanDist, int &CouplNr); - TDynamicObject * GetFirstDynamic(int cpl_type, CouplingSet cf = Coupling::coupler); + TDynamicObject * GetFirstDynamic(VehicleEnd 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 @@ -747,7 +747,7 @@ private: double off_track_offset() const; // the gap between the ends of the vehicle and the one at its End, as they meet off the track [m]: negative the // buffers pressed in - double off_track_gap( int End ) const; + double off_track_gap( VehicleEnd End ) const; private: // the axles moved along their tracks by the distance void move_axles( double Distance ); @@ -792,14 +792,14 @@ private: // the most triangles of terrain taken around the vehicle off the track static constexpr std::size_t off_track_triangles { 400000 }; bool m_offtrackplaced { false }; // placed off the track: placed on it again once it's back on the rails - std::array m_pulledoff; // the distance the coupling of an end pulled the vehicle coupled there over the climbing limit + ByEnd m_pulledoff; // the distance the coupling of an end pulled the vehicle coupled there over the climbing limit derailment::stretch m_struck; // on the rails: the distance a body off the track pushed it sideways over the climbing limit // the model, the axes and the coupling points placed by the motion off the track void place_off_track(); public: void RenderSounds(); // plays the sounds of the mirrors on the Side, of the occupied cab, starting the Event - void play_mirror_sounds( side const Side, mirror_moves::event const Event ); + void play_mirror_sounds( VehicleSide const Side, mirror_moves::event const Event ); inline glm::dvec3 GetPosition() const { return vPosition; }; // converts location from vehicle coordinates frame to world frame @@ -811,7 +811,7 @@ public: // pobranie współrzędnych tyłu inline glm::dvec3 RearPosition() const { return vCoulpler[iDirection]; }; - inline glm::dvec3 CouplerPosition( end const End ) const { + inline glm::dvec3 CouplerPosition( VehicleEnd const End ) const { return vCoulpler[ End ]; } inline glm::dvec3 AxlePositionGet() { return iAxleFirst ? @@ -870,21 +870,21 @@ public: Axle1.GetTrack() : Axle0.GetTrack(); }; - void couple( int const Side ); - int uncouple( int const Side ); - bool attach_coupler_adapter( int const Side, bool const Enforce = false ); - bool remove_coupler_adapter( int const Side ); + void couple( VehicleEnd const Side ); + int uncouple( VehicleEnd const Side ); + bool attach_coupler_adapter( VehicleEnd const Side, bool const Enforce = false ); + bool remove_coupler_adapter( VehicleEnd const Side ); void RadioStop(); void Damage(char flag); void pants_up(); void SetLights(); void SetLightDimmings(); void RaLightsSet(int head, int rear); - int LightList( end const Side ) const { return iInventory[ Side ]; } + int LightList( VehicleEnd const Side ) const { return iInventory[ Side ]; } bool has_signal_pc1_on() const; bool has_signal_pc2_on() const; bool has_signal_pc5_on() const; - bool has_signal_on( int const Side, int const Pattern ) const; + bool has_signal_on( VehicleEnd const Side, int const Pattern ) const; void set_cab_lights( int const Cab, float const Level ); TDynamicObject * FirstFind(int &coupler_nr, CouplingSet cf = Coupling::coupler); float GetEPP(); // wyliczanie sredniego cisnienia w PG diff --git a/vehicle/Train.h b/vehicle/Train.h index 8e51447ce..9c017a628 100644 --- a/vehicle/Train.h +++ b/vehicle/Train.h @@ -243,10 +243,10 @@ class TTrain { void update_sounds_radio(); void update_sounds_fmradio( double const Deltatime ); inline - end cab_to_end( int const End ) const { - return End == 2 ? end::rear : end::front; } + VehicleEnd cab_to_end( int const End ) const { + return End == 2 ? VehicleEnd::rear : VehicleEnd::front; } inline - end cab_to_end() const { + VehicleEnd cab_to_end() const { return cab_to_end( iCabn ); } void update_screens(double dt); void update_script_screens(); @@ -961,7 +961,7 @@ private: std::string asCarName[20]; // nazwa czlonu bool bMains[8]; // WSy float fCntVol[8]; // napiecie NN - bool bPants[8][2]; // podniesienie pantografow + std::array, 8> bPants; // podniesienie pantografow bool bFuse[8]; // nadmiarowe bool bBatt[8]; // baterie bool bConv[8]; // przetwornice @@ -985,7 +985,7 @@ private: bool m_dirneutral{ false }; // helper, true if direction set to neutral bool m_dirbackward{ false }; // helper, true if direction set to backward bool m_doorpermits{ false }; // helper, true if any door permit is active - float m_doorpermittimers[2] = { -1.f, -1.f }; + BySide m_doorpermittimers = { -1.f, -1.f }; float trainLenghtMeasureTimer = { -1.f }; // ld substitute bool m_couplingdisconnect { false }; diff --git a/vehicle/ai/consist.cpp b/vehicle/ai/consist.cpp index 8fa123ed9..b0774eccf 100644 --- a/vehicle/ai/consist.cpp +++ b/vehicle/ai/consist.cpp @@ -66,7 +66,7 @@ void TController::Activation() ZeroDirection(); mvOccupied->CabOccupied = mvOccupied->CabActive; // użytkownik moze zmienić CabOccupied wychodząc mvOccupied->CabDeactivisation(); // tak jest w Train.cpp - if (pVehicle->MoverParameters->Couplers[iDirectionOrder < 0 ? end::rear : end::front].CouplingFlag.HasAll(Coupling::control)) { + if (pVehicle->MoverParameters->Couplers[iDirectionOrder < 0 ? VehicleEnd::rear : VehicleEnd::front].CouplingFlag.HasAll(Coupling::control)) { ZeroLocalBrake(); if( initialspringbrakestate ) { mvOccupied->SpringBrakeActivate( false ); @@ -78,7 +78,7 @@ void TController::Activation() // przejście AI na drugą stronę EN57, ET41 itp. // TODO: clean this up, there's lot of redundancy with TMoverParameters::ChangeCab() and TTrain::MoveToVehicle() { - int movedirection { ( iDirection < 0 ? end::rear : end::front ) }; + int movedirection { NumberOf( iDirection < 0 ? VehicleEnd::rear : VehicleEnd::front ) }; 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 @@ -304,7 +304,7 @@ bool TController::CheckVehicles(DriverOrders user) if (!p) p = pVehicle; auto *const frontvehicle { p }; // stays the consist head for the rest of this check - pVehicles[end::front] = frontvehicle; + pVehicles[VehicleEnd::front] = frontvehicle; // liczenie pojazdów w składzie i ustalenie parametrów auto dir = d = 1 - d; // a dalej będziemy zliczać od czoła do tyłu fLength = 0.0; // długość składu do badania wyjechania za ograniczenie @@ -333,7 +333,7 @@ bool TController::CheckVehicles(DriverOrders user) } } ++iVehicles; // jest jeden pojazd więcej - pVehicles[end::rear] = p; // zapamiętanie ostatniego + pVehicles[VehicleEnd::rear] = p; // zapamiętanie ostatniego fLength += p->MoverParameters->Dim.L; // dodanie długości pojazdu fMass += p->MoverParameters->TotalMass; // dodanie masy łącznie z ładunkiem fVelMax = min_speed( fVelMax, p->MoverParameters->Vmax ); // ustalenie maksymalnej prędkości dla składu @@ -441,7 +441,7 @@ bool TController::CheckVehicles(DriverOrders user) } // detect push-pull train configurations and mark them accordingly - if( frontvehicle->is_connected( pVehicles[ end::rear ], Coupling::control ) ) { + if( frontvehicle->is_connected( pVehicles[ VehicleEnd::rear ], Coupling::control ) ) { // zmiana czoła przez zmianę kabiny drivingFlags.pushPull = true; } @@ -462,7 +462,7 @@ bool TController::CheckVehicles(DriverOrders user) // światła manewrowe (Tb1) tylko z przodu, aby nie pozostawić odczepionego ze światłem if (mvOccupied->DirActive >= 0) { // jak ma kierunek do przodu - pVehicles[end::rear]->RaLightsSet(-1, 0); + pVehicles[VehicleEnd::rear]->RaLightsSet(-1, 0); } else { // jak dociska @@ -477,7 +477,7 @@ bool TController::CheckVehicles(DriverOrders 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[ VehicleEnd::rear ], Coupling::heating ) : true ) }; auto const isheatingneeded { (is_emu() || is_dmu() ? true : @@ -505,8 +505,8 @@ bool TController::CheckVehicles(DriverOrders user) void TController::Lights(int head, int rear) { // zapalenie świateł w skłądzie - pVehicles[ end::front ]->RaLightsSet(head, -1); // zapalenie przednich w pierwszym - pVehicles[ end::rear ]->RaLightsSet(-1, rear); // zapalenie końcówek w ostatnim + pVehicles[ VehicleEnd::front ]->RaLightsSet(head, -1); // zapalenie przednich w pierwszym + pVehicles[ VehicleEnd::rear ]->RaLightsSet(-1, rear); // zapalenie końcówek w ostatnim } void TController::DirectionInitial() @@ -706,12 +706,12 @@ TController::determine_consist_state() { mvOccupied->PipePress < std::max(3.9, mvOccupied->BrakePressureActual.PipePressureVal) + 0.1; fAccGravity = 0.0; // przyspieszenie wynikające z pochylenia IsAnyCouplerStretched = false; - IsAnyDoorOnlyOpen[ side::right ] = IsAnyDoorOnlyOpen[ side::left ] = false; - IsAnyDoorOpen[ side::right ] = IsAnyDoorOpen[ side::left ] = false; - IsAnyDoorPermitActive[ side::right ] = IsAnyDoorPermitActive[ side::left ] = false; + IsAnyDoorOnlyOpen[ VehicleSide::right ] = IsAnyDoorOnlyOpen[ VehicleSide::left ] = false; + IsAnyDoorOpen[ VehicleSide::right ] = IsAnyDoorOpen[ VehicleSide::left ] = false; + IsAnyDoorPermitActive[ VehicleSide::right ] = IsAnyDoorPermitActive[ VehicleSide::left ] = false; auto doorclosure { door_closure_t::none }; ConsistShade = 0.0; - auto *p { pVehicles[ end::front ] }; // pojazd na czole składu + auto *p { pVehicles[ VehicleEnd::front ] }; // pojazd na czole składu double dy; // składowa styczna grawitacji, w przedziale <0,1> // starting uphill the power is applied against the train brake on purpose, until the power holds the train and // then while the brake releases @@ -774,24 +774,24 @@ TController::determine_consist_state() { // check coupler state IsAnyCouplerStretched = IsAnyCouplerStretched - || vehicle->Couplers[end::front].stretch_duration > 0.0 - || vehicle->Couplers[end::rear].stretch_duration > 0.0; + || vehicle->Couplers[VehicleEnd::front].stretch_duration > 0.0 + || vehicle->Couplers[VehicleEnd::rear].stretch_duration > 0.0; // check door state { auto const switchsides{ p->DirectionGet() != (iDirection == 0 ? mvOccupied->CabOccupied : iDirection) }; - auto const &rightdoor { vehicle->Doors.instances[ ( switchsides ? side::left : side::right ) ] }; - auto const &leftdoor { vehicle->Doors.instances[ ( switchsides ? side::right : side::left ) ] }; + auto const &rightdoor { vehicle->Doors.instances[ ( switchsides ? VehicleSide::left : VehicleSide::right ) ] }; + auto const &leftdoor { vehicle->Doors.instances[ ( switchsides ? VehicleSide::right : VehicleSide::left ) ] }; if( vehicle->Doors.close_control != control_t::autonomous ) { - IsAnyDoorOpen[ side::right ] |= false == rightdoor.is_closed; - IsAnyDoorOpen[ side::left ] |= false == leftdoor.is_closed; + IsAnyDoorOpen[ VehicleSide::right ] |= false == rightdoor.is_closed; + IsAnyDoorOpen[ VehicleSide::left ] |= false == leftdoor.is_closed; } if (vehicle->Doors.close_control != control_t::autonomous) { - IsAnyDoorOnlyOpen[ side::right ] |= false == rightdoor.is_door_closed; - IsAnyDoorOnlyOpen[ side::left ] |= false == leftdoor.is_door_closed; + IsAnyDoorOnlyOpen[ VehicleSide::right ] |= false == rightdoor.is_door_closed; + IsAnyDoorOnlyOpen[ VehicleSide::left ] |= false == leftdoor.is_door_closed; } if( vehicle->Doors.permit_needed ) { - IsAnyDoorPermitActive[ side::right ] |= rightdoor.open_permit; - IsAnyDoorPermitActive[ side::left ] |= leftdoor.open_permit; + IsAnyDoorPermitActive[ VehicleSide::right ] |= rightdoor.open_permit; + IsAnyDoorPermitActive[ VehicleSide::left ] |= leftdoor.open_permit; } doorclosure = std::max( doorclosure, vehicle->door_closure() ); } @@ -842,7 +842,7 @@ TController::determine_consist_state() { auto absaccs { fAccGravity }; // Ra 2014-03: jesli skład stoi, to działa na niego składowa styczna grawitacji if( mvOccupied->Vel > EU07_AI_NOMOVEMENT ) { absaccs = 0; - auto *d = pVehicles[ end::front ]; // pojazd na czele składu + auto *d = pVehicles[ VehicleEnd::front ]; // pojazd na czele składu while( d ) { absaccs += d->MoverParameters->TotalMass * d->MoverParameters->AccS * ( d->DirectionGet() == iDirection ? 1 : -1 ); d = d->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła) @@ -941,7 +941,7 @@ TController::determine_consist_state() { } // second pass, for diesel engines verify the (live) engines are fully started // TODO: cache presence of diesel engines in the consist, to skip this test if there isn't any - p = pVehicles[ end::front ]; // pojazd na czole składu + p = pVehicles[ VehicleEnd::front ]; // pojazd na czole składu while( true == Ready && p != nullptr ) { diff --git a/vehicle/ai/controls.cpp b/vehicle/ai/controls.cpp index 4163afc9e..ac39a106a 100644 --- a/vehicle/ai/controls.cpp +++ b/vehicle/ai/controls.cpp @@ -147,12 +147,12 @@ 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 - && mvOccupied->Couplers[end::rear].Connected->Couplers[end::rear].Connected != nullptr ) { + if( mvOccupied->Couplers[VehicleEnd::rear].CouplingFlag & Coupling::permanent + && mvOccupied->Couplers[VehicleEnd::rear].Connected->Couplers[VehicleEnd::rear].Connected != nullptr ) { standalone = false; } - if( mvOccupied->Couplers[end::front].CouplingFlag & Coupling::permanent - && mvOccupied->Couplers[end::front].Connected->Couplers[end::front].Connected != nullptr ) { + if( mvOccupied->Couplers[VehicleEnd::front].CouplingFlag & Coupling::permanent + && mvOccupied->Couplers[VehicleEnd::front].Connected->Couplers[VehicleEnd::front].Connected != nullptr ) { standalone = false; } } @@ -171,18 +171,18 @@ bool TController::IncBrake() ( ( mvOccupied->Couplers[ 0 ].CouplingFlag.Empty() ) && ( mvOccupied->Couplers[ 1 ].CouplingFlag.Empty() ) ); */ - if( pVehicles[ end::front ] != pVehicles[ end::rear ] ) { + if( pVehicles[ VehicleEnd::front ] != pVehicles[ VehicleEnd::rear ] ) { // more detailed version, will use manual braking also for coupled sets of controlled vehicles - auto *vehicle = pVehicles[ end::front ]; // start from first + auto *vehicle = pVehicles[ VehicleEnd::front ]; // start from first while( true == standalone && vehicle != nullptr ) { // 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 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::rear].Connected == nullptr || - (vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[end::rear].Connected->Power > 1)); + (vehicle->MoverParameters->Couplers[VehicleEnd::front].Connected == nullptr || + (vehicle->MoverParameters->Couplers[VehicleEnd::front].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[VehicleEnd::front].Connected->Power > 1)) && + (vehicle->MoverParameters->Couplers[VehicleEnd::rear].Connected == nullptr || + (vehicle->MoverParameters->Couplers[VehicleEnd::rear].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[VehicleEnd::rear].Connected->Power > 1)); vehicle = vehicle->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła) } } diff --git a/vehicle/ai/doors.cpp b/vehicle/ai/doors.cpp index 967e603cb..665c6de5f 100644 --- a/vehicle/ai/doors.cpp +++ b/vehicle/ai/doors.cpp @@ -120,7 +120,7 @@ void TController::Doors( bool const Open, int const Side ) { } // if applicable close manually-operated doors in vehicles which may ignore remote signals { - const auto *vehicle = pVehicles[ end::front ]; // pojazd na czole składu + const auto *vehicle = pVehicles[ VehicleEnd::front ]; // pojazd na czole składu while( vehicle != nullptr ) { // zamykanie drzwi w pojazdach - flaga zezwolenia była by lepsza auto const ismanualdoor { @@ -131,8 +131,8 @@ void TController::Doors( bool const Open, int const Side ) { if( true == ismanualdoor && ( vehicle->LoadExchangeTime() == 0.f || vehicle->MoverParameters->Vel > EU07_AI_MOVEMENT ) ) { - vehicle->MoverParameters->OperateDoors( side::right, false, range_t::local ); - vehicle->MoverParameters->OperateDoors( side::left, false, range_t::local ); + vehicle->MoverParameters->OperateDoors( VehicleSide::right, false, range_t::local ); + vehicle->MoverParameters->OperateDoors( VehicleSide::left, false, range_t::local ); } vehicle = vehicle->Next(); // pojazd podłączony z tyłu (patrząc od czoła) } @@ -147,13 +147,13 @@ void TController::Doors( bool const Open, int const Side ) { bool TController::doors_open() const { - return IsAnyDoorOpen[side::right] || IsAnyDoorOpen[side::left]; + return IsAnyDoorOpen[VehicleSide::right] || IsAnyDoorOpen[VehicleSide::left]; } bool TController::doors_permit_active() const { - return IsAnyDoorPermitActive[side::right] || IsAnyDoorPermitActive[side::left]; + return IsAnyDoorPermitActive[VehicleSide::right] || IsAnyDoorPermitActive[VehicleSide::left]; } void @@ -166,7 +166,7 @@ TController::announce( announcement_t const Announcement ) { return; } - auto *vehicle { pVehicles[ end::front ] }; + auto *vehicle { pVehicles[ VehicleEnd::front ] }; while( vehicle ) { vehicle->announce( Announcement ); vehicle = vehicle->Next(); @@ -242,7 +242,7 @@ TController::check_load_exchange() { if( fStopTime > 0 ) { return; } // czas postoju przed dalszą jazdą (np. na przystanku) - auto *vehicle { pVehicles[ end::front ] }; + auto *vehicle { pVehicles[ VehicleEnd::front ] }; while( vehicle != nullptr ) { auto const vehicleexchangetime { vehicle->LoadExchangeTime() }; DoesAnyDoorNeedOpening |= vehicleexchangetime > 0 && vehicle->LoadExchangeSpeed() == 0; @@ -273,7 +273,7 @@ TController::check_load_exchange() { void TController::GuardOpenDoor() { if (drivingFlags.guardOpenDoor) { - auto *vehicle{ pVehicles[end::front] }; + auto *vehicle{ pVehicles[VehicleEnd::front] }; while (vehicle != nullptr && vehicle->MoverParameters->Doors.range == 0) { vehicle = vehicle->Next(); } @@ -281,10 +281,10 @@ TController::GuardOpenDoor() { auto const lewe = vehicle->DirectionGet() > 0 ? 1 : 2; auto const prawe = 3 - lewe; if (m_lastexchangeplatforms & lewe) { - vehicle->MoverParameters->OperateDoors(side::left, true, range_t::local); + vehicle->MoverParameters->OperateDoors(VehicleSide::left, true, range_t::local); } if (m_lastexchangeplatforms & prawe) { - vehicle->MoverParameters->OperateDoors(side::right, true, range_t::local); + vehicle->MoverParameters->OperateDoors(VehicleSide::right, true, range_t::local); } } else { diff --git a/vehicle/ai/driver.cpp b/vehicle/ai/driver.cpp index 20d6e6fa1..7ad7d61d3 100644 --- a/vehicle/ai/driver.cpp +++ b/vehicle/ai/driver.cpp @@ -58,12 +58,12 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche, AIControllFlag( AI ), pVehicle( NewControll ) { if( pVehicle != nullptr ) { - pVehicles[ end::front ] = pVehicle->GetFirstDynamic( end::front ); // pierwszy w kierunku jazdy (Np. Pc1) - pVehicles[ end::rear ] = pVehicle->GetFirstDynamic( end::rear ); // ostatni w kierunku jazdy (końcówki) + pVehicles[ VehicleEnd::front ] = pVehicle->GetFirstDynamic( VehicleEnd::front ); // pierwszy w kierunku jazdy (Np. Pc1) + pVehicles[ VehicleEnd::rear ] = pVehicle->GetFirstDynamic( VehicleEnd::rear ); // ostatni w kierunku jazdy (końcówki) } else { - pVehicles[ end::front ] = nullptr; - pVehicles[ end::rear ] = nullptr; + pVehicles[ VehicleEnd::front ] = nullptr; + pVehicles[ VehicleEnd::rear ] = nullptr; } ControllingSet(); // utworzenie połączenia do sterowanego pojazdu if( mvOccupied != nullptr ) { @@ -133,17 +133,17 @@ TBrakeSystem TController::consist_brake_system() const { if( mvOccupied->BrakeSystem != TBrakeSystem::ElectroPneumatic ) { return mvOccupied->BrakeSystem; } auto isepcapable = true; - if( pVehicles[ end::front ] != pVehicles[ end::rear ] ) { + if( pVehicles[ VehicleEnd::front ] != pVehicles[ VehicleEnd::rear ] ) { // more detailed version, will use manual braking also for coupled sets of controlled vehicles - auto *vehicle = pVehicles[ end::front ]; // start from first + auto *vehicle = pVehicles[ VehicleEnd::front ]; // start from first while( true == isepcapable && vehicle != nullptr ) { // 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::rear].Connected == nullptr || - (vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[end::rear].Connected->Power > -1)); + isepcapable = (vehicle->MoverParameters->Couplers[VehicleEnd::front].Connected == nullptr || + (vehicle->MoverParameters->Couplers[VehicleEnd::front].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[VehicleEnd::front].Connected->Power > -1)) && + (vehicle->MoverParameters->Couplers[VehicleEnd::rear].Connected == nullptr || + (vehicle->MoverParameters->Couplers[VehicleEnd::rear].CouplingFlag & Coupling::control && vehicle->MoverParameters->Couplers[VehicleEnd::rear].Connected->Power > -1)); vehicle = vehicle->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła) } } @@ -239,7 +239,7 @@ void TController::record_station( TSpeedPos const &Point, std::uint8_t const Kin entry.arrival = ( line.Ah >= 0 ? static_cast( line.Ah * 60 ) + line.Am : -1.0f ); entry.departure = ( line.Dh >= 0 ? static_cast( line.Dh * 60 ) + line.Dm : -1.0f ); } - simulation::Blackbox.station( pVehicles[ end::front ], std::move( entry ) ); + simulation::Blackbox.station( pVehicles[ VehicleEnd::front ], std::move( entry ) ); } void TController::WaitingSet(double Seconds) @@ -420,12 +420,12 @@ void TController::TakeControl( bool const Aidriver, bool const Forcevehiclecheck // jeśli nic nie robi OrderNext( DriverOrder::prepareEngine ); if( pVehicle->MoverParameters->iLights[ ( mvOccupied->CabActive < 0 ? - end::rear : - end::front ) ] + VehicleEnd::rear : + VehicleEnd::front ) ] & ( light::headlight_left | light::headlight_right | light::headlight_upper ) ) // któreś ze świateł zapalone? { // od wersji 357 oczekujemy podania komend dla AI przez scenerię /* - if( pVehicle->MoverParameters->iLights[ mvOccupied->CabActive < 0 ? end::rear : end::front ] & light::headlight_upper ) // górne światło zapalone + if( pVehicle->MoverParameters->iLights[ mvOccupied->CabActive < 0 ? VehicleEnd::rear : VehicleEnd::front ] & light::headlight_upper ) // górne światło zapalone OrderNext( DriverOrder::obeyTrain ); // jazda pociągowa else OrderNext( DriverOrder::shunt ); // jazda manewrowa diff --git a/vehicle/ai/engine.cpp b/vehicle/ai/engine.cpp index 8194aecb7..7c134e4b5 100644 --- a/vehicle/ai/engine.cpp +++ b/vehicle/ai/engine.cpp @@ -167,10 +167,10 @@ bool TController::PrepareEngine() cue_action( driver_hint::waitpressuretoolow ); } // enable motor blowers - if( mvOccupied->MotorBlowers[ end::front ].speed != 0 ) { + if( mvOccupied->MotorBlowers[ VehicleEnd::front ].speed != 0 ) { cue_action( driver_hint::frontmotorblowerson ); } - if( mvOccupied->MotorBlowers[ end::rear ].speed != 0 ) { + if( mvOccupied->MotorBlowers[ VehicleEnd::rear ].speed != 0 ) { cue_action( driver_hint::rearmotorblowerson ); } } @@ -237,8 +237,8 @@ TController::report_power_stall( bool const Poweravailable, double const Pantogr state.standing = mvOccupied->Vel < EU07_AI_NOMOVEMENT; if( mvPantographUnit->PantPress >= Pantographpressure ) { state.pantographs_up = - mvPantographUnit->Pantographs[ end::front ].is_active - || mvPantographUnit->Pantographs[ end::rear ].is_active; + mvPantographUnit->Pantographs[ VehicleEnd::front ].is_active + || mvPantographUnit->Pantographs[ VehicleEnd::rear ].is_active; } // the pantographs of the vehicle carrying them hold the wire they found above them if( auto const *carrier { pVehicle->FindPantographCarrier() }; @@ -424,11 +424,11 @@ TController::PrepareDirection() { /* if( iDirection == 0 ) { // jeśli nie ma ustalonego kierunku - if( mvOccupied->Couplers[ end::rear ].Connected == nullptr ) { + if( mvOccupied->Couplers[ VehicleEnd::rear ].Connected == nullptr ) { // jeśli z tyłu nie ma nic iDirection = -1; // jazda w kierunku sprzęgu 1 } - if( mvOccupied->Couplers[ end::front ].Connected == nullptr ) { + if( mvOccupied->Couplers[ VehicleEnd::front ].Connected == nullptr ) { // jeśli z przodu nie ma nic iDirection = 1; // jazda w kierunku sprzęgu 0 } diff --git a/vehicle/ai/force.cpp b/vehicle/ai/force.cpp index 72c87dc28..33db87ede 100644 --- a/vehicle/ai/force.cpp +++ b/vehicle/ai/force.cpp @@ -245,7 +245,7 @@ void TController::control_uphill_start() { return; } fUphillTractiveForce = 0.0; - for( auto const *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { + for( auto const *vehicle { pVehicles[ VehicleEnd::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { // Ft is signed in the vehicle's own frame, and turned into the direction of travel as AbsAccS is fUphillTractiveForce += std::max( 0.0, vehicle->MoverParameters->Ft * ( vehicle->DirectionGet() == iDirection ? 1 : -1 ) * ( iDirection >= 0 ? 1 : -1 ) ); } @@ -286,7 +286,7 @@ bool TController::uphill_brake_top_up() { auto trainbrakeforce { 0.0 }; auto haswagons { false }; - for( auto const *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { + for( auto const *vehicle { pVehicles[ VehicleEnd::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { if( vehicle->MoverParameters->Power < 0.01 ) { trainbrakeforce += vehicle->MoverParameters->Fb; haswagons = true; @@ -710,7 +710,7 @@ void TController::update_brake_charging() { if( BrakeChargingStart < 0.0 ) { BrakeChargingStart = ElapsedTime; } - for( auto const *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { + for( auto const *vehicle { pVehicles[ VehicleEnd::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { auto const isovercharged { vehicle->MoverParameters != mvOccupied && vehicle->MoverParameters->PipePress > FSOverchargePipePress }; @@ -732,7 +732,7 @@ bool TController::is_departure_blocked( double const Delay ) const { double TController::consist_max_crp() const { auto result { 0.0 }; - for( auto const *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { + for( auto const *vehicle { pVehicles[ VehicleEnd::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { result = std::max( result, vehicle->MoverParameters->Hamulec->GetCRP() ); } return result; diff --git a/vehicle/ai/obstacles.cpp b/vehicle/ai/obstacles.cpp index 16c237684..4ddd60df1 100644 --- a/vehicle/ai/obstacles.cpp +++ b/vehicle/ai/obstacles.cpp @@ -48,12 +48,12 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/ai/internal.h" -basic_event * TController::CheckTrackEventBackward(double fDirection, TTrack *Track, TDynamicObject *Vehicle, int const Eventdirection, end const End) +basic_event * TController::CheckTrackEventBackward(double fDirection, TTrack *Track, TDynamicObject *Vehicle, int const Eventdirection, VehicleEnd const End) { // sprawdzanie eventu w torze, czy jest sygnałowym - skanowanie do tyłu // NOTE: this method returns only one event which meets the conditions, due to limitations in the caller // TBD, TODO: clean up the caller and return all suitable events, as in theory things will go awry if the track has more than one signal auto const dir{ Vehicle->VectorFront() * (double)Vehicle->DirectionGet() }; - auto const pos{ End == end::front ? Vehicle->RearPosition() : Vehicle->HeadPosition() }; + auto const pos{ End == VehicleEnd::front ? Vehicle->RearPosition() : Vehicle->HeadPosition() }; auto const &eventsequence { ( fDirection * Eventdirection > 0 ? Track->m_events2 : Track->m_events1 ) }; for( auto const &event : eventsequence ) { if( event.second != nullptr @@ -63,7 +63,7 @@ basic_event * TController::CheckTrackEventBackward(double fDirection, TTrack *Tr auto const sl{ event.second->input_location() }; // położenie komórki pamięci auto const sem{ sl - pos }; // wektor do komórki pamięci od końca składu auto const isahead { dir.x * sem.x + dir.z * sem.z > 0 }; - if( End == end::front ? isahead : !isahead ) { + if( End == VehicleEnd::front ? isahead : !isahead ) { // iloczyn skalarny jest ujemny, gdy sygnał stoi z tyłu return event.second; } @@ -72,7 +72,7 @@ basic_event * TController::CheckTrackEventBackward(double fDirection, TTrack *Tr return nullptr; }; -TTrack * TController::BackwardTraceRoute(double &fDistance, double &fDirection, TDynamicObject *Vehicle, basic_event *&Event, int const Eventdirection, end const End, bool const Untiloccupied ) +TTrack * TController::BackwardTraceRoute(double &fDistance, double &fDirection, TDynamicObject *Vehicle, basic_event *&Event, int const Eventdirection, VehicleEnd const End, bool const Untiloccupied ) { // szukanie sygnalizatora w kierunku przeciwnym jazdy (eventu odczytu komórki pamięci) auto *Track = Vehicle->GetTrack(); double fCurrentDistance = Vehicle->RaTranslationGet(); // aktualna pozycja na torze @@ -192,9 +192,9 @@ TCommandType TController::BackwardScan( double const Range ) basic_event *e = nullptr; // event potencjalnie od semafora // opcjonalnie może być skanowanie od "wskaźnika" z przodu, np. W5, Tm=Ms1, koniec toru wg // drugiej osi w kierunku ruchu - auto const *scantrack{BackwardTraceRoute(scandist, scandir, pVehicles[end::front], e)}; + auto const *scantrack{BackwardTraceRoute(scandist, scandir, pVehicles[VehicleEnd::front], e)}; auto const dir{(double)startdir * - pVehicles[end::front]->VectorFront()}; // wektor w kierunku jazdy/szukania + pVehicles[VehicleEnd::front]->VectorFront()}; // wektor w kierunku jazdy/szukania // jeśli wstecz wykryto koniec toru to raczej nic się nie da w takiej sytuacji zrobić if (e == nullptr) @@ -216,7 +216,7 @@ TCommandType TController::BackwardScan( double const Range ) { // najpierw sprawdzamy, czy semafor czy inny znak został przejechany auto const sl{e->input_location()}; // położenie komórki pamięci - auto const pos{pVehicles[end::rear]->RearPosition()}; // pozycja tyłu + auto const pos{pVehicles[VehicleEnd::rear]->RearPosition()}; // pozycja tyłu if (auto const sem{sl - pos}; dir.x * sem.x + dir.z * sem.z < 0) // wektor do komórki pamięci od końca składu { // jeśli został minięty @@ -373,7 +373,7 @@ TController::scan_obstacles( double const Range ) { // HACK: vehicle order in the consist is based on intended travel direction // if our actual travel direction doesn't match that, we should be scanning from the other end of the consist // we cast to int to avoid getting confused by microstutters - auto *frontvehicle { pVehicles[ ( static_cast( mvOccupied->V ) * iDirection >= 0 ? end::front : end::rear ) ] }; + auto *frontvehicle { pVehicles[ ( static_cast( mvOccupied->V ) * iDirection >= 0 ? VehicleEnd::front : VehicleEnd::rear ) ] }; int routescandirection; // for moving vehicle determine heading from velocity; for standing fall back on the set direction @@ -381,11 +381,11 @@ TController::scan_obstacles( double const Range ) { frontvehicle->MoverParameters->V > 0.0 : pVehicle->DirectionGet() == frontvehicle->DirectionGet() ? iDirection >= 0 : iDirection <= 0 ) { // towards coupler 0 - routescandirection = end::front; + routescandirection = NumberOf( VehicleEnd::front ); } else { // towards coupler 1 - routescandirection = end::rear; + routescandirection = NumberOf( VehicleEnd::rear ); } /* if( pVehicle->MoverParameters->CabOccupied < 0 ) { diff --git a/vehicle/ai/orders.cpp b/vehicle/ai/orders.cpp index 091a443ef..ce905afec 100644 --- a/vehicle/ai/orders.cpp +++ b/vehicle/ai/orders.cpp @@ -226,12 +226,12 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N // NOTE: this may result in visually ugly quick switch between closing and opening the doors, but eh if( pVehicle->MoverParameters->Doors.close_control == control_t::driver || pVehicle->MoverParameters->Doors.close_control == control_t::mixed ) { - pVehicle->MoverParameters->OperateDoors( side::right, false ); - pVehicle->MoverParameters->OperateDoors( side::left, false ); + pVehicle->MoverParameters->OperateDoors( VehicleSide::right, false ); + pVehicle->MoverParameters->OperateDoors( VehicleSide::left, false ); } if( pVehicle->MoverParameters->Doors.permit_needed ) { - pVehicle->MoverParameters->PermitDoors( side::right, false ); - pVehicle->MoverParameters->PermitDoors( side::left, false ); + pVehicle->MoverParameters->PermitDoors( VehicleSide::right, false ); + pVehicle->MoverParameters->PermitDoors( VehicleSide::left, false ); } } drivingFlags.doorOpened = false; @@ -269,7 +269,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N NewCommand = TrainParams.Relation2; // relacja docelowa z rozkładu } // jeszcze poustawiać tekstury na wyświetlaczach - TDynamicObject *p = pVehicles[end::front]; + TDynamicObject *p = pVehicles[VehicleEnd::front]; while (p) { p->DestinationSet(NewCommand, TrainParams.TrainName); // relacja docelowa @@ -505,13 +505,13 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N if( NewValue1 >= 0.0 ) { // jeśli ilość wagonów inna niż wszystkie będzie odczepianie, // ale jeśli wagony są z przodu, to trzeba najpierw zmienić kierunek - if( mvOccupied->Couplers[mvOccupied->DirAbsolute > 0 ? end::rear : end::front].Connected == nullptr // z tyłu nic - && mvOccupied->Couplers[mvOccupied->DirAbsolute > 0 ? end::front : end::rear].Connected != nullptr ) { // a z przodu skład + if( mvOccupied->Couplers[mvOccupied->DirAbsolute > 0 ? VehicleEnd::rear : VehicleEnd::front].Connected == nullptr // z tyłu nic + && mvOccupied->Couplers[mvOccupied->DirAbsolute > 0 ? VehicleEnd::front : VehicleEnd::rear].Connected != nullptr ) { // a z przodu skład iDirectionOrder = -iDirection; // zmiana na ciągnięcie OrderNext( DriverOrder::changeDirection ); // najpierw zmień kierunek (zastąpi Disconnect) OrderPush( DriverOrder::disconnect ); // a odczep już po zmianie kierunku } - else if( mvOccupied->Couplers[ mvOccupied->DirAbsolute > 0 ? end::rear : end::front ].Connected != nullptr ) { // z tyłu coś + else if( mvOccupied->Couplers[ mvOccupied->DirAbsolute > 0 ? VehicleEnd::rear : VehicleEnd::front ].Connected != nullptr ) { // z tyłu coś OrderNext( DriverOrder::disconnect ); // jak ciągnie, to tylko odczep (NewValue1) wagonów } else { @@ -573,7 +573,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N fWarningDuration = NewValue1; // czas trąbienia cue_action( driver_hint::hornon, NewValue2 ); // horn combination flag simulation::Blackbox.horn_requested( - pVehicles[ end::front ], NewValue1, NewValue2, NewLocation != nullptr ? *NewLocation : pVehicles[ end::front ]->GetPosition() ); + pVehicles[ VehicleEnd::front ], NewValue1, NewValue2, NewLocation != nullptr ? *NewLocation : pVehicles[ VehicleEnd::front ]->GetPosition() ); } return true; } @@ -597,8 +597,8 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N if( NewCommand == "SetLights" ) { // set consist lights pattern hints - m_lighthints[ end::front ] = static_cast( NewValue1 ); - m_lighthints[ end::rear ] = static_cast( NewValue2 ); + m_lighthints[ VehicleEnd::front ] = static_cast( NewValue1 ); + m_lighthints[ VehicleEnd::rear ] = static_cast( NewValue2 ); if( true == OrderCurrentGet().HasAll(DriverOrder::obeyTrain) ) { // light hints only apply in the obey_train mode CheckVehicles(); @@ -664,7 +664,7 @@ void TController::OrderCheck() if( OrderCurrentGet() != DriverOrder::obeyTrain ) { // reset light hints - m_lighthints[ end::front ] = m_lighthints[ end::rear ] = -1; + m_lighthints[ VehicleEnd::front ] = m_lighthints[ VehicleEnd::rear ] = -1; } if( OrderCurrentGet() & ( DriverOrder::shunt | DriverOrder::looseShunt | DriverOrder::connect | DriverOrder::obeyTrain | DriverOrder::bank ) ) { CheckVehicles(); // sprawdzić światła @@ -918,7 +918,7 @@ TController::UpdateLooseShunt() { && mvOccupied->Vel < 1.0 ) { auto *vehicle { Obstacle.vehicle }; - auto const direction { ( vehicle->Prev() != nullptr ? end::front : end::rear ) }; + auto const direction { ( vehicle->Prev() != nullptr ? VehicleEnd::front : VehicleEnd::rear ) }; while( vehicle != nullptr ) { if( vehicle->MoverParameters->BrakePress > 0.2 ) { vehicle->MoverParameters->BrakeLevelSet( 0 ); // hamulec na zero, aby nie hamował @@ -926,7 +926,7 @@ TController::UpdateLooseShunt() { } // NOTE: we trust the consist to be arranged in a valid chain // TBD, TODO: traversal direction validation? - vehicle = direction == end::front ? vehicle->Prev() : vehicle->Next(); + vehicle = direction == VehicleEnd::front ? vehicle->Prev() : vehicle->Next(); } } } @@ -985,7 +985,7 @@ TController::UpdateConnect() { auto expectedcoupling { iCoupler }; if( neighbour.vehicle != nullptr ) { auto const neighbourend { neighbour.vehicle_end != 2 ? neighbour.vehicle_end : vehicleparameters->Couplers[ couplingend ].ConnectedNr }; - expectedcoupling = vehicleparameters->CompatibleCoupling( couplingend, *neighbour.vehicle->MoverParameters, neighbourend, iCoupler ); + expectedcoupling = vehicleparameters->CompatibleCoupling( EndOf( couplingend ), *neighbour.vehicle->MoverParameters, EndOf( neighbourend ), iCoupler ); } if( vehicleparameters->Couplers[ couplingend ].CouplingFlag != expectedcoupling ) { if( neighbour.vehicle != nullptr && neighbour.distance < 10 ) { @@ -1024,7 +1024,7 @@ TController::UpdateConnect() { if( Obstacle.distance <= 20.0 && !iCouplingVehicle ) { // write down which vehicle should be coupled with the target consist, // so we don't lose track of it if the user does something unexpected - iCouplingVehicle = {pVehicles[end::front], (pVehicles[end::front]->DirectionGet() > 0 ? end::front : end::rear)}; + iCouplingVehicle = {pVehicles[VehicleEnd::front], NumberOf(pVehicles[VehicleEnd::front]->DirectionGet() > 0 ? VehicleEnd::front : VehicleEnd::rear)}; drivingFlags.connect = true; } } @@ -1037,8 +1037,8 @@ TController::unit_count( int const Threshold ) const { auto unitcount { 1 }; do { auto const decoupledend{ ( vehicle->DirectionGet() > 0 ? // numer sprzęgu od strony czoła składu - end::rear : - end::front ) }; + VehicleEnd::rear : + VehicleEnd::front ) }; auto const coupling { vehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag }; if( coupling == Coupling::none ) { break; @@ -1083,9 +1083,9 @@ TController::UpdateDisconnect() { auto vehiclecount { iVehicleCount }; // ile wagonów ma zostać // szukanie pojazdu do odczepienia do { - decoupledend = decoupledvehicle->DirectionGet() > 0 ? // numer sprzęgu od strony czoła składu - end::front : - end::rear; + decoupledend = NumberOf( decoupledvehicle->DirectionGet() > 0 ? // numer sprzęgu od strony czoła składu + VehicleEnd::front : + VehicleEnd::rear ); // jeżeli sprzęg zablokowany to liczymy człony jako jeden if( decoupledvehicle->MoverParameters->Couplers[ decoupledend ].CouplingFlag & Coupling::permanent ) { ++vehiclecount; @@ -1121,7 +1121,7 @@ TController::UpdateDisconnect() { decoupledvehicle->remove_coupler_adapter( decoupledend ); } */ - if( pVehicles[ end::front ]->MoverParameters->Couplers[ decoupledend ].has_adapter() ) { + if( pVehicles[ VehicleEnd::front ]->MoverParameters->Couplers[ decoupledend ].has_adapter() ) { cue_action( driver_hint::couplingadapterremove, decoupledend ); } } diff --git a/vehicle/ai/routescan.cpp b/vehicle/ai/routescan.cpp index 35fd170fc..aaf7f3988 100644 --- a/vehicle/ai/routescan.cpp +++ b/vehicle/ai/routescan.cpp @@ -442,7 +442,7 @@ void TController::TableCheck(double fDistance) { // przeliczenie odległości w tabelce, ewentualnie doskanowanie (bez analizy prędkości itp.) if( iTableDirection != iDirection ) { // jak zmiana kierunku, to skanujemy od końca składu - TableTraceRoute( fDistance, pVehicles[ end::rear ] ); + TableTraceRoute( fDistance, pVehicles[ VehicleEnd::rear ] ); TableSort(); } else if (iTableDirection) @@ -479,7 +479,7 @@ void TController::TableCheck(double fDistance) SemNextStopIndex = npos; } tLast = sSpeedTable[ i ].trTrack; - TableTraceRoute( fDistance, pVehicles[ end::rear ] ); + TableTraceRoute( fDistance, pVehicles[ VehicleEnd::rear ] ); TableSort(); // nie kontynuujemy pętli, trzeba doskanować ciąg dalszy break; @@ -515,7 +515,7 @@ void TController::TableCheck(double fDistance) CheckSignalPassed( sSpeedTable[ iLast ], lastpassedbefore ); // WriteLog("TableCheck: Upate last track. Dist=" + AnsiString(sSpeedTable[iLast].fDist)); if( sSpeedTable[ iLast ].fDist < fDistance ) { - TableTraceRoute( fDistance, pVehicles[ end::rear ] ); // doskanowanie dalszego odcinka + TableTraceRoute( fDistance, pVehicles[ VehicleEnd::rear ] ); // doskanowanie dalszego odcinka TableSort(); } // garbage collection @@ -578,7 +578,7 @@ void TController::CheckSignalPassed( TSpeedPos const &Point, bool const Passedbe // automatic block signal is kept as the speed allowed after it, with a flag of its own auto const speedatsignal { Point.flags.HasAll(SpeedPointFlag::stopOnAutomaticBlock) ? 0.0 : Point.fVelNext }; simulation::Blackbox.signal_passed( - pVehicles[ end::front ], *Point.evEvent, + pVehicles[ VehicleEnd::front ], *Point.evEvent, speedatsignal, Point.evEvent->input_value( 2 ), mvOccupied->Vel, -Point.fDist, passing_flags_of( Point, speedatsignal, false == OrderCurrentGet().HasAny( DriverOrder::shunt | DriverOrder::looseShunt ) ) ); diff --git a/vehicle/ai/situation.cpp b/vehicle/ai/situation.cpp index 06cab6d70..9ef52112f 100644 --- a/vehicle/ai/situation.cpp +++ b/vehicle/ai/situation.cpp @@ -178,10 +178,10 @@ TController::control_pantographs() { if( fOverhead2 > 0.0 || iOverheadDown ) { // jazda z opuszczonymi pantografami - if( mvPantographUnit->Pantographs[ end::front ].is_active ) { + if( mvPantographUnit->Pantographs[ VehicleEnd::front ].is_active ) { cue_action( driver_hint::frontpantographvalveoff ); } - if( mvPantographUnit->Pantographs[ end::rear ].is_active ) { + if( mvPantographUnit->Pantographs[ VehicleEnd::rear ].is_active ) { cue_action( driver_hint::rearpantographvalveoff ); } } @@ -451,14 +451,14 @@ TController::sync_lights_selector() { if( mvOccupied->LightsPosNo <= 0 ) { return; } - auto const *headvehicle { pVehicles[ end::front ] }; + auto const *headvehicle { pVehicles[ VehicleEnd::front ] }; if( headvehicle == nullptr ) { return; } // same choice of the light table as in TDynamicObject::SetLights() - auto const lightstable { ( mvOccupied->CabOccupied * pVehicle->DirectionGet() >= 0 ? end::front : end::rear ) }; + auto const lightstable { ( mvOccupied->CabOccupied * pVehicle->DirectionGet() >= 0 ? VehicleEnd::front : VehicleEnd::rear ) }; // same choice of the lit vehicle end as in TDynamicObject::RaLightsSet() - auto const headend { ( headvehicle->iDirection > 0 ? end::front : end::rear ) }; + auto const headend { ( headvehicle->iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear ) }; auto const position { handover::light_selector_position( - *mvOccupied, lightstable, headvehicle->MoverParameters->iLights[ headend ], headvehicle->LightList( headend ) ) }; + *mvOccupied, NumberOf( lightstable ), headvehicle->MoverParameters->iLights[ headend ], headvehicle->LightList( headend ) ) }; if( position == mvOccupied->LightsPos ) { return; } mvOccupied->LightsPos = position; @@ -476,8 +476,8 @@ TController::sync_lights_dimmer() { if( mvOccupied->dimPositions.empty() ) { return; } - auto const *headvehicle { pVehicles[ end::front ] }; - auto const headend { ( headvehicle != nullptr && headvehicle->iDirection > 0 ? end::front : end::rear ) }; + auto const *headvehicle { pVehicles[ VehicleEnd::front ] }; + auto const headend { ( headvehicle != nullptr && headvehicle->iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear ) }; auto const headlightson { headvehicle != nullptr && ( headvehicle->MoverParameters->iLights[ headend ] & ( light::headlight_left | light::headlight_right | light::headlight_upper ) ) != 0 }; @@ -503,25 +503,25 @@ TController::control_lights() { // jeśli jazda pociągowa if( true == OrderCurrentGet().HasAll(DriverOrder::obeyTrain) ) { // head lights - if( m_lighthints[ end::front ] == -1 ) { + if( m_lighthints[ VehicleEnd::front ] == -1 ) { cue_action( driver_hint::headcodepc1 ); } - else if( m_lighthints[ end::front ] == ( light::redmarker_left | light::headlight_right | light::headlight_upper ) ) { + else if( m_lighthints[ VehicleEnd::front ] == ( light::redmarker_left | light::headlight_right | light::headlight_upper ) ) { cue_action( driver_hint::headcodepc2 ); } else { // custom light pattern if( AIControllFlag ) { - pVehicles[ end::front ]->RaLightsSet( m_lighthints[ end::front ], -1 ); + pVehicles[ VehicleEnd::front ]->RaLightsSet( m_lighthints[ VehicleEnd::front ], -1 ); } } // tail lights - if( m_lighthints[ end::rear ] == -1 ) { + if( m_lighthints[ VehicleEnd::rear ] == -1 ) { cue_action( driver_hint::headcodepc5 ); } else { if( AIControllFlag ) { - pVehicles[ end::rear ]->RaLightsSet( -1, m_lighthints[ end::rear ] ); + pVehicles[ VehicleEnd::rear ]->RaLightsSet( -1, m_lighthints[ VehicleEnd::rear ] ); } } } diff --git a/vehicle/ai/speed.cpp b/vehicle/ai/speed.cpp index 84525a670..1e461e3f9 100644 --- a/vehicle/ai/speed.cpp +++ b/vehicle/ai/speed.cpp @@ -763,7 +763,7 @@ TController::adjust_desired_speed_for_current_speed() { } } // HACK: limit acceleration for cargo trains, to reduce probability of breaking couplers on sudden jolts - auto MaxAcc{ 0.5 * mvOccupied->Couplers[(mvOccupied->DirAbsolute >= 0 ? end::rear : end::front)].FmaxC / fMass }; + auto MaxAcc{ 0.5 * mvOccupied->Couplers[(mvOccupied->DirAbsolute >= 0 ? VehicleEnd::rear : VehicleEnd::front)].FmaxC / fMass }; if( iVehicles - ControlledEnginesCount > 0 ) { MaxAcc *= std::clamp( vel * 0.025, 0.2, 1.0 ); } diff --git a/vehicle/ai/speedtable.cpp b/vehicle/ai/speedtable.cpp index ca7f5511e..12fa2f964 100644 --- a/vehicle/ai/speedtable.cpp +++ b/vehicle/ai/speedtable.cpp @@ -462,7 +462,7 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub m_lastexchangestop = asNextStop; m_lastexchangedirection = pVehicle->DirectionGet(); m_lastexchangeplatforms = static_cast( std::floor( std::abs( Point.evEvent->input_value( 2 ) ) ) ) % 10; - auto const exchangetime { simulation::Station.update_load( pVehicles[ end::front ], TrainParams, m_lastexchangeplatforms ) }; + auto const exchangetime { simulation::Station.update_load( pVehicles[ VehicleEnd::front ], TrainParams, m_lastexchangeplatforms ) }; WaitingSet( exchangetime ); // announce the stop name while at it announce( announcement_t::current ); @@ -573,7 +573,7 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub asNextStop = TrainParams.NextStop(); // informacja o końcu trasy TrainParams.NewName("none"); // czyszczenie nieaktualnego rozkładu // koniec kursu, gasimy wyświetlacze relacji (tablice blaszane zostają) - for( auto *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { + for( auto *vehicle { pVehicles[ VehicleEnd::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) { vehicle->DestinationClear(); } // ma nie podjeżdżać pod W4 i ma je pomijać @@ -723,9 +723,9 @@ double TController::point_limit_end( glm::dvec3 const &Heading ) const { auto const origin { pVehicle->GetPosition() }; auto result { 0.0 }; auto first { true }; - for( auto const *vehicle : { pVehicles[ end::front ], pVehicles[ end::rear ] } ) { + for( auto const *vehicle : { pVehicles[ VehicleEnd::front ], pVehicles[ VehicleEnd::rear ] } ) { if( vehicle == nullptr ) { continue; } - for( auto const side : { end::front, end::rear } ) { + for (auto const side : VehicleEnds) { auto const along { glm::dot( vehicle->CouplerPosition( side ) - origin, Heading ) }; result = ( first ? along : std::max( result, along ) ); first = false; @@ -779,8 +779,8 @@ void TController::update_point_limits() { m_pointlimitsvehicle = pVehicle; m_pointlimitsposition = position; // the consist, as its end vehicles and its length - auto const *front { pVehicles[ end::front ] }; - auto const *rear { pVehicles[ end::rear ] }; + auto const *front { pVehicles[ VehicleEnd::front ] }; + auto const *rear { pVehicles[ VehicleEnd::rear ] }; auto const consistchanged { false == ( ( front == m_pointlimitsends[ 0 ] && rear == m_pointlimitsends[ 1 ] ) || ( front == m_pointlimitsends[ 1 ] && rear == m_pointlimitsends[ 0 ] ) ) @@ -877,7 +877,7 @@ glm::dvec3 TController::travel_direction() const { if( pVehicle == nullptr || iDirection == 0 ) { return glm::dvec3 { 0.0 }; } // the direction is given against the couplers of the vehicle the driver is in, which is the vehicle measured; // along its own length it follows the track, where the chord of a long consist on a curve doesn't - auto const along { pVehicle->CouplerPosition( end::front ) - pVehicle->CouplerPosition( end::rear ) }; + auto const along { pVehicle->CouplerPosition( VehicleEnd::front ) - pVehicle->CouplerPosition( VehicleEnd::rear ) }; auto const length { glm::length( along ) }; if( length < 0.001 ) { return glm::dvec3 { 0.0 }; } return ( iDirection > 0 ? along : -along ) / length; @@ -943,7 +943,7 @@ TController::TableUpdateEvent( double &Velocity, TCommandType &Command, TSpeedPo case TCommandType::cm_SecuritySystemMagnet: { // NOTE: magnet induction calculation presumes the driver is located in the front vehicle // TBD, TODO: take into account actual position of controlled/occupied vehicle in the consist, whichever comes first - auto const magnetlocation { pVehicles[ end::front ]->MoverParameters->SecuritySystem.MagnetLocation }; + auto const magnetlocation { pVehicles[ VehicleEnd::front ]->MoverParameters->SecuritySystem.MagnetLocation }; auto const magnetrange { 1.0 }; auto const ismagnetpassed { Point.fDist < -( magnetlocation + magnetrange ) }; if( Point.fDist < -magnetlocation && (mvOccupied->Vel > EU07_AI_NOMOVEMENT || false == ismagnetpassed) ) { @@ -1026,9 +1026,9 @@ TController::TableUpdateEvent( double &Velocity, TCommandType &Command, TSpeedPo basic_event *foundevent = nullptr; if( Point.fDist - fMaxProximityDist > 0 ) { auto scandistance{ Point.fDist + fLength - fMaxProximityDist }; - auto *scanvehicle{ pVehicles[ end::rear ] }; + auto *scanvehicle{ pVehicles[ VehicleEnd::rear ] }; auto scandirection{ scanvehicle->DirectionGet() * scanvehicle->RaDirectionGet() }; - auto *foundtrack = BackwardTraceRoute( scandistance, scandirection, scanvehicle, foundevent, -1, end::front, false ); + auto *foundtrack = BackwardTraceRoute( scandistance, scandirection, scanvehicle, foundevent, -1, VehicleEnd::front, false ); } if( foundevent == nullptr ) { drivingFlags.trackEnd = true; // to dalsza jazda trwale ograniczona (W5, koniec toru) diff --git a/vehicle/cab/auxiliarycommands.cpp b/vehicle/cab/auxiliarycommands.cpp index f24eb9cb6..92685e888 100644 --- a/vehicle/cab/auxiliarycommands.cpp +++ b/vehicle/cab/auxiliarycommands.cpp @@ -1068,7 +1068,7 @@ void TTrain::OnCommand_motorblowerstogglefront(TTrain *Train, command_data const return; } - if (false == Train->mvControlled->MotorBlowers[end::front].is_enabled) + if (false == Train->mvControlled->MotorBlowers[VehicleEnd::front].is_enabled) { // turn on OnCommand_motorblowersenablefront(Train, Command); @@ -1096,13 +1096,13 @@ void TTrain::OnCommand_motorblowersenablefront(TTrain *Train, command_data const { // visual feedback Train->ggMotorBlowersFrontButton.UpdateValue(1.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(true, end::front); + Train->mvControlled->MotorBlowersSwitch(true, VehicleEnd::front); } else if (Command.action == GLFW_RELEASE) { // visual feedback Train->ggMotorBlowersFrontButton.UpdateValue(0.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(false, end::front); + Train->mvControlled->MotorBlowersSwitch(false, VehicleEnd::front); } } else @@ -1112,8 +1112,8 @@ void TTrain::OnCommand_motorblowersenablefront(TTrain *Train, command_data const { // visual feedback Train->ggMotorBlowersFrontButton.UpdateValue(1.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(true, end::front); - Train->mvControlled->MotorBlowersSwitchOff(false, end::front); + Train->mvControlled->MotorBlowersSwitch(true, VehicleEnd::front); + Train->mvControlled->MotorBlowersSwitchOff(false, VehicleEnd::front); } } } @@ -1139,8 +1139,8 @@ void TTrain::OnCommand_motorblowersdisablefront(TTrain *Train, command_data cons { // visual feedback Train->ggMotorBlowersFrontButton.UpdateValue(0.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(false, end::front); - Train->mvControlled->MotorBlowersSwitchOff(true, end::front); + Train->mvControlled->MotorBlowersSwitch(false, VehicleEnd::front); + Train->mvControlled->MotorBlowersSwitchOff(true, VehicleEnd::front); } } } @@ -1167,7 +1167,7 @@ void TTrain::OnCommand_motorblowerstogglerear(TTrain *Train, command_data const return; } - if (false == Train->mvControlled->MotorBlowers[end::rear].is_enabled) + if (false == Train->mvControlled->MotorBlowers[VehicleEnd::rear].is_enabled) { // turn on OnCommand_motorblowersenablerear(Train, Command); @@ -1195,13 +1195,13 @@ void TTrain::OnCommand_motorblowersenablerear(TTrain *Train, command_data const { // visual feedback Train->ggMotorBlowersRearButton.UpdateValue(1.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(true, end::rear); + Train->mvControlled->MotorBlowersSwitch(true, VehicleEnd::rear); } else if (Command.action == GLFW_RELEASE) { // visual feedback Train->ggMotorBlowersRearButton.UpdateValue(0.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(false, end::rear); + Train->mvControlled->MotorBlowersSwitch(false, VehicleEnd::rear); } } else @@ -1211,8 +1211,8 @@ void TTrain::OnCommand_motorblowersenablerear(TTrain *Train, command_data const { // visual feedback Train->ggMotorBlowersRearButton.UpdateValue(1.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(true, end::rear); - Train->mvControlled->MotorBlowersSwitchOff(false, end::rear); + Train->mvControlled->MotorBlowersSwitch(true, VehicleEnd::rear); + Train->mvControlled->MotorBlowersSwitchOff(false, VehicleEnd::rear); } } } @@ -1238,8 +1238,8 @@ void TTrain::OnCommand_motorblowersdisablerear(TTrain *Train, command_data const { // visual feedback Train->ggMotorBlowersRearButton.UpdateValue(0.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitch(false, end::rear); - Train->mvControlled->MotorBlowersSwitchOff(true, end::rear); + Train->mvControlled->MotorBlowersSwitch(false, VehicleEnd::rear); + Train->mvControlled->MotorBlowersSwitchOff(true, VehicleEnd::rear); } } } @@ -1259,15 +1259,15 @@ void TTrain::OnCommand_motorblowersdisableall(TTrain *Train, command_data const { // visual feedback Train->ggMotorBlowersAllOffButton.UpdateValue(1.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitchOff(true, end::front); - Train->mvControlled->MotorBlowersSwitchOff(true, end::rear); + Train->mvControlled->MotorBlowersSwitchOff(true, VehicleEnd::front); + Train->mvControlled->MotorBlowersSwitchOff(true, VehicleEnd::rear); } else if (Command.action == GLFW_RELEASE) { // visual feedback Train->ggMotorBlowersAllOffButton.UpdateValue(0.f, Train->dsbSwitch); - Train->mvControlled->MotorBlowersSwitchOff(false, end::front); - Train->mvControlled->MotorBlowersSwitchOff(false, end::rear); + Train->mvControlled->MotorBlowersSwitchOff(false, VehicleEnd::front); + Train->mvControlled->MotorBlowersSwitchOff(false, VehicleEnd::rear); } } else @@ -1279,16 +1279,16 @@ void TTrain::OnCommand_motorblowersdisableall(TTrain *Train, command_data const if (Train->ggMotorBlowersAllOffButton.GetDesiredValue() < 0.5f) { // switch is off, activate - Train->mvControlled->MotorBlowersSwitchOff(true, end::front); - Train->mvControlled->MotorBlowersSwitchOff(true, end::rear); + Train->mvControlled->MotorBlowersSwitchOff(true, VehicleEnd::front); + Train->mvControlled->MotorBlowersSwitchOff(true, VehicleEnd::rear); // visual feedback Train->ggMotorBlowersRearButton.UpdateValue(1.f, Train->dsbSwitch); } else { // deactivate - Train->mvControlled->MotorBlowersSwitchOff(false, end::front); - Train->mvControlled->MotorBlowersSwitchOff(false, end::rear); + Train->mvControlled->MotorBlowersSwitchOff(false, VehicleEnd::front); + Train->mvControlled->MotorBlowersSwitchOff(false, VehicleEnd::rear); // visual feedback Train->ggMotorBlowersRearButton.UpdateValue(0.f, Train->dsbSwitch); } diff --git a/vehicle/cab/cabcommands.cpp b/vehicle/cab/cabcommands.cpp index 496fbb917..5b505ed85 100644 --- a/vehicle/cab/cabcommands.cpp +++ b/vehicle/cab/cabcommands.cpp @@ -555,11 +555,11 @@ 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)}; + auto const exitdirection{(movedirection > 0 ? VehicleEnd::front : VehicleEnd::rear)}; if (Train->mvOccupied->Couplers[exitdirection].CouplingFlag.HasAll(Coupling::gangway)) { // przejscie do nastepnego pojazdu - auto *targetvehicle = exitdirection == end::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected(); + auto *targetvehicle = exitdirection == VehicleEnd::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected(); targetvehicle->MoverParameters->CabOccupied = Train->mvOccupied->Neighbours[exitdirection].vehicle_end ? -1 : 1; Train->MoveToVehicle(targetvehicle); } @@ -585,11 +585,11 @@ void TTrain::OnCommand_cabchangebackward(TTrain *Train, command_data const &Comm if (auto const movedirection{-1}; false == Train->CabChange(movedirection)) { // 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)}; + auto const exitdirection{(movedirection > 0 ? VehicleEnd::front : VehicleEnd::rear)}; if (Train->mvOccupied->Couplers[exitdirection].CouplingFlag.HasAll(Coupling::gangway)) { // przejscie do nastepnego pojazdu - auto *targetvehicle = exitdirection == end::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected(); + auto *targetvehicle = exitdirection == VehicleEnd::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected(); targetvehicle->MoverParameters->CabOccupied = Train->mvOccupied->Neighbours[exitdirection].vehicle_end ? -1 : 1; Train->MoveToVehicle(targetvehicle); } diff --git a/vehicle/cab/couplingcommands.cpp b/vehicle/cab/couplingcommands.cpp index 618b64da4..4013fa0fd 100644 --- a/vehicle/cab/couplingcommands.cpp +++ b/vehicle/cab/couplingcommands.cpp @@ -61,7 +61,7 @@ void TTrain::OnCommand_nearestcarcouplingincrease(TTrain *Train, command_data co if (couplerindex != -1 && vehicle != nullptr) { - vehicle->couple(couplerindex); + vehicle->couple(EndOf(couplerindex)); } if (Train->DynamicObject->Mechanik) { @@ -85,7 +85,7 @@ void TTrain::OnCommand_nearestcarcouplingdisconnect(TTrain *Train, command_data if (couplerindex != -1 && vehicle != nullptr) { - vehicle->uncouple(couplerindex); + vehicle->uncouple(EndOf(couplerindex)); } if (Train->DynamicObject->Mechanik) { @@ -108,7 +108,7 @@ void TTrain::OnCommand_nearestcarcoupleradapterattach(TTrain * /*Train*/, comman } auto const couplerindex = - glm::length2(glm::vec3{vehicle->CouplerPosition(end::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(end::rear)} - Command.location) ? end::front : end::rear; + glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::rear)} - Command.location) ? VehicleEnd::front : VehicleEnd::rear; vehicle->attach_coupler_adapter(couplerindex); } @@ -127,7 +127,7 @@ void TTrain::OnCommand_nearestcarcoupleradapterremove(TTrain * /*Train*/, comman } auto const couplerindex = - glm::length2(glm::vec3{vehicle->CouplerPosition(end::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(end::rear)} - Command.location) ? end::front : end::rear; + glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::rear)} - Command.location) ? VehicleEnd::front : VehicleEnd::rear; vehicle->remove_coupler_adapter(couplerindex); } @@ -182,7 +182,7 @@ void TTrain::OnCommand_occupiedcarcouplingdisconnectback(TTrain *Train, command_ if (Train->DynamicObject) { - Train->DynamicObject->uncouple(1 - Train->cab_to_end()); + Train->DynamicObject->uncouple(Opposite(Train->cab_to_end())); if (Train->DynamicObject->Mechanik) { // aktualizacja flag kierunku w składzie diff --git a/vehicle/cab/doorcommands.cpp b/vehicle/cab/doorcommands.cpp index 1b57e69b3..6205647c6 100644 --- a/vehicle/cab/doorcommands.cpp +++ b/vehicle/cab/doorcommands.cpp @@ -168,7 +168,7 @@ void TTrain::OnCommand_doorpermitleft(TTrain *Train, command_data const &Command return; } - auto const side{(Train->cab_to_end() == end::front ? side::left : side::right)}; + auto const side{(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right)}; if (Command.action == GLFW_PRESS) { @@ -214,7 +214,7 @@ void TTrain::OnCommand_doorpermitright(TTrain *Train, command_data const &Comman return; } - auto const side{(Train->cab_to_end() == end::front ? side::right : side::left)}; + auto const side{(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left)}; if (Command.action == GLFW_PRESS) { @@ -289,7 +289,7 @@ void TTrain::OnCommand_dooropenleft(TTrain *Train, command_data const &Command) if (Command.action == GLFW_PRESS) { - Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::left : side::right, true); + Train->mvOccupied->OperateDoors(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right, true); // visual feedback if (Train->ggDoorLeftOnButton.SubModel != nullptr) { @@ -339,7 +339,7 @@ void TTrain::OnCommand_doorcloseleft(TTrain *Train, command_data const &Command) else { // TODO: move door opening/closing to the update, so the switch animation doesn't hinge on door working - Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::left : side::right, false); + Train->mvOccupied->OperateDoors(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right, false); } // visual feedback if (Train->ggDoorLeftOffButton.SubModel != nullptr) @@ -361,7 +361,7 @@ void TTrain::OnCommand_doorcloseleft(TTrain *Train, command_data const &Command) // automatic departure signal delays actual door closing until the button is released Train->mvOccupied->signal_departure(false); // now we can actually close the door - Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::left : side::right, false); + Train->mvOccupied->OperateDoors(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right, false); } // visual feedback // dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position @@ -463,7 +463,7 @@ void TTrain::OnCommand_dooropenright(TTrain *Train, command_data const &Command) if (Command.action == GLFW_PRESS) { - Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::right : side::left, true); + Train->mvOccupied->OperateDoors(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left, true); // visual feedback if (Train->ggDoorRightOnButton.SubModel != nullptr) { @@ -512,7 +512,7 @@ void TTrain::OnCommand_doorcloseright(TTrain *Train, command_data const &Command } else { - Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::right : side::left, false); + Train->mvOccupied->OperateDoors(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left, false); } // visual feedback if (Train->ggDoorRightOffButton.SubModel != nullptr) @@ -534,7 +534,7 @@ void TTrain::OnCommand_doorcloseright(TTrain *Train, command_data const &Command // automatic departure signal delays actual door closing until the button is released Train->mvOccupied->signal_departure(false); // now we can actually close the door - Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::right : side::left, false); + Train->mvOccupied->OperateDoors(Train->cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left, false); } // visual feedback // dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position @@ -565,8 +565,8 @@ void TTrain::OnCommand_dooropenall(TTrain *Train, command_data const &Command) if (Command.action == GLFW_PRESS) { - Train->mvOccupied->OperateDoors(side::right, true); - Train->mvOccupied->OperateDoors(side::left, true); + Train->mvOccupied->OperateDoors(VehicleSide::right, true); + Train->mvOccupied->OperateDoors(VehicleSide::left, true); // visual feedback Train->ggDoorAllOnButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -606,8 +606,8 @@ void TTrain::OnCommand_doorcloseall(TTrain *Train, command_data const &Command) if (Train->ggDoorAllOffButton.type() != TGaugeType::push_delayed) { // delays the action until the button is released - Train->mvOccupied->OperateDoors(side::right, false); - Train->mvOccupied->OperateDoors(side::left, false); + Train->mvOccupied->OperateDoors(VehicleSide::right, false); + Train->mvOccupied->OperateDoors(VehicleSide::left, false); } // visual feedback Train->ggDoorLeftButton.UpdateValue(0.0, Train->dsbSwitch); @@ -624,8 +624,8 @@ void TTrain::OnCommand_doorcloseall(TTrain *Train, command_data const &Command) if (Train->ggDoorAllOffButton.type() == TGaugeType::push_delayed) { // now we can actually close the door - Train->mvOccupied->OperateDoors(side::right, false); - Train->mvOccupied->OperateDoors(side::left, false); + Train->mvOccupied->OperateDoors(VehicleSide::right, false); + Train->mvOccupied->OperateDoors(VehicleSide::left, false); } // visual feedback if (Train->ggDoorAllOffButton.SubModel) diff --git a/vehicle/cab/equipmentcommands.cpp b/vehicle/cab/equipmentcommands.cpp index 38c90754d..fc0128325 100644 --- a/vehicle/cab/equipmentcommands.cpp +++ b/vehicle/cab/equipmentcommands.cpp @@ -414,7 +414,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; auto const flag{CouplingSet::FromBits(Train->DynamicObject->MoverParameters->inductionMotor.inverterControlCouplings)}; - TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); + TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, flag); while (p) { if (p->MoverParameters->inductionMotor.traction.maxPower > 1) @@ -453,7 +453,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; auto const flag{CouplingSet::FromBits(Train->DynamicObject->MoverParameters->inductionMotor.inverterControlCouplings)}; - TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); + TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, flag); while (p) { if (p->MoverParameters->inductionMotor.traction.maxPower > 1) @@ -492,7 +492,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; auto const flag{CouplingSet::FromBits(Train->DynamicObject->MoverParameters->inductionMotor.inverterControlCouplings)}; - TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); + TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, flag); while (p) { if (p->MoverParameters->inductionMotor.traction.maxPower > 1) diff --git a/vehicle/cab/lightcommands.cpp b/vehicle/cab/lightcommands.cpp index 2c13201cd..5089e3f85 100644 --- a/vehicle/cab/lightcommands.cpp +++ b/vehicle/cab/lightcommands.cpp @@ -203,8 +203,8 @@ void TTrain::OnCommand_headlighttoggleleft(TTrain *Train, command_data const &Co void TTrain::OnCommand_lightsset(TTrain *Train, command_data const &Command) { // set custom item in Lights inventory - Train->mvOccupied->Lights[end::front][17] = static_cast(Command.param1); - Train->mvOccupied->Lights[end::rear][17] = static_cast(Command.param2); + Train->mvOccupied->Lights[VehicleEnd::front][17] = static_cast(Command.param1); + Train->mvOccupied->Lights[VehicleEnd::rear][17] = static_cast(Command.param2); Train->mvOccupied->LightsPos = 18; // nasza custom pozycja Train->Dynamic()->SetLights(); } @@ -249,7 +249,7 @@ void TTrain::OnCommand_headlightdisableleft(TTrain *Train, command_data const &C if (Command.action == GLFW_PRESS) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - int const vehicleend{Train->cab_to_end()}; + auto const vehicleend{Train->cab_to_end()}; if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_left) == 0) { @@ -623,7 +623,7 @@ void TTrain::OnCommand_headlighttogglerearleft(TTrain *Train, command_data const if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_right) == 0) { @@ -646,7 +646,7 @@ void TTrain::OnCommand_headlightenablerearleft(TTrain *Train, command_data const if (Command.action == GLFW_PRESS) { - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already enabled if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_right) == 0) { @@ -667,7 +667,7 @@ void TTrain::OnCommand_headlightdisablerearleft(TTrain *Train, command_data cons } if (Command.action == GLFW_PRESS) { - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already disabled if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_right) == 0) { @@ -686,7 +686,7 @@ void TTrain::OnCommand_headlighttogglerearright(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_left) == 0) { @@ -710,7 +710,7 @@ void TTrain::OnCommand_headlightenablerearright(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_left) == 0) { @@ -733,7 +733,7 @@ void TTrain::OnCommand_headlightdisablerearright(TTrain *Train, command_data con if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already disabled if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_left) == 0) { @@ -759,7 +759,7 @@ void TTrain::OnCommand_headlighttogglerearupper(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_upper) == 0) { OnCommand_headlightenablerearupper(Train, Command); @@ -783,7 +783,7 @@ void TTrain::OnCommand_headlightenablerearupper(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_upper) == 0) { // turn on @@ -806,7 +806,7 @@ void TTrain::OnCommand_headlightdisablerearupper(TTrain *Train, command_data con if (Command.action == GLFW_PRESS) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already disabled? if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_upper) == 0) { @@ -863,7 +863,7 @@ void TTrain::OnCommand_redmarkertogglerearleft(TTrain *Train, command_data const if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_right) == 0) { @@ -888,7 +888,7 @@ void TTrain::OnCommand_redmarkerenablerearleft(TTrain *Train, command_data const if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_right) == 0) { // turn on @@ -911,7 +911,7 @@ void TTrain::OnCommand_redmarkerdisablerearleft(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_right) == 0) { return; @@ -935,7 +935,7 @@ void TTrain::OnCommand_redmarkertogglerearright(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_left) == 0) { @@ -960,7 +960,7 @@ void TTrain::OnCommand_redmarkerenablerearright(TTrain *Train, command_data cons if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_left) == 0) { // turn on @@ -983,7 +983,7 @@ void TTrain::OnCommand_redmarkerdisablerearright(TTrain *Train, command_data con if (Command.action == GLFW_PRESS) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc - auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)}; + auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_left) == 0) { return; diff --git a/vehicle/cab/pantographcommands.cpp b/vehicle/cab/pantographcommands.cpp index 7c96a8b3e..2bf0f0d46 100644 --- a/vehicle/cab/pantographcommands.cpp +++ b/vehicle/cab/pantographcommands.cpp @@ -59,7 +59,7 @@ void TTrain::OnCommand_pantographtogglefront(TTrain *Train, command_data const & if (Command.action == GLFW_PRESS) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - auto const &pantograph{Train->mvPantographUnit->Pantographs[end::front]}; + auto const &pantograph{Train->mvPantographUnit->Pantographs[VehicleEnd::front]}; auto const state{pantograph.valve.is_enabled || pantograph.is_active}; // fallback for impulse switches if (state) { @@ -76,7 +76,7 @@ void TTrain::OnCommand_pantographtogglefront(TTrain *Train, command_data const & if (Train->mvOccupied->PantSwitchType == "impulse") { auto const ismanual{Train->iCabn == 0}; - Train->mvOccupied->OperatePantographValve(end::front, operation_t::none, ismanual ? range_t::local : range_t::consist); + Train->mvOccupied->OperatePantographValve(VehicleEnd::front, operation_t::none, ismanual ? range_t::local : range_t::consist); } } } @@ -93,7 +93,7 @@ void TTrain::OnCommand_pantographtogglerear(TTrain *Train, command_data const &C if (Command.action == GLFW_PRESS) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - auto const &pantograph{Train->mvPantographUnit->Pantographs[end::rear]}; + auto const &pantograph{Train->mvPantographUnit->Pantographs[VehicleEnd::rear]}; auto const state{pantograph.valve.is_enabled || pantograph.is_active}; // fallback for impulse switches if (state) { @@ -110,7 +110,7 @@ void TTrain::OnCommand_pantographtogglerear(TTrain *Train, command_data const &C if (Train->mvOccupied->PantSwitchType == "impulse") { auto const ismanual{Train->iCabn == 0}; - Train->mvOccupied->OperatePantographValve(end::rear, operation_t::none, ismanual ? range_t::local : range_t::consist); + Train->mvOccupied->OperatePantographValve(VehicleEnd::rear, operation_t::none, ismanual ? range_t::local : range_t::consist); } } } @@ -134,7 +134,7 @@ void TTrain::OnCommand_pantographraisefront(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down // HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers auto const ismanual{Train->iCabn == 0}; - Train->mvOccupied->OperatePantographValve(end::front, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::enable_on : operation_t::enable, + Train->mvOccupied->OperatePantographValve(VehicleEnd::front, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::enable_on : operation_t::enable, ismanual ? range_t::local : range_t::consist); } else if (Command.action == GLFW_RELEASE) @@ -163,7 +163,7 @@ void TTrain::OnCommand_pantographraiserear(TTrain *Train, command_data const &Co // only reacting to press, so the switch doesn't flip back and forth if key is held down // HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers auto const ismanual{Train->iCabn == 0}; - Train->mvOccupied->OperatePantographValve(end::rear, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::enable_on : operation_t::enable, + Train->mvOccupied->OperatePantographValve(VehicleEnd::rear, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::enable_on : operation_t::enable, ismanual ? range_t::local : range_t::consist); } else if (Command.action == GLFW_RELEASE) @@ -192,7 +192,7 @@ void TTrain::OnCommand_pantographlowerfront(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down // HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers auto const ismanual{Train->iCabn == 0}; - Train->mvOccupied->OperatePantographValve(end::front, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::disable_on : operation_t::disable, + Train->mvOccupied->OperatePantographValve(VehicleEnd::front, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::disable_on : operation_t::disable, ismanual ? range_t::local : range_t::consist); } else if (Command.action == GLFW_RELEASE) @@ -221,7 +221,7 @@ void TTrain::OnCommand_pantographlowerrear(TTrain *Train, command_data const &Co // only reacting to press, so the switch doesn't flip back and forth if key is held down // HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers auto const ismanual{Train->iCabn == 0}; - Train->mvOccupied->OperatePantographValve(end::rear, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::disable_on : operation_t::disable, + Train->mvOccupied->OperatePantographValve(VehicleEnd::rear, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::disable_on : operation_t::disable, ismanual ? range_t::local : range_t::consist); } else if (Command.action == GLFW_RELEASE) @@ -419,12 +419,12 @@ void TTrain::update_pantograph_valves() auto const &selection{mvOccupied->PantsPreset.second[cab_to_end()]}; auto const preset{presets[selection] - '0'}; - auto const swapends{cab_to_end() != end::front}; + auto const swapends{cab_to_end() != VehicleEnd::front}; // check desired states for both pantographs; value: whether the pantograph should be raised auto const frontstate{preset & (swapends ? 2 : 1)}; auto const rearstate{preset & (swapends ? 1 : 2)}; - mvOccupied->OperatePantographValve(end::front, frontstate ? enable : disable); - mvOccupied->OperatePantographValve(end::rear, rearstate ? enable : disable); + mvOccupied->OperatePantographValve(VehicleEnd::front, frontstate ? enable : disable); + mvOccupied->OperatePantographValve(VehicleEnd::rear, rearstate ? enable : disable); } void TTrain::change_pantograph_selection(int const Change) @@ -500,8 +500,8 @@ void TTrain::OnCommand_pantographvalvesoff(TTrain *Train, command_data const &Co if (Command.action == GLFW_PRESS) { // implement action - Train->mvOccupied->OperatePantographValve(end::front, operation_t::disable); - Train->mvOccupied->OperatePantographValve(end::rear, operation_t::disable); + Train->mvOccupied->OperatePantographValve(VehicleEnd::front, operation_t::disable); + Train->mvOccupied->OperatePantographValve(VehicleEnd::rear, operation_t::disable); // visual feedback if (hasSeparateSwitches) Train->ggPantValvesOff.UpdateValue(1.0, Train->dsbSwitch); diff --git a/vehicle/cab/setup.cpp b/vehicle/cab/setup.cpp index 3af70a82e..d1bac2763 100644 --- a/vehicle/cab/setup.cpp +++ b/vehicle/cab/setup.cpp @@ -938,13 +938,13 @@ void TTrain::set_cab_controls(int const Cab) if( mvOccupied->PantSwitchType != "impulse" ) { if( ggPantFrontButton.SubModel ) { ggPantFrontButton.PutValue( - ( mvControlled->Pantographs[end::front].valve.is_enabled ? + ( mvControlled->Pantographs[VehicleEnd::front].valve.is_enabled ? 1.f : 0.f ) ); } if( ggPantFrontButtonOff.SubModel ) { ggPantFrontButtonOff.PutValue( - ( mvControlled->Pantographs[end::front].valve.is_disabled ? + ( mvControlled->Pantographs[VehicleEnd::front].valve.is_disabled ? 1.f : 0.f ) ); } @@ -952,13 +952,13 @@ void TTrain::set_cab_controls(int const Cab) if( mvOccupied->PantSwitchType != "impulse" ) { if( ggPantRearButton.SubModel ) { ggPantRearButton.PutValue( - ( mvControlled->Pantographs[end::rear].valve.is_enabled ? + ( mvControlled->Pantographs[VehicleEnd::rear].valve.is_enabled ? 1.f : 0.f ) ); } if( ggPantRearButtonOff.SubModel ) { ggPantRearButtonOff.PutValue( - ( mvControlled->Pantographs[end::rear].valve.is_disabled ? + ( mvControlled->Pantographs[VehicleEnd::rear].valve.is_disabled ? 1.f : 0.f ) ); } @@ -1059,16 +1059,16 @@ void TTrain::set_cab_controls(int const Cab) // doors permits if (false == ggDoorLeftPermitButton.is_push()) { - ggDoorLeftPermitButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::left : side::right].open_permit ? 1.f : 0.f); + ggDoorLeftPermitButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right].open_permit ? 1.f : 0.f); } if (false == ggDoorRightPermitButton.is_push()) { - ggDoorRightPermitButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::right : side::left].open_permit ? 1.f : 0.f); + ggDoorRightPermitButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left].open_permit ? 1.f : 0.f); } ggDoorPermitPresetButton.PutValue(static_cast(mvOccupied->Doors.permit_preset)); // door controls - ggDoorLeftButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::left : side::right].is_closed ? 0.f : 1.f); - ggDoorRightButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::right : side::left].is_closed ? 0.f : 1.f); + ggDoorLeftButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right].is_closed ? 0.f : 1.f); + ggDoorRightButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left].is_closed ? 0.f : 1.f); // door lock ggDoorSignallingButton.PutValue(mvOccupied->Doors.lock_enabled ? 1.f : 0.f); // door step @@ -1144,15 +1144,15 @@ void TTrain::set_cab_controls(int const Cab) // traction motor fans if (ggMotorBlowersFrontButton.type() != TGaugeType::push) { - ggMotorBlowersFrontButton.PutValue(mvControlled->MotorBlowers[end::front].is_enabled ? 1.f : 0.f); + ggMotorBlowersFrontButton.PutValue(mvControlled->MotorBlowers[VehicleEnd::front].is_enabled ? 1.f : 0.f); } if (ggMotorBlowersRearButton.type() != TGaugeType::push) { - ggMotorBlowersRearButton.PutValue(mvControlled->MotorBlowers[end::rear].is_enabled ? 1.f : 0.f); + ggMotorBlowersRearButton.PutValue(mvControlled->MotorBlowers[VehicleEnd::rear].is_enabled ? 1.f : 0.f); } if (ggMotorBlowersAllOffButton.type() != TGaugeType::push) { - ggMotorBlowersAllOffButton.PutValue(mvControlled->MotorBlowers[end::front].is_disabled || mvControlled->MotorBlowers[end::rear].is_disabled ? 1.f : 0.f); + ggMotorBlowersAllOffButton.PutValue(mvControlled->MotorBlowers[VehicleEnd::front].is_disabled || mvControlled->MotorBlowers[VehicleEnd::rear].is_disabled ? 1.f : 0.f); } // second controller if (ggScndCtrl.is_push()) @@ -1181,7 +1181,7 @@ void TTrain::set_cab_controls(int const Cab) { int itemindex = itemstart; itemstart++; - TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag); + TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, flag); while (p) { if (p->MoverParameters->inductionMotor.traction.maxPower > 1) @@ -1652,10 +1652,10 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con std::unordered_map const autoboolgauges = { {"doormode_sw:", &mvOccupied->Doors.remote_only}, {"coolingfans_sw:", &mvControlled->RVentForceOn}, - {"pantfront_sw:", &mvPantographUnit->Pantographs[end::front].valve.is_enabled}, - {"pantrear_sw:", &mvPantographUnit->Pantographs[end::rear].valve.is_enabled}, - {"pantfrontoff_sw:", &mvPantographUnit->Pantographs[end::front].valve.is_disabled}, - {"pantrearoff_sw:", &mvPantographUnit->Pantographs[end::rear].valve.is_disabled}, + {"pantfront_sw:", &mvPantographUnit->Pantographs[VehicleEnd::front].valve.is_enabled}, + {"pantrear_sw:", &mvPantographUnit->Pantographs[VehicleEnd::rear].valve.is_enabled}, + {"pantfrontoff_sw:", &mvPantographUnit->Pantographs[VehicleEnd::front].valve.is_disabled}, + {"pantrearoff_sw:", &mvPantographUnit->Pantographs[VehicleEnd::rear].valve.is_disabled}, {"radio_sw:", &mvOccupied->Radio}, {"radiofuse_sw:", &mvOccupied->RadioFuse}, {"cablight_sw:", &Cabine[iCabn].bLight}, diff --git a/vehicle/cab/train.cpp b/vehicle/cab/train.cpp index 9920635bb..757be2871 100644 --- a/vehicle/cab/train.cpp +++ b/vehicle/cab/train.cpp @@ -181,29 +181,29 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const dict->insert("converter_overload", mvControlled->ConvOvldFlag); dict->insert("compress", mvControlled->CompressorFlag); dict->insert("pant_compressor", mvPantographUnit->PantCompFlag); - dict->insert("lights_front", mvOccupied->iLights[end::front]); - dict->insert("lights_rear", mvOccupied->iLights[end::rear]); + dict->insert("lights_front", mvOccupied->iLights[VehicleEnd::front]); + dict->insert("lights_rear", mvOccupied->iLights[VehicleEnd::rear]); dict->insert("off_from_dimmer", mvOccupied->currentDimPosition().isOff); dict->insert("lights_compartments", mvOccupied->CompartmentLights.is_active || mvOccupied->CompartmentLights.is_disabled); if (Dynamic()->Mechanik) { auto const *controller{Dynamic()->Mechanik}; - auto const cabmodifier{cab_to_end() == end::front ? 1 : -1}; + auto const cabmodifier{cab_to_end() == VehicleEnd::front ? 1 : -1}; auto const traindirection{controller->Direction() * cabmodifier}; - auto const *frontvehicle{controller->Vehicle(traindirection >= 0 ? end::front : end::rear)}; - auto const *rearvehicle{controller->Vehicle(traindirection >= 0 ? end::rear : end::front)}; + auto const *frontvehicle{controller->Vehicle(traindirection >= 0 ? VehicleEnd::front : VehicleEnd::rear)}; + auto const *rearvehicle{controller->Vehicle(traindirection >= 0 ? VehicleEnd::rear : VehicleEnd::front)}; auto const frontvehicledirection{(frontvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1)}; auto const rearvehicledirection{(rearvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1)}; - auto const fronttrainlights{frontvehicle->MoverParameters->iLights[frontvehicledirection * cabmodifier >= 0 ? end::front : end::rear]}; - auto const reartrainlights{rearvehicle->MoverParameters->iLights[rearvehicledirection * cabmodifier >= 0 ? end::rear : end::front]}; + auto const fronttrainlights{frontvehicle->MoverParameters->iLights[frontvehicledirection * cabmodifier >= 0 ? VehicleEnd::front : VehicleEnd::rear]}; + auto const reartrainlights{rearvehicle->MoverParameters->iLights[rearvehicledirection * cabmodifier >= 0 ? VehicleEnd::rear : VehicleEnd::front]}; dict->insert("lights_train_front", fronttrainlights); dict->insert("lights_train_rear", reartrainlights); } else { // fallback, in the unlikely case we lose the controller - dict->insert("lights_train_front", mvOccupied->iLights[end::front]); - dict->insert("lights_train_rear", mvOccupied->iLights[end::rear]); + dict->insert("lights_train_front", mvOccupied->iLights[VehicleEnd::front]); + dict->insert("lights_train_rear", mvOccupied->iLights[VehicleEnd::rear]); } // reverser dict->insert("direction", mvOccupied->DirActive); @@ -257,8 +257,8 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const dict->insert("radio_volume", m_radiovolume); dict->insert("door_lock", mvOccupied->Doors.lock_enabled); dict->insert("door_step", mvOccupied->Doors.step_enabled); - dict->insert("door_permit_left", mvOccupied->Doors.instances[side::left].open_permit); - dict->insert("door_permit_right", mvOccupied->Doors.instances[side::right].open_permit); + dict->insert("door_permit_left", mvOccupied->Doors.instances[VehicleSide::left].open_permit); + dict->insert("door_permit_right", mvOccupied->Doors.instances[VehicleSide::right].open_permit); // movement data dict->insert("velocity", std::abs(mvOccupied->Vel)); dict->insert("tractionforce", std::abs(mvOccupied->Ft)); @@ -315,7 +315,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, Coupling::control); + TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); int in = 0; while (p && in < 8) { @@ -424,10 +424,10 @@ TTrain::state_t TTrain::get_state() const btLampkaNapNastHam.GetValue(), mvOccupied->DirActive > 0, mvOccupied->DirActive < 0, - mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::right : side::left].open_permit, - mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::right : side::left].is_open, - mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::left : side::right].open_permit, - mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::left : side::right].is_open, + mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? VehicleSide::right : VehicleSide::left].open_permit, + mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? VehicleSide::right : VehicleSide::left].is_open, + mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? VehicleSide::left : VehicleSide::right].open_permit, + mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? VehicleSide::left : VehicleSide::right].is_open, mvOccupied->Doors.step_enabled, mvOccupied->Power24vIsAvailable, 0, @@ -519,13 +519,13 @@ 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 == mvControlled->Couplers[end::front].CouplingFlag.HasAll(Coupling::permanent)) + if (mvControlled->Couplers[VehicleEnd::front].Connected != nullptr && true == mvControlled->Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::permanent)) { - mvControlled->Couplers[end::front].Connected->StLinSwitchOff = State; + mvControlled->Couplers[VehicleEnd::front].Connected->StLinSwitchOff = State; } - if (mvControlled->Couplers[end::rear].Connected != nullptr && true == mvControlled->Couplers[end::rear].CouplingFlag.HasAll(Coupling::permanent)) + if (mvControlled->Couplers[VehicleEnd::rear].Connected != nullptr && true == mvControlled->Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::permanent)) { - mvControlled->Couplers[end::rear].Connected->StLinSwitchOff = State; + mvControlled->Couplers[VehicleEnd::rear].Connected->StLinSwitchOff = State; } } } diff --git a/vehicle/cab/update.cpp b/vehicle/cab/update.cpp index 1639801b5..23441daa4 100644 --- a/vehicle/cab/update.cpp +++ b/vehicle/cab/update.cpp @@ -123,7 +123,7 @@ bool TTrain::Update(double const Deltatime) doorpermittimer -= static_cast(Deltatime); if (doorpermittimer < 0.f) { - mvOccupied->OperateDoors(static_cast(idx), true); + mvOccupied->OperateDoors(static_cast(idx), true); } } @@ -146,16 +146,16 @@ bool TTrain::Update(double const Deltatime) // helper variables if (DynamicObject->Mechanik != nullptr) { - m_doors = DynamicObject->Mechanik->IsAnyDoorOpen[side::right] || DynamicObject->Mechanik->IsAnyDoorOpen[side::left]; - m_doorpermits = DynamicObject->Mechanik->IsAnyDoorPermitActive[side::right] || DynamicObject->Mechanik->IsAnyDoorPermitActive[side::left]; - m_doorspermitleft = mvOccupied->Doors.instances[cab_to_end() == end::front ? side::left : side::right].open_permit && + m_doors = DynamicObject->Mechanik->IsAnyDoorOpen[VehicleSide::right] || DynamicObject->Mechanik->IsAnyDoorOpen[VehicleSide::left]; + m_doorpermits = DynamicObject->Mechanik->IsAnyDoorPermitActive[VehicleSide::right] || DynamicObject->Mechanik->IsAnyDoorPermitActive[VehicleSide::left]; + m_doorspermitleft = mvOccupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right].open_permit && (simulation::Time.data().wSecond % 2 < 1 || mvOccupied->DoorsPermitLightBlinking < 1 || - mvOccupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::left : side::right] || - (mvOccupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == end::front ? side::left : side::right])); - m_doorspermitright = mvOccupied->Doors.instances[cab_to_end() == end::front ? side::right : side::left].open_permit && + mvOccupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right] || + (mvOccupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right])); + m_doorspermitright = mvOccupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left].open_permit && (simulation::Time.data().wSecond % 2 < 1 || mvOccupied->DoorsPermitLightBlinking < 1 || - mvOccupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::right : side::left] || - (mvOccupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == end::front ? side::right : side::left])); + mvOccupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left] || + (mvOccupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left])); } m_dirforward = mvControlled->DirActive > 0; m_dirneutral = mvControlled->DirActive == 0; @@ -285,7 +285,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, Coupling::control); + TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); int in = 0; fEIMParams[0][6] = 0; iCarNo = 0; @@ -321,10 +321,10 @@ bool TTrain::Update(double const Deltatime) fPress[i][6] = static_cast(p->MoverParameters->SpringBrake.SBP); bBrakes[i][0] = p->MoverParameters->SpringBrake.IsActive; bBrakes[i][1] = p->MoverParameters->SpringBrake.ShuttOff; - bDoors[i][1] = p->MoverParameters->Doors.instances[side::left].position > 0.f; - bDoors[i][2] = p->MoverParameters->Doors.instances[side::right].position > 0.f; - bDoors[i][3] = p->MoverParameters->Doors.instances[side::left].step_position > 0.f; - bDoors[i][4] = p->MoverParameters->Doors.instances[side::right].step_position > 0.f; + bDoors[i][1] = p->MoverParameters->Doors.instances[VehicleSide::left].position > 0.f; + bDoors[i][2] = p->MoverParameters->Doors.instances[VehicleSide::right].position > 0.f; + bDoors[i][3] = p->MoverParameters->Doors.instances[VehicleSide::left].step_position > 0.f; + bDoors[i][4] = p->MoverParameters->Doors.instances[VehicleSide::right].step_position > 0.f; bDoors[i][0] = bDoors[i][1] || bDoors[i][2]; iDoorNo[i] = p->iAnimType[ANIM_DOORS]; iUnits[i] = iUnitNo; @@ -332,8 +332,8 @@ bool TTrain::Update(double const Deltatime) asCarName[i] = p->name(); if (p->MoverParameters->EnginePowerSource.SourceType == TPowerSource::CurrentCollector) { - bPants[iUnitNo - 1][end::front] = bPants[iUnitNo - 1][end::front] || p->MoverParameters->Pantographs[end::front].is_active; - bPants[iUnitNo - 1][end::rear] = bPants[iUnitNo - 1][end::rear] || p->MoverParameters->Pantographs[end::rear].is_active; + bPants[iUnitNo - 1][VehicleEnd::front] = bPants[iUnitNo - 1][VehicleEnd::front] || p->MoverParameters->Pantographs[VehicleEnd::front].is_active; + bPants[iUnitNo - 1][VehicleEnd::rear] = bPants[iUnitNo - 1][VehicleEnd::rear] || p->MoverParameters->Pantographs[VehicleEnd::rear].is_active; } // TBD, TODO: clean up compressor data arrangement? if (iUnitNo <= 8) @@ -495,9 +495,9 @@ bool TTrain::Update(double const Deltatime) // youBy - prad w drugim czlonie: galaz lub calosc { TDynamicObject const *tmp{nullptr}; - if (DynamicObject->NextConnected() && mvControlled->Couplers[end::rear].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied == 1) + if (DynamicObject->NextConnected() && mvControlled->Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied == 1) tmp = DynamicObject->NextConnected(); - if (DynamicObject->PrevConnected() && mvControlled->Couplers[end::front].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied == -1) + if (DynamicObject->PrevConnected() && mvControlled->Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::control) && mvOccupied->CabOccupied == -1) tmp = DynamicObject->PrevConnected(); if (tmp && tmp->MoverParameters->Power > 0) { @@ -697,7 +697,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(mvControlled->Couplers[mvControlled->CabOccupied == 1 ? rear : front].CouplingFlag.HasAll(Coupling::control)); + btLampkaUkrotnienie.Turn(mvControlled->Couplers[mvControlled->CabOccupied == 1 ? VehicleEnd::rear : VehicleEnd::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 @@ -776,8 +776,8 @@ bool TTrain::Update(double const Deltatime) // NBMX wrzesien 2003 - drzwi oraz sygnał odjazdu if (DynamicObject->Mechanik != nullptr) { - btLampkaDoorLeft.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::left : side::right]); - btLampkaDoorRight.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::right : side::left]); + btLampkaDoorLeft.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right]); + btLampkaDoorRight.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left]); } if (DynamicObject->Mechanik != nullptr) { @@ -818,16 +818,16 @@ bool TTrain::Update(double const Deltatime) btLampkaSpringBrakeInactive.Turn(!mvOccupied->SpringBrake.IsActive); // light indicators // NOTE: sides are hardcoded to deal with setups where single cab is equipped with all indicators - btLampkaUpperLight.Turn((mvOccupied->iLights[end::front] & light::headlight_upper) != 0); - btLampkaLeftLight.Turn((mvOccupied->iLights[end::front] & light::headlight_left) != 0); - btLampkaRightLight.Turn((mvOccupied->iLights[end::front] & light::headlight_right) != 0); - btLampkaLeftEndLight.Turn((mvOccupied->iLights[end::front] & light::redmarker_left) != 0); - btLampkaRightEndLight.Turn((mvOccupied->iLights[end::front] & light::redmarker_right) != 0); - btLampkaRearUpperLight.Turn((mvOccupied->iLights[end::rear] & light::headlight_upper) != 0); - btLampkaRearLeftLight.Turn((mvOccupied->iLights[end::rear] & light::headlight_left) != 0); - btLampkaRearRightLight.Turn((mvOccupied->iLights[end::rear] & light::headlight_right) != 0); - btLampkaRearLeftEndLight.Turn((mvOccupied->iLights[end::rear] & light::redmarker_left) != 0); - btLampkaRearRightEndLight.Turn((mvOccupied->iLights[end::rear] & light::redmarker_right) != 0); + btLampkaUpperLight.Turn((mvOccupied->iLights[VehicleEnd::front] & light::headlight_upper) != 0); + btLampkaLeftLight.Turn((mvOccupied->iLights[VehicleEnd::front] & light::headlight_left) != 0); + btLampkaRightLight.Turn((mvOccupied->iLights[VehicleEnd::front] & light::headlight_right) != 0); + btLampkaLeftEndLight.Turn((mvOccupied->iLights[VehicleEnd::front] & light::redmarker_left) != 0); + btLampkaRightEndLight.Turn((mvOccupied->iLights[VehicleEnd::front] & light::redmarker_right) != 0); + btLampkaRearUpperLight.Turn((mvOccupied->iLights[VehicleEnd::rear] & light::headlight_upper) != 0); + btLampkaRearLeftLight.Turn((mvOccupied->iLights[VehicleEnd::rear] & light::headlight_left) != 0); + btLampkaRearRightLight.Turn((mvOccupied->iLights[VehicleEnd::rear] & light::headlight_right) != 0); + btLampkaRearLeftEndLight.Turn((mvOccupied->iLights[VehicleEnd::rear] & light::redmarker_left) != 0); + btLampkaRearRightEndLight.Turn((mvOccupied->iLights[VehicleEnd::rear] & light::redmarker_right) != 0); // others btLampkaMalfunction.Turn(mvControlled->diesel.heat.PA); // overheat indicator lamps @@ -835,7 +835,7 @@ bool TTrain::Update(double const Deltatime) btLampkaWaterOverheat.Turn(mvControlled->diesel.heat.water.is_hot); btLampkaWaterAuxOverheat.Turn(mvControlled->diesel.heat.water_aux.is_hot); btLampkaEngineOverheat.Turn(mvControlled->diesel.heat.engine_is_hot); - btLampkaMotorBlowers.Turn(mvControlled->MotorBlowers[end::front].is_active && mvControlled->MotorBlowers[end::rear].is_active); + btLampkaMotorBlowers.Turn(mvControlled->MotorBlowers[VehicleEnd::front].is_active && mvControlled->MotorBlowers[VehicleEnd::rear].is_active); btLampkaCoolingFans.Turn(mvControlled->RventRot > 1.0); btLampkaLouvresClosed.Turn(mvControlled->LouvresClosed()); btLampkaTempomat.Turn(mvOccupied->SpeedCtrlUnit.IsActive); @@ -1217,7 +1217,7 @@ bool TTrain::Update(double const Deltatime) InstrumentLightType == 4 ? mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable : false)}; InstrumentLightActive = InstrumentLightType == 3 ? true : // TODO: link the light state with the state of the master key - InstrumentLightType == 4 ? mvOccupied->iLights[end::front] != 0 || mvOccupied->iLights[end::rear] != 0 : + InstrumentLightType == 4 ? mvOccupied->iLights[VehicleEnd::front] != 0 || mvOccupied->iLights[VehicleEnd::rear] != 0 : InstrumentLightActive; btInstrumentLight.Turn(InstrumentLightActive && lightpower); btDashboardLight.Turn(DashboardLightActive && lightpower); diff --git a/vehicle/crewchange.cpp b/vehicle/crewchange.cpp index 8f44556b4..06d72ab12 100644 --- a/vehicle/crewchange.cpp +++ b/vehicle/crewchange.cpp @@ -31,7 +31,7 @@ constexpr int consist_walk_limit{300}; // alone, as the driver's own check of the consist does, so it works for a consist nobody has put in order template void for_each_in_consist(TDynamicObject &Vehicle, Function_ const Function) { - auto side{static_cast(end::front)}; + auto side{static_cast(VehicleEnd::front)}; auto *vehicle{Vehicle.FirstFind(side)}; side = 1 - side; auto count{0}; diff --git a/vehicle/dynamic/animations.cpp b/vehicle/dynamic/animations.cpp index 72a853408..f726ee58d 100644 --- a/vehicle/dynamic/animations.cpp +++ b/vehicle/dynamic/animations.cpp @@ -265,10 +265,10 @@ void TDynamicObject::SetPneumatic(bool front, bool red) ten = GetPneumatic(front, red); // 1=lewy skos,2=prawy skos,3=dwa proste if (front) if (PrevConnected()) // pojazd od strony sprzęgu 0 - tamten = PrevConnected()->GetPneumatic(PrevConnectedNo() == end::front ? true : false, red); + tamten = PrevConnected()->GetPneumatic(EndOf(PrevConnectedNo()) == VehicleEnd::front ? true : false, red); if (!front) if (NextConnected()) // pojazd od strony sprzęgu 1 - tamten = NextConnected()->GetPneumatic(NextConnectedNo() == end::front ? true : false, red); + tamten = NextConnected()->GetPneumatic(EndOf(NextConnectedNo()) == VehicleEnd::front ? true : false, red); if (ten == tamten) // jeśli układ jest symetryczny switch (ten) { @@ -279,7 +279,7 @@ void TDynamicObject::SetPneumatic(bool front, bool red) x = 3; break; // mamy prawy skos, dać prawe skosy case 3: // wszystkie cztery na prosto - if (MoverParameters->Couplers[front ? end::front : end::rear].Render) + if (MoverParameters->Couplers[front ? VehicleEnd::front : VehicleEnd::rear].Render) x = 1; else x = 4; @@ -355,8 +355,8 @@ float door_position( TMoverParameters const &Mover, TAnim const *Animation ) { return Mover.Doors.instances[ ( door_wings::on_right_side( Animation->iNumber ) ? - side::right : - side::left ) ].position; + VehicleSide::right : + VehicleSide::left ) ].position; } // the wing in the main model, and its namesake in the low poly interior; either can be missing @@ -514,8 +514,8 @@ void TDynamicObject::UpdatePlatformTranslate( TAnim *pAnim ) { auto const &door { MoverParameters->Doors.instances[ ( ( pAnim->iNumber & 1 ) == 0 ? - side::right : - side::left ) ] }; + VehicleSide::right : + VehicleSide::left ) ] }; pAnim->smAnimated->SetTranslate( glm::vec3{ @@ -531,8 +531,8 @@ void TDynamicObject::UpdatePlatformRotate( TAnim *pAnim ) { auto const &door { MoverParameters->Doors.instances[ ( ( pAnim->iNumber & 1 ) == 0 ? - side::right : - side::left ) ] }; + VehicleSide::right : + VehicleSide::left ) ] }; pAnim->smAnimated->SetRotate( float3( 0, 1, 0 ), @@ -546,8 +546,8 @@ void TDynamicObject::UpdateMirror( TAnim *pAnim ) { // only animate the mirror if it's located on the same end of the vehicle as the active cab auto const isactive { ( - MoverParameters->CabOccupied > 0 ? ( pAnim->iNumber >> 4 == end::front ? 1.0 : 0.0 ) : - MoverParameters->CabOccupied < 0 ? ( pAnim->iNumber >> 4 == end::rear ? 1.0 : 0.0 ) : + MoverParameters->CabOccupied > 0 ? ( EndOf( pAnim->iNumber >> 4 ) == VehicleEnd::front ? 1.0 : 0.0 ) : + MoverParameters->CabOccupied < 0 ? ( EndOf( pAnim->iNumber >> 4 ) == VehicleEnd::rear ? 1.0 : 0.0 ) : 0.0 ) }; if( pAnim->iNumber & 1 ) diff --git a/vehicle/dynamic/consist.cpp b/vehicle/dynamic/consist.cpp index d912c1693..2a53e7d2b 100644 --- a/vehicle/dynamic/consist.cpp +++ b/vehicle/dynamic/consist.cpp @@ -70,11 +70,11 @@ TDynamicObject * TDynamicObject::FirstFind(int &coupler_nr, CouplingSet const cf return nullptr; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów 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) + if (EndOf(coupler_nr) == VehicleEnd::front) { // jeżeli szukamy od sprzęgu 0 if (temp->PrevConnected()) // jeśli mamy coś z przodu { - if (temp->PrevConnectedNo() == end::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony + if (EndOf(temp->PrevConnectedNo()) == VehicleEnd::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu temp = temp->PrevConnected(); // ten jest od strony 0 } @@ -85,7 +85,7 @@ TDynamicObject * TDynamicObject::FirstFind(int &coupler_nr, CouplingSet const cf { if (temp->NextConnected()) { - if (temp->NextConnectedNo() == end::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony + if (EndOf(temp->NextConnectedNo()) == VehicleEnd::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu temp = temp->NextConnected(); // ten pojazd jest od strony 1 } @@ -117,7 +117,7 @@ float TDynamicObject::GetEPP() { // jeżeli szukamy od sprzęgu 0 if (temp->PrevConnected()) // jeśli mamy coś z przodu { - if (temp->PrevConnectedNo() == end::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony + if (EndOf(temp->PrevConnectedNo()) == VehicleEnd::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu temp = temp->PrevConnected(); // ten jest od strony 0 } @@ -128,7 +128,7 @@ float TDynamicObject::GetEPP() { if (temp->NextConnected()) { - if (temp->NextConnectedNo() == end::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony + if (EndOf(temp->NextConnectedNo()) == VehicleEnd::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu temp = temp->NextConnected(); // ten pojazd jest od strony 1 } @@ -151,7 +151,7 @@ float TDynamicObject::GetEPP() { // jeżeli szukamy od sprzęgu 0 if (temp->PrevConnected()) // jeśli mamy coś z przodu { - if (temp->PrevConnectedNo() == end::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony + if (EndOf(temp->PrevConnectedNo()) == VehicleEnd::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu temp = temp->PrevConnected(); // ten jest od strony 0 } @@ -162,7 +162,7 @@ float TDynamicObject::GetEPP() { if (temp->NextConnected()) { - if (temp->NextConnectedNo() == end::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony + if (EndOf(temp->NextConnectedNo()) == VehicleEnd::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu temp = temp->NextConnected(); // ten pojazd jest od strony 1 } @@ -176,11 +176,12 @@ float TDynamicObject::GetEPP() }; //--------------------------------------------------------------------------- -TDynamicObject * TDynamicObject::GetFirstDynamic(int cpl_type, CouplingSet const cf) +TDynamicObject * TDynamicObject::GetFirstDynamic(VehicleEnd const 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 - return FirstFind(cpl_type, cf); // używa referencji + int coupler { NumberOf( cpl_type ) }; + return FirstFind(coupler, cf); // używa referencji }; int TDynamicObject::DirectionSet(int d) @@ -265,7 +266,7 @@ TDynamicObject::Neighbour(int &dir) { void TDynamicObject::update_neighbours() { - for( int end = end::front; end <= end::rear; ++end ) { + for (auto const end : VehicleEnds) { auto &neighbour { MoverParameters->Neighbours[ end ] }; auto const &coupler { MoverParameters->Couplers[ end ] }; @@ -294,7 +295,7 @@ TDynamicObject::update_neighbours() { auto const scanrange { std::max( 10.0, std::abs( MoverParameters->V ) ) + 40.0 }; // physics.derailment new: a vehicle off the track beside the other one doesn't run into it, the scan goes on // past it to the vehicles beyond - auto const lookup { find_vehicle( end, scanrange, true ) }; + auto const lookup { find_vehicle( NumberOf( end ), scanrange, true ) }; if( false == std::get( lookup ) ) { continue; } @@ -334,7 +335,7 @@ TDynamicObject::in_line_with( TDynamicObject const &Other ) const { std::tuple TDynamicObject::find_vehicle( int const Direction, double const Distance, bool const InLine ) const { - auto direction { ( Direction == end::front ? 1 : -1 ) }; + auto direction { ( EndOf( Direction ) == VehicleEnd::front ? 1 : -1 ) }; auto const initialdirection { direction }; // zapamiętanie kierunku poszukiwań na torze początkowym, względem sprzęgów auto const *track { RaTrackGet() }; @@ -344,7 +345,7 @@ TDynamicObject::find_vehicle( int const Direction, double const Distance, bool c } // (teraz względem toru) - auto const mycoupler { ( initialdirection < 0 ? end::rear : end::front ) }; // numer sprzęgu do podłączenia w obiekcie szukajacym + auto const mycoupler { NumberOf( initialdirection < 0 ? VehicleEnd::rear : VehicleEnd::front ) }; // numer sprzęgu do podłączenia w obiekcie szukajacym auto foundcoupler { -1 }; // numer sprzęgu w znalezionym obiekcie (znaleziony wypełni) auto distance { 0.0 }; // przeskanowana odleglość; odległość do zawalidrogi auto *foundobject { ABuFindObject( foundcoupler, distance, track, direction, mycoupler, InLine ) }; // zaczynamy szukać na tym samym torze @@ -470,7 +471,7 @@ void TDynamicObject::ParamSet(int what, int into) // dla 8 różnych if (what & 1) // na razie mamy lewe oraz prawe, czyli używamy maskę 1=lewe, // 2=prawe, 3=wszystkie - if( MoverParameters->Doors.instances[side::left].is_open ) + if( MoverParameters->Doors.instances[VehicleSide::left].is_open ) { // są otwarte if (!into) // jeśli zamykanie { @@ -485,7 +486,7 @@ void TDynamicObject::ParamSet(int what, int into) } } if (what & 2) // prawe działają niezależnie od lewych - if( MoverParameters->Doors.instances[side::right].is_open ) + if( MoverParameters->Doors.instances[VehicleSide::right].is_open ) { // są otwarte if (!into) // jeśli zamykanie { @@ -511,12 +512,12 @@ int TDynamicObject::RouteWish(TTrack *tr) }; // the vehicles coupled at the ends, and the ends of theirs facing this one -TDynamicObject *TDynamicObject::NextConnected() { return MoverParameters->Neighbours[ end::rear ].vehicle; } -TDynamicObject *TDynamicObject::PrevConnected() { return MoverParameters->Neighbours[ end::front ].vehicle; } -TDynamicObject *TDynamicObject::NextConnected() const { return MoverParameters->Neighbours[ end::rear ].vehicle; } -TDynamicObject *TDynamicObject::PrevConnected() const { return MoverParameters->Neighbours[ end::front ].vehicle; } -int TDynamicObject::NextConnectedNo() const { return MoverParameters->Neighbours[ end::rear ].vehicle_end; } -int TDynamicObject::PrevConnectedNo() const { return MoverParameters->Neighbours[ end::front ].vehicle_end; } +TDynamicObject *TDynamicObject::NextConnected() { return MoverParameters->Neighbours[ VehicleEnd::rear ].vehicle; } +TDynamicObject *TDynamicObject::PrevConnected() { return MoverParameters->Neighbours[ VehicleEnd::front ].vehicle; } +TDynamicObject *TDynamicObject::NextConnected() const { return MoverParameters->Neighbours[ VehicleEnd::rear ].vehicle; } +TDynamicObject *TDynamicObject::PrevConnected() const { return MoverParameters->Neighbours[ VehicleEnd::front ].vehicle; } +int TDynamicObject::NextConnectedNo() const { return MoverParameters->Neighbours[ VehicleEnd::rear ].vehicle_end; } +int TDynamicObject::PrevConnectedNo() const { return MoverParameters->Neighbours[ VehicleEnd::front ].vehicle_end; } void TDynamicObject::SetdMoveLen( double dMoveLen ) { MoverParameters->dMoveLen = dMoveLen; } void TDynamicObject::ResetdMoveLen() { MoverParameters->dMoveLen = 0; } diff --git a/vehicle/dynamic/couplers.cpp b/vehicle/dynamic/couplers.cpp index 706d9452e..90ab27a1b 100644 --- a/vehicle/dynamic/couplers.cpp +++ b/vehicle/dynamic/couplers.cpp @@ -106,7 +106,7 @@ int TDynamicObject::Dettach(int dir) } void -TDynamicObject::couple( int const Side ) { +TDynamicObject::couple( VehicleEnd const Side ) { auto const &neighbour { MoverParameters->Neighbours[ Side ] }; @@ -123,7 +123,7 @@ TDynamicObject::couple( int const Side ) { & othercoupler.AllowedFlag & Coupling::coupler ) == Coupling::coupler ) { if( MoverParameters->Attach( - Side, neighbour.vehicle_end, + Side, neighbour.FacingEnd(), othervehicleparams, Coupling::coupler ) ) { // one coupling type per key press @@ -140,11 +140,11 @@ TDynamicObject::couple( int const Side ) { & othercoupler.AllowedFlag & Coupling::brakeHose ) == Coupling::brakeHose ) { if( MoverParameters->Attach( - Side, neighbour.vehicle_end, + Side, neighbour.FacingEnd(), othervehicleparams, coupler.CouplingFlag | Coupling::brakeHose ) ) { - SetPneumatic( Side != 0, true ); - othervehicle->SetPneumatic( Side != 0, true ); + SetPneumatic( Side != VehicleEnd::front, true ); + othervehicle->SetPneumatic( Side != VehicleEnd::front, true ); // one coupling type per key press return; } @@ -156,11 +156,11 @@ TDynamicObject::couple( int const Side ) { & othercoupler.AllowedFlag & Coupling::mainHose ) == Coupling::mainHose ) { if( MoverParameters->Attach( - Side, neighbour.vehicle_end, + Side, neighbour.FacingEnd(), othervehicleparams, coupler.CouplingFlag | Coupling::mainHose ) ) { - SetPneumatic( Side != 0, false ); - othervehicle->SetPneumatic( Side != 0, false ); + SetPneumatic( Side != VehicleEnd::front, false ); + othervehicle->SetPneumatic( Side != VehicleEnd::front, false ); // one coupling type per key press return; } @@ -170,9 +170,9 @@ TDynamicObject::couple( int const Side ) { // ukrotnionko 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 ).HasAny( Coupling::control ) ) { + && MoverParameters->CompatibleCoupling( Side, *othervehicleparams, neighbour.FacingEnd(), coupler.CouplingFlag | Coupling::control ).HasAny( Coupling::control ) ) { if( MoverParameters->Attach( - Side, neighbour.vehicle_end, + Side, neighbour.FacingEnd(), othervehicleparams, coupler.CouplingFlag | Coupling::control ) ) { // one coupling type per key press @@ -186,7 +186,7 @@ TDynamicObject::couple( int const Side ) { & othercoupler.AllowedFlag & Coupling::gangway ) == Coupling::gangway ) { if( MoverParameters->Attach( - Side, neighbour.vehicle_end, + Side, neighbour.FacingEnd(), othervehicleparams, coupler.CouplingFlag | Coupling::gangway ) ) { // one coupling type per key press @@ -200,7 +200,7 @@ TDynamicObject::couple( int const Side ) { & othercoupler.AllowedFlag & Coupling::heating ) == Coupling::heating ) { if( MoverParameters->Attach( - Side, neighbour.vehicle_end, + Side, neighbour.FacingEnd(), othervehicleparams, coupler.CouplingFlag | Coupling::heating ) ) { // one coupling type per key press @@ -212,20 +212,20 @@ TDynamicObject::couple( int const Side ) { } int -TDynamicObject::uncouple( int const Side ) { +TDynamicObject::uncouple( VehicleEnd const Side ) { - if( DettachStatus(Side) >= 0 + if( DettachStatus( NumberOf( Side ) ) >= 0 || true == MoverParameters->Couplers[Side].CouplingFlag.HasAll(Coupling::permanent) ) { // can't uncouple, return existing coupling state return MoverParameters->Couplers[ Side ].CouplingFlag.Bits(); } // jeżeli sprzęg niezablokowany, jest co odczepić i się da - auto const couplingflag { Dettach( Side ) }; + auto const couplingflag { Dettach( NumberOf( Side ) ) }; return couplingflag; } bool -TDynamicObject::attach_coupler_adapter( int const Side, bool const Enforce ) { +TDynamicObject::attach_coupler_adapter( VehicleEnd const Side, bool const Enforce ) { auto &coupler { MoverParameters->Couplers[ Side ] }; // sanity check(s) @@ -263,7 +263,7 @@ TDynamicObject::attach_coupler_adapter( int const Side, bool const Enforce ) { } bool -TDynamicObject::remove_coupler_adapter( int const Side ) { +TDynamicObject::remove_coupler_adapter( VehicleEnd const Side ) { auto &coupler{ MoverParameters->Couplers[ Side ] }; @@ -303,13 +303,13 @@ void TDynamicObject::AttachNext(TDynamicObject *Object, int iType) if( othercoupler.type() == TCouplerType::Automatic ) { // try to attach adapter to the vehicle attach_coupler_adapter( - vehicleend, + EndOf( vehicleend ), true ); } else if( coupler.type() == TCouplerType::Automatic ) { // try to attach adapter to the other vehicle Object->attach_coupler_adapter( - othervehicleend != 2 ? othervehicleend : coupler.ConnectedNr, + EndOf( othervehicleend != 2 ? othervehicleend : coupler.ConnectedNr ), true ); } // update distance to neighbours on account of potentially attached adapter diff --git a/vehicle/dynamic/lifecycle.cpp b/vehicle/dynamic/lifecycle.cpp index 128fb73c2..e63aa4c0e 100644 --- a/vehicle/dynamic/lifecycle.cpp +++ b/vehicle/dynamic/lifecycle.cpp @@ -622,31 +622,31 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" m_headsignal22.Init( "headsignal22", mdModel ); m_headsignal23.Init( "headsignal23", mdModel ); // informacja, czy ma poszczególne światła - iInventory[ end::front ] |= m_endsignal12.Active() ? light::redmarker_right : 0; - iInventory[ end::front ] |= m_endsignal13.Active() ? light::redmarker_left : 0; - iInventory[ end::rear ] |= m_endsignal22.Active() ? light::redmarker_right : 0; - iInventory[ end::rear ] |= m_endsignal23.Active() ? light::redmarker_left : 0; - iInventory[ end::front ] |= m_endsignals1.Active() ? light::redmarker_left | light::redmarker_right : 0; - iInventory[ end::rear ] |= m_endsignals2.Active() ? light::redmarker_left | light::redmarker_right : 0; - iInventory[ end::front ] |= m_endtab1.Active() ? light::rearendsignals : 0; // tabliczki blaszane - iInventory[ end::rear ] |= m_endtab2.Active() ? light::rearendsignals : 0; - iInventory[ end::front ] |= m_headlamp11.Active() ? light::headlight_upper : 0; - iInventory[ end::front ] |= m_headlamp12.Active() ? light::headlight_right : 0; - iInventory[ end::front ] |= m_headlamp13.Active() ? light::headlight_left : 0; + iInventory[ VehicleEnd::front ] |= m_endsignal12.Active() ? light::redmarker_right : 0; + iInventory[ VehicleEnd::front ] |= m_endsignal13.Active() ? light::redmarker_left : 0; + iInventory[ VehicleEnd::rear ] |= m_endsignal22.Active() ? light::redmarker_right : 0; + iInventory[ VehicleEnd::rear ] |= m_endsignal23.Active() ? light::redmarker_left : 0; + iInventory[ VehicleEnd::front ] |= m_endsignals1.Active() ? light::redmarker_left | light::redmarker_right : 0; + iInventory[ VehicleEnd::rear ] |= m_endsignals2.Active() ? light::redmarker_left | light::redmarker_right : 0; + iInventory[ VehicleEnd::front ] |= m_endtab1.Active() ? light::rearendsignals : 0; // tabliczki blaszane + iInventory[ VehicleEnd::rear ] |= m_endtab2.Active() ? light::rearendsignals : 0; + iInventory[ VehicleEnd::front ] |= m_headlamp11.Active() ? light::headlight_upper : 0; + iInventory[ VehicleEnd::front ] |= m_headlamp12.Active() ? light::headlight_right : 0; + iInventory[ VehicleEnd::front ] |= m_headlamp13.Active() ? light::headlight_left : 0; - iInventory[end::front] |= m_highbeam12.Active() ? light::highbeamlight_right : 0; - iInventory[end::front] |= m_highbeam13.Active() ? light::highbeamlight_left : 0; + iInventory[VehicleEnd::front] |= m_highbeam12.Active() ? light::highbeamlight_right : 0; + iInventory[VehicleEnd::front] |= m_highbeam13.Active() ? light::highbeamlight_left : 0; - iInventory[ end::rear ] |= m_headlamp21.Active() ? light::headlight_upper : 0; - iInventory[ end::rear ] |= m_headlamp22.Active() ? light::headlight_right : 0; - iInventory[ end::rear ] |= m_headlamp23.Active() ? light::headlight_left : 0; - iInventory[ end::front ] |= m_headsignal12.Active() ? light::auxiliary_right : 0; - iInventory[ end::front ] |= m_headsignal13.Active() ? light::auxiliary_left : 0; - iInventory[ end::rear ] |= m_headsignal22.Active() ? light::auxiliary_right : 0; - iInventory[ end::rear ] |= m_headsignal23.Active() ? light::auxiliary_left : 0; + iInventory[ VehicleEnd::rear ] |= m_headlamp21.Active() ? light::headlight_upper : 0; + iInventory[ VehicleEnd::rear ] |= m_headlamp22.Active() ? light::headlight_right : 0; + iInventory[ VehicleEnd::rear ] |= m_headlamp23.Active() ? light::headlight_left : 0; + iInventory[ VehicleEnd::front ] |= m_headsignal12.Active() ? light::auxiliary_right : 0; + iInventory[ VehicleEnd::front ] |= m_headsignal13.Active() ? light::auxiliary_left : 0; + iInventory[ VehicleEnd::rear ] |= m_headsignal22.Active() ? light::auxiliary_right : 0; + iInventory[ VehicleEnd::rear ] |= m_headsignal23.Active() ? light::auxiliary_left : 0; - iInventory[end::rear] |= m_highbeam22.Active() ? light::highbeamlight_right : 0; - iInventory[end::rear] |= m_highbeam23.Active() ? light::highbeamlight_left : 0; + iInventory[VehicleEnd::rear] |= m_highbeam22.Active() ? light::highbeamlight_right : 0; + iInventory[VehicleEnd::rear] |= m_highbeam23.Active() ? light::highbeamlight_left : 0; btExteriorOnly.Init("external_only", mdModel, false); diff --git a/vehicle/dynamic/lights.cpp b/vehicle/dynamic/lights.cpp index cd38662e1..9fcd1bc02 100644 --- a/vehicle/dynamic/lights.cpp +++ b/vehicle/dynamic/lights.cpp @@ -63,20 +63,20 @@ void TDynamicObject::SetLights() { int const automaticmarkers { MoverParameters->CabActive == 0 && MoverParameters->InactiveCabFlag & activation::redmarkers ? light::redmarker_left + light::redmarker_right : 0 }; auto const lightpos { MoverParameters->LightsPos - 1 }; - std::array const cablights { - automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::front ][ lightpos ], - automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::rear ][ lightpos ] }; + ByEnd const cablights { + automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ VehicleEnd::front ][ lightpos ], + automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ VehicleEnd::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 ? VehicleEnd::front : VehicleEnd::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 ) { + auto const iscoupled { [ vehicle, ignorecouplings ]( VehicleEnd const Side ) { return false == ignorecouplings && 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 ) } ) }; + cablights, isfrontcaboccupied, vehicle->iDirection, { iscoupled( VehicleEnd::front ), iscoupled( VehicleEnd::rear ) } ) }; vehicle->RaLightsSet( lights.head, lights.rear ); vehicle = isfrontcaboccupied ? vehicle->Next(Coupling::control) : vehicle->Prev(Coupling::control); } @@ -102,8 +102,8 @@ void TDynamicObject::RaLightsSet(int head, int rear) if( rear == ( light::redmarker_left | light::redmarker_right | light::rearendsignals ) ) // jeśli nadal obydwie możliwości if( iInventory[ ( iDirection ? - end::rear : - end::front ) ] & ( light::redmarker_left | light::redmarker_right ) ) { + VehicleEnd::rear : + VehicleEnd::front ) ] & ( light::redmarker_left | light::redmarker_right ) ) { // czy ma jakieś światła czerowone od danej strony rear = light::redmarker_left | light::redmarker_right; // dwa światła czerwone } @@ -113,7 +113,7 @@ void TDynamicObject::RaLightsSet(int head, int rear) } // w zależności od kierunku pojazdu w składzie if( head >= 0 ) { - auto const vehicleend { iDirection > 0 ? end::front : end::rear }; + auto const vehicleend { iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear }; MoverParameters->iLights[ vehicleend ] = head & iInventory[vehicleend]; bool tLeft = MoverParameters->iLights[vehicleend] & (light::auxiliary_left | light::headlight_left); // roboczo czy jakiekolwiek swiatlo z lewej jest zapalone bool tRight = MoverParameters->iLights[vehicleend] & (light::auxiliary_right | light::headlight_right); // a tu z prawej @@ -133,10 +133,10 @@ void TDynamicObject::RaLightsSet(int head, int rear) DimHeadlights = false; switch (MoverParameters->CabActive) { - case end::front: + case NumberOf(VehicleEnd::front): HeadlightsAoff = true; break; - case end::rear: + case NumberOf(VehicleEnd::rear): HeadlightsBoff = true; break; default: @@ -147,10 +147,10 @@ void TDynamicObject::RaLightsSet(int head, int rear) { switch (MoverParameters->CabActive) { - case end::front: + case NumberOf(VehicleEnd::front): HeadlightsAoff = false; break; - case end::rear: + case NumberOf(VehicleEnd::rear): HeadlightsBoff = false; break; default: @@ -170,14 +170,14 @@ void TDynamicObject::RaLightsSet(int head, int rear) } if( rear >= 0 ) { - auto const vehicleend{ iDirection > 0 ? end::rear : end::front }; + auto const vehicleend{ iDirection > 0 ? VehicleEnd::rear : VehicleEnd::front }; MoverParameters->iLights[ vehicleend ] = rear & iInventory[vehicleend]; } }; void TDynamicObject::SetLightDimmings() { - auto const vehicleend{iDirection > 0 ? end::front : end::rear}; + auto const vehicleend{iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear}; if (Controller == Humandriver) { @@ -195,10 +195,10 @@ void TDynamicObject::SetLightDimmings() DimHeadlights = false; switch (vehicleend) { - case end::front: + case VehicleEnd::front: HeadlightsAoff = true; break; - case end::rear: + case VehicleEnd::rear: HeadlightsBoff = true; break; default: @@ -209,10 +209,10 @@ void TDynamicObject::SetLightDimmings() { switch (vehicleend) { - case end::front: + case VehicleEnd::front: HeadlightsAoff = false; break; - case end::rear: + case VehicleEnd::rear: HeadlightsBoff = false; break; default: @@ -237,7 +237,7 @@ void TDynamicObject::SetLightDimmings() bool TDynamicObject::has_signal_pc1_on() const { - auto const vehicleend { iDirection > 0 ? end::front : end::rear }; + auto const vehicleend { iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear }; auto const equippedlights { iInventory[ vehicleend ] }; auto const pattern { equippedlights & ( light::headlight_left | light::headlight_right | light::headlight_upper ) }; auto const patternfallback { equippedlights & ( light::auxiliary_left | light::auxiliary_right | light::headlight_upper ) }; @@ -250,7 +250,7 @@ bool TDynamicObject::has_signal_pc1_on() const { bool TDynamicObject::has_signal_pc2_on() const { - auto const vehicleend { iDirection > 0 ? end::front : end::rear }; + auto const vehicleend { iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear }; auto const equippedlights { iInventory[ vehicleend ] }; auto const pattern { equippedlights & ( light::redmarker_left | light::headlight_right | light::headlight_upper ) }; auto const patternfallback { equippedlights & ( light::redmarker_left | light::auxiliary_right | light::headlight_upper ) }; @@ -262,7 +262,7 @@ bool TDynamicObject::has_signal_pc2_on() const { bool TDynamicObject::has_signal_pc5_on() const { - auto const vehicleend { iDirection > 0 ? end::rear : end::front }; + auto const vehicleend { iDirection > 0 ? VehicleEnd::rear : VehicleEnd::front }; auto const equippedlights { iInventory[ vehicleend ] }; auto const pattern { equippedlights & ( light::redmarker_left | light::redmarker_right ) }; auto const patternfallback { equippedlights & light::rearendsignals }; @@ -271,7 +271,7 @@ bool TDynamicObject::has_signal_pc5_on() const { return (pattern != 0 && activelights == pattern) || (patternfallback != 0 && activelights == patternfallback); } -bool TDynamicObject::has_signal_on( int const Side, int const Pattern ) const { +bool TDynamicObject::has_signal_on( VehicleEnd const Side, int const Pattern ) const { /* auto const vehicleend { iDirection > 0 ? Side : 1 - Side }; auto const pattern { iInventory[ vehicleend ] & Pattern }; diff --git a/vehicle/dynamic/load.cpp b/vehicle/dynamic/load.cpp index 658a1ed0c..42c9e7913 100644 --- a/vehicle/dynamic/load.cpp +++ b/vehicle/dynamic/load.cpp @@ -67,10 +67,10 @@ void TDynamicObject::LoadExchange( int const Disembark, int const Embark, int co auto const lewe = ( DirectionGet() > 0 ) ? 1 : 2; auto const prawe = 3 - lewe; if( Platform & lewe ) { - MoverParameters->OperateDoors( side::left, true, range_t::local ); + MoverParameters->OperateDoors( VehicleSide::left, true, range_t::local ); } if( Platform & prawe ) { - MoverParameters->OperateDoors( side::right, true, range_t::local ); + MoverParameters->OperateDoors( VehicleSide::right, true, range_t::local ); } } */ @@ -108,10 +108,10 @@ float TDynamicObject::LoadExchangeSpeed() const { auto const lewe { DirectionGet() > 0 ? 1 : 2 }; auto const prawe { 3 - lewe }; if( m_exchange.platforms & lewe ) { - exchangespeedfactor += MoverParameters->Doors.instances[side::left].is_open ? 1.f : 0.f; + exchangespeedfactor += MoverParameters->Doors.instances[VehicleSide::left].is_open ? 1.f : 0.f; } if( m_exchange.platforms & prawe ) { - exchangespeedfactor += MoverParameters->Doors.instances[side::right].is_open ? 1.f : 0.f; + exchangespeedfactor += MoverParameters->Doors.instances[VehicleSide::right].is_open ? 1.f : 0.f; } return exchangespeedfactor; @@ -134,14 +134,14 @@ void TDynamicObject::update_exchange( double const Deltatime ) { auto const lewe { DirectionGet() > 0 ? 1 : 2 }; auto const prawe { 3 - lewe }; if( m_exchange.platforms & lewe - && false == (MoverParameters->Doors.instances[side::left].is_open || MoverParameters->Doors.instances[side::left].is_opening) ) { + && false == (MoverParameters->Doors.instances[VehicleSide::left].is_open || MoverParameters->Doors.instances[VehicleSide::left].is_opening) ) { // try to open left door - MoverParameters->OperateDoors( side::left, true, range_t::local ); + MoverParameters->OperateDoors( VehicleSide::left, true, range_t::local ); } if( m_exchange.platforms & prawe - && false == (MoverParameters->Doors.instances[side::right].is_open || MoverParameters->Doors.instances[side::right].is_opening) ) { + && false == (MoverParameters->Doors.instances[VehicleSide::right].is_open || MoverParameters->Doors.instances[VehicleSide::right].is_opening) ) { // try to open right door - MoverParameters->OperateDoors( side::right, true, range_t::local ); + MoverParameters->OperateDoors( VehicleSide::right, true, range_t::local ); } } @@ -197,8 +197,8 @@ void TDynamicObject::update_exchange( double const Deltatime ) { // remotely controlled door are more likely to be left open MoverParameters->Doors.close_control == control_t::passenger ? 0.75 : 0.50) ) { - MoverParameters->OperateDoors( side::left, false, range_t::local ); - MoverParameters->OperateDoors( side::right, false, range_t::local ); + MoverParameters->OperateDoors( VehicleSide::left, false, range_t::local ); + MoverParameters->OperateDoors( VehicleSide::right, false, range_t::local ); } } // if the vehicle was emptied potentially switch load visualization model diff --git a/vehicle/dynamic/mmd.cpp b/vehicle/dynamic/mmd.cpp index edd971e4a..190ba7153 100644 --- a/vehicle/dynamic/mmd.cpp +++ b/vehicle/dynamic/mmd.cpp @@ -784,9 +784,9 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co // we don't expect more than 2-4 mirrors, so it should be safe to store submodel location (front/rear) in the higher bits // parzyste działają inaczej niż nieparzyste pAnimations[ i + j ].iNumber = - ( ( pAnimations[ i + j ].smAnimated->offset().z > 0 ? - end::front : - end::rear ) << 4 ) + ( NumberOf( pAnimations[ i + j ].smAnimated->offset().z > 0 ? + VehicleEnd::front : + VehicleEnd::rear ) << 4 ) + i; pAnimations[ i + j ].fMaxDist = 150 * 150; // drzwi to z daleka widać /* @@ -993,9 +993,9 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co blowertemplate.owner( this ); auto const amplitudedivisor { static_cast( - MoverParameters->MotorBlowers[ end::front ].speed > 0 ? MoverParameters->MotorBlowers[ end::front ].speed * MoverParameters->nmax * 60 + MoverParameters->Power * 3 : + MoverParameters->MotorBlowers[ VehicleEnd::front ].speed > 0 ? MoverParameters->MotorBlowers[ VehicleEnd::front ].speed * MoverParameters->nmax * 60 + MoverParameters->Power * 3 : blowertemplate.has_bookends() ? 1 : // NOTE: for motorblowers with fixed speed if the sound has defined bookends we skip revolutions-based part of frequency/volume adjustments - MoverParameters->MotorBlowers[ end::front ].speed * -1 ) }; + MoverParameters->MotorBlowers[ VehicleEnd::front ].speed * -1 ) }; blowertemplate.m_amplitudefactor /= amplitudedivisor; blowertemplate.m_frequencyfactor /= amplitudedivisor; @@ -1500,7 +1500,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co || sides == "left" ) { // left... auto const location { glm::vec3 { MoverParameters->Dim.W * 0.5f, MoverParameters->Dim.H * 0.5f, offset } }; - door.placement = side::left; + door.placement = VehicleSide::left; door.rsDoorClose.offset( location ); door.rsDoorOpen.offset( location ); door.lock.offset( location ); @@ -1514,7 +1514,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co || sides == "right" ) { // ...and right auto const location { glm::vec3 { MoverParameters->Dim.W * -0.5f, 2.f, offset } }; - door.placement = side::right; + door.placement = VehicleSide::right; door.rsDoorClose.offset( location ); door.rsDoorOpen.offset( location ); door.lock.offset( location ); @@ -1538,10 +1538,10 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co // vehicle faces +Z in 'its' space, as for the doors negative value means ahead of centre auto const offset { std::atof( token.c_str() ) * -1.f }; mirror_sounds mirror; - mirror.end = offset >= 0.f ? end::front : end::rear; - for( auto const mirrorside : { side::left, side::right } ) { + mirror.end = offset >= 0.f ? VehicleEnd::front : VehicleEnd::rear; + for( auto const mirrorside : { VehicleSide::left, VehicleSide::right } ) { auto const location { glm::vec3 { - MoverParameters->Dim.W * ( mirrorside == side::left ? 0.5f : -0.5f ), + MoverParameters->Dim.W * ( mirrorside == VehicleSide::left ? 0.5f : -0.5f ), MoverParameters->Dim.H * 0.5f, offset } }; mirror.placement = mirrorside; @@ -2077,43 +2077,43 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co } // couplers auto const frontcoupleroffset { glm::vec3{ 0.f, 1.f, MoverParameters->Dim.L * 0.5f } }; - m_couplersounds[ end::front ].attach_coupler.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].attach_brakehose.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].attach_mainhose.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].attach_control.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].attach_gangway.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].attach_heating.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].detach_coupler.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].detach_brakehose.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].detach_mainhose.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].detach_control.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].detach_gangway.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].detach_heating.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].dsbCouplerStretch.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].dsbCouplerStretch_loud.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].dsbBufferClamp.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].dsbBufferClamp_loud.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].dsbAdapterAttach.offset( frontcoupleroffset ); - m_couplersounds[ end::front ].dsbAdapterRemove.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].attach_coupler.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].attach_brakehose.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].attach_mainhose.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].attach_control.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].attach_gangway.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].attach_heating.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].detach_coupler.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].detach_brakehose.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].detach_mainhose.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].detach_control.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].detach_gangway.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].detach_heating.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].dsbCouplerStretch.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].dsbCouplerStretch_loud.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].dsbBufferClamp.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].dsbBufferClamp_loud.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].dsbAdapterAttach.offset( frontcoupleroffset ); + m_couplersounds[ VehicleEnd::front ].dsbAdapterRemove.offset( frontcoupleroffset ); auto const rearcoupleroffset { glm::vec3{ 0.f, 1.f, MoverParameters->Dim.L * -0.5f } }; - m_couplersounds[ end::rear ].attach_coupler.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].attach_brakehose.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].attach_mainhose.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].attach_control.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].attach_gangway.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].attach_heating.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].detach_coupler.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].detach_brakehose.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].detach_mainhose.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].detach_control.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].detach_gangway.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].detach_heating.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].dsbCouplerStretch.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].dsbCouplerStretch_loud.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].dsbBufferClamp.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].dsbBufferClamp_loud.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].dsbAdapterAttach.offset( rearcoupleroffset ); - m_couplersounds[ end::rear ].dsbAdapterRemove.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].attach_coupler.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].attach_brakehose.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].attach_mainhose.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].attach_control.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].attach_gangway.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].attach_heating.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].detach_coupler.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].detach_brakehose.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].detach_mainhose.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].detach_control.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].detach_gangway.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].detach_heating.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].dsbCouplerStretch.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].dsbCouplerStretch_loud.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].dsbBufferClamp.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].dsbBufferClamp_loud.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].dsbAdapterAttach.offset( rearcoupleroffset ); + m_couplersounds[ VehicleEnd::rear ].dsbAdapterRemove.offset( rearcoupleroffset ); } TModel3d * diff --git a/vehicle/dynamic/movement.cpp b/vehicle/dynamic/movement.cpp index d5f0a4ccf..77bcfbfff 100644 --- a/vehicle/dynamic/movement.cpp +++ b/vehicle/dynamic/movement.cpp @@ -155,8 +155,8 @@ void TDynamicObject::place_by_axles() } // obliczanie pozycji sprzęgów do liczenia zderzeń auto dir = 0.5 * MoverParameters->Dim.L * vFront; // wektor sprzęgu - vCoulpler[end::front] = vPosition + dir; // współrzędne sprzęgu na początku - vCoulpler[end::rear] = vPosition - dir; // współrzędne sprzęgu na końcu + vCoulpler[VehicleEnd::front] = vPosition + dir; // współrzędne sprzęgu na początku + vCoulpler[VehicleEnd::rear] = vPosition - dir; // współrzędne sprzęgu na końcu // bCameraNear= // if (bCameraNear) //jeśli istotne są szczegóły (blisko kamery) { // przeliczenie cienia diff --git a/vehicle/dynamic/offtrack.cpp b/vehicle/dynamic/offtrack.cpp index ddd629fba..c1dab3d46 100644 --- a/vehicle/dynamic/offtrack.cpp +++ b/vehicle/dynamic/offtrack.cpp @@ -148,8 +148,8 @@ glm::dvec3 level_left_of( glm::dvec3 const &Front ) { // the end of the vehicle where it meets the one coupled to it: the middle of its buffer beam, the way it faces. off the // track, over its base on the ground as it stands: rolled over, its ends go with it as far as the coupling holds them, // and the buffers of the side it rolled to miss those of an upright one -derail_motion::end_point end_point_of( TDynamicObject const &Vehicle, int const End ) { - auto const facing { End == end::front ? 1.0 : -1.0 }; +derail_motion::end_point end_point_of( TDynamicObject const &Vehicle, VehicleEnd const End ) { + auto const facing { End == VehicleEnd::front ? 1.0 : -1.0 }; auto const &motion { Vehicle.MoverParameters->OffTrack }; glm::dvec3 const front { Vehicle.VectorFront().x, 0.0, Vehicle.VectorFront().z }; auto const length { glm::length( front ) }; @@ -162,8 +162,8 @@ derail_motion::end_point end_point_of( TDynamicObject const &Vehicle, int const } // the push of the buffers on the end of the vehicle [N], negative the pull of its coupling -double compression_of( TMoverParameters const &Vehicle, int const End ) { - return ( End == end::front ? -1.0 : 1.0 ) * Vehicle.Couplers[ End ].CForce; +double compression_of( TMoverParameters const &Vehicle, VehicleEnd const End ) { + return ( End == VehicleEnd::front ? -1.0 : 1.0 ) * Vehicle.Couplers[ End ].CForce; } } // namespace @@ -183,13 +183,13 @@ std::string_view side_name( int const Side ) { } // namespace -double TDynamicObject::off_track_gap( int const End ) const { +double TDynamicObject::off_track_gap( VehicleEnd const End ) const { auto const *neighbour { MoverParameters->Neighbours[ End ].vehicle }; if( neighbour == nullptr ) { return 0.0; } - return derail_motion::meet( end_point_of( *this, End ), end_point_of( *neighbour, MoverParameters->Neighbours[ End ].vehicle_end ) ).gap; + return derail_motion::meet( end_point_of( *this, End ), end_point_of( *neighbour, MoverParameters->Neighbours[ End ].FacingEnd() ) ).gap; } double TDynamicObject::off_track_offset() const { @@ -389,14 +389,14 @@ void TDynamicObject::move_off_track( double const Distance ) { m_offtracksite.bed( track_bed() ); // the buffers and the couplings of its ends push and pull it, at an angle to it where the vehicle coupled there is std::array ends {}; - for( int end = end::front; end <= end::rear; ++end ) { + for (auto const end : VehicleEnds) { auto const *neighbour { MoverParameters->Neighbours[ end ].vehicle }; auto const compression { compression_of( *MoverParameters, end ) }; if( neighbour == nullptr || compression == 0.0 ) { continue; } - ends[ end ] = derail_motion::force_on( - derail_motion::meet( end_point_of( *this, end ), end_point_of( *neighbour, MoverParameters->Neighbours[ end ].vehicle_end ) ), compression ); + ends[ NumberOf( end ) ] = derail_motion::force_on( + derail_motion::meet( end_point_of( *this, end ), end_point_of( *neighbour, MoverParameters->Neighbours[ end ].FacingEnd() ) ), compression ); } auto const reversals { motion.reversals() }; motion.step( time, Distance, MoverParameters->V, m_offtracksite, ends ); @@ -440,14 +440,14 @@ void TDynamicObject::place_off_track() { modelRot.z = std::atan2( -vFront.x, vFront.z ); mMatrix = glm::inverse( BasisChange( vLeft, vUp, vFront ) ); auto const half { 0.5 * MoverParameters->Dim.L * vFront }; - vCoulpler[ end::front ] = vPosition + half; - vCoulpler[ end::rear ] = vPosition - half; + vCoulpler[ VehicleEnd::front ] = vPosition + half; + vCoulpler[ VehicleEnd::rear ] = vPosition - half; m_offtrackplaced = true; } void TDynamicObject::pull_neighbours( double const Distance ) { - for( int end = end::front; end <= end::rear; ++end ) { + for (auto const end : VehicleEnds) { auto const &coupler { MoverParameters->Couplers[ end ] }; auto *neighbour { MoverParameters->Neighbours[ end ].vehicle }; if( coupler.CouplingFlag == Coupling::none || neighbour == nullptr || neighbour->MoverParameters->OffTrack.active() @@ -456,7 +456,7 @@ void TDynamicObject::pull_neighbours( double const Distance ) { continue; } auto &other { *neighbour->MoverParameters }; - auto const otherend { MoverParameters->Neighbours[ end ].vehicle_end }; + auto const otherend { MoverParameters->Neighbours[ end ].FacingEnd() }; glm::dvec3 const otherfront { neighbour->vFront.x, 0.0, neighbour->vFront.z }; if( glm::length( otherfront ) < 1e-6 ) { continue; diff --git a/vehicle/dynamic/sounds.cpp b/vehicle/dynamic/sounds.cpp index ee5828877..a9c402145 100644 --- a/vehicle/dynamic/sounds.cpp +++ b/vehicle/dynamic/sounds.cpp @@ -458,7 +458,7 @@ void TDynamicObject::RenderSounds() { } } // NBMX Obsluga drzwi, MC: zuniwersalnione - std::array const sides { side::right, side::left }; + auto const &sides { VehicleSides }; for( auto const side : sides ) { auto const &door { MoverParameters->Doors.instances[ side ] }; @@ -873,12 +873,12 @@ void TDynamicObject::RenderSounds() { } } -void TDynamicObject::play_mirror_sounds( side const Side, mirror_moves::event const Event ) { +void TDynamicObject::play_mirror_sounds( VehicleSide const Side, mirror_moves::event const Event ) { if( Event == mirror_moves::event::none ) { return; } // as UpdateMirror(), only the mirrors of the occupied cab move if( MoverParameters->CabOccupied == 0 ) { return; } - auto const cabend { MoverParameters->CabOccupied > 0 ? end::front : end::rear }; + auto const cabend { MoverParameters->CabOccupied > 0 ? VehicleEnd::front : VehicleEnd::rear }; for( auto &mirror : m_mirrorsounds ) { if( mirror.placement != Side || mirror.end != cabend ) { continue; } auto &sound { Event == mirror_moves::event::unfolding ? mirror.unfold : mirror.fold }; @@ -1283,11 +1283,11 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub if( false == motorblowers.empty() ) { for( auto &blowersound : motorblowers ) { // match the motor blower and the sound source based on whether they're located in the front or the back of the vehicle - auto const &blower { Vehicle.MotorBlowers[ ( blowersound.offset().z > 0 ? end::front : end::rear ) ] }; + auto const &blower { Vehicle.MotorBlowers[ ( blowersound.offset().z > 0 ? VehicleEnd::front : VehicleEnd::rear ) ] }; // TODO: for the sounds with provided bookends invoke stop() when the stop is triggered and revolutions start dropping, instead of after full stop if( blower.revolutions > 1 ) { // NOTE: for motorblowers with fixed speed if the sound has defined bookends we skip revolutions-based part of frequency/volume adjustments - auto const revolutionmodifier { Vehicle.MotorBlowers[end::front].speed < 0.f && blowersound.has_bookends() ? 1.f : blower.revolutions }; + auto const revolutionmodifier { Vehicle.MotorBlowers[VehicleEnd::front].speed < 0.f && blowersound.has_bookends() ? 1.f : blower.revolutions }; blowersound .pitch( true == blowersound.is_combined() ? diff --git a/vehicle/dynamic/update.cpp b/vehicle/dynamic/update.cpp index 03057e4f8..275e4996c 100644 --- a/vehicle/dynamic/update.cpp +++ b/vehicle/dynamic/update.cpp @@ -191,8 +191,8 @@ bool TDynamicObject::Update(double dt, double dt1) // jeśli jedzie if( MoverParameters->Vel > 0.5 ) { // Ra 2014-07: doraźna blokada logowania zimnych lokomotyw - zrobić to trzeba inaczej - if( MoverParameters->Pantographs[end::front].is_active - || MoverParameters->Pantographs[end::rear].is_active ) { + if( MoverParameters->Pantographs[VehicleEnd::front].is_active + || MoverParameters->Pantographs[VehicleEnd::rear].is_active ) { if( MoverParameters->Mains // Ra 15-01: logować tylko, jeśli WS załączony && MoverParameters->GetTrainsetHighVoltage() < 0.1f // yB 16-03: i nie jest to asynchron zasilany z daleka && false == MoverParameters->GensetSelected() ) { // nor a dual-mode vehicle running on its genset @@ -274,7 +274,7 @@ 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, Coupling::control); p; + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); p; kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { ++np; @@ -317,11 +317,11 @@ bool TDynamicObject::Update(double dt, double dt1) Mechanik->fMedAmax = amax; auto doorisopen { - false == MoverParameters->Doors.instances[side::left].is_closed - || false == MoverParameters->Doors.instances[side::right].is_closed + false == MoverParameters->Doors.instances[VehicleSide::left].is_closed + || false == MoverParameters->Doors.instances[VehicleSide::right].is_closed || ( MoverParameters->Doors.permit_needed - && ( MoverParameters->Doors.instances[ side::left ].open_permit - || MoverParameters->Doors.instances[ side::right ].open_permit ) ) }; + && ( MoverParameters->Doors.instances[ VehicleSide::left ].open_permit + || MoverParameters->Doors.instances[ VehicleSide::right ].open_permit ) ) }; doorisopen &= !(MoverParameters->ReleaseParkingBySpringBrakeWhenDoorIsOpen && MoverParameters->SpringBrake.IsActive); if (MoverParameters->Vel < 0.5 && (eimic < 0 || doorisopen || MoverParameters->Hamulec->GetEDBCP())) @@ -426,7 +426,7 @@ 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, Coupling::control); p; + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); p; p = kier == true ? p->Next(Coupling::control) : p->Prev(Coupling::control) ) { auto const Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] - @@ -454,7 +454,7 @@ bool TDynamicObject::Update(double dt, double dt1) test = false; i = 0; float przek = 0; - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); p; p = kier == true ? p->Next(Coupling::control) : p->Prev(Coupling::control) ) { if (FzEP[i] > 0.01 && @@ -478,7 +478,7 @@ bool TDynamicObject::Update(double dt, double dt1) } i = 0; przek = przek / (np - nPrzekrF); - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); p; true == kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { if (!PrzekrF[i]) @@ -489,7 +489,7 @@ bool TDynamicObject::Update(double dt, double dt1) } } i = 0; - for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, Coupling::control); p; + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); p; true == kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { float Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] - @@ -542,7 +542,7 @@ 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, Coupling::control); p; + for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control); p; true == kier ? p = p->Next(Coupling::control) : p = p->Prev(Coupling::control)) { MEDLogFile << "\t" << p->MoverParameters->BrakePress; @@ -788,7 +788,7 @@ bool TDynamicObject::Update(double dt, double dt1) } else { if( pantograph->hvPowerWire != nullptr - && true == MoverParameters->Pantographs[end::front].is_active + && true == MoverParameters->Pantographs[VehicleEnd::front].is_active && pantograph->PantTraction - pantograph->PantWys < 0.01 ) { // tolerancja niedolegania ++activepantographs; } @@ -827,7 +827,7 @@ bool TDynamicObject::Update(double dt, double dt1) 0.95 * MoverParameters->EnginePowerSource.MaxVoltage : 0.0; } - else if( true == MoverParameters->Pantographs[end::front].is_active + else if( true == MoverParameters->Pantographs[VehicleEnd::front].is_active && PantDiff < 0.01 ) // tolerancja niedolegania { if (p->hvPowerWire) { @@ -870,7 +870,7 @@ bool TDynamicObject::Update(double dt, double dt1) 0.95 * MoverParameters->EnginePowerSource.MaxVoltage : 0.0; } - else if ( true == MoverParameters->Pantographs[end::rear].is_active + else if ( true == MoverParameters->Pantographs[VehicleEnd::rear].is_active && PantDiff < 0.01 ) { if (p->hvPowerWire) { @@ -969,8 +969,8 @@ bool TDynamicObject::Update(double dt, double dt1) } } // koniec pętli po pantografach // TBD, TODO: generate sound event during mover update instead? - if( MoverParameters->Pantographs[end::front].sound_event != MoverParameters->Pantographs[ end::front ].is_active ) { - if( MoverParameters->Pantographs[ end::front ].is_active ) { + if( MoverParameters->Pantographs[VehicleEnd::front].sound_event != MoverParameters->Pantographs[ VehicleEnd::front ].is_active ) { + if( MoverParameters->Pantographs[ VehicleEnd::front ].is_active ) { // pantograph moving up // TBD: add a sound? } @@ -983,10 +983,10 @@ bool TDynamicObject::Update(double dt, double dt1) } } } - MoverParameters->Pantographs[ end::front ].sound_event = MoverParameters->Pantographs[ end::front ].is_active; + MoverParameters->Pantographs[ VehicleEnd::front ].sound_event = MoverParameters->Pantographs[ VehicleEnd::front ].is_active; } - if( MoverParameters->Pantographs[ end::rear ].sound_event != MoverParameters->Pantographs[ end::rear ].is_active ) { - if( MoverParameters->Pantographs[ end::rear ].is_active ) { + if( MoverParameters->Pantographs[ VehicleEnd::rear ].sound_event != MoverParameters->Pantographs[ VehicleEnd::rear ].is_active ) { + if( MoverParameters->Pantographs[ VehicleEnd::rear ].is_active ) { // pantograph moving up // TBD: add a sound? } @@ -999,7 +999,7 @@ bool TDynamicObject::Update(double dt, double dt1) } } } - MoverParameters->Pantographs[ end::rear ].sound_event = MoverParameters->Pantographs[ end::rear ].is_active; + MoverParameters->Pantographs[ VehicleEnd::rear ].sound_event = MoverParameters->Pantographs[ VehicleEnd::rear ].is_active; } } else if (MoverParameters->EnginePowerSource.SourceType == TPowerSource::InternalSource) @@ -1190,20 +1190,20 @@ bool TDynamicObject::Update(double dt, double dt1) else { // unfold mirror on the side with open doors, if not moving too fast if( dMirrorMoveL < 1.0 - && true == MoverParameters->Doors.instances[side::left].open_permit ) { + && true == MoverParameters->Doors.instances[VehicleSide::left].open_permit ) { dMirrorMoveL = std::min( 1.0, dMirrorMoveL + 1.0 * dt1 ); } if( dMirrorMoveR < 1.0 - && true == MoverParameters->Doors.instances[side::right].open_permit ) { + && true == MoverParameters->Doors.instances[VehicleSide::right].open_permit ) { dMirrorMoveR = std::min( 1.0, dMirrorMoveR + 1.0 * dt1 ); } } - play_mirror_sounds( side::left, m_mirrormotion[ side::left ].update( dMirrorMoveL - mirrorleft ) ); - play_mirror_sounds( side::right, m_mirrormotion[ side::right ].update( dMirrorMoveR - mirrorright ) ); + play_mirror_sounds( VehicleSide::left, m_mirrormotion[ VehicleSide::left ].update( dMirrorMoveL - mirrorleft ) ); + play_mirror_sounds( VehicleSide::right, m_mirrormotion[ VehicleSide::right ].update( dMirrorMoveR - mirrorright ) ); // compartment lights // if the vehicle has a controller, we base the light state on state of the controller otherwise we check the vehicle itself @@ -1250,14 +1250,14 @@ void TDynamicObject::pants_up() { d = this; 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->MoverParameters->OperatePantographValve(VehicleEnd::front, operation_t::enable, range_t::local); + d->MoverParameters->OperatePantographValve(VehicleEnd::rear, operation_t::enable, range_t::local); d = d->Next(Coupling::control); // pozostałe też } 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->MoverParameters->OperatePantographValve(VehicleEnd::front, operation_t::enable, range_t::local); + d->MoverParameters->OperatePantographValve(VehicleEnd::rear, operation_t::enable, range_t::local); d = d->Prev(Coupling::control); // w drugą stronę też } } diff --git a/vehicle/dynamic/vehicletable.cpp b/vehicle/dynamic/vehicletable.cpp index 7292576cc..689ef28c4 100644 --- a/vehicle/dynamic/vehicletable.cpp +++ b/vehicle/dynamic/vehicletable.cpp @@ -72,7 +72,7 @@ std::vector coupled_train( TDynamicObject *Vehicle ) { std::vector train { Vehicle }; - for( int direction = end::front; direction <= end::rear; ++direction ) { + for (auto const direction : VehicleEnds) { auto *vehicle { Vehicle }; auto side { direction }; // a train of more vehicles than are on the tracks would be one coupled into a ring @@ -86,7 +86,7 @@ coupled_train( TDynamicObject *Vehicle ) { } train.emplace_back( next ); // onwards from the end of the next vehicle away from this one - side = 1 - mover.Neighbours[ side ].vehicle_end; + side = EndOf( 1 - mover.Neighbours[ side ].vehicle_end ); vehicle = next; } } @@ -99,7 +99,7 @@ trains_closing_in( std::vector const &Train ) { std::vector trains; for( auto *vehicle : Train ) { - for( int side = end::front; side <= end::rear; ++side ) { + for (auto const side : VehicleEnds) { auto const &mover { *vehicle->MoverParameters }; auto const &neighbour { mover.Neighbours[ side ] }; if( neighbour.vehicle == nullptr @@ -220,7 +220,7 @@ vehicle_table::update( double Deltatime, int Iterationcount ) { if( mover->accelerating() ) { ++awake.acceleration; } if( mover->LastSwitchingTime < 5 ) { ++awake.switching; } if( mover->is_multiple_unit() ) { ++awake.multipleunit; } - if( moving( mover->Neighbours[ end::front ] ) || moving( mover->Neighbours[ end::rear ] ) ) { ++awake.neighbour; } + if( moving( mover->Neighbours[ VehicleEnd::front ] ) || moving( mover->Neighbours[ VehicleEnd::rear ] ) ) { ++awake.neighbour; } } } } @@ -397,7 +397,7 @@ derail_motion::contact_body contact_body_of( TDynamicObject const &Vehicle ) { std::string_view overlap_kind( TDynamicObject const &First, TDynamicObject const &Second ) { auto const offtrack { First.MoverParameters->OffTrack.active() && Second.MoverParameters->OffTrack.active() }; - for( int end = end::front; end <= end::rear; ++end ) { + for (auto const end : VehicleEnds) { if( First.MoverParameters->Couplers[ end ].Connected == Second.MoverParameters && First.MoverParameters->Couplers[ end ].CouplingFlag != Coupling::none ) { return offtrack ? "coupled, both off the track" : "coupled, one on the rails"; @@ -609,7 +609,7 @@ vehicle_table::update_steps_parallel( double const Deltatime, int const Iteratio return Index; }; for( std::size_t index = 0; index < itemcount; ++index ) { auto const *mover { m_items[ index ]->MoverParameters }; - for( auto const end : { end::front, end::rear } ) { + for (auto const end : VehicleEnds) { auto const *neighbour { mover->Neighbours[ end ].vehicle }; if( ( mover->Couplers[ end ].Connected != nullptr ) && ( ( neighbour == nullptr ) || ( neighbour->MoverParameters != mover->Couplers[ end ].Connected ) ) ) { diff --git a/vehicle/dynamic/visual.cpp b/vehicle/dynamic/visual.cpp index 3f01e16de..5d7e83562 100644 --- a/vehicle/dynamic/visual.cpp +++ b/vehicle/dynamic/visual.cpp @@ -126,8 +126,8 @@ 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( MoverParameters->Couplers[ end::front ].CouplingFlag.HasAll(Coupling::coupler) ) { - if( MoverParameters->Couplers[ end::front ].Render ) { + if( MoverParameters->Couplers[ VehicleEnd::front ].CouplingFlag.HasAll(Coupling::coupler) ) { + if( MoverParameters->Couplers[ VehicleEnd::front ].Render ) { btCoupler1.TurnOn(); } else { @@ -136,13 +136,13 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } else { - if( true == MoverParameters->Couplers[ end::front ].has_adapter() ) { + if( true == MoverParameters->Couplers[ VehicleEnd::front ].has_adapter() ) { btCoupler1.TurnxOnWithOffAsFallback(); btnOn = true; } } - if( MoverParameters->Couplers[ end::rear ].CouplingFlag.HasAll(Coupling::coupler) ) { - if( MoverParameters->Couplers[ end::rear ].Render ) { + if( MoverParameters->Couplers[ VehicleEnd::rear ].CouplingFlag.HasAll(Coupling::coupler) ) { + if( MoverParameters->Couplers[ VehicleEnd::rear ].Render ) { btCoupler2.TurnOn(); } else { @@ -151,7 +151,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } else { - if( true == MoverParameters->Couplers[ end::rear ].has_adapter() ) { + if( true == MoverParameters->Couplers[ VehicleEnd::rear ].has_adapter() ) { btCoupler2.TurnxOnWithOffAsFallback(); btnOn = true; } @@ -168,7 +168,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) SetPneumatic(true, true); // ktore z nich nalezy SetPneumatic(false, true); // wyswietlic w tej klatce - if (MoverParameters->Couplers[end::front].CouplingFlag.HasAll(Coupling::brakeHose)) + if (MoverParameters->Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::brakeHose)) { switch (cp1) { @@ -188,7 +188,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } - if (MoverParameters->Couplers[end::rear].CouplingFlag.HasAll(Coupling::brakeHose)) + if (MoverParameters->Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::brakeHose)) { switch (cp2) { @@ -209,7 +209,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } // przewody zasilajace, j.w. (yB) - if (MoverParameters->Couplers[end::front].CouplingFlag.HasAll(Coupling::mainHose)) + if (MoverParameters->Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::mainHose)) { switch (sp1) { @@ -229,7 +229,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } - if (MoverParameters->Couplers[end::rear].CouplingFlag.HasAll(Coupling::mainHose)) + if (MoverParameters->Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::mainHose)) { switch (sp2) { @@ -254,18 +254,18 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) { // przewody powietrzne j.w., ABu: decyzja czy rysowac tylko na podstawie // 'render' - if (MoverParameters->Couplers[end::front].CouplingFlag.HasAll(Coupling::brakeHose)) + if (MoverParameters->Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::brakeHose)) { - if (MoverParameters->Couplers[end::front].Render) + if (MoverParameters->Couplers[VehicleEnd::front].Render) btCPneumatic1.TurnOn(); else btCPneumatic1r.TurnOn(); btnOn = true; } - if (MoverParameters->Couplers[end::rear].CouplingFlag.HasAll(Coupling::brakeHose)) + if (MoverParameters->Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::brakeHose)) { - if (MoverParameters->Couplers[end::rear].Render) + if (MoverParameters->Couplers[VehicleEnd::rear].Render) btCPneumatic2.TurnOn(); else btCPneumatic2r.TurnOn(); @@ -348,36 +348,36 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) if (MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable) { // sygnaly konca pociagu if (m_endsignals1.Active()) { - if (TestFlag(MoverParameters->iLights[end::front], light::redmarker_left | light::redmarker_right ) ) { + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::redmarker_left | light::redmarker_right ) ) { m_endsignals1.Turn( true ); btnOn = true; } } else { - if (TestFlag(MoverParameters->iLights[end::front], light::redmarker_left) && !HeadlightsAoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::redmarker_left) && !HeadlightsAoff) { m_endsignal13.Turn( true ); btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::front], light::redmarker_right) && !HeadlightsAoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::redmarker_right) && !HeadlightsAoff) { m_endsignal12.Turn( true ); btnOn = true; } } if (m_endsignals2.Active()) { - if (TestFlag(MoverParameters->iLights[end::rear], light::redmarker_left | light::redmarker_right ) ) { + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::redmarker_left | light::redmarker_right ) ) { m_endsignals2.Turn( true ); btnOn = true; } } else { - if (TestFlag(MoverParameters->iLights[end::rear], light::redmarker_left) && !HeadlightsBoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::redmarker_left) && !HeadlightsBoff) { m_endsignal23.Turn( true ); btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::rear], light::redmarker_right) && !HeadlightsBoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::redmarker_right) && !HeadlightsBoff) { m_endsignal22.Turn( true ); btnOn = true; @@ -385,12 +385,12 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } } // tablice blaszane: - if (TestFlag(MoverParameters->iLights[end::front], light::rearendsignals)) { + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::rearendsignals)) { m_endtab1.Turn( true ); btnOn = true; } // else btEndSignalsTab1.TurnOff(); - if (TestFlag(MoverParameters->iLights[end::rear], light::rearendsignals)) { + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::rearendsignals)) { m_endtab2.Turn( true ); btnOn = true; } @@ -438,7 +438,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) // ograniczeń odległości, by były widoczne z // daleka - if (TestFlag(MoverParameters->iLights[end::front], light::headlight_left) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::headlight_left) && !HeadlightsAoff && !HighBeamLights) { if( DimHeadlights ) { @@ -449,7 +449,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::front], light::headlight_upper) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::headlight_upper) && !HeadlightsAoff) { if( DimHeadlights ) { @@ -460,7 +460,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::front], light::headlight_right) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::headlight_right) && !HeadlightsAoff && !HighBeamLights) { if( DimHeadlights ) { @@ -472,7 +472,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } // else btHeadSignals13.TurnOff(); - if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_left) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::headlight_left) && !HeadlightsBoff && !HighBeamLights) { if( DimHeadlights ) { @@ -483,7 +483,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_upper) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::headlight_upper) && !HeadlightsBoff) { if( DimHeadlights ) { @@ -494,7 +494,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_right) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::headlight_right) && !HeadlightsBoff && !HighBeamLights) { if( DimHeadlights ) { @@ -506,7 +506,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } // auxiliary lights - if (TestFlag(MoverParameters->iLights[end::front], light::auxiliary_left) && !HeadlightsAoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::auxiliary_left) && !HeadlightsAoff) { if( DimHeadlights ) { m_headsignal13.TurnxOnWithOnAsFallback(); @@ -516,7 +516,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::front], light::auxiliary_right) && !HeadlightsAoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::auxiliary_right) && !HeadlightsAoff) { if( DimHeadlights ) { m_headsignal12.TurnxOnWithOnAsFallback(); @@ -526,7 +526,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::rear], light::auxiliary_left) && !HeadlightsBoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::auxiliary_left) && !HeadlightsBoff) { if( DimHeadlights ) { m_headsignal23.TurnxOnWithOnAsFallback(); @@ -536,7 +536,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(MoverParameters->iLights[end::rear], light::auxiliary_right) && !HeadlightsBoff) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::auxiliary_right) && !HeadlightsBoff) { if( DimHeadlights ) { m_headsignal22.TurnxOnWithOnAsFallback(); @@ -548,26 +548,26 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } // logika dlugich - if (TestFlag(MoverParameters->iLights[end::front], light::headlight_left) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::headlight_left) && !HeadlightsAoff && HighBeamLights) m_highbeam13.TurnxOnWithOnAsFallback(); else m_highbeam13.TurnOff(); - if (TestFlag(MoverParameters->iLights[end::front], light::headlight_right) + if (TestFlag(MoverParameters->iLights[VehicleEnd::front], light::headlight_right) && !HeadlightsAoff && HighBeamLights) m_highbeam12.TurnxOnWithOnAsFallback(); else m_highbeam12.TurnOff(); // i to samo od dupy strony - if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_left) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::headlight_left) && !HeadlightsBoff && HighBeamLights) m_highbeam23.TurnxOnWithOnAsFallback(); else m_highbeam23.TurnOff(); - if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_right) + if (TestFlag(MoverParameters->iLights[VehicleEnd::rear], light::headlight_right) && !HeadlightsBoff && HighBeamLights) m_highbeam22.TurnxOnWithOnAsFallback(); else diff --git a/vehicle/enginestart.cpp b/vehicle/enginestart.cpp index a1178196e..df29fae07 100644 --- a/vehicle/enginestart.cpp +++ b/vehicle/enginestart.cpp @@ -59,7 +59,7 @@ TMoverParameters *engine(TMoverParameters const &Occupied, TMoverParameters &Con // the cab's own vehicle is the first one auto others{Number - 1}; // behind the cab is the rear end of a vehicle driven from its front cab, and the other way round - int const behind{Occupied.CabOccupied < 0 ? end::front : end::rear}; + int const behind{NumberOf(Occupied.CabOccupied < 0 ? VehicleEnd::front : VehicleEnd::rear)}; if (auto *found{find_along(Occupied, behind, Controlled, others)}; found != nullptr) { return found; } diff --git a/vehicle/lightsprogrammer.h b/vehicle/lightsprogrammer.h index c603ace27..bf9728b1e 100644 --- a/vehicle/lightsprogrammer.h +++ b/vehicle/lightsprogrammer.h @@ -23,18 +23,18 @@ struct consist_lights { int rear; }; -// Cablights: the selector's lights for the occupied cab's front and back (Lights[end::front / end::rear]). +// Cablights: the selector's lights for the occupied cab's front and back (Lights[VehicleEnd::front / VehicleEnd::rear]). // Cabfacinghead: the occupied cab faces the head of the consist. -// Direction: the vehicle's iDirection, 1 when its end::front is towards the head of the consist. -// Coupled: whether another vehicle is coupled at the vehicle's end::front / end::rear; an end with a coupled +// Direction: the vehicle's iDirection, 1 when its VehicleEnd::front is towards the head of the consist. +// Coupled: whether another vehicle is coupled at the vehicle's VehicleEnd::front / VehicleEnd::rear; an end with a coupled // vehicle stays dark -inline consist_lights vehicle_lights(std::array const &Cablights, bool const Cabfacinghead, int const Direction, std::array const &Coupled) { - auto const headlights{Cablights[Cabfacinghead ? end::front : end::rear]}; - auto const rearlights{Cablights[Cabfacinghead ? end::rear : end::front]}; +inline consist_lights vehicle_lights(ByEnd const &Cablights, bool const Cabfacinghead, int const Direction, ByEnd const &Coupled) { + auto const headlights{Cablights[Cabfacinghead ? VehicleEnd::front : VehicleEnd::rear]}; + auto const rearlights{Cablights[Cabfacinghead ? VehicleEnd::rear : VehicleEnd::front]}; // the head lights go to the vehicle's end towards the head of the consist whichever way the cab faces, // so the coupling which keeps them dark is the one at that same end (eu07/maszyna#395) - auto const headend{Direction > 0 ? end::front : end::rear}; - auto const rearend{Direction > 0 ? end::rear : end::front}; + auto const headend{Direction > 0 ? VehicleEnd::front : VehicleEnd::rear}; + auto const rearend{Direction > 0 ? VehicleEnd::rear : VehicleEnd::front}; return {Coupled[headend] ? 0 : headlights, Coupled[rearend] ? 0 : rearlights}; } diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp index 02b924bad..86966de40 100644 --- a/widgets/vehicleparams.cpp +++ b/widgets/vehicleparams.cpp @@ -63,9 +63,9 @@ void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover) { ImGui::Image((ImTextureID)(intptr_t)(tex.get_id()), ImVec2(x, y), ImVec2(0, 1), ImVec2(1, 0)); - if (mover.Pantographs[end::rear].is_active) + if (mover.Pantographs[VehicleEnd::rear].is_active) draw_infobutton("╨╨╨", ImVec2(126, 10)); - if (mover.Pantographs[end::front].is_active) + if (mover.Pantographs[VehicleEnd::front].is_active) draw_infobutton("╨╨╨", ImVec2(290, 10)); if (mover.Battery) @@ -80,17 +80,17 @@ void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover) if (mover.WarningSignal) draw_infobutton(STR_C("horn"), ImVec2(361, 11)); - if (mover.iLights[end::front] & light::redmarker_left) + if (mover.iLights[VehicleEnd::front] & light::redmarker_left) draw_infobutton("o", ImVec2(490, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); - else if (mover.iLights[end::front] & light::headlight_left) + else if (mover.iLights[VehicleEnd::front] & light::headlight_left) draw_infobutton("O", ImVec2(490, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - if (mover.iLights[end::front] & light::redmarker_right) + if (mover.iLights[VehicleEnd::front] & light::redmarker_right) draw_infobutton("o", ImVec2(443, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); - else if (mover.iLights[end::front] & light::headlight_right) + else if (mover.iLights[VehicleEnd::front] & light::headlight_right) draw_infobutton("O", ImVec2(443, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - if (mover.iLights[end::front] & light::headlight_upper) + if (mover.iLights[VehicleEnd::front] & light::headlight_upper) draw_infobutton("O", ImVec2(467, 18), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); } ImGui::EndChild(); @@ -148,8 +148,8 @@ void ui::vehicleparams_panel::render_contents() std::snprintf(buffer.data(), buffer.size(), STR_C("Devices: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%s%s\nPower transfers: %.0f@%.0f%s%s%s%.0f@%.0f"), // devices - (mover.Battery ? 'B' : '.'), (mover.Mains ? 'M' : '.'), (mover.FuseFlag ? '!' : '.'), (mover.Pantographs[end::rear].is_active ? (mover.PantRearVolt > 0.0 ? 'O' : 'o') : '.'), - (mover.Pantographs[end::front].is_active ? (mover.PantFrontVolt > 0.0 ? 'P' : 'p') : '.'), (mover.PantPressLockActive ? '!' : (mover.PantPressSwitchActive ? '*' : '.')), + (mover.Battery ? 'B' : '.'), (mover.Mains ? 'M' : '.'), (mover.FuseFlag ? '!' : '.'), (mover.Pantographs[VehicleEnd::rear].is_active ? (mover.PantRearVolt > 0.0 ? 'O' : 'o') : '.'), + (mover.Pantographs[VehicleEnd::front].is_active ? (mover.PantFrontVolt > 0.0 ? 'P' : 'p') : '.'), (mover.PantPressLockActive ? '!' : (mover.PantPressSwitchActive ? '*' : '.')), (mover.WaterPump.is_active ? 'W' : (false == mover.WaterPump.breaker ? '-' : (mover.WaterPump.is_enabled ? 'w' : '.'))), (true == mover.WaterHeater.is_damaged ? '!' : (mover.WaterHeater.is_active ? 'H' : (false == mover.WaterHeater.breaker ? '-' : (mover.WaterHeater.is_enabled ? 'h' : '.')))), (mover.FuelPump.is_active ? 'F' : (mover.FuelPump.is_enabled ? 'f' : '.')), (mover.OilPump.is_active ? 'O' : (mover.OilPump.is_enabled ? 'o' : '.')), @@ -157,9 +157,9 @@ void ui::vehicleparams_panel::render_contents() (mover.CompressorFlag ? 'C' : (false == mover.CompressorAllowLocal ? '-' : ((mover.CompressorAllow || mover.CompressorStart == start_t::automatic) ? 'c' : '.'))), (mover.CompressorGovernorLock ? '!' : '.'), "", std::string(isdieselenginepowered ? STR(" oil pressure: ") + to_string(mover.OilPump.pressure, 2) : "").c_str(), // power transfers - mover.Couplers[end::front].power_high.voltage, mover.Couplers[end::front].power_high.current, std::string(mover.Couplers[end::front].power_high.is_local ? "" : "-").c_str(), - std::string(vehicle.DirectionGet() ? ":<<:" : ":>>:").c_str(), std::string(mover.Couplers[end::rear].power_high.is_local ? "" : "-").c_str(), - mover.Couplers[end::rear].power_high.voltage, mover.Couplers[end::rear].power_high.current); + mover.Couplers[VehicleEnd::front].power_high.voltage, mover.Couplers[VehicleEnd::front].power_high.current, std::string(mover.Couplers[VehicleEnd::front].power_high.is_local ? "" : "-").c_str(), + std::string(vehicle.DirectionGet() ? ":<<:" : ":>>:").c_str(), std::string(mover.Couplers[VehicleEnd::rear].power_high.is_local ? "" : "-").c_str(), + mover.Couplers[VehicleEnd::rear].power_high.voltage, mover.Couplers[VehicleEnd::rear].power_high.current); ImGui::TextUnformatted(buffer.data()); @@ -172,8 +172,8 @@ void ui::vehicleparams_panel::render_contents() // engine mover.EnginePower, std::abs(mover.TrainType == train_type::emu ? mover.ShowCurrent(0) : mover.Im), // revolutions - std::abs(mover.enrot) * 60, std::abs(mover.nrot) * mover.Transmision.Ratio * 60, mover.RventRot * 60, std::abs(mover.MotorBlowers[end::front].revolutions), - std::abs(mover.MotorBlowers[end::rear].revolutions), mover.diesel.heat.rpmw, mover.diesel.heat.rpmw2); + std::abs(mover.enrot) * 60, std::abs(mover.nrot) * mover.Transmision.Ratio * 60, mover.RventRot * 60, std::abs(mover.MotorBlowers[VehicleEnd::front].revolutions), + std::abs(mover.MotorBlowers[VehicleEnd::rear].revolutions), mover.diesel.heat.rpmw, mover.diesel.heat.rpmw2); ImGui::TextUnformatted(buffer.data());