From c5676629132eed0358c5f95fe5ef3f83ea79b641 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Thu, 12 Nov 2026 05:26:57 +0100 Subject: [PATCH] fix(ai): release the hand brake when the first order is Connect CheckVehicles() ran the inspector (AutoRewident(), which also releases the hand and spring brakes of the AI's train) only under Shunt, Loose_shunt, Obey_train and Bank. A locomotive loaded cold (trainset velocity 0) starts with its hand brake on; when the first order it drives under is Connect (Shunt x,y with a coupler, e.g. Shunt -2 -3 after Prepare_engine), it pulled against the hand brake for good and never reached the wagons. The inspector now also runs under Connect, except for the look the AI takes at the moment it couples (CheckVehicles(Connect)): the wagons just coupled keep their hand brakes until the order after the coupling looks at the new train, as before, so those to be left standing again (Shunt x,-y) stay braked. Wagons not yet coupled are never touched: AutoRewident() goes over the vehicles coupled to the AI's train only. The rule is brake_setting::inspects_train(), with a unit test. --- tests/unit/test_brake_setting.cpp | 23 +++++++++++++++++++++++ vehicle/Driver.cpp | 2 +- vehicle/brakesetting.cpp | 4 ++++ vehicle/brakesetting.h | 9 +++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_brake_setting.cpp b/tests/unit/test_brake_setting.cpp index 5034bf3c5..39b0e2117 100644 --- a/tests/unit/test_brake_setting.cpp +++ b/tests/unit/test_brake_setting.cpp @@ -474,6 +474,29 @@ TEST_CASE("brake setting: a bank engine's run counts as a train, shunting doesn' CHECK(false == brake_setting::is_cut_out(car.mover())); } +TEST_CASE("brake setting: the AI looks at its train under the orders it drives it under, Connect included") { + CHECK(brake_setting::inspects_train(Shunt, false)); + CHECK(brake_setting::inspects_train(Loose_shunt, false)); + CHECK(brake_setting::inspects_train(Obey_train, false)); + CHECK(brake_setting::inspects_train(Bank, false)); + // the run up to the wagons: a locomotive standing cold has its hand brake to release first + CHECK(brake_setting::inspects_train(Connect, false)); + CHECK(brake_setting::inspects_train(Connect | Change_direction, false)); + // but not at the coupling: the wagons just coupled wait for the next order, which may leave some of them + CHECK(false == brake_setting::inspects_train(Connect, true)); + CHECK(false == brake_setting::inspects_train(Connect | Change_direction, true)); + // a train run with a coupling on it is still a train run + CHECK(brake_setting::inspects_train(Obey_train | Connect, true)); + CHECK(brake_setting::inspects_train(Shunt, true)); + // standing, starting or stopping the engine, turning round, uncoupling: nothing to look at + CHECK(false == brake_setting::inspects_train(Wait_for_orders, false)); + CHECK(false == brake_setting::inspects_train(Prepare_engine, false)); + CHECK(false == brake_setting::inspects_train(Release_engine, false)); + CHECK(false == brake_setting::inspects_train(Change_direction, false)); + CHECK(false == brake_setting::inspects_train(Disconnect, false)); + CHECK(false == brake_setting::inspects_train(Jump_to_first_order, false)); +} + TEST_CASE("brake setting: R+Mg brakes as hard as R at speed, the rapid stage of an LSt kept") { // the inspector sets R+Mg (Cw-1 §18.2), the bits of R and Mg together: the valves test the bit of R, not // the whole setting, so the high stage of R at speed stays on with Mg. the EU07's LSt given an Mg here diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index eb74344bf..ce41ee780 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -2876,7 +2876,7 @@ bool TController::CheckVehicles(TOrders user) = 0; } - if( OrderCurrentGet() & ( Shunt | Loose_shunt | Obey_train | Bank ) ) { + if( brake_setting::inspects_train( OrderCurrentGet(), user == Connect ) ) { // nastawianie hamulca do jazdy pociągowej AutoRewident(); /* diff --git a/vehicle/brakesetting.cpp b/vehicle/brakesetting.cpp index ceffe3180..918da3d02 100644 --- a/vehicle/brakesetting.cpp +++ b/vehicle/brakesetting.cpp @@ -177,6 +177,10 @@ bool runs_as_train(int const Orders) { return (Orders & (Obey_train | Bank)) != 0; } +bool inspects_train(int const Orders, bool const Coupled) { + return (Orders & (Shunt | Loose_shunt | Obey_train | Bank)) != 0 || ((Orders & Connect) != 0 && false == Coupled); +} + bool at_standstill(double const Velocity) { return std::abs(Velocity) < EU07_AI_MOVEMENT; } diff --git a/vehicle/brakesetting.h b/vehicle/brakesetting.h index cb7ad5225..e3e5b4974 100644 --- a/vehicle/brakesetting.h +++ b/vehicle/brakesetting.h @@ -65,6 +65,15 @@ std::vector choose(std::vector const &Consist, bool Train); // train run too (with the braking of a train). Orders is the order of the AI (TOrders) bool runs_as_train(int Orders); +// the AI has the inspector look at its train (TController::AutoRewident(): the brake settings, and the hand and +// spring brakes of the train released) under the orders it drives the train under: shunting, loose shunting, the +// train run, banking, and the run up to the wagons to couple to (Connect), which a locomotive left standing cold, +// with its hand brake on, would make pulling against it. Coupled: the look the AI takes at the moment it couples +// (CheckVehicles(Connect)); Connect doesn't count for it, so the wagons just coupled keep their hand brakes until +// the order after the coupling looks at the new train, as before: those of them to be left standing again +// (Shunt x,-y) stay braked. Orders is the order of the AI (TOrders) +bool inspects_train(int Orders, bool Coupled); + // 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), so a stricter threshold would miss those checks; a train really on the run (an order changed mid-run)