18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-18 21:06:00 +01:00
Commit Graph

82 Commits

Author SHA1 Message Date
f908ae307b Merge pull request #265 from pwarszawski/feat/ai-braking-gradients
AI on up gradients: hold a train coming to a stand, start on the train brake
2026-11-09 12:59:34 +00:00
889aa2d5db Merge pull request #278 from MaSzyna-EU07/feat/shunt-lock-resistive
Field shunting locked at zero and on resistive positions (eu07/maszyna#402)
2026-11-09 12:53:57 +00:00
4a9ab1447e Merge pull request #279 from MaSzyna-EU07/fix/multiple-unit-electric-diesel
No multiple-unit control between electric and diesel locomotives (eu07/maszyna#520)
2026-11-09 12:53:30 +00:00
0c95dbfa5a Merge pull request #280 from MaSzyna-EU07/feat/radio-fuse
Radio fuse: a cut-off in the radio's power supply (eu07/maszyna#438)
2026-11-09 12:53:14 +00:00
ebc9eb8740 Merge pull request #281 from MaSzyna-EU07/feat/shunt-pantograph-config
AI: suggested pantograph setup for shunting in the .fiz (eu07/maszyna#461)
2026-11-09 12:52:58 +00:00
c1089a6b16 Merge pull request #292 from MaSzyna-EU07/fix/en57-ep2-brake-charging
EN57 brakes: charging when hauled with the brake hose alone, Knorr EP brake only with control power
2026-11-09 12:48:13 +00:00
maj00r
9fecba82f0 Merge pull request #291 from MaSzyna-EU07/fix/sod-lamp-whole-consist
SOD lamp: doors of the whole consist, three states (eu07/maszyna#288)
2026-11-08 20:56:20 +01:00
maj00r
17676863bc Merge pull request #266 from MaSzyna-EU07/feat/exe-test-mode
Test mode: `--test` runs a scenery unattended and exits with the result (#541)
2026-11-08 20:41:57 +01:00
pwarszawski
1cb365a2a8 Merge master into feat/ai-braking-gradients (after #297) 2026-11-08 20:40:54 +01:00
jerrrrycho
43fc80f452 fix: radio fuse review: working push buttons, own hint, HUD
- radioon_sw:/radiooff_sw:/radiofuseon_sw:/radiofuseoff_sw: are now loaded
  as push-button gauges in initialize_gauge, so they can be clicked; the
  enable/disable commands press them while held. radiotoggle and
  radiofusetoggle flip the state directly, so they don't move them.
- New driver hint "Close radio fuse" (radiofuseon); "Switch on radio" is
  given only when the radio's own switch is off.
- The HUD shows the radio channel only with the fuse closed.

(eu07/maszyna#438)
2026-11-08 17:52:39 +01:00
jerrrrycho
200d3ae73b fix: review of the EN57 EP brake (Sonar null check, EP fuse of the cab car, AI re-asserts the EP brake)
- tests: REQUIRE the brake handle before dereferencing it (Sonar cpp:S2259)
- TESt::FillBrakeRes is const (S5817)
- cab EP brake command: drop the mvControlled->EpFuse check, SwitchEPBrake
  already checks the cab car's (mvOccupied) EP fuse with the control supply
- AI: with the handle already at the EP brake position, switch the EP brake
  on again once the control supply is back
2026-11-08 17:37:56 +01:00
pwarszawski
8cc8158d2a AI: making for a passenger stop, leave room only for the brake's own fill time
Since #187 the braking curve towards a stop or a lower speed leaves room for
the time the brake takes to respond, as long as the train brake handle is
still in the running position. The horizon it takes has the AI's old
look-ahead, (1 - a0) * 30/3.6 s, about 7-8 s, as its floor; at 60 km/h that
is over 100 m, up to half of the braking distance. Stops at signals were
tuned with it. A vehicle that brakes with its independent brake (an SN61, a
light engine) leaves the train brake handle where it is, so it kept that
room the whole way in: it braked early and gently, came down to 10 km/h
some 50 m out and crawled the rest, applying power and the brake in turn.

Making for a passenger stop (the point the train is to stop at, found by the
scan of the route, is a W4), the room now covers only the time the brake
takes to fill (half its application time), without the look-ahead floor.
Stops at signals and anything else keep the room as it was.

When a vehicle ahead is closer than the stop the scan found, the train makes
for that vehicle, so the room is the full one again.
2026-11-08 16:25:12 +01:00
pwarszawski
63fe5bde57 AI on up gradients: what the review found
- The tractive force that tells the start on the train brake is over is
  projected on the direction of travel: Ft is in the vehicle's own frame, so
  a locomotive driven from its rear cab, or turned the other way in the
  consist, counted as nothing.
- Rolling back faster than 0.5 km/h ends the start on the train brake, so
  the rules for a train slipping back apply the brakes again.
- One threshold for an up gradient that rolls a standing train back,
  EU07_AI_UPHILLGRAVITY (-0.025 m/s2, about 2.5 per mille), for the stop
  hold, the locomotive brake on rollback, the start, uphill_brake_committed()
  and hold_train_coming_to_stand_uphill(); the stop hold and the rollback
  rule started at 0.5 per mille before, on almost level track.
- hold_train_coming_to_stand_uphill() brakes on the brake's response time
  only for a train that is not to pull up further.
- Starting against the brake keeps the train Ready only at a standstill; in
  motion a braking force left in the train stops it as before.
2026-11-08 15:56:32 +01:00
pwarszawski
f067478154 Merge master into feat/ai-braking-gradients (after #295) 2026-11-08 14:52:34 +01:00
pawelw
3487e75f9a AI: the passenger stop flag no longer turns itself on and off (#295)
Whether a train is at a passenger stop (IsAtPassengerStop) was checked against
the final approach margins fMinProximityDist and fMaxProximityDist, which are
themselves set from that flag: 10-15 m and 15-40 m at a stop, 8 m and 50 m
otherwise. With the two sets different, the flag switched on and off on every
other scan of the route on the way to a W4. Each time the train went from a
final approach to a stop 50 m long to one 15 m long and back: braking in one
scan, full power below the 10 km/h coasting speed in the next. Close to the
stop the braking demand did not hold the train to a standstill, and below
1 km/h the stop counted as done, so an SN61 drove off without ever standing
still (#290).

The margins are now worked out in train_proximity_margins(), and the check of
the stop uses the margins of a passenger stop whatever the flag is at the
moment. A vehicle that is not a train keeps the present ones, as before.
2026-11-08 14:40:13 +01:00
jerrrrycho
491ed3e6da Merge remote-tracking branch 'origin/master' into feat/exe-test-mode 2026-11-08 10:58:43 +01:00
jerrrrycho
547706b54d refactor(simulation): fix the Sonar remarks on the test mode code
- TController::TableCheck() calls TSpeedPos::Update() as it did before the
  test mode: the check for a signal passed at danger is a call of its own
  after it (CheckSignalPassedAtDanger), so the update lines nest no deeper
  than on master (S134). A switch is a track, so a signal's update never
  takes the switch-change branch and the check runs in the same place as
  before; the physicslogs of all 15 scenario cases are byte for byte the
  same.
- null_imgui_renderer is final (S1235), to_string(test_result) uses
  `using enum` (S6177), init_result_cell() is const (S5817),
  ConfigParseTest() takes a std::string_view (S6009) and the test settings
  struct is declared apart from its member (S3646).
2026-11-08 09:35:59 +01:00
jerrrrycho
4b769d95c1 fix: SOD lamp shows the doors of the whole consist in three states (eu07/maszyna#288)
The door closure signalling lamp (i-door_blocked) showed only Doors.is_locked
of the occupied vehicle, so a door open in another car or a coupled unit
didn't show on it.

TMoverParameters::door_closure() gives the state of one vehicle (none, locked,
released, open), the driver gathers the most severe one of the train in
determine_consist_state(), next to IsAnyDoorOpen, and the lamp is lit for
locked doors, blinks for closed but released ones (a permit given, or no lock
engaged on doors that need no permit) and is dark with a door open.

doorclosuresignal in eu07.ini (default yes) switches it; with no the lamp
shows is_locked of the occupied vehicle as before. No data change needed.
2026-11-08 02:05:45 +01:00
pwarszawski
b992df7ab7 AI braking: slowdowndistance in the init-statement of its if (Sonar S6004) 2026-11-07 23:53:02 +01:00
pwarszawski
95ceb815d2 AI braking: the braking curve outside the final approach in a method of its own
Takes care of the last two Sonar remarks, with no change in what the AI does:

- S134: the braking curve followed outside the final approach moves out of
  adjust_desired_speed_for_target_speed() into
  adjust_desired_speed_for_braking_curve(), with early returns.
- S6004: deltaAcc of increase_train_brake() is declared in the
  init-statement of its if.
2026-11-07 22:55:09 +01:00
pwarszawski
99cf46866a AI braking, ESt3: take care of the Sonar remarks on the braking PRs
No change in what the AI or the distributor does:

- S134: the step of the train brake sized from the consist brake table
  moves out of IncBrake() into increase_train_brake(), with early returns.
- S134, S1066: while starting uphill, the check of the released brakes
  leaves Ready as it was by assigning the flag instead of nesting an if.
- S6004: the uphill condition of control_uphill_start(), and the target
  cylinder pressure of TNESt3::CheckState(), are declared in the
  init-statement of their if.
- S5350: the loop summing the tractive force walks the consist through a
  pointer to const.
- S3776: the cylinder nozzle calibration for the AL2 relay moves out of
  TNESt3::SetSize() into ScaleNozzlesForAL2().
2026-11-07 22:00:30 +01:00
pwarszawski
292092a7aa AI braking: take care of the Sonar remarks on the new braking code
No change in what the AI does; only the structure of the code that came in
with the braking changes:

- S107: shaped_braking_demand() takes the consist brake table as a struct
  instead of four separate parameters; its lambdas capture explicitly.
- S3358: brake_response_horizon() picks the BrakeDelay entry without a
  nested conditional operator.
- S5276: the speed passed to braking_distance_multiplier() is converted to
  float explicitly, as it was implicitly before.
- S134: the stop case of the proximity range is an else-if of its own, and
  its body a method of its own, adjust_desired_speed_for_final_approach(),
  with early returns instead of nested ifs. The cargo train threshold
  push is a conditional subtraction instead of a nested if.
- S3776: pick_optimal_speed() hands the uncoupling stages and the uphill
  stand to set_velocity_for_uncoupling() and
  hold_train_coming_to_stand_uphill().
2026-11-07 21:40:02 +01:00
jerrrrycho
30bdc3da61 feat: radio fuse, a cut-off in the radio's power supply (eu07/maszyna#438)
TMoverParameters::RadioFuse, closed by default, stands for a fuse in the
cabinet, a lever on the desk or the switch on the radio's power supply.
RadioPowered() needs it closed, so with it open the radio's buttons, calls,
messages and the radio-stop stop working; opening it at a standstill resets
the radio-stop as switching the radio off does, and the radio and radio-stop
lamps go out. New commands radiofusetoggle/radiofuseenable/radiofusedisable
(no default keys), cab controls radiofuse_sw: (follows the fuse state),
radiofuseon_sw: and radiofuseoff_sw:, and radio_fuse for the Python screens.
The AI turning the radio back on closes the fuse too.

Existing vehicles don't change: the fuse starts closed and opens only from a
new cab control or a bound key. SVN data, optional: cabs that have such a
fuse or lever get one of the new controls in their .mmd, in the form of
radio_sw: (e.g. "radiofuse_sw: { <submodel> rot 0 0 0 }"); lang/*.po can
translate "radio fuse".

(eu07/maszyna#438)
2026-11-07 21:33:28 +01:00
jerrrrycho
8f51ea9a19 feat(ai): suggested pantograph setup for shunting in the .fiz (eu07/maszyna#461)
A new optional key in the AI section of the .fiz, ShuntPantstate= (bits as in
Pantstate: 1 front, 2 rear, 3 both), sets the pantographs the AI driver keeps
up while its order is Shunt or Loose_shunt, moving and standing alike: it
raises those of the setup and lowers the others once one of the setup
collects the voltage, and doesn't raise more when idling. Lowering on the
track's demand still comes first. Without the key (default 0) nothing
changes, so an ET41 no longer has to shunt on all four pantographs once its
.fiz says so.

SVN data, optional: add "AI: ShuntPantstate=<1|2|3>" to the .fiz of vehicles
that should shunt on fewer pantographs, e.g. dynamic/pkp/et41_v2/203e-a.fiz,
203e-b.fiz and their _dsa150 variants (no AI line there yet). Without it the
vehicles behave as before.

(eu07/maszyna#461)
2026-11-07 21:32:41 +01:00
pwarszawski
84fbd75e8f Merge branch 'feat/ai-braking-earlier-steps' into feat/ai-braking-gradients 2026-11-07 21:17:13 +01:00
pwarszawski
04b208bbaf Merge branch 'fix/est3-valve' into feat/ai-braking-earlier-steps 2026-11-07 21:17:12 +01:00
pwarszawski
71d4645e09 Merge remote-tracking branch 'origin/master' into fix/est3-valve 2026-11-07 21:17:04 +01:00
jerrrrycho
6dc1239553 fix: no multiple-unit control between electric and diesel locomotives
An electric and a diesel locomotive got their control coupled whenever the
scenario (and so the Starter) asked for it, since the scenery coupling ignores
ControlType, or when neither coupler named a control system, so a Vectron and
an SM42 ran in multiple unit.

TMoverParameters::Attach() now leaves the control connection out between an
electric (ElectricSeriesMotor, ElectricInductionMotor) and a diesel
(DieselEngine, DieselElectric/DumbDE) traction vehicle, for the scenery, the
AI, the coupling keys and the automatic couplers alike, and logs it. Vehicles
without own traction (cars, control trailers) are not affected, nor are
permanent couplings within a unit, nor couplers that both name the same
ControlType, which stays the vehicle authors' way to allow such a pair. The
AI coupling order expects the coupling the vehicles can take, so it doesn't
wait for the control connection forever.

Existing scenarios coupling such a pair still load, without the control
connection. "controlcoupling.enginecheck no" in eu07.ini turns the check off.
No SVN data change is needed. (eu07/maszyna#520)
2026-11-07 21:16:19 +01:00
jerrrrycho
5bc4e7cd2e feat: lock field shunting at zero and on resistive positions
New optional Cntrl. key ScndCtrlResistiveLock=Yes: IncScndCtrl() refuses
to step the shunt controller up while the master controller is at its
no-power position or on a resistive RList position (R >= 0.01), as the
interlock of the ET21, ET22 and EP09 does. Decreasing the shunt stays
allowed so it can't get stuck. The AI doesn't choose field shunting
while the lock applies. Without the key nothing changes.

Game data: the key is to be added to the Cntrl. line of the ET21
(et21_v2), ET22 (et22_v3, et22-2000_v2) and EP09 (ep09_v1, ep09_v2)
.fiz files that define it; until then they behave as before.

(eu07/maszyna#402)
2026-11-07 21:01:54 +01:00
pwarszawski
137eb9641f AI: start a train uphill on the train brake
Starting uphill the AI released the train brake (and the locomotive
brake with it) at once, while the power came on only later: a train on
10 per mille rolled back 20-30 m (E186 with 19 container wagons), and an
E189 with 7 Z2 coaches rolled back for minutes without power, because
the brake applied again for the rollback kept the power off. Many
locomotives cannot pull while their own cylinder is under pressure
(asynchronous drives switch to braking, others have a control pressure
switch), so holding the train on the locomotive brake is no way out.

A train standing on an up gradient with the train brake applied now
starts as a driver of a heavy train does:

- the train brake stays applied, the locomotive brake is released and
  the locomotive's own share of the train brake is let off with the
  releaser;
- the power is applied against the braked train (Ready does not hold
  it back meanwhile, and the rule that brakes a train slipping back
  is off);
- the train brake is released only once the tractive force exceeds 1.1
  times the gradient force, the train moves forward, or after 45 s if
  the locomotive cannot hold the train on its own power.

Multiple units are not affected.
2026-11-07 18:10:47 +01:00
pwarszawski
8d1d9eec9b AI braking: smaller steps, earlier, while approaching a stop or a lower speed
Changes to how the AI works the train brake on the way to a lower speed
or a stop, so that it uses few, early applications instead of a late
deep one:

- Approaching a lower speed, the deceleration may fall short of the
  demand by only half of a step (fBrake_a1) before the brake is applied
  harder. With a full step the demand crept up meanwhile and a long G
  train got its next step many seconds too late.
- The shortfall is checked every 3 s. If it keeps growing at a handle
  left alone for longer than the brake takes to respond, the AI adds a
  small step at once instead of waiting until the margin calls for a
  deep one. A shortfall that shrinks on its own (brake still filling,
  blocks gripping harder at lower speed) does not trigger it.
- Releasing, a position short of the first one counts as giving the
  minimum stage of the distributor, not less.
- Holding the speed on a descent, the predicted excess speed is taken
  off over the time the brake takes to respond, not at once, so a slow
  brake does not get a deep application that then takes as long to
  release.
2026-11-07 18:10:47 +01:00
pwarszawski
f53e184949 AI braking: hold a train coming to a stand uphill
Uphill a long train often came to a stand with its brake on the way
off and rolled back several metres: the AI released the train brake
to 0 about 20 m short of the stop (the gradient alone would have
stopped the train short of the stopping window), applied only the
first step again at the last moment, and a G train cannot apply its
brake again within the few seconds the gradient takes to stop it.

Coming to a stand on an up gradient (also when only part of the train
is on it) the AI now:

- applies the brake before the train stops on the gradient alone, once
  the time left to the stand is no longer than half of what the brake
  takes to apply;
- does not let the train coast on or pull up while the brake is applied
  and the gradient would stop the train sooner than the brake of the
  consist can be released;
- does not release the train brake any further below 10 km/h on the
  way to a stand (unless the train is to be driven on);
- puts the locomotive brake on below 3 km/h when the train will reach
  the point it is to stop at (not when it has slowed down short of it
  and is to pull up), and at once if the train rolls back.
2026-11-07 18:10:47 +01:00
jerrrrycho
441caeed64 refactor(simulation): tidy the test mode code
The test manager is reached through simulation::test() instead of a global,
the result cell is owned by a unique_ptr until the memory table takes it, the
cell value is compared with a margin, strings are built with std::format and
the --test settings moved to apply_test_mode_settings(). The driver's signal
check is folded into UpdateSpeedPosition(), which updates a speed table entry
and reports a signal at stop the head of the train just passed. The test.*
keys are listed with the other settings at the start of the log.
2026-11-07 17:12:11 +01:00
jerrrrycho
02e29f6971 feat(simulation): test mode, --test runs a scenery unattended and exits with the result (eu07/maszyna#541)
eu07 --test -s <scenery> [--test-timeout <s>] runs the scenery in ghostview with
the null renderer (models loaded, no textures), a hidden window, no sound,
network or python, and in fixed steps of 0.03 s of simulation time per frame
(three 10 ms physics steps) as fast as it can. Without -seed it uses a fixed
seed, so two runs give byte-identical physicslogs.

The scenery reports its result to the __test.result memory cell, which the
simulator always creates: value 1 passes once every vehicle has stood still for
1 s, value 0 fails at once. The run ends with exit code
  0 pass, 1 fail,
  2 a train passed a signal at stop (SetVelocity 0 0, as seen in its driver's
    speed table; SetVelocity 0 x on automatic block doesn't count),
  3 timeout (test.timeout, default 3600 s of simulation time),
  4 standstill (every vehicle still for test.standstill s, default 300, with no
    result; a pass with test.pass_on_standstill yes),
  5 error (no -s, the scenery didn't load or has no vehicles, an exception).
The test.* keys go in the scenery's config block; test.fail_if_stop_overran no
only logs a signal passed at danger. Outside the test mode a signal passed at
danger is logged.

The null renderer gets a ui backend which draws nothing, hands out the null
texture and material instead of throwing, and ends the ui frame. A GL context
is still made for the hidden window, without asking for a version, as parts
of the ui create textures with gl calls of their own. No crash dialog or
message box in test mode; the window code no longer needs a monitor.
2026-11-07 16:20:42 +01:00
jerrrrycho
fe9e2f77c2 feat(log): vehicle speed column in the physicslog
The Velocity column is the wheel speed, which stays at 0 while the wheels
are locked in a skid, so a vehicle sliding on locked wheels looked as if
it stood still. Add the signed vehicle speed in km/h as the last column.
2026-11-07 16:20:42 +01:00
pwarszawski
439e892abd AI: use the locomotive releaser only when starting off
The rule "wyluzuj lokomotywe, to szybciej ruszymy" released the
locomotive's own brake whenever power was asked for and the locomotive
cylinder held more than 0.4 bar. It had no speed condition, so it also
fired in motion, at 50-75 km/h, right after an application. On a
locomotive with the EStED distributor (E186) this vented the control
reservoir; with the pipe not yet recharged the locomotive brake then
faded to nothing at the next application.

The rule is meant for starting off, so it now applies only below
1 km/h.
2026-11-07 15:35:35 +01:00
pwarszawski
18bc7e06bf AI braking: move the uphill power-off check into its own function
The condition added for holding the speed uphill near a stop pushed the
cognitive complexity of control_tractive_force() to 26, over the 25
SonarCloud allows. It now lives in is_too_fast_uphill(); the behaviour
is unchanged.
2026-11-02 16:43:16 +01:00
pwarszawski
1f3cf4fe56 AI braking: don't let the running brake test override a stop ahead
adjust_desired_speed_for_braking_test runs after the target speed was
worked out and overwrites AccDesired. In its third phase it holds the
deceleration near fAccThreshold until the speed has dropped by 8 km/h.
On a 20 per mille descent that application barely holds the speed, so
the phase can last minutes, and a stop signal coming up meanwhile is
ignored. In one real-time run an E186 with 19 container wagons started
the test 1290 m before a stop signal, lost 7 km/h by the signal and
overran it by 274 m after the emergency application.

While the test runs the AI now uses whichever of the two asks for the
harder braking: the test may brake harder than the route needs, never
softer.

Measured in real time, four runs of 32 consists each on a 20 per mille
descent, on the flat and on the descent with half the rail adhesion:
the test no longer runs within 600 m of a stop signal (before: down to
414 m on this branch, and 14 m with the overrun above in a build with
other brake changes), no overruns, stops 8-15 m short of the signal 86,
117 and 83 of 128 (before 90, 117 and 78).
2026-11-02 16:02:14 +01:00
pwarszawski
6b82f1471a AI braking: take power off when holding the speed uphill near a stop
Within fMaxProximityDist of a stop, going uphill, the AI holds its speed
with AccDesired = min(0, AccPreferred). control_tractive_force only cut
the power uphill when AccDesired < 0, so an AccDesired of exactly 0 kept
the controller where it was. A consist that came into that range under
power kept full power and crept up to the signal.

Holding the speed uphill on the way to a stop now asks for no speeding
up: power comes off once the train is faster than AccDesired allows.

With the current brake valves this rarely shows: on a 10 per mille climb,
four real-time runs of 32 consists each, the E186 with 25 empty 408W drew
power in 0-14 samples of the last 50 m before and 0-8 after, no overruns
either way. It surfaced once the AI predicted the ESt3 brake closer to
what the valve delivers, where the same train crept to 12 km/h from 40 m
out and overran the signal; with this change it stopped short in all runs.
2026-11-02 16:02:06 +01:00
jerrrrycho
d995674bee fix(physics): automatic couplers don't catch above the safe collision… (#217)
* fix: automatic coupler crashes, horns, compressor start delay, radio and cab lever sounds

fix(cab): the line contactors lamp goes out with the pressure switch (eu07/maszyna#470)

The lamp of the open line contactors, which tells the start can be made, went out at 1 bar in the brake
cylinders, while the pressure switch cuts the start off only at 2 bar (or below 3.6 bar in the main pipe), so
with the brakes partly applied the start could be made with the lamp out. With a pressure switch fitted the lamp
now follows it; without one it goes out at 1 bar as before. The same holds for the lamp of the second unit, which
used to keep its last state between 1 bar and the cut-off. The condition is
TMoverParameters::LineContactorsLampLit().

Tests: tests/unit/test_line_contactors.cpp.

refactor: Sonar findings of PR 217

- horn_supply::pneumatic shadowed the pneumatic enumerator of the sound flags (cpp:S1117), it's horn_supply::air;
  the supplies read with using enum (S6177),
- CouplerForce(): the automatic coupling refused or caught without another level of nested ifs (S134), the
  same outcome: too fast, the coupling is locked; caught, coupled and locked; otherwise left to try again,
- CompressorCheck(): the power the compressor doesn't draw yet noted without a TODO (S1135),
- tests: the previous crash damage setting in an in-class initializer (S3230), the loops which stop early with
  break rather than in their conditions (S886), the stand-ins of test::pair in a std::vector rather than an array
  (S5945), units in the comments of the example without /* */ (S1103).

test: the cases the changes of the branch left without a test

- Cntrl.: BDelay1 to BDelay4 reach the brake delays (now through std::format), the default start types of the
  ground and converter overload relays of a multiple unit and of other vehicles (out of the nested conditionals),
- the compressor: fed from the low voltage it waits from the low voltage coming on; the pressure switch stops it
  above the cut-out pressure, without one the excess air is vented (the vented fraction rewritten),
- the horns: a vehicle without any air sounds as before, the threshold pressure, an electric horn on 110 V,
- the positions of a cab control below zero, and a control without position sounds.

refactor(cab): the kind of the train heating switch as a flag

Read once with the vehicle definition, rather than compared as text in each of the switch commands.

feat(cab): train heating switch springing back (MaSzyna-EU07/maszyna#85)

TrainHeating=[toggle]|impulse in the Switches: section of the vehicle definition makes the train heating switch
an unstable one: it goes up to switch the heating on, down to switch it off, and back to the middle once let go,
instead of staying where it was put. The position of such a switch isn't set from the heating state when the cab
is entered.

Tests: tests/unit/test_switches.cpp.

feat(sound): mirror sounds (MaSzyna-EU07/maszyna#84, eu07/maszyna#322)

The sound definitions of a vehicle (.mmd) take mirroropen: and mirrorclose:, played as a mirror sets off
unfolding or folding, and the locations section mirrors: <offset>... end, the offsets along the vehicle of the
mirror pairs, as for the doors (negative ahead of the centre), each pair at the sides of the vehicle. As the
animation, only the mirrors at the occupied cab sound. The start of a move is mirror_moves::motion in
vehicle/mirrors.h.

Tests: tests/unit/test_mirrors.cpp.

feat(cab): joint oil and fuel pump switch (MaSzyna-EU07/maszyna#81)

A cab control oilfuelpump_sw: switches both the oil and the fuel pump at once, with the new command
oilfuelpumptoggle (no key by default). As a two-state switch it turns both pumps off when both are on and both on
otherwise; as an impulse switch it's held to start them, like the separate pump switches. Its position follows
the pumps when the cab is entered.

refactor(editor): text fields filled without strncpy (MaSzyna-EU07/maszyna#112)

The last three strncpy calls Sonar flags (cpp:S5816), in the road and track editors, copy the text into the
ImGui field buffers with std::string::copy and terminate it right after; the text gets cut to the buffer as
before.

fix: automatic coupler crashes, horns, compressor start delay, radio and cab lever sounds

- automatic couplers don't catch above the safe collision speed (#86): with crash damage on they couple at a
  closing speed of 15 km/h at most, a faster hit locks the coupling until the vehicles part and the collision
  runs its course. On the way: CollisionVelocity() read a head-on 10 + 10 km/h as 14.1 km/h (quaternions turn
  by half the angle), it's now taken from the touching ends; CollisionDetect() took the other vehicle's speed
  the wrong way round for vehicles facing each other. Head-on hits now derail sooner, at the intended limit,
- a single horn lever can't sound both tones at once (eu07/maszyna#392),
- a skid ends once the vehicle stops on locked wheels (eu07/maszyna#479),
- electronic destination signs are blanked at the end of the timetable (eu07/maszyna#446),
- horns need the air or the voltage to sound (eu07/maszyna#290, #76): HornType=[Pneumatic]|Electric and
  Horn3Type in Cntrl.; a pneumatic horn needs 0.2 MPa in the main reservoir (or the main pipe without one),
  an electric one the low voltage; the lever stays where it was put,
- compressor start delay (#67): CompressorStartDelay [s] in Brake., counted from the compressor getting its
  power, after the engine starts say; none by default,
- the channel and volume buttons of a radio without power do nothing (eu07/maszyna#429); the power check of
  the radio is TMoverParameters::RadioPowered(),
- a lever moved smoothly sounds the positions it passes (#83).

Sonar findings in the functions changed: nesting, nested conditionals, commented-out code, std::format,
references to const. Unit tests: test::pair for two vehicles running into each other, test_couplers,
test_horn, test_wheelslip, test_compressor, test_radio, test_gauge_positions.

* fix: review findings of PR 217

- the pressures of the mover are in bar (MinCP=7.0 in the vehicle definitions), so the 0.2 the pneumatic horns
  needed was 0.2 bar; it's 2 bar now, and the tests take their pressures in bar too,
- the lamps of the ground relay and of the motor overload relays follow the pressure switch as the line
  contactors one does, TMoverParameters::MainCircuitLampsEnabled(), so the lamps of one cab go out together,
- the joint oil and fuel pump switch leaves out a pump started automatically, which ignores the switching:
  with one, it couldn't turn the other off, and showed off with both running (OilFuelPumpsEnabled()),
- the kind of the train heating switch comes from the occupied vehicle on entering the cab too, as in the
  switch commands; in a multiple unit these are different vehicles,
- CouplerForce() put the force taken back by the other vehicle on its far coupler when the vehicles faced each
  other (Couplers[1 - End] rather than the coupler it's coupled with),
- the velocity difference along the coupler axis computed once, CouplerVelocityDifference(), for CouplerForce()
  and CollisionVelocity(),
- the attachcoupler flag added without the SetFlag() call with 0, the index of the mirror moves noted as by side.

Tests: the coupler force of vehicles facing each other, the joint switch with an automatic pump, the lamps of
the main circuit, the horn and compressor pressures in bar.

* fix: coupler force of vehicles facing each other taken back along the other vehicle's axis

CForce runs along the axis of its own vehicle, so the force the other vehicle takes back on its coupler of the pair
is turned around once more when the vehicles face each other (-CF * DirPatch()), as that vehicle computes it itself.

Tests: the coupler forces of the pair facing each other and facing the same way.
2026-11-01 09:12:36 +01:00
pwarszawski
8112733e0d Merge remote-tracking branch 'origin/master' into fix187
# Conflicts:
#	McZapkie/Oerlikon_ESt.h
#	McZapkie/hamulce.h
2026-10-22 07:08:29 +02:00
40a4267bd3 Merge pull request #189 from pwarszawski/fix/ai-ready-released-brakes
AI: don't cut the power for a brake already released below 0.4 bar
2026-10-21 09:00:34 +02:00
jerrrrycho
c7f9796387 fix(ai): release horn when human driver takes over from AI (#210)
* fix(ai): release what the AI was holding when the player takes over

* fix(ai): keep the light selector lookup within its table, Sonar findings of the handover

- the light selector size comes from the vehicle definition (LightsList Size)
  and isn't limited, while the table holds 18 positions; a bigger selector
  read past the table, and so did a table index other than the front or
  rear one. Only the positions the table holds are looked at now, and the
  selector stays where it is for a bad table index (cpp:S2259),
- the lambdas of the handover capture what they use explicitly (cpp:S3608),
- the chained assignments resetting the headlight state on the AI taking
  over are split (cpp:S1121).
2026-10-16 14:44:30 +02:00
pwarszawski
71a19f32fb Compare the brake force with 10 kN directly 2026-10-12 06:54:17 +02:00
pwarszawski
504d69b26a AI braking: keep braking for a lower speed inside the proximity range
Inside the proximity range only a stop had a final approach of its own;
for a lower speed ahead that branch set nothing, so AccDesired stayed at
the preferred acceleration. With the range at 50 m, which this PR uses so
that trains stop 8-15 m short of a signal, the AI stopped braking within
the last 50 m before a speed restriction and even took power: EMUs reached
a 20 km/h restriction at 25 km/h. On master the range is 15-40 m, which
kept this mostly out of sight.

A lower speed ahead now keeps the braking curve right up to where it
begins. Stops are unchanged.

Measured in real time on current master (with #199), with a 20 km/h
restriction one coach long, two runs of 32 consists each: over 22 km/h in
the restriction on the flat 9 on master, 15 before this change, 1 after
(a 36WEa at 22.1 km/h); on the 20 per mille descent 15, 0 and 0. Stops
8-15 m short of the signal stay as they were (flat 57 and 55 of 64,
descent 44 and 42), no overruns.
2026-10-10 23:39:19 +02:00
c26041f2e7 Merge pull request #199 from MaSzyna-EU07/brake-diag
AI - prevent overcharge when pipe pressure of car is too high for too long
2026-10-10 20:37:12 +02:00
9935257783 Add nosonar tags 2026-10-09 18:40:31 +02:00
917c8f7285 Merge branch 'master' into feat/modern-editor 2026-10-08 17:44:58 +02:00
maj00r
4e406fdd86 fix(ai): end brake charging on control reservoir overcharge, charge on blocked departures
- end the charging position when the control reservoir of any vehicle, the
  locomotive included, rises 0.05 bar above the nominal pipe pressure
- standing and unable to depart for 10 s: allow the charging position
  regardless of the equivalent pipe pressure and the train type
2026-10-07 18:17:59 +02:00
jerrrrycho
79bd0c8e91 fix(sonar): addressing reliability/security issues (#202) 2026-10-04 20:00:13 +02:00