From 9043d2d5fcb2854b67a1b8ecf5f99328b5bf9ef9 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 08:17:06 +0100 Subject: [PATCH] fix(ai): a brake cut-out skipped on the run is done once the train stands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A train formed by coupling is inspected at the first buffer contact, above the speed the inspector takes for a standstill, so its wagons without G kept their brakes (Cw-1 §19.9) until some later stop, if any. brake_setting::apply() now tells when it left a cut-out because the train was moving; AutoRewident keeps that as a pending re-inspection and TController::reinspect_brakes() runs it again once the train is below EU07_AI_MOVEMENT. The flag is dropped when the order stops being a train run. The legacy inspector (ai.brakesetting.cw1 no) never cuts a brake out and is unchanged. --- tests/unit/test_brake_setting.cpp | 89 +++++++++++++++++++++++++++++-- vehicle/Driver.cpp | 32 +++++++++-- vehicle/Driver.h | 2 + vehicle/brakesetting.cpp | 26 +++++---- vehicle/brakesetting.h | 12 +++-- 5 files changed, 141 insertions(+), 20 deletions(-) diff --git a/tests/unit/test_brake_setting.cpp b/tests/unit/test_brake_setting.cpp index 93fb54a76..5034bf3c5 100644 --- a/tests/unit/test_brake_setting.cpp +++ b/tests/unit/test_brake_setting.cpp @@ -224,6 +224,24 @@ int inspect_light_train(test::vehicle &Vehicle) { return setting; } +// the inspector at work on a whole heavy train on G, the vehicles at its end, the way AutoRewident() goes through +// the train. tells whether it left a cut-out for the next standstill, as AutoRewident() notes for reinspect_brakes() +bool inspection_pending(std::vector const &Vehicles, bool const Train, bool const Standstill) { + auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))}; + for (auto *vehicle : Vehicles) { + consist.emplace_back(brake_setting::describe(vehicle->mover(), false)); + } + auto const settings{brake_setting::choose(consist, Train)}; + auto setting{settings.end() - static_cast(Vehicles.size())}; + auto pending{false}; + for (auto *vehicle : Vehicles) { + if (brake_setting::apply(vehicle->mover(), *setting++, Standstill)) { + pending = true; + } + } + return pending; +} + } // namespace TEST_CASE("brake setting: the inspector cuts the brake out in a train on G and puts it back in a train on P") { @@ -346,9 +364,74 @@ TEST_CASE("brake setting: the inspector doesn't cut a brake out on the run, it w CHECK(false == car->BrakeCutOutByInspector); } -TEST_CASE("brake setting: a train creeping to a stop or coupling counts as standing, one on the run doesn't") { - // the AI looks at the train at a W4 and when it switches from shunting to the train run below 1 km/h, and as it - // couples at the coupling speed: the inspector takes those for a standstill +TEST_CASE("brake setting: a cut-out skipped on the run is reported, and done at the next inspection standing") { + // a train formed by coupling: the AI looks at it as the buffers meet, above 1 km/h. two cars without G and + // a freight wagon at the end of a heavy train on G + test::vehicle first{passenger_car_definition()}; + test::vehicle second{passenger_car_definition()}; + test::vehicle wagon{test::definition::load("wagon").set("Cntrl", "BrakeDelays", "GP")}; + std::vector const vehicles{&first, &second, &wagon}; + for (auto *vehicle : vehicles) { + charge_and_apply(*vehicle); + } + auto const setting{first->BrakeDelayFlag}; + // moving: nothing is cut out, and the inspector tells it has to come back + CHECK(inspection_pending(vehicles, as_train, brake_setting::at_standstill(3.0))); + for (auto *vehicle : vehicles) { + CHECK(false == brake_setting::is_cut_out(vehicle->mover())); + CHECK(false == vehicle->mover().BrakeCutOutByInspector); + } + CHECK(first->BrakeDelayFlag == setting); + CHECK(wagon->BrakeDelayFlag == G); + // still moving: still pending + CHECK(inspection_pending(vehicles, as_train, moving)); + // the train stands (its brake pipe charging after the coupling): the cars get cut out, nothing is left + CHECK(false == inspection_pending(vehicles, as_train, brake_setting::at_standstill(0.0))); + CHECK(brake_setting::is_cut_out(first.mover())); + CHECK(first->BrakeCutOutByInspector); + CHECK(brake_setting::is_cut_out(second.mover())); + CHECK(second->BrakeCutOutByInspector); + CHECK(false == brake_setting::is_cut_out(wagon.mover())); + // and nothing is pending when the train moves off + CHECK(false == inspection_pending(vehicles, as_train, moving)); + CHECK(brake_setting::is_cut_out(first.mover())); +} + +TEST_CASE("brake setting: an inspection on the run with nothing to cut out leaves nothing pending") { + // a wagon with G in a heavy train on G + test::vehicle wagon{test::definition::load("wagon").set("Cntrl", "BrakeDelays", "GP")}; + CHECK(false == inspection_pending({&wagon}, as_train, moving)); + CHECK(wagon->BrakeDelayFlag == G); + // a car without G in a consist being shunted: it keeps its brake, on P + test::vehicle car{passenger_car_definition()}; + CHECK(false == inspection_pending({&car}, shunting, moving)); + CHECK(false == brake_setting::is_cut_out(car.mover())); + // a car whose brake is cut out already, for a reason of its own or by the inspector + test::vehicle damaged{passenger_car_definition()}; + damaged->Hamulec->SetBrakeStatus(damaged->Hamulec->GetBrakeStatus() | b_dmg); + CHECK(false == inspection_pending({&damaged}, as_train, moving)); + CHECK(false == damaged->BrakeCutOutByInspector); + test::vehicle done{passenger_car_definition()}; + REQUIRE(false == inspection_pending({&done}, as_train, standstill)); + REQUIRE(done->BrakeCutOutByInspector); + CHECK(false == inspection_pending({&done}, as_train, moving)); + // a brake put back on the run (the train became a consist being shunted) leaves nothing either + CHECK(false == inspection_pending({&done}, shunting, moving)); + CHECK(false == brake_setting::is_cut_out(done.mover())); + // a single vehicle's apply() tells the same + test::vehicle single{passenger_car_definition()}; + CHECK(brake_setting::apply(single.mover(), brake_setting::cut_out, moving)); + CHECK(false == brake_setting::apply(single.mover(), P, moving)); + CHECK(false == brake_setting::apply(single.mover(), 0, moving)); + CHECK(false == brake_setting::apply(single.mover(), brake_setting::cut_out, standstill)); + CHECK(false == brake_setting::apply(single.mover(), brake_setting::cut_out, moving)); +} + +TEST_CASE("brake setting: a train creeping to a stop counts as standing, one on the run or coupling doesn't") { + // the AI looks at the train at a W4 and when it switches from shunting to the train run below 1 km/h: the + // inspector takes those for a standstill. it couples faster than that (it drives onto the standing cut at up + // to 4 km/h and looks at the new train at the first buffer contact), so the brakes to cut out then wait for + // the look the AI takes once the train stands (the test above) CHECK(brake_setting::at_standstill(0.0)); CHECK(brake_setting::at_standstill(0.04)); CHECK(brake_setting::at_standstill(0.9)); diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index dab54bd1a..6e626bec2 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -2435,9 +2435,10 @@ void TController::AutoRewident() // brakes are cut out (Cw-1 §19.9) only in a train (a bank engine's run included), not in a consist being shunted auto const train{brake_setting::runs_as_train(OrderCurrentGet())}; auto const settings{Global.AIBrakeSettingCw1 ? brake_setting::choose(consist, train) : brake_setting::choose_legacy(consist)}; - // and only at a standstill, the train creeping to a stop or coupling included: a check on the run (the order changed - // mid-run) leaves them to the next one + // and only at a standstill, the train creeping to a stop included: a check on the run (the order changed mid-run, or + // the train was just formed by coupling, which the AI does above that speed) leaves them to reinspect_brakes() auto const standstill{brake_setting::at_standstill(mvOccupied->Vel)}; + auto reinspect{false}; // a light engine counts as a passenger train for the braking below auto const passengertrain{brake_setting::passenger(brake_setting::choose_train_setting(consist))}; // 3. Nastawianie @@ -2448,11 +2449,15 @@ void TController::AutoRewident() continue; } // the setting, a brake cut out in a train on G (Cw-1 §19.9) or put back when the train no longer needs it cut out - brake_setting::apply(*d->MoverParameters, *setting, standstill); + if (brake_setting::apply(*d->MoverParameters, *setting, standstill)) { + // a brake to cut out, with the train moving: left for the next standstill + reinspect = true; + } // potentially release manual brake d->MoverParameters->DecManualBrakeLevel( ManualBrakePosNo ); d->MoverParameters->SpringBrake.Activate = false; } + BrakeReinspectionPending = reinspect; //ustawianie trybu pracy zadajnika hamulca, wystarczy raz po inicjalizacji AI if( true == AIControllFlag ) { // if a human is in charge leave the brake mode up to them, otherwise do as you like @@ -2545,6 +2550,25 @@ void TController::AutoRewident() } +// a brake the inspector had to cut out (Cw-1 §19.9) while the train was moving gets cut out once the train stands. +// a train formed by coupling is looked at as the buffers meet, above the speed the inspector takes for a standstill, +// and with no stop ahead nothing would look at it standing again (eu07/maszyna#350) +void TController::reinspect_brakes() +{ + if (false == BrakeReinspectionPending) { + return; + } + if (false == brake_setting::runs_as_train(OrderCurrentGet())) { + // no longer a train: nothing is cut out in a consist being shunted + BrakeReinspectionPending = false; + return; + } + if (brake_setting::at_standstill(mvOccupied->Vel)) { + // standing, the inspector leaves nothing for later: this clears the flag + AutoRewident(); + } +} + double TController::ESMVelocity(bool Main) { double fCurrentCoeff = 0.9; @@ -5320,6 +5344,8 @@ TController::Update( double const Timedelta ) { // mode specific actions handle_engine(); handle_orders(); + // a brake the wagon inspector left to cut out while the train was moving + reinspect_brakes(); // situational velocity and acceleration adjustments pick_optimal_speed( awarenessrange ); if( iEngineActive ) { diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 69f5cffc0..1657825dc 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -674,6 +674,8 @@ private: bool doors_open() const; bool doors_permit_active() const; void AutoRewident(); // ustawia hamulce w składzie + void reinspect_brakes(); // AutoRewident() again once the train stands, when it left a brake to cut out on the run + bool BrakeReinspectionPending{ false }; // AutoRewident() left a brake to cut out (Cw-1 §19.9) for the next standstill void announce( announcement_t const Announcement ); // members double fLength = 0.0; // długość składu (do wyciągania z ograniczeń) diff --git a/vehicle/brakesetting.cpp b/vehicle/brakesetting.cpp index f27c136ca..ceffe3180 100644 --- a/vehicle/brakesetting.cpp +++ b/vehicle/brakesetting.cpp @@ -260,23 +260,28 @@ vehicle describe(TMoverParameters const &Vehicle, bool const Driven) { return described; } -void apply(TMoverParameters &Vehicle, int const Setting, bool const Standstill) { +bool apply(TMoverParameters &Vehicle, int const Setting, bool const Standstill) { auto &brake{*Vehicle.Hamulec}; if (Vehicle.BrakeCutOutByInspector && false == is_cut_out(Vehicle)) { // someone put the brake back in the meantime, it's theirs now Vehicle.BrakeCutOutByInspector = false; } if (Setting == cut_out) { - if (false == is_cut_out(Vehicle) && Standstill) { - // close the cut-out cock and empty the brake with the releaser, as the scenery's '0' does: the - // distributor, cut off the brake pipe, has no air left to brake with and lets the cylinders go - brake.ForceEmptiness(); - brake.SetBrakeStatus(brake.GetBrakeStatus() | b_dmg); - Vehicle.BrakeCutOutByInspector = true; + if (is_cut_out(Vehicle)) { + // a brake cut out already, by the inspector or for a reason of its own, stays as it is + return false; } - // a brake cut out already, by the inspector or for a reason of its own, stays as it is. on the run the - // vehicle is left alone, brake and setting, until the inspector looks at the train standing - return; + if (false == Standstill) { + // on the run the vehicle is left alone, brake and setting, until the inspector looks at the train + // standing: the caller is told to come back + return true; + } + // close the cut-out cock and empty the brake with the releaser, as the scenery's '0' does: the + // distributor, cut off the brake pipe, has no air left to brake with and lets the cylinders go + brake.ForceEmptiness(); + brake.SetBrakeStatus(brake.GetBrakeStatus() | b_dmg); + Vehicle.BrakeCutOutByInspector = true; + return false; } if (Vehicle.BrakeCutOutByInspector) { // open the cut-out cock: the distributor charges from the brake pipe again @@ -286,6 +291,7 @@ void apply(TMoverParameters &Vehicle, int const Setting, bool const Standstill) if (Setting != 0) { Vehicle.BrakeDelaySwitch(Setting); } + return false; } } // namespace brake_setting diff --git a/vehicle/brakesetting.h b/vehicle/brakesetting.h index b555850fb..cb7ad5225 100644 --- a/vehicle/brakesetting.h +++ b/vehicle/brakesetting.h @@ -67,8 +67,10 @@ bool runs_as_train(int Orders); // the train stands for the inspector: slower than the AI takes for a deliberate movement (EU07_AI_MOVEMENT). // the AI looks at the train while it still creeps to a stop (at a W4, or switching from shunting to the train -// run) and as it couples (at the coupling speed), so a stricter threshold would miss those checks; a train -// really on the run (an order changed mid-run) stays above it +// run), so a stricter threshold would miss those checks; a train really on the run (an order changed mid-run) +// stays above it, and so does one being formed by coupling: the AI drives onto the standing cut faster than +// that and looks at the new train at the first buffer contact. apply() tells of the cut-outs such a look +// left for the next one, at a standstill bool at_standstill(double Velocity); // the inspector of the releases before eu07/maszyna#350, kept for ai.brakesetting.cw1 no. the settings @@ -89,7 +91,9 @@ vehicle describe(TMoverParameters const &Vehicle, bool Driven); // (Standstill): on the run the vehicle is left as it is until the inspector looks at the train again // standing, rather than losing its brake while moving. Any other setting first puts back a brake the // inspector cut out (it charges from the brake pipe again), then sets the vehicle to it (0: leaves the -// setting as it is). A brake cut out by anyone else stays cut out -void apply(TMoverParameters &Vehicle, int Setting, bool Standstill); +// setting as it is). A brake cut out by anyone else stays cut out. +// Returns true when a cut-out was left for later because the train was moving: the inspector has to look +// at the train again once it stands (TController::reinspect_brakes() does) +bool apply(TMoverParameters &Vehicle, int Setting, bool Standstill); } // namespace brake_setting