18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 23:14:59 +01:00

fix: the inspector takes a train below 1 km/h for standing and a bank run for a train (review of #282)

The AI inspects the train while it still creeps to a stop (W4, Shunt to Obey_train) and as it couples, so the 0.05 km/h threshold missed the §19.9 cut-out; it now uses EU07_AI_MOVEMENT. Bank counts as a train, as in the braking tables.
This commit is contained in:
jerrrrycho
2026-11-08 21:38:16 +01:00
parent 276b36d85f
commit 64d1b7f847
4 changed files with 77 additions and 10 deletions

View File

@@ -5,6 +5,7 @@
#include "McZapkie/hamulce.h" #include "McZapkie/hamulce.h"
#include "vehicle.h" #include "vehicle.h"
#include "vehicle/brakesetting.h" #include "vehicle/brakesetting.h"
#include "vehicle/Driver.h"
// the brake settings the AI wagon inspector (TController::AutoRewident) chooses for a train, by the // the brake settings the AI wagon inspector (TController::AutoRewident) chooses for a train, by the
// brake instruction Cw-1 (Mw56) §18 and §19 (eu07/maszyna#350) // brake instruction Cw-1 (Mw56) §18 and §19 (eu07/maszyna#350)
@@ -18,7 +19,7 @@ constexpr int P{bdelay_P};
constexpr int R{bdelay_R}; constexpr int R{bdelay_R};
constexpr int M{bdelay_M}; constexpr int M{bdelay_M};
// how the AI runs the consist the inspector looks at: as a train (Obey_train), or shunting it // how the AI runs the consist the inspector looks at: as a train (Obey_train or Bank), or shunting it
constexpr bool as_train{true}; constexpr bool as_train{true};
constexpr bool shunting{false}; constexpr bool shunting{false};
// whether the train stands, as AutoRewident() tells the inspector // whether the train stands, as AutoRewident() tells the inspector
@@ -345,6 +346,51 @@ TEST_CASE("brake setting: the inspector doesn't cut a brake out on the run, it w
CHECK(false == car->BrakeCutOutByInspector); 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
CHECK(brake_setting::at_standstill(0.0));
CHECK(brake_setting::at_standstill(0.04));
CHECK(brake_setting::at_standstill(0.9));
CHECK(brake_setting::at_standstill(-0.9));
CHECK(false == brake_setting::at_standstill(EU07_AI_MOVEMENT));
CHECK(false == brake_setting::at_standstill(30.0));
// checked at 0.9 km/h: the brake is cut out
test::vehicle creeping{passenger_car_definition()};
charge_and_apply(creeping);
CHECK(inspect_heavy_train(creeping, as_train, brake_setting::at_standstill(0.9)) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(creeping.mover()));
CHECK(creeping->BrakeCutOutByInspector);
// checked at 30 km/h: the car keeps its brake
test::vehicle running{passenger_car_definition()};
charge_and_apply(running);
CHECK(inspect_heavy_train(running, as_train, brake_setting::at_standstill(30.0)) == brake_setting::cut_out);
CHECK(false == brake_setting::is_cut_out(running.mover()));
CHECK(false == running->BrakeCutOutByInspector);
running.run(5.0);
CHECK(running->BrakePress > 1.0);
}
TEST_CASE("brake setting: a bank engine's run counts as a train, shunting doesn't") {
CHECK(brake_setting::runs_as_train(Obey_train));
CHECK(brake_setting::runs_as_train(Bank));
CHECK(brake_setting::runs_as_train(Obey_train | Connect));
CHECK(false == brake_setting::runs_as_train(Shunt));
CHECK(false == brake_setting::runs_as_train(Loose_shunt));
CHECK(false == brake_setting::runs_as_train(Connect));
CHECK(false == brake_setting::runs_as_train(Wait_for_orders));
// a heavy consist on G banked: the wagon without G has its brake cut out, as in a train
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
CHECK(inspect_heavy_train(car, brake_setting::runs_as_train(Bank)) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(car.mover()));
// shunted: it's back on P
CHECK(inspect_heavy_train(car, brake_setting::runs_as_train(Shunt)) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
}
TEST_CASE("brake setting: R+Mg brakes as hard as R at speed, the rapid stage of an LSt kept") { 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 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 // 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

@@ -2167,11 +2167,12 @@ void TController::AutoRewident()
consist.emplace_back(brake_setting::describe(*d->MoverParameters, d == pVehicle)); consist.emplace_back(brake_setting::describe(*d->MoverParameters, d == pVehicle));
} }
// 2. Określenie typu pociągu i nastaw: by the brake instruction Cw-1 (eu07/maszyna#350), or as the releases before it did. // 2. Określenie typu pociągu i nastaw: by the brake instruction Cw-1 (eu07/maszyna#350), or as the releases before it did.
// brakes are cut out (Cw-1 §19.9) only in a train, not in a consist being shunted // 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{(OrderCurrentGet() & Obey_train) != 0}; auto const train{brake_setting::runs_as_train(OrderCurrentGet())};
auto const settings{Global.AIBrakeSettingCw1 ? brake_setting::choose(consist, train) : brake_setting::choose_legacy(consist)}; auto const settings{Global.AIBrakeSettingCw1 ? brake_setting::choose(consist, train) : brake_setting::choose_legacy(consist)};
// and only at a standstill: 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 or coupling included: a check on the run (the order changed
auto const standstill{false == (mvOccupied->Vel > EU07_AI_NOMOVEMENT)}; // mid-run) leaves them to the next one
auto const standstill{brake_setting::at_standstill(mvOccupied->Vel)};
// a light engine counts as a passenger train for the braking below // a light engine counts as a passenger train for the braking below
auto const passengertrain{brake_setting::passenger(brake_setting::choose_train_setting(consist))}; auto const passengertrain{brake_setting::passenger(brake_setting::choose_train_setting(consist))};
// 3. Nastawianie // 3. Nastawianie

View File

@@ -12,8 +12,10 @@ http://mozilla.org/MPL/2.0/.
#include "McZapkie/MOVER.h" #include "McZapkie/MOVER.h"
#include "McZapkie/hamulce.h" #include "McZapkie/hamulce.h"
#include "vehicle/Driver.h"
#include <algorithm> #include <algorithm>
#include <cmath>
namespace brake_setting { namespace brake_setting {
@@ -156,8 +158,8 @@ std::vector<int> choose(std::vector<vehicle> const &Consist, bool const Train) {
} }
else if (item.powered || item.driven || item.delays == 0 || false == Train) { else if (item.powered || item.driven || item.delays == 0 || false == Train) {
// a locomotive, or the vehicle the train is driven from, keeps a working brake: on P. a vehicle // a locomotive, or the vehicle the train is driven from, keeps a working brake: on P. a vehicle
// which tells no settings at all is left alone. a consist being shunted isn't a train and §19.9 // which tells no settings at all is left alone. a consist being shunted isn't a train (a bank
// doesn't apply to it: its wagons keep their brakes, on P // engine's run is) and §19.9 doesn't apply to it: its wagons keep their brakes, on P
settings.emplace_back(pick(item.delays, bdelay_P, bdelay_P)); settings.emplace_back(pick(item.delays, bdelay_P, bdelay_P));
} }
else { else {
@@ -171,6 +173,14 @@ std::vector<int> choose(std::vector<vehicle> const &Consist, bool const Train) {
return settings; return settings;
} }
bool runs_as_train(int const Orders) {
return (Orders & (Obey_train | Bank)) != 0;
}
bool at_standstill(double const Velocity) {
return std::abs(Velocity) < EU07_AI_MOVEMENT;
}
std::vector<int> choose_legacy(std::vector<vehicle> const &Consist) { std::vector<int> choose_legacy(std::vector<vehicle> const &Consist) {
wagon_counts const counts{Consist}; wagon_counts const counts{Consist};
auto length{0.0}; auto length{0.0};

View File

@@ -56,11 +56,21 @@ constexpr bool passenger(train_setting const Setting) {
// without the setting the train needs gets the other one of G and P it has, and 0 (left as it is) // without the setting the train needs gets the other one of G and P it has, and 0 (left as it is)
// when it has neither. In a train on G (freight_g) a wagon without G gets cut_out instead: its brake // when it has neither. In a train on G (freight_g) a wagon without G gets cut_out instead: its brake
// is to be cut out (Cw-1 §19.9). A locomotive and the vehicle the train is driven from keep their // is to be cut out (Cw-1 §19.9). A locomotive and the vehicle the train is driven from keep their
// brake working, on P. Train tells the AI runs the consist as a train (Obey_train): §19.9 is about // brake working, on P. Train tells the AI runs the consist as a train (runs_as_train()): §19.9 is about
// trains, so in shunting (or banking) nothing is cut out and a wagon without G brakes on P, which puts // trains, so in shunting nothing is cut out and a wagon without G brakes on P, which puts back a brake
// back a brake the inspector cut out before // the inspector cut out before
std::vector<int> choose(std::vector<vehicle> const &Consist, bool Train); std::vector<int> choose(std::vector<vehicle> const &Consist, bool Train);
// the AI runs the consist as a train, rather than shunting it: Obey_train, or Bank, which it drives as a
// train run too (with the braking of a train). Orders is the order of the AI (TOrders)
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
bool at_standstill(double Velocity);
// the inspector of the releases before eu07/maszyna#350, kept for ai.brakesetting.cw1 no. the settings // the inspector of the releases before eu07/maszyna#350, kept for ai.brakesetting.cw1 no. the settings
// are requests: a vehicle which doesn't have the one asked for keeps its own // are requests: a vehicle which doesn't have the one asked for keeps its own
std::vector<int> choose_legacy(std::vector<vehicle> const &Consist); std::vector<int> choose_legacy(std::vector<vehicle> const &Consist);