18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 06:35:21 +01:00

Merge pull request #488 from MaSzyna-EU07/fix/inactive-cab-mirrors-flag

fix(vehicle): fold the mirrors of an inactive cab only when InactiveCabFlag says so
This commit is contained in:
2026-12-01 23:38:42 +00:00
committed by GitHub
4 changed files with 49 additions and 5 deletions
+5
View File
@@ -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:
+2
View File
@@ -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:*/
+39
View File
@@ -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);
}
}
+3 -5
View File
@@ -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,