diff --git a/physics/components/cab.cpp b/physics/components/cab.cpp index b17bd8624..99025c534 100644 --- a/physics/components/cab.cpp +++ b/physics/components/cab.cpp @@ -180,6 +180,11 @@ bool physics::Vehicle::CabDeactivisationAuto(bool const Enforce) return OK; } +bool physics::Vehicle::MirrorsFold() const +{ + return (Vel > MirrorVelClose) || (CabActive == 0 && (InactiveCabFlag & activation::mirrors) != 0) || mirrorForbidden; +} + // ************************************************************************************************* // pullee mode ("jazda ciÄ…gniona", MaSzyna-EU07/maszyna#64): prepares the vehicle for being hauled dead in a // train, or puts it back in service. while in the mode the vehicle: diff --git a/physics/vehicle.h b/physics/vehicle.h index 6b6e0b741..95738ea54 100644 --- a/physics/vehicle.h +++ b/physics/vehicle.h @@ -1314,6 +1314,8 @@ class Vehicle bool CabDeactivisation(bool const Enforce = false); bool CabActivisationAuto(bool const Enforce = false); bool CabDeactivisationAuto(bool const Enforce = false); + // whether the cab mirrors fold (or stay folded): above MirrorVelClose, in an inactive cab when InactiveCabFlag says so, or switched off + bool MirrorsFold() const; /*! funkcje zwiekszajace/zmniejszajace nastawniki*/ /*! glowny nastawnik:*/ diff --git a/tests/unit/test_cab.cpp b/tests/unit/test_cab.cpp index 5cf01117f..b8ed93a97 100644 --- a/tests/unit/test_cab.cpp +++ b/tests/unit/test_cab.cpp @@ -428,3 +428,42 @@ TEST_CASE("cab: the vigilance button held too long, its alarm not cleared by the } CHECK(security.is_vigilance_blinking()); } + +// the cab mirrors fold above MirrorVelClose, when switched off (MirrorForbidden), and in an inactive cab only +// if the vehicle's InactiveCabFlag has the mirrors bit; vehicles without it leave the mirrors alone there +TEST_CASE("cab: the mirrors folded by speed, by the switch, and in an inactive cab where InactiveCabFlag says so") { + vehicle cab{definition::load("cab_vehicle"), 0.0, "test", 1}; + auto &mover{cab.physics()}; + REQUIRE(mover.MirrorVelClose == doctest::Approx(5.0)); + for (auto const flag : {0, int(activation::mirrors), 0xff & ~int(activation::mirrors), 0xff}) { + for (auto const cabactive : {0, 1, -1}) { + for (auto const fast : {false, true}) { + for (auto const forbidden : {false, true}) { + CAPTURE(flag); + CAPTURE(cabactive); + CAPTURE(fast); + CAPTURE(forbidden); + mover.InactiveCabFlag = flag; + mover.CabActive = cabactive; + mover.Vel = fast ? 5.1 : 5.0; + mover.SetMirrorForbidden(forbidden); + auto const inactivefold{cabactive == 0 && (flag & activation::mirrors) != 0}; + CHECK(mover.MirrorsFold() == (fast || forbidden || inactivefold)); + } + } + } + } +} + +TEST_CASE("cab: the mirrors of a deactivated cab, folded by the Impuls (InactiveCabFlag 239) but not by the Elf 22WEc (9)") { + for (auto const &[path, folds] : {std::pair{"impuls_v1/31we-a_pr", true}, std::pair{"elf_v1/22wec-a", false}}) { + CAPTURE(path); + vehicle unit{definition::fiz(path), 0.0, "test", 1}; + REQUIRE(unit->CabActivisation()); + REQUIRE(unit->CabActive == 1); + CHECK_FALSE(unit->MirrorsFold()); + REQUIRE(unit->CabDeactivisation()); + REQUIRE(unit->CabActive == 0); + CHECK(unit->MirrorsFold() == folds); + } +} diff --git a/vehicle/dynamic/update.cpp b/vehicle/dynamic/update.cpp index a2328b958..b85d1cb20 100644 --- a/vehicle/dynamic/update.cpp +++ b/vehicle/dynamic/update.cpp @@ -960,16 +960,14 @@ void TDynamicObject::updateWipers( double const dt1 ) } } -// the mirrors folded above their speed or when they may not be out, otherwise unfolded on the side of open doors +// the mirrors folded above their speed, in an inactive cab where InactiveCabFlag says so or when they may not be out, otherwise unfolded on the side of open doors void TDynamicObject::updateMirrors( double const dt1 ) { // mirrors auto const mirrorleft { dMirrorMoveL }; auto const mirrorright { dMirrorMoveR }; - if( physics->Vel > physics->MirrorVelClose - || physics->CabActive == 0 && activation::mirrors - || physics->MirrorForbidden() ) { - // automatically fold mirrors when above velocity threshold + if( physics->MirrorsFold() ) { + // automatically fold mirrors when above velocity threshold, in an inactive cab if the vehicle wants it, or when switched off if( dMirrorMoveL > 0.0 ) { dMirrorMoveL = std::max( 0.0,