18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 08:04:57 +01:00

fix: AI wagon inspector cuts out the brake of wagons without G in a train on G (eu07/maszyna#350)

Cw-1 §19.9: in a freight train braked on G, the brake of a vehicle that has
no G setting (e.g. a passenger car with P and R) is cut out. The inspector
put such wagons on P; now it cuts their brake out the way the scenery's '0'
flag does (b_dmg, the distributor's reservoirs emptied), so the brake
releases and stays off.

- The vehicle remembers the inspector cut it out
  (TMoverParameters::BrakeCutOutByInspector); the next inspection puts such
  a brake back and sets it to what the new train needs. A brake cut out for
  any other reason (scenery, player, damage) is never put back; the cab's
  cut-out toggle hands an inspector's cut-out over to the player.
- Locomotives and the vehicle the train is driven from keep a working
  brake (on P). In the long locomotive setting (§19.3b) the train runs on
  P, so a wagon without G stays on P there.
- The braking tables after the settings leave cut-out brakes out.
- §18.3: a car with R whose brake is cut out counts as one on P.
- ai.brakesetting.cw1 no keeps the earlier behaviour: nothing cut out.

The choice and the cutting out stay in vehicle/brakesetting.{h,cpp}, with
unit tests on real wagons.
This commit is contained in:
jerrrrycho
2026-11-08 13:03:06 +01:00
parent 1e650e375a
commit 81f10e4d90
6 changed files with 273 additions and 19 deletions

View File

@@ -1,7 +1,9 @@
#include "stdafx.h"
#include "doctest.h"
#include "McZapkie/MOVER.h"
#include "McZapkie/hamulce.h"
#include "vehicle.h"
#include "vehicle/brakesetting.h"
// the brake settings the AI wagon inspector (TController::AutoRewident) chooses for a train, by the
@@ -91,18 +93,182 @@ TEST_CASE("brake setting: a locomotive in the middle of the train doesn't put fi
CHECK(legacy[15] == P);
}
TEST_CASE("brake setting: a heavy freight train runs on G, a vehicle without G on P") {
TEST_CASE("brake setting: a heavy freight train runs on G, a wagon without G has its brake cut out (Cw-1 §19.9)") {
auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))};
consist.emplace_back(passenger_car(P));
consist.emplace_back(passenger_car());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_g);
auto const settings{brake_setting::choose(consist)};
for (std::size_t i = 0; i + 1 < settings.size(); ++i) {
for (std::size_t i = 0; i + 2 < settings.size(); ++i) {
CAPTURE(i);
CHECK(settings[i] == G);
}
CHECK(settings[settings.size() - 2] == brake_setting::cut_out);
CHECK(settings.back() == brake_setting::cut_out);
// the inspector of the earlier releases put them on P
auto const legacy{brake_setting::choose_legacy(consist)};
CHECK(legacy[settings.size() - 2] == P);
CHECK(legacy.back() == P);
}
TEST_CASE("brake setting: in a train on G a locomotive and the vehicle it's driven from keep a working brake") {
auto consist{train(locomotive(P | R), 30, freight_wagon(15.0, 80.0))};
// a dead locomotive without G at the end, and a car which tells no settings at all
consist.emplace_back(locomotive(P | R));
consist.emplace_back(0, false, 20.0, 40000.0);
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_g);
auto settings{brake_setting::choose(consist)};
CHECK(settings.front() == P);
CHECK(settings[settings.size() - 2] == P);
CHECK(settings.back() == 0);
// a control car without G, the train driven from it, pushed by the locomotive at the rear
brake_setting::vehicle controlcar{P | R, false, 24.5, 45000.0};
controlcar.driven = true;
consist.front() = controlcar;
consist.back() = locomotive();
settings = brake_setting::choose(consist);
CHECK(settings.front() == P);
CHECK(settings.back() == G);
}
TEST_CASE("brake setting: in the long locomotive setting a vehicle without G brakes on P, not cut out (Cw-1 §19.3b)") {
// the train runs on P, so §19.9 doesn't apply to it, among the first five wagons kept on G or behind them
auto consist{train(locomotive(), 2, freight_wagon(15.0, 60.0))};
consist.emplace_back(passenger_car());
consist.insert(consist.end(), 8, freight_wagon(15.0, 60.0));
consist.emplace_back(passenger_car());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_gp);
auto const settings{brake_setting::choose(consist)};
CHECK(settings[2] == G);
CHECK(settings[3] == P);
CHECK(settings[4] == G);
CHECK(settings[6] == P);
CHECK(settings.back() == P);
}
TEST_CASE("brake setting: a car with its brake cut out counts as one on P in a passenger train (Cw-1 §18.3)") {
auto consist{train(locomotive(), 5, passenger_car())};
consist.insert(consist.end(), 3, passenger_car(P));
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
// one car with R cut out makes four on P
consist[1].cut_out = true;
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_p);
// with fewer P-only cars, three on P and four on R still run on R
consist.pop_back();
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
// a cut out brake changes nothing about a train being a passenger or a freight one
auto freight{train(locomotive(), 4, freight_wagon())};
freight.emplace_back(passenger_car());
freight.back().cut_out = true;
CHECK(brake_setting::choose_train_setting(freight) == train_setting::freight_p);
}
namespace {
// a passenger car with P and R, with the KE distributor of the test wagon
test::definition passenger_car_definition() {
return test::definition::load("wagon").set("Cntrl", "BrakeDelays", "PR");
}
// charges the brake of the vehicle from a brake pipe at 5 bar, then makes a full service application
void charge_and_apply(test::vehicle &Vehicle) {
Vehicle.hold_brake_pipe(5.0);
Vehicle.run(90.0);
Vehicle.hold_brake_pipe(3.5);
Vehicle.run(20.0);
}
// the inspector at work on a heavy train on G with the vehicle at its end, as AutoRewident() does it
int inspect_heavy_train(test::vehicle &Vehicle) {
auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))};
consist.emplace_back(brake_setting::describe(Vehicle.mover(), false));
auto const setting{brake_setting::choose(consist).back()};
brake_setting::apply(Vehicle.mover(), setting);
return setting;
}
// the same on a light train, which runs on P
int inspect_light_train(test::vehicle &Vehicle) {
auto consist{train(locomotive(), 4, freight_wagon())};
consist.emplace_back(brake_setting::describe(Vehicle.mover(), false));
auto const setting{brake_setting::choose(consist).back()};
brake_setting::apply(Vehicle.mover(), setting);
return setting;
}
} // 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") {
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
REQUIRE(car->BrakePress > 1.0);
// made up into a heavy train on G: the brake is cut out and released
REQUIRE(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(car.mover()));
CHECK(car->BrakeCutOutByInspector);
car.run(30.0);
CHECK(car->BrakePress < 0.1);
// and it stays off whatever the brake pipe does
car.hold_brake_pipe(5.0);
car.run(60.0);
car.hold_brake_pipe(3.5);
car.run(20.0);
CHECK(car->BrakePress < 0.1);
car.hold_brake_pipe(0.0);
car.run(20.0);
CHECK(car->BrakePress < 0.1);
// to the inspector looking at the train again it's a car like any other, and the train needs it cut out still
CHECK(false == brake_setting::describe(car.mover(), false).cut_out);
REQUIRE(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(car->BrakeCutOutByInspector);
// made up into a light train: the brake is back on P, charges and brakes again
CHECK(inspect_light_train(car) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
CHECK(false == car->BrakeCutOutByInspector);
CHECK(car->BrakeDelayFlag == P);
// the reservoirs emptied when it was cut out take some five minutes to charge from the brake pipe
car.hold_brake_pipe(5.0);
car.run(300.0);
CHECK(car->Hamulec->GetBRP() > 4.9);
charge_and_apply(car);
CHECK(car->BrakePress > 1.0);
}
TEST_CASE("brake setting: the inspector never puts back a brake cut out for another reason") {
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
// cut out the way the scenery's '0' does it
car->Hamulec->ForceEmptiness();
car->Hamulec->SetBrakeStatus(car->Hamulec->GetBrakeStatus() | b_dmg);
CHECK(brake_setting::describe(car.mover(), false).cut_out);
// a train on G wants it cut out anyway: it isn't the inspector's to put back
CHECK(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(false == car->BrakeCutOutByInspector);
// a train on P would want it working: it stays cut out
CHECK(inspect_light_train(car) == P);
CHECK(brake_setting::is_cut_out(car.mover()));
charge_and_apply(car);
CHECK(car->BrakePress < 0.1);
// a brake the inspector cut out, which someone else puts back and cuts out again, is theirs from then on
test::vehicle other{passenger_car_definition()};
REQUIRE(inspect_heavy_train(other) == brake_setting::cut_out);
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() & ~b_dmg);
CHECK(inspect_heavy_train(other) == brake_setting::cut_out); // the inspector cuts it out again, and it's its own again
CHECK(other->BrakeCutOutByInspector);
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() & ~b_dmg);
CHECK(inspect_light_train(other) == P);
CHECK(false == other->BrakeCutOutByInspector);
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() | b_dmg);
CHECK(inspect_light_train(other) == P);
CHECK(brake_setting::is_cut_out(other.mover()));
}
TEST_CASE("brake setting: a vehicle without the setting the train needs gets the other one of G and P") {
// a light freight train with a wagon which has G only
auto consist{train(locomotive(), 4, freight_wagon(15.0, 20.0))};