From 3beb317ae712a886d246fafcc5c4f641d768551e Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Tue, 24 Nov 2026 01:08:34 +0100 Subject: [PATCH] fix(vehicle): fold the mirrors of an inactive cab only when InactiveCabFlag says so The mirror condition in TDynamicObject::Update() tested `CabActive == 0 && activation::mirrors`. activation::mirrors is a non-zero enum constant, so the term was just `CabActive == 0`: the mirrors bit of the .fiz key InactiveCabFlag was never read, and the mirrors folded in every inactive cab. The condition now masks the flag, the way the other activation bits are tested, and lives in TMoverParameters::MirrorsFold() so the unit tests can reach it. Vehicles without the mirrors bit (2) no longer fold their mirrors when the cab is deactivated. --- McZapkie/MOVER.h | 2 ++ McZapkie/Mover.cpp | 5 +++++ tests/unit/test_cab.cpp | 39 +++++++++++++++++++++++++++++++++++++++ vehicle/DynObj.cpp | 6 ++---- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index e34dbc252..6d52f7a12 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2637,6 +2637,8 @@ class TMoverParameters 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/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index b1735d0c5..98f2d4aea 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -3895,6 +3895,11 @@ bool TMoverParameters::CabDeactivisationAuto(bool const Enforce) return OK; } +bool TMoverParameters::MirrorsFold() const +{ + return (Vel > MirrorVelClose) || (CabActive == 0 && (InactiveCabFlag & activation::mirrors) != 0) || MirrorForbidden; +} + // ************************************************************************************************* // Q: 20160710 // Siła napędzająca drezynę po naciśnięciu wajhy diff --git a/tests/unit/test_cab.cpp b/tests/unit/test_cab.cpp index 063e70911..b629276fa 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.mover()}; + 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.MirrorForbidden = 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/DynObj.cpp b/vehicle/DynObj.cpp index 7a301930a..766fc4f8e 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -4329,10 +4329,8 @@ bool TDynamicObject::Update(double dt, double dt1) // mirrors auto const mirrorleft { dMirrorMoveL }; auto const mirrorright { dMirrorMoveR }; - if( MoverParameters->Vel > MoverParameters->MirrorVelClose - || MoverParameters->CabActive == 0 && activation::mirrors - || MoverParameters->MirrorForbidden ) { - // automatically fold mirrors when above velocity threshold + if( MoverParameters->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,