18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

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.
This commit is contained in:
jerrrrycho
2026-11-12 05:26:57 +01:00
parent bac9954ad5
commit c567662913
4 changed files with 37 additions and 1 deletions

View File

@@ -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

View File

@@ -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();
/*

View File

@@ -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;
}

View File

@@ -65,6 +65,15 @@ std::vector<int> choose(std::vector<vehicle> 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)