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

@@ -2167,11 +2167,12 @@ void TController::AutoRewident()
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.
// brakes are cut out (Cw-1 §19.9) only in a train, not in a consist being shunted
auto const train{(OrderCurrentGet() & Obey_train) != 0};
// 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: a check on the run (the order changed mid-run) leaves them to the next one
auto const standstill{false == (mvOccupied->Vel > EU07_AI_NOMOVEMENT)};
// 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
auto const standstill{brake_setting::at_standstill(mvOccupied->Vel)};
// 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

View File

@@ -12,8 +12,10 @@ http://mozilla.org/MPL/2.0/.
#include "McZapkie/MOVER.h"
#include "McZapkie/hamulce.h"
#include "vehicle/Driver.h"
#include <algorithm>
#include <cmath>
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) {
// 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
// doesn't apply to it: its wagons keep their brakes, on P
// which tells no settings at all is left alone. a consist being shunted isn't a train (a bank
// 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));
}
else {
@@ -171,6 +173,14 @@ std::vector<int> choose(std::vector<vehicle> const &Consist, bool const Train) {
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) {
wagon_counts const counts{Consist};
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)
// 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
// brake working, on P. Train tells the AI runs the consist as a train (Obey_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
// back a brake the inspector cut out before
// 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 nothing is cut out and a wagon without G brakes on P, which puts back a brake
// the inspector cut out before
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
// 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);