18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

fix(timetable): the station of departure written in capitals is still a stop (#343)

The first row of a timetable, which usually gives only the departure time,
became a stop only when its name matched the relation's first station
case-sensitively. Os33733 of linia_107_poludnie.scn writes ZAGORZ in the rows
and Zagorz in the relation, so its driver counted Zagorz as passed at the
start, left before its departure time and the train manager never gave the
departure signal. The names are now compared regardless of case
(timetable::starts_at in the core library).

Tests: unit test of the rule; td.scn scenario cases with a timetable of the
case's own (first row STACJA1, and Stacja1 as control) and the td.scn train
started with its head 80 m past the W4 of Stacja1; the scenario runner can
copy a timetable of the case into the game for the run.
This commit is contained in:
jerrrrycho
2026-11-20 16:35:59 +01:00
committed by GitHub
parent 8bff785886
commit 2f12768815
14 changed files with 277 additions and 6 deletions

View File

@@ -575,6 +575,7 @@ set(CORE_SOURCES
"vehicle/linebreaker.cpp"
"vehicle/smoke.cpp"
"vehicle/odometer.cpp"
"world/timetablestart.cpp"
"vehicle/timetableservice.cpp"
"world/timetableflags.cpp"
"world/timetablereader.cpp"

View File

@@ -135,7 +135,7 @@ Python 3.10+, no extra packages. Options:
`cmake-build-*/bin/Release/eu07*.exe`. The build needs the `--test` and `-ini` command
line options.
- name one or more cases to run only those, e.g. `run.py ... eu07_td_timetable`.
- `-j N` runs N cases at once. Each case prints its results when it is done. The 19 cases
- `-j N` runs N cases at once. Each case prints its results when it is done. The 22 cases
that aren't `slow` take about 30 s with `-j 4` and 2 minutes one at a time, loading included.
- `--watch` runs a case the old way, in a visible window in real time (or faster with
`--timespeed N`), closed after the case's `duration`; the exit code isn't checked then. For
@@ -214,6 +214,7 @@ to `logs/`.
| `ini` | extra `eu07.ini` lines for the run, after the common ones of the runner's `-ini` file, e.g. `["crashdamage yes"]` |
| `fragment` | `.scn` file in `cases/` added to the scenery: trainsets after `FirstInit` (before it they derail on unlinked track), the rest before it (launchers read after it never fire). Optional when the case keeps the scenery's trainsets |
| `vars` | values for `{{name}}` in the fragment; a list becomes one line per item |
| `timetable` | a timetable file in `cases/` for a trainset of the fragment, for a train whose timetable no scenery of the game has: copied to the game's `scenery/` dir as `autotest_<case>.txt` for the run and removed after it; the fragment names it `{{timetable}}` |
| `expect` | the result the test mode should end with: `pass`, `fail`, `signal_passed_at_danger`, `timeout`, `standstill` or `error`, or `wall_timeout` for the timeout of the real time watchdog (the timeout code with a verdict saying it was the real time; a case expecting `timeout` fails on it). Default `timeout` for a case with `duration`, else `pass` |
| `duration` | seconds of simulation to record: the test timeout of the run (`--test-timeout`) |
| `timeout` | wall-clock seconds before giving up, loading included: the simulator's `--test-wall-timeout` (default 600) |
@@ -236,6 +237,18 @@ and slides past the signal, so those cases set `test.fail_if_stop_overran no`.
`td_red_signal_pass.scn` adds the `test_pass` event, which `test_mode_pass` puts as `event0`
on `tor1k`, the track in front of the signal.
`eu07_td_departure_station_capitals` runs an EU07 from where `td_timetable.scn` puts it, with the W4 of Stacja1 about
35 m ahead, on a timetable of its own (`td_departure_station_capitals.txt`, fragment `td_departure_station.scn`):
its first row, the station of departure, gives no arrival time and is written in capitals (`STACJA1`), the relation
says `Stacja1`, as in some timetables of the game (`Os33733` of linia_107_poludnie.scn starts at `ZAGORZ`). The
train has to stop there and leave at its departure time, 10:35, which the log shows as `as TEST24: at 10:35 next
Przystanek`; taking Stacja1 for a station it passes through, the driver logs `passed STACJA1` at once and leaves as
soon as the route is set at 10:34, and the train manager gives no departure signal. `eu07_td_departure_station` is the
same with the row written as in the relation. `eu07_td_timetable_past_w4` (fragment `td_timetable_past_w4.scn`) puts
the td/rozklad train, an EU07 with three coaches, with its head 80 m past the W4 of Stacja1, on `tor1k`: the W4 stays
under the consist, behind the head, and the driver still counts Stacja1 and leaves at 10:35, since the scan of the
route begins at the last vehicle and keeps a W4 behind the head.
The `test_mode_*` cases show the ends of the test mode: `test_mode_pass` (exit 0, the pass
event), `test_mode_signal_passed_at_danger` (exit 11), `test_mode_timeout` (exit 12, from
`test.timeout`), `test_mode_standstill` (exit 13, from `test.standstill`) and

View File

@@ -0,0 +1,35 @@
{
"description": "Control for eu07_td_departure_station_capitals: the same timetable with the first row written as in the relation (Stacja1). The train stops at Stacja1 and leaves at 10:35.",
"base_scenery": "td.scn",
"time": "10:33",
"fragment": "td_departure_station.scn",
"timetable": "td_departure_station.txt",
"vars": {
"consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic"
},
"duration": 360,
"timeout": 600,
"checks": [
{
"type": "log_lacks",
"pattern": "as TEST25: at \\d+:\\d+ passed Stacja1"
},
{
"type": "log_contains",
"pattern": "as TEST25: at 10:35 next Przystanek"
},
{
"type": "starts",
"min_speed": 20,
"within": 240
},
{
"type": "stops",
"moving_speed": 20,
"stop_speed": 1.0,
"hold": 0,
"min_distance": 1380,
"max_distance": 1420
}
]
}

View File

@@ -0,0 +1,35 @@
{
"description": "EU07 on td.scn on a timetable whose first row, the station of departure, is written in capitals (STACJA1) and gives no arrival time, while the relation says Stacja1. The train is to stop there and wait for its departure at 10:35, not take Stacja1 for a station it passes through and leave as soon as the route is set at 10:34 (linia_107_poludnie.scn, Os33733 at ZAGORZ).",
"base_scenery": "td.scn",
"time": "10:33",
"fragment": "td_departure_station.scn",
"timetable": "td_departure_station_capitals.txt",
"vars": {
"consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic"
},
"duration": 360,
"timeout": 600,
"checks": [
{
"type": "log_lacks",
"pattern": "as TEST24: at \\d+:\\d+ passed STACJA1"
},
{
"type": "log_contains",
"pattern": "as TEST24: at 10:35 next Przystanek"
},
{
"type": "starts",
"min_speed": 20,
"within": 240
},
{
"type": "stops",
"moving_speed": 20,
"stop_speed": 1.0,
"hold": 0,
"min_distance": 1380,
"max_distance": 1420
}
]
}

View File

@@ -0,0 +1,28 @@
{
"description": "EU07 with three coaches on td.scn on the td/rozklad timetable, placed with its head 80 m past the W4 of Stacja1, the first station of the timetable, which stays under the consist. The driver counts Stacja1 as the stop it stands at and leaves at 10:35.",
"base_scenery": "td.scn",
"time": "10:34",
"fragment": "td_timetable_past_w4.scn",
"vars": {
"offset": 15,
"consist": [
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic"
]
},
"duration": 300,
"timeout": 600,
"checks": [
{
"type": "log_contains",
"pattern": "as ROJ65113: at 10:35 next Przystanek"
},
{
"type": "starts",
"min_speed": 20,
"within": 240
}
]
}

View File

@@ -0,0 +1,9 @@
// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed.
// the same start as td_timetable.scn, the W4 of Stacja1 about 35 m ahead of the train, but on the case's own
// timetable: {{timetable}}, a copy of the case's "timetable" file, Stacja1 10:35 -> Przystanek -> Stacja2 whose
// first row gives no arrival time, only the departure. the route out of track 1 is set at 10:34
trainset {{timetable}} tdo_n1734 0.0 0.1
{{consist}}
endtrainset
node -1 0 autotest_route eventlauncher 0 0 0 -1 none 1034 keyctrl04 end

View File

@@ -0,0 +1,20 @@
________________________________________________________________
[ Rodzaj i numer pociagu | TEST25 ]
[ Kategoria | RO ]
[________________________________________________|______________]
[ | Stacja1 ]
[ Relacja pociagu | Stacja2 ]
[________________________________________________|______________]
[ Wymagany % ciezaru hamujacego | 88% ]
[________________________________________________|______________]
[ Seria i obciazenie lokomotywy | EU07 210 ]
[________________________________________________|______________]
[ | | Stacja1 2 | | ]
[ | 60 | R1,L,H,RT,PP 2 10.35 | ]
[ | |----------------------------------1----------|---]
[ | | Przystanek 1 10.37 | 4 ]
[ |_____| R1,+,L,H,PP,pt 1 10.37.3 | ]
[ | 90 |----------------------------------1----------|---]
[ | | Stacja2 1 10.39 | 1 ]
[ | | R1 1 10.40 | ]
[_______|_____|__________________________________1__________|___]

View File

@@ -0,0 +1,20 @@
________________________________________________________________
[ Rodzaj i numer pociagu | TEST24 ]
[ Kategoria | RO ]
[________________________________________________|______________]
[ | Stacja1 ]
[ Relacja pociagu | Stacja2 ]
[________________________________________________|______________]
[ Wymagany % ciezaru hamujacego | 88% ]
[________________________________________________|______________]
[ Seria i obciazenie lokomotywy | EU07 210 ]
[________________________________________________|______________]
[ | | STACJA1 2 | | ]
[ | 60 | R1,L,H,RT,PP 2 10.35 | ]
[ | |----------------------------------1----------|---]
[ | | Przystanek 1 10.37 | 4 ]
[ |_____| R1,+,L,H,PP,pt 1 10.37.3 | ]
[ | 90 |----------------------------------1----------|---]
[ | | Stacja2 1 10.39 | 1 ]
[ | | R1 1 10.40 | ]
[_______|_____|__________________________________1__________|___]

View File

@@ -0,0 +1,9 @@
// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed.
// the timetable train of td.scn (td/rozklad, Stacja1 10:35 -> Przystanek -> Stacja2) placed past the W4 of
// Stacja1 instead of before it: the head {{offset}} m into tor1k, the track after the one with the W4, which is
// left under the consist, behind the head. the route out of track 1 is set at 10:34
trainset td/rozklad tor1k {{offset}} 0.1
{{consist}}
endtrainset
node -1 0 autotest_route eventlauncher 0 0 0 -1 none 1034 keyctrl04 end

View File

@@ -146,6 +146,15 @@ def scenery_cache(game_dir: Path, case_name: str) -> Path:
return game_dir / "scenery" / f"autotest_{case_name}.sbt"
def timetable_name(case_name: str) -> str:
"""The case's own timetable as a trainset names it: {{timetable}} in the fragment."""
return f"autotest_{case_name}"
def timetable_path(game_dir: Path, case_name: str) -> Path:
return game_dir / "scenery" / f"{timetable_name(case_name)}.txt"
def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> str:
"""Writes the case scenery into the game's scenery dir and returns its file name."""
scenery_dir = game_dir / "scenery"
@@ -165,9 +174,9 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s
text = text.replace(old, new)
# a case on a mission of the base scenery may have nothing to add but its test_config
fragment = (CASES_DIR / case["fragment"]).read_bytes().decode("latin-1") if "fragment" in case else ""
# vars first: {{vehicle}} inside a var's value gets filled in the second pass
fragment = fill_vars(fragment, case.get("vars", {}), keep={"vehicle"})
fragment = fill_vars(fragment, {"vehicle": vehicle})
# vars first: {{vehicle}} and {{timetable}} inside a var's value get filled in the second pass
fragment = fill_vars(fragment, case.get("vars", {}), keep={"vehicle", "timetable"})
fragment = fill_vars(fragment, {"vehicle": vehicle, "timetable": timetable_name(case_name)})
# FirstInit binds event launchers to their events and links the tracks. so launchers and
# events of the case go in before it (read after it they never fire), trainsets after it
# (placed before it they stand on unlinked track and derail at once)
@@ -185,6 +194,9 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s
text += header + trainsets + "\n"
name = f"autotest_{case_name}.scn"
(scenery_dir / name).write_bytes(text.encode("latin-1"))
# a timetable of the case's own, for a train whose timetable the sceneries of the game have none like
if "timetable" in case:
shutil.copyfile(CASES_DIR / case["timetable"], timetable_path(game_dir, case_name))
# the simulator caches the scenery's static geometry in <name>.sbt and reads it instead of
# the terrain in the .scn (tracks, events and trainsets always come from the .scn), so
# drop the cache once the base scenery has changed
@@ -838,6 +850,7 @@ def _run_case(name: str, case: dict, exe: Path, game_dir: Path, timespeed: float
result = run_simulator(exe, game_dir, scenery, ini, physicslog,
duration, float(case.get("timeout", 600)), watch, say,
expect_rows=with_physicslog and not own_vehicle)
timetable_path(game_dir, name).unlink(missing_ok=True)
# a case that asked for no geometry cache (file.binary.terrain no) leaves none of an earlier run behind
if any(line.split()[:2] == ["file.binary.terrain", "no"] for line in case.get("ini", [])):
scenery_cache(game_dir, name).unlink(missing_ok=True)

View File

@@ -0,0 +1,39 @@
#include "stdafx.h"
#include "doctest.h"
#include "world/timetablestart.h"
// the first row of a timetable is the station of departure, a stop the train waits at for its departure time,
// when it names the station the relation starts at. the loader then takes the departure time for the arrival
// one, which the row usually leaves out; a row without an arrival time is otherwise a station passed through
TEST_CASE("timetable: the first row naming the station of the relation is the station of departure") {
CHECK(timetable::starts_at("Stacja1", "Stacja1"));
CHECK(timetable::starts_at("Zagorz", "Zagorz"));
}
TEST_CASE("timetable: the station of departure written in capitals in the rows is still the one of the relation") {
// linia_107_poludnie.scn, Os33733: ZAGORZ in the rows, Zagorz in the relation (both with the polish letters
// stripped by the loader). taken for a station passed through, the AI left before its departure time and the
// train manager never gave the departure signal
CHECK(timetable::starts_at("ZAGORZ", "Zagorz"));
CHECK(timetable::starts_at("LEOSIN", "Leosin"));
CHECK(timetable::starts_at("Warszawa_Wschodnia", "WARSZAWA_WSCHODNIA"));
}
TEST_CASE("timetable: a first row naming another station is not the station of departure") {
// a timetable which starts on the way, at a station the train passes through
CHECK_FALSE(timetable::starts_at("Tarnawa_Dolna", "Zagorz"));
CHECK_FALSE(timetable::starts_at("Nowy_Zagorz", "Zagorz"));
CHECK_FALSE(timetable::starts_at("Zagorz", "Nowy_Zagorz"));
// a name which only begins like the other one
CHECK_FALSE(timetable::starts_at("Zagorz_Towarowy", "Zagorz"));
CHECK_FALSE(timetable::starts_at("Zagorz", "Zagorz_Towarowy"));
}
TEST_CASE("timetable: the station names are compared as a whole, letters and the rest") {
CHECK_FALSE(timetable::starts_at("Stacja1", "Stacja2"));
CHECK_FALSE(timetable::starts_at("Stacja_1", "Stacja-1"));
CHECK_FALSE(timetable::starts_at("Stacja1", ""));
CHECK_FALSE(timetable::starts_at("", "Stacja1"));
}

View File

@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "world/mtable.h"
#include "world/timetablestart.h"
#include "utilities/Globals.h"
#include "simulation/simulationtime.h"
#include "utilities/dictionary.h"
@@ -355,8 +356,8 @@ bool TTrainParameters::LoadTTfile(std::string const &scnpath, int iPlus, double
}
}
}
// jeśli nazwa pierwszego zgodna z relacją
if (conversionerror == 0 && TimeTable[1].StationName == Relation1 && TimeTable[1].Ah < 0) // a nie podany czas przyjazdu
// jeśli nazwa pierwszego zgodna z relacją (bez względu na wielkość liter)
if (conversionerror == 0 && timetable::starts_at( TimeTable[1].StationName, Relation1 ) && TimeTable[1].Ah < 0) // a nie podany czas przyjazdu
{ // to mamy zatrzymanie na pierwszym, a nie przelot
TimeTable[1].Ah = TimeTable[1].Dh;
TimeTable[1].Am = TimeTable[1].Dm;

25
world/timetablestart.cpp Normal file
View File

@@ -0,0 +1,25 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "world/timetablestart.h"
#include <algorithm>
#include <cctype>
namespace timetable {
bool starts_at(std::string_view const Firststation, std::string_view const Relationfrom) {
// the station names are plain ascii by now, the timetable loader strips the polish letters
return std::ranges::equal(Firststation, Relationfrom, [](char const Left, char const Right) {
return std::tolower(static_cast<unsigned char>(Left)) == std::tolower(static_cast<unsigned char>(Right));
});
}
} // namespace timetable

23
world/timetablestart.h Normal file
View File

@@ -0,0 +1,23 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string_view>
// the first row of a timetable
namespace timetable {
// whether the first row of a timetable is the station the train sets off from: it names the station
// the relation starts at. such a row is a stop even with no arrival time given, the train waits there
// for its departure time. the names are compared regardless of case, as the timetables write the
// station of departure in capitals as often as not (ZAGORZ in the rows, Zagorz in the relation)
bool starts_at(std::string_view Firststation, std::string_view Relationfrom);
} // namespace timetable