18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00
Commit Graph

12 Commits

Author SHA1 Message Date
jerrrrycho a81d149541 feat: a memory cell of its own for the derailment of a vehicle
report_derailment() writes the memory cell at once and only queues the
events, which run later in Events.update(). A collision derails both
vehicles in one frame, so when <A>:derailed ran, __simulation.derailment
already held B. The scenery can now declare the memory cell
<vehicle>:derailed, written the same way and with the same three fields
as __simulation.derailment, for the events of that one vehicle to read.

Documented that __simulation.derailment keeps only the last derailment
of a frame; eu07_td_off_track_end_scenery_told checks the cell of the
locomotive now.
2026-11-30 00:15:50 +01:00
jerrrrycho 61aaaa7c62 Merge staging into feat/derailment-event
# Conflicts:
#	physics/derailment.cpp
#	physics/derailment.h
#	tests/scenarios/README.md
#	tests/unit/test_derailment.cpp
2026-11-30 00:12:29 +01:00
jerrrrycho c1d1f1aead Merge staging into feat/derailment-event
# Conflicts:
#	McZapkie/Mover.cpp
#	vehicle/DynObj.cpp
2026-11-29 14:57:22 +01:00
jerrrrycho 1e825cb596 Merge staging into feat/derailment-trust-limits
# Conflicts:
#	McZapkie/Mover.cpp
2026-11-29 14:56:21 +01:00
jerrrrycho d6dba363e3 feat(derailment): a derailment is told to the scenery, the black box and the test mode
Every way a vehicle leaves the rails records what derailed it and its speed in the mover
(DerailedBy, DerailVelocity), by any physics.derailment model and the collisions. After all
vehicles moved, TDynamicObject::new_derailment() notices each derailment once, and
state_manager::report_derailment() tells:

- the log: "derailment: <vehicle> derailed (<cause>) on track <track> at <speed> km/h";
- a scenery that asked for it: its memory cell __simulation.derailment gets
  "<vehicle> <cause> <track>", the speed and the code of the cause, then its events
  __simulation.derailment and <vehicle>:derailed run with the vehicle as activator. Nothing
  is made at the start, so a scenery without them runs as before (no draw of the random
  numbers for a new node);
- the black box: a derailment record with the new phase 2, for any model, and every
  derailment record gets the finer cause and the track at its end;
- the test mode: test.fail_on_derailment yes (default no) ends the run of a tested train
  that derailed with the new result derailment, exit code 15; otherwise the verdict line
  ends with " [derailed: ...]".

run.py knows exit code 15 and shows the derailment of the train under test in the summary.
New cases eu07_td_buckle_derails_ends_test and eu07_td_off_track_end_scenery_told; the other
83 end as before and their physics logs are byte-identical to staging.
2026-11-29 05:29:37 +01:00
jerrrrycho 096e60ff38 feat(derailment): trust the speed limit of the track (physics.derailment.trustlimits)
With physics.derailment new, a verdict the curve and the cant alone give
(the criterion holds for the vehicle without its coupler forces, on the
track without a buckle, damage flags or unevenness) is held back while
the vehicle runs under the trusted speed of the track: its speed limit
times 1.1 plus 5 km/h. The log names the track once as a defect of the
scenery ("derailment monitor: data: ..."). Over the trusted speed, on a
track without a limit, and for whatever the couplings, a buckle or the
damage of the track bring about, the verdict goes as before.

physics.derailment.trustlimits yes|no, default yes; no is the behaviour
before. The decision is a set of pure functions in McZapkie/derailment
(trusted_speed, from_track_alone, limited_verdict, held_back_report);
check_derailment only calls them.

The 144 tracks physics.trackcheck finds with limits their curves don't
take (backlog L4) no longer derail trains that keep to them, so the
default of physics.derailment can be decided apart from the data fixes.

Tests: unit tests of the decision and of a vehicle on a curve with a bad
limit; scenario cases eu07_td_overspeed_bad_limit (140 km/h, held on),
_fast (175 km/h, overturns) and _untrusted (trustlimits no, overturns).
2026-11-29 03:26:32 +01:00
Hirek 5a537e69f2 refactor(physics): McZapkie/ becomes physics/, its files get English names
The folder of the vehicle physics was named after the author of its first
version (2001). Its name now says what it holds, and so do its files:

  McZapkie/MOVER.h, Mover.cpp       -> physics/mover.h, mover.cpp
  McZapkie/hamulce.h, hamulce.cpp   -> physics/brakes.h, brakes.cpp
  McZapkie/Oerlikon_ESt.h, .cpp     -> physics/oerlikonest.h, .cpp
  friction, collision, couplerphysics, derailment: same names in physics/

Every include names the folder ("physics/mover.h"); the McZapkie include
directory is gone from CMakeLists.txt. The comments and documents that
named the old paths name the new ones. The credits to McZapkie stay.

Renames only: git sees every file as renamed (98-100%). 1142/1142 tests,
golden traces exact against staging 62f7a29b.
2026-11-27 17:11:46 +01:00
jerrrrycho 0074197c1d feat(physics): physics.trackcheck logs the tracks of a scenery the criteria of derailment find suspicious
With physics.trackcheck yes (no by default) every rail track is checked once the scenery loaded, and the suspicious
ones are logged, a line for each (trackcheck:), with a summary of the count of each kind: a speed limit over the speed
a reference vehicle overturns or climbs the rail at in the curve (an EU07 and a 4-axle coach from the defaults of
derailment.h, no .fiz needed; a track without a limit of its own gets 125 km/h and is counted apart), cant held on a
straight track, cant over 160 mm, a curve under 40 m with a limit over 40 km/h, and unevenness out of the plausible
range. The damage flags are only counted by their value: the sceneries set them for the jolts. The radius is the
tightest of the design geometry of the path, so curves given by their control points only count as well.

The check is a plain function of the data of the tracks with a log sink (world/TrackCheck.h, in eu07_core), tested on
its own; derailment::climbing_speed() gives the speed the flange climbs at, none where it doesn't.
2026-11-15 20:11:11 +01:00
jerrrrycho c83c987e3f feat(physics): physics.derailment monitor tells what the criteria would do, the legacy draw decides
With monitor the run goes as with old: the legacy draw derails a vehicle too fast in a curve, with the legacy effects.
The criteria of derailment.h are evaluated as with new, and where they would derail a vehicle the log gets one line
(derailment monitor:) with the data of the entry of a real derailment: the vehicle, the track, the speed, the radius,
the cant, the lateral acceleration, D, Y/Q, the mass, the centre of gravity, the forces of the couplings, the damage
flags and the cross level. Once for a vehicle on a track, so one run of a scenery shows what new would do without
changing its course.

The entry of a derailment by the criteria names the track as well; derailment::report() writes both. The names of the
models in eu07.ini go through derailment_model_of() and name_of(), read and written back alike.
2026-11-15 20:11:10 +01:00
jerrrrycho 6111773f53 test(physics): count the steps of the derailment tests in integers, read the distances checked
SonarCloud: a float loop counter (S2193) and the optional read after REQUIRE taken for a garbage value (S836).
2026-11-15 18:57:04 +01:00
jerrrrycho f1dd033f24 feat(physics): the damage flags of a track make the ride rougher, a derailed vehicle once stopped stays put
Found running line 107 with every train driven by the AI:

- a 401Ka wagon of a freight train overturned into a 282 m curve with a
  cant of 179 mm at 28 km/h: line 107 has damage 31 on every track, which
  scaled the whole lateral acceleration by 2.1, the cant too. The sceneries
  set the flags for the jolts of a worn track (thousands of tracks with 2,
  31, 4 or 16), so they now scale only the sway of the body and the short
  waves of the uneven track, and no longer take load off the wheels; the
  cross level of the uneven track still does
- the overturned wagon crept and stopped in turn in every step (the friction
  of the ballast against the pull of its train), which kept the physics of
  the whole train awake: the run went at half the speed after it. The
  friction now holds a stopped derailed vehicle until the forces on it are
  larger
- a vehicle without a mass got Y/Q 1e9 (no wheel load), now none
- the log of a derailment tells the mass, the centre of gravity, the forces
  of the couplings, the damage flags and the cross level as well
2026-11-15 11:40:56 +01:00
jerrrrycho 3360988144 feat(physics): criteria of derailment: overturning and flange climbing held over 2 m
McZapkie/derailment.{h,cpp} in eu07_core: plain functions of the vehicle and
the track under it, for the speed in a curve now and the collisions and the
buckled track later.

- overturning: the wheel unloading D = 2/s * a/g * (h + s0 (h - hc)) of the
  lateral acceleration the cant doesn't balance, v^2/R - g sin(cant), with the
  lean of the body on its suspension (s0 0.4, hc 0.5 m of the kinematic gauge),
  a lateral vibration of 0.05 g and the uneven track; over at D = 1
- flange climbing: Y/Q of the flanging wheel over 1.2 (Nadal, 70 degrees,
  friction 0.36). Y from the force the cant doesn't balance, the sideways part
  of the forces of the couplings in the curve and the guiding force of the
  leading axle; Q with the load the lateral forces move onto the wheel and the
  twist of the track takes off it
- either has to hold over 2 m of track (the window of EN 14363), so the
  decision doesn't depend on the step
- the centre of gravity of a vehicle from the height of its body, raised by
  the load; the friction of a vehicle sliding off the rails
2026-11-15 10:28:06 +01:00