18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-29 01:24:37 +01:00

feat(timetable): station names keep their polish letters, a W4 finds its station by one key

MaSzyna-EU07/maszyna#94. The timetable reader and the W4 event (putvalues PassengerStopPoint:<station>) threw
the polish letters of a name away as they read it. Now:

- the reader keeps the name as the file spells it in TMTableEntry::StationLabel and
  timetable_data::RelationLabel1/2 (TTrainParameters::RelationLabel1/2), for showing; StationName and
  Relation1/2 hold the ascii form as before, byte for byte, so the announcement files, the destination
  boards, the memory cells written by WhoIs events, the python dictionary, the log and the black box get
  what they always got
- the W4 event keeps its text as the scenery spells it (a scenery saved by the editor no longer loses the
  letters of its W4 events); the black box map still gets the ascii form
- world/stationnames.h has the one place which tells whether a W4 is for a station:
  timetable::stop_point_is_for(), used by TController::TableUpdateStopPoint() and
  TTrainParameters::RewindTimeTable(). It compares keys (ascii form, lower case, spaces as underscores), so
  the timetable and the W4 may each spell the station with or without the letters
- TTrainParameters::relation_caption() / station_caption() and TController::NextStop() give the names for
  the player: with the letters, in utf-8

The folding stays in the matching because the game data needs it: in 36 scenario x station pairs of the
Steam install (6 of the SVN) the timetable and the W4 spell the station differently (BALTYK_GLOWNY in
capitals against Baltyk_Glowny, Rzepedz with one of its two marks, Lupkow without them), and no
announcement file has a letter outside of ascii in its name.

Every W4 which matched a station still does. New matches, none of them in the game data: a memory cell
text spelled with polish letters, a space where the timetable has an underscore, a name longer than the 32
characters (sizeof(std::string)) the old comparison took. A memory cell text with a # part is still
compared whole.

win1250_to_ascii() builds its map once: the comparison runs it for every stop point a driver scans.
This commit is contained in:
jerrrrycho
2026-11-18 23:50:07 +01:00
parent c0a0a4204e
commit 022e59fde3
13 changed files with 459 additions and 23 deletions

View File

@@ -565,6 +565,7 @@ set(CORE_SOURCES
"vehicle/timetableservice.cpp"
"world/timetableflags.cpp"
"world/timetablereader.cpp"
"world/stationnames.cpp"
)
add_library(eu07_core STATIC ${CORE_SOURCES})
target_link_libraries(eu07_core PUBLIC eu07_settings)

View File

@@ -122,16 +122,19 @@ void minimap_tool::gather_stations()
if (false == stale(m_stations_seen))
return;
std::map<std::string, station> found;
// the texts are in windows-1250; the ones of the events lost their polish letters as they were read
auto const add = [&](std::string const &Text, bool const Letters, glm::dvec3 const &Point, TTrack *Track) {
// the texts are in windows-1250; the stop points of a station can spell it with or without its polish letters
std::unordered_set<std::string> lettered;
auto const add = [&](std::string const &Text, glm::dvec3 const &Point, TTrack *Track) {
auto const name{stop_name(Text)};
if (name.empty())
return;
auto const key{folded(name)};
auto &entry{found[key]};
entry.key = key;
// the station is shown by a spelling with the letters, when any of its stop points has one
auto const letters{std::ranges::any_of(name, [](char const Character) { return static_cast<unsigned char>(Character) >= 0x80; })};
// the timetables join the words with underscores
if (entry.name.empty() || Letters)
if (entry.name.empty() || (letters && lettered.insert(key).second))
{
entry.name = win1250_to_utf8(name);
std::replace(entry.name.begin(), entry.name.end(), '_', ' ');
@@ -145,10 +148,10 @@ void minimap_tool::gather_stations()
};
for (auto *cell : simulation::Memory.sequence())
if (cell != nullptr && cell->Text().starts_with(stop_prefix))
add(cell->Text(), true, cell->location(), cell->Track);
add(cell->Text(), cell->location(), cell->Track);
for (auto *event : simulation::Events.sequence())
if (auto const *values{dynamic_cast<putvalues_event const *>(event)}; values != nullptr && values->input_command() == TCommandType::cm_PassengerStopPoint)
add(values->input_text(), false, values->input_location(), nullptr);
add(values->input_text(), values->input_location(), nullptr);
std::vector<station> stations;
for (auto &entry : found)
stations.push_back(std::move(entry.second));

View File

@@ -24,6 +24,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include "utilities/utilities.h"
#include "world/stationnames.h"
#include <algorithm>
#include <cctype>
@@ -380,8 +381,9 @@ void blackbox_recorder::write_map() {
if (values == nullptr)
continue;
auto const &text{values->input_text()};
// the name in the form the station records and the rows of the timetable have theirs, as it always was
if (text.starts_with(stoppoint))
m_writer->stop_point(stoppoints++, text_of(std::string_view{text}.substr(stoppoint.size())), values->input_location(),
m_writer->stop_point(stoppoints++, text_of(timetable::station_ascii(text.substr(stoppoint.size()))), values->input_location(),
static_cast<float>(values->input_value(1)), static_cast<float>(values->input_value(2)), heading_of(values->input_location()));
else if (text == "Warning_signal")
m_writer->horn_point(hornpoints++, text_of(values->name()), values->input_location(), static_cast<float>(values->input_value(1)),

View File

@@ -0,0 +1,295 @@
#include "stdafx.h"
#include "doctest.h"
#include "utilities/utilities.h"
#include "world/stationnames.h"
#include "world/timetablereader.h"
#include <sstream>
#include <string>
#include <vector>
// the names of the stations (MaSzyna-EU07/maszyna#94): the timetable keeps a name as its file spells it, with its polish
// letters, for showing; the W4 stop points of the scenery, spelled in their own files, still find their station whatever
// the spelling; the form the announcement files, the scenery events and the scripts get stays the ascii one.
// the texts are windows-1250, written as bytes: the build reads the sources in any code page
using timetable::same_station;
using timetable::station_ascii;
using timetable::station_caption;
using timetable::station_key;
using timetable::stop_point_is_for;
namespace {
// Biała_Podlaska, Łódź_Żabieniec, Częstochowa_Osobowa in windows-1250
std::string const biala{"Bia\xB3" "a_Podlaska"};
std::string const lodz{"\xA3\xF3" "d\x9F_\xAF" "abieniec"};
std::string const czestochowa{"Cz\xEAstochowa_Osobowa"};
// the 18 polish letters in windows-1250, as in test_win1250.cpp
std::string const letters1250{"\xA5\xC6\xCA\xA3\xD1\xD3\x8C\x8F\xAF\xB9\xE6\xEA\xB3\xF1\xF3\x9C\x9F\xBF"};
// a timetable with polish letters in the relation and in the names of the stations
std::string const timetable_text{
" ___________________________________________________________________\n"
"[ Rodzaj i numer pociagu | Os1234 ]\n"
"[ Kategoria | Os ]\n"
"[________________________________________________|__________________]\n"
"[ | Bia\xB3" "a_Podlaska ]\n"
"[ Relacja pociagu | \xA3\xF3" "d\x9F_\xAF" "abieniec ]\n"
"[________________________________________________|__________________]\n"
"[ Wymagany % ciezaru hamujacego | 60% ]\n"
"[________________________________________________|__________________]\n"
"[ Seria i obciazenie lokomotywy | EN57 120 ]\n"
"[________________________________________________|__________________]\n"
"[ 1.13 | 60 | Bia\xB3" "a_Podlaska 1 | | ]\n"
"[ | | R2,H 1 12.47 | ]\n"
"[ | |----------------------------------1---------|--------]\n"
"[ 5.06 |_____| Cz\xEAstochowa_Osobowa 1 12.54 | 7 ]\n"
"[ | 40 | po 1 12.55 | ]\n"
"[ | |----------------------------------1---------|--------]\n"
"[ 9.16 | | \xA3\xF3" "d\x9F_\xAF" "abieniec 2 13.01 | 6 ]\n"
"[ | | R3 2 | | ]\n"
"[_______|_____|__________________________________2_________|________]\n"};
Mtable::timetable_data read(std::string const &Text) {
std::istringstream input{Text};
Mtable::timetable_data data;
data.TrainName = "file";
REQUIRE(Mtable::read_timetable(input, data) == 0);
return data;
}
// the text of a W4 as the driver gets it: a putvalues event cuts what follows # when the scenery is read
// (putvalues_event::deserialize_), a memory cell keeps the whole of its text
std::string text_seen(std::string Text, bool const Event) {
if (auto const hash{Text.find('#')}; Event && hash != std::string::npos) {
Text.erase(hash);
}
return Text;
}
// the comparison of a W4 text with the next stop of the timetable as TController::TableUpdateStopPoint() made it before
// the names kept their letters: the text of a putvalues event lost its polish letters too when the scenery was read;
// 32 is the sizeof( std::string ) the code had for the length
bool matched_before(std::string const &Text, bool const Event, std::string const &Nextstop) {
auto text{text_seen(Text, Event)};
if (Event) {
win1250_to_ascii(text);
}
return ToLower(text).compare(19, 32, ToLower(Nextstop)) == 0;
}
bool matched_now(std::string const &Text, bool const Event, std::string const &Nextstop) {
return stop_point_is_for(text_seen(Text, Event), Nextstop);
}
} // namespace
TEST_CASE("station names: the ascii form takes the marks off the polish letters and nothing else") {
CHECK(station_ascii(biala) == "Biala_Podlaska");
CHECK(station_ascii(lodz) == "Lodz_Zabieniec");
CHECK(station_ascii(czestochowa) == "Czestochowa_Osobowa");
CHECK(station_ascii(letters1250) == "ACELNOSZZacelnoszz");
// a name without them stays, the case, the underscores and the spaces included
CHECK(station_ascii("Warszawa_Zachodnia") == "Warszawa_Zachodnia");
CHECK(station_ascii("Nowy Targ") == "Nowy Targ");
// what win1250_to_ascii() always made of a name: letters of other languages stay as they are
auto ostrava{std::string{"Ostrava_hl.n\xE1" "dra\x9E\xED"}};
auto const expected{ostrava};
CHECK(station_ascii(ostrava) == expected);
win1250_to_ascii(ostrava);
CHECK(ostrava == expected);
}
TEST_CASE("station names: the file names of a station come from the ascii form, as before") {
// the announcement of a stop is <scenery>/<name>.ogg or sounds/sip/<name>.ogg, of the name the timetable entry has
// as StationName; the files have no polish letters in their names
auto const data{read(timetable_text)};
CHECK(data.TimeTable[2].StationName + ".ogg" == "Czestochowa_Osobowa.ogg");
CHECK(data.TimeTable[3].StationName + ".ogg" == "Lodz_Zabieniec.ogg");
// the destination board is looked up by the last station of the relation, through Bezogonkow()
CHECK(Bezogonkow(data.Relation2) == "Lodz_Zabieniec");
}
TEST_CASE("station names: a timetable with polish letters keeps them for showing") {
auto const data{read(timetable_text)};
REQUIRE(data.StationCount == 3);
// as written
CHECK(data.RelationLabel1 == biala);
CHECK(data.RelationLabel2 == lodz);
CHECK(data.TimeTable[1].StationLabel == biala);
CHECK(data.TimeTable[2].StationLabel == czestochowa);
CHECK(data.TimeTable[3].StationLabel == lodz);
// what the player sees: utf-8, spaces for the underscores
CHECK(station_caption(data.TimeTable[1].StationLabel) == "Bia\xC5\x82" "a Podlaska");
CHECK(station_caption(data.TimeTable[2].StationLabel) == "Cz\xC4\x99stochowa Osobowa");
CHECK(station_caption(data.TimeTable[3].StationLabel) == "\xC5\x81\xC3\xB3" "d\xC5\xBA \xC5\xBB" "abieniec");
CHECK(station_caption(data.RelationLabel2) == "\xC5\x81\xC3\xB3" "d\xC5\xBA \xC5\xBB" "abieniec");
// the rest of the row reads as it did
CHECK(data.TimeTable[2].StationWare == "po");
CHECK(data.TimeTable[2].Ah == 12);
CHECK(data.TimeTable[3].TrackNo == 2);
}
TEST_CASE("station names: the name a timetable is matched and handed over by stays the ascii one") {
auto const data{read(timetable_text)};
// TMTableEntry::StationName and the relation: what the W4 comparison, the announcement files, the scenery events
// (WhoIs) and the python screens get
CHECK(data.Relation1 == "Biala_Podlaska");
CHECK(data.Relation2 == "Lodz_Zabieniec");
CHECK(data.TimeTable[1].StationName == "Biala_Podlaska");
CHECK(data.TimeTable[2].StationName == "Czestochowa_Osobowa");
CHECK(data.TimeTable[3].StationName == "Lodz_Zabieniec");
// the first station is still told to be the start of the relation by the two names being the same
CHECK(data.TimeTable[1].StationName == data.Relation1);
}
TEST_CASE("station names: a timetable without polish letters has the same name in both forms") {
auto const plain{station_ascii(timetable_text)};
auto const data{read(plain)};
REQUIRE(data.StationCount == 3);
CHECK(data.RelationLabel1 == data.Relation1);
CHECK(data.RelationLabel2 == data.Relation2);
for (auto i{1}; i <= data.StationCount; ++i) {
CAPTURE(i);
CHECK(data.TimeTable[i].StationLabel == data.TimeTable[i].StationName);
}
// and reads the same as the one with the letters, but for the labels
auto const lettered{read(timetable_text)};
for (auto i{0}; i <= data.StationCount; ++i) {
CAPTURE(i);
CHECK(data.TimeTable[i].StationName == lettered.TimeTable[i].StationName);
CHECK(data.TimeTable[i].Dh == lettered.TimeTable[i].Dh);
CHECK(data.TimeTable[i].Dm == lettered.TimeTable[i].Dm);
}
// the entry before the first station is the technical one in both forms
CHECK(data.TimeTable[0].StationName == "nowhere");
CHECK(data.TimeTable[0].StationLabel == "nowhere");
}
TEST_CASE("station names: two spellings of a station have one key") {
// with and without the letters
CHECK(same_station(biala, "Biala_Podlaska"));
CHECK(same_station("Biala_Podlaska", biala));
CHECK(same_station(lodz, "Lodz_Zabieniec"));
// some of the letters only (linia 107 has the W4 of Rzepedz spelled so)
CHECK(same_station("Rzep\xEA" "d\x9F", "Rzeped\x9F"));
// in any case, the letters with marks included (baltyk has BALTYK_GLOWNY in capitals in a timetable)
CHECK(same_station("BA\xA3TYK_G\xA3\xD3WNY", "Ba\xB3tyk_G\xB3\xF3wny"));
CHECK(same_station("BA\xA3TYK_G\xA3\xD3WNY", "baltyk_glowny"));
CHECK(same_station("ZAG\xD3RZ", "Zag\xF3rz"));
// with spaces or underscores
CHECK(same_station("Bia\xB3" "a Podlaska", biala));
CHECK(same_station("Biala Podlaska", biala));
CHECK(same_station("Biala Podlaska", "biala_podlaska"));
// the key itself
CHECK(station_key(biala) == "biala_podlaska");
CHECK(station_key("Bia\xB3" "a Podlaska") == "biala_podlaska");
CHECK(station_key(letters1250) == "acelnoszzacelnoszz");
CHECK(station_key("").empty());
}
TEST_CASE("station names: different stations have different keys") {
CHECK_FALSE(same_station(biala, "Biala"));
CHECK_FALSE(same_station("Biala_Podlaska", "Biala_Podlaska_po"));
CHECK_FALSE(same_station("Lodz_Zabieniec", "Lodz_Kaliska"));
CHECK_FALSE(same_station("Gorna", "Dolna"));
CHECK_FALSE(same_station("Gorna", ""));
// no other separator stands for a space
CHECK_FALSE(same_station("Biala-Podlaska", "Biala_Podlaska"));
CHECK_FALSE(same_station("BialaPodlaska", "Biala_Podlaska"));
// letters of other languages aren't folded, as they never were
CHECK_FALSE(same_station("Ostrava_hl.n\xE1" "dra\x9E\xED", "Ostrava_hl.nadrazi"));
CHECK(same_station("Ostrava_hl.n\xE1" "dra\x9E\xED", "ostrava_hl.n\xE1" "dra\x9E\xED"));
}
TEST_CASE("station names: a W4 finds the station of the timetable whatever the two spellings") {
auto const data{read(timetable_text)};
// the next stop of the driver is the StationName of the entry
auto const &nextstop{data.TimeTable[1].StationName};
// the W4 spelled with the letters, without them, in another case, with a space
CHECK(stop_point_is_for("PassengerStopPoint:" + biala, nextstop));
CHECK(stop_point_is_for("PassengerStopPoint:Biala_Podlaska", nextstop));
CHECK(stop_point_is_for("PassengerStopPoint:BIA\xA3" "A_PODLASKA", nextstop));
CHECK(stop_point_is_for("PassengerStopPoint:biala_podlaska", nextstop));
CHECK(stop_point_is_for("PassengerStopPoint:Bia\xB3" "a Podlaska", nextstop));
CHECK(stop_point_is_for("PassengerStopPoint:Biala Podlaska", nextstop));
// the usual W4 of a scenery, with the part which makes its event unique: the event cuts it as it's read
CHECK(matched_now("PassengerStopPoint:" + biala + "#W4-P1-T2-1", true, nextstop));
CHECK(matched_now("PassengerStopPoint:Biala_Podlaska#W4-1", true, nextstop));
// and the other way round: the timetable name as written against a W4 without the letters
CHECK(stop_point_is_for("PassengerStopPoint:Biala_Podlaska", data.TimeTable[1].StationLabel));
CHECK(stop_point_is_for("PassengerStopPoint:Lodz_Zabieniec", data.TimeTable[3].StationLabel));
// another station, a text which isn't a W4 one
CHECK_FALSE(stop_point_is_for("PassengerStopPoint:Biala", nextstop));
CHECK_FALSE(stop_point_is_for("PassengerStopPoint:Biala_Podlaska_po", nextstop));
CHECK_FALSE(stop_point_is_for("PassengerStopPoint:" + lodz, nextstop));
CHECK_FALSE(stop_point_is_for("Biala_Podlaska", nextstop));
CHECK_FALSE(stop_point_is_for("passengerstoppoint:Biala_Podlaska", nextstop));
CHECK_FALSE(stop_point_is_for("SetVelocity", nextstop));
CHECK_FALSE(stop_point_is_for("", nextstop));
// a memory cell keeps what follows the #: as before, it is a W4 only of a station which has that in its name
CHECK_FALSE(matched_now("PassengerStopPoint:Biala_Podlaska#W4-1", false, nextstop));
CHECK(matched_now("PassengerStopPoint:Gorna#1", false, "Gorna#1"));
CHECK_FALSE(matched_now("PassengerStopPoint:Gorna", false, "Gorna#1"));
// a W4 without a name is for the end of the timetable, where the next stop has none either
CHECK(stop_point_is_for("PassengerStopPoint:", ""));
CHECK_FALSE(stop_point_is_for("PassengerStopPoint:", nextstop));
CHECK_FALSE(stop_point_is_for("PassengerStopPoint:Biala_Podlaska", ""));
}
TEST_CASE("station names: every W4 the driver matched before is matched now") {
// the next stops as the timetable gives them (ascii), and the special ones the driver has when there's no station
std::vector<std::string> const nextstops{"Biala_Podlaska", "Lodz_Zabieniec", "Czestochowa_Osobowa", "BALTYK_GLOWNY", "Gorna", "Gorna#1", "Rzepedz", "", "nowhere", "[End of route]",
"Ostrava_hl.n\xE1" "dra\x9E\xED"};
std::vector<std::string> const names{biala, "Biala_Podlaska", "biala_podlaska", "BIA\xA3" "A_PODLASKA", "Bia\xB3" "a Podlaska", lodz, "Lodz_Zabieniec", czestochowa,
"Ba\xB3tyk_G\xB3\xF3wny", "Rzeped\x9F", "Rzep\xEA" "d\x9F", "Gorna", "Gorna#1", "Dolna", "", "nowhere", "Ostrava_hl.n\xE1" "dra\x9E\xED",
"Ostrava_hl.nadrazi", "Biala", "Biala_Podlaska_po"};
auto matches{0};
auto gained{0};
for (auto const &nextstop : nextstops) {
for (auto const &name : names) {
for (auto const *suffix : {"", "#W4-1"}) {
auto const text{"PassengerStopPoint:" + name + suffix};
for (auto const event : {true, false}) {
CAPTURE(nextstop);
CAPTURE(text);
CAPTURE(event);
auto const before{matched_before(text, event, nextstop)};
auto const now{matched_now(text, event, nextstop)};
// nothing is lost
CHECK((false == before || now));
// and nothing changes for the spellings the comparison never told apart: a name without polish letters
// and without spaces
if (name == station_ascii(name) && name.find(' ') == std::string::npos) {
CHECK(before == now);
}
matches += (now ? 1 : 0);
gained += (now && false == before ? 1 : 0);
}
}
}
}
CHECK(matches > 0);
// what is new: a memory cell spelled with the polish letters, a space for an underscore
CHECK(gained > 0);
CHECK(matched_now("PassengerStopPoint:" + biala, false, "Biala_Podlaska"));
CHECK_FALSE(matched_before("PassengerStopPoint:" + biala, false, "Biala_Podlaska"));
CHECK(matched_now("PassengerStopPoint:Biala Podlaska", true, "Biala_Podlaska"));
CHECK_FALSE(matched_before("PassengerStopPoint:Biala Podlaska", true, "Biala_Podlaska"));
// and a name longer than the 32 characters the old comparison took of it
std::string const longname{"Bardzo_Dluga_Nazwa_Stacji_Wezlowej_Osobowej"};
CHECK(matched_now("PassengerStopPoint:" + longname, true, longname));
CHECK_FALSE(matched_before("PassengerStopPoint:" + longname, true, longname));
}
TEST_CASE("station names: the caption of a station is its name as written, in utf-8, with spaces") {
CHECK(station_caption(biala) == "Bia\xC5\x82" "a Podlaska");
CHECK(station_caption(lodz) == "\xC5\x81\xC3\xB3" "d\xC5\xBA \xC5\xBB" "abieniec");
CHECK(station_caption("Warszawa_Zachodnia") == "Warszawa Zachodnia");
CHECK(station_caption("[End of route]") == "[End of route]");
CHECK(station_caption("").empty());
// a name already in utf-8 stays
CHECK(station_caption("Bia\xC5\x82" "a_Podlaska") == "Bia\xC5\x82" "a Podlaska");
}

View File

@@ -323,7 +323,7 @@ std::string ToUpper(std::string const &text)
void win1250_to_ascii(std::string &Input)
{
std::unordered_map<char, char> const charmap{{165, 'A'}, {198, 'C'}, {202, 'E'}, {163, 'L'}, {209, 'N'}, {211, 'O'}, {140, 'S'}, {143, 'Z'}, {175, 'Z'},
static std::unordered_map<char, char> const charmap{{165, 'A'}, {198, 'C'}, {202, 'E'}, {163, 'L'}, {209, 'N'}, {211, 'O'}, {140, 'S'}, {143, 'Z'}, {175, 'Z'},
{185, 'a'}, {230, 'c'}, {234, 'e'}, {179, 'l'}, {241, 'n'}, {243, 'o'}, {156, 's'}, {159, 'z'}, {191, 'z'}};
std::unordered_map<char, char>::const_iterator lookup;
for (auto &input : Input)

View File

@@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/.
#include "vehicle/handover.h"
#include "vehicle/timetableservice.h"
#include "world/mtable.h"
#include "world/stationnames.h"
#include "vehicle/DynObj.h"
#include "world/Event.h"
#include "world/MemCell.h"
@@ -1201,8 +1202,9 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub
if( ( OrderCurrentGet() & ( Shunt | Loose_shunt | Obey_train | Bank ) ) == 0 ) { return true; }
// jeśli przystanek, trzeba obsłużyć wg rozkładu
iDrivigFlags |= moveStopPointFound;
// first 19 chars of the command is expected to be "PassengerStopPoint:" so we skip them
if( ToLower( Point.evEvent->input_text() ).compare( 19, sizeof( asNextStop ), ToLower( asNextStop ) ) != 0 )
// the W4 and the timetable name the station each in its own file, so the two spellings are compared by their key:
// with or without the polish letters, in any case, with spaces or underscores
if( false == timetable::stop_point_is_for( Point.evEvent->input_text(), asNextStop ) )
{ // jeśli nazwa nie jest zgodna
if( false == IsScheduledPassengerStopVisible // check if our next scheduled stop didn't show up earlier in the scan
&& Point.fDist < 1.15 * fBrakeDist + 300
@@ -6139,7 +6141,8 @@ std::string TController::NextStop() const
if (asNextStop == "[End of route]")
return ""; // nie zawiera nazwy stacji, gdy dojechał do końca
// dodać godzinę odjazdu
auto nextstop{ Bezogonkow( asNextStop, true ) };
// the name the way the timetable spells it, in utf-8 as the user interface takes it
auto nextstop{ TrainParams.station_caption( asNextStop ) };
auto const *t{ TrainParams.TimeTable + TrainParams.StationIndex };
if( t->Ah >= 0 ) {
// przyjazd

View File

@@ -716,7 +716,8 @@ putvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
if( contains( token, '#' ) ) {
token.erase( token.find( '#' ) ); // obcięcie unikatowości
}
win1250_to_ascii( token ); // get rid of non-ascii chars
// NOTE: the name stays as the scenery spells it, with its polish letters; whoever matches it with the name
// a timetable has goes by timetable::stop_point_is_for(), which takes any spelling of the station
m_input.command_type = TCommandType::cm_PassengerStopPoint;
// nie do kolejki (dla SetVelocity też, ale jak jest do toru dowiązany)
m_passive = true;

View File

@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
#include "simulation/simulationtime.h"
#include "utilities/dictionary.h"
#include "utilities/utilities.h"
#include "world/stationnames.h"
double TTrainParameters::CheckTrainLatency() const
{
@@ -160,12 +161,14 @@ bool TTrainParameters::UpdateMTable(double hh, double mm, std::string_view NewNa
bool Mtable::TTrainParameters::RewindTimeTable(std::string actualStationName) {
if( actualStationName.compare( 0, 19, "PassengerStopPoint:" ) == 0 ) {
actualStationName = ToLower( actualStationName.substr( 19 ) );
}
// the text of a W4 or a plain name, spelled the way its file has it: with or without the polish letters, in any case
auto const isstoppoint { actualStationName.starts_with( timetable::stop_point_prefix ) };
for( auto i = 1; i <= StationCount; ++i ) {
// przechodzimy po całej tabelce i sprawdzamy nazwy stacji (bez pierwszej)
if (ToLower(TimeTable[i].StationName) == actualStationName) {
auto const &stationname { TimeTable[i].StationName };
if( isstoppoint ?
timetable::stop_point_is_for( actualStationName, stationname ) :
timetable::same_station( actualStationName, stationname ) ) {
// nazwa stacji zgodna więc ustawiamy na poprzednią, żeby w następnym kroku poprawnie obsłużyć
StationIndex = i;
NextStationName = TimeTable[ i ].StationName;
@@ -218,6 +221,29 @@ std::string TTrainParameters::ShowRelation() const
return "";
}
std::string TTrainParameters::relation_caption() const
{
if (Relation1 != "" && Relation2 != "")
return timetable::station_caption( RelationLabel1 ) + " - " + timetable::station_caption( RelationLabel2 );
else
return "";
}
std::string TTrainParameters::station_caption( std::string const &Name ) const
{
// the station the train makes for first, then the rest of the table
if( StationIndex >= 0 && StationIndex <= StationCount && TimeTable[ StationIndex ].StationName == Name ) {
return timetable::station_caption( TimeTable[ StationIndex ].StationLabel );
}
for( auto i = 1; i <= StationCount; ++i ) {
if( TimeTable[ i ].StationName == Name ) {
return timetable::station_caption( TimeTable[ i ].StationLabel );
}
}
// not a station of the timetable
return timetable::station_caption( Name );
}
TTrainParameters::TTrainParameters(std::string const &NewTrainName)
/*wstępne ustawienie parametrów rozkładu jazdy*/
{
@@ -236,6 +262,8 @@ void TTrainParameters::NewName(std::string_view NewTrainName)
Direction = 1;
Relation1 = "";
Relation2 = "";
RelationLabel1 = "";
RelationLabel2 = "";
for (auto &tableline : TimeTable)
{
tableline = TMTableLine();
@@ -307,6 +335,8 @@ bool TTrainParameters::LoadTTfile(std::string const &scnpath, int iPlus, double
TrainLabel = data.TrainLabel;
Relation1 = data.Relation1;
Relation2 = data.Relation2;
RelationLabel1 = data.RelationLabel1;
RelationLabel2 = data.RelationLabel2;
BrakeRatio = data.BrakeRatio;
LocSeries = data.LocSeries;
LocLoad = data.LocLoad;

View File

@@ -42,6 +42,9 @@ class TTrainParameters
double TTVmax;
std::string Relation1;
std::string Relation2; // nazwy stacji danego odcinka
// the two as the timetable spells them, with their letters (see TMTableEntry::StationLabel)
std::string RelationLabel1;
std::string RelationLabel2;
double BrakeRatio;
std::string LocSeries; // seria (typ) pojazdu
double LocLoad;
@@ -55,6 +58,9 @@ class TTrainParameters
double CheckTrainLatency() const;
/*todo: str hh:mm to int i z powrotem*/
std::string ShowRelation() const;
// the relation and the name of given station for the player: utf-8, with the letters the timetable has
std::string relation_caption() const;
std::string station_caption( std::string const &Name ) const;
double WatchMTable(double DistCounter) const;
std::string NextStop() const;
// wpis rozkladu Offset pozycji za StationIndex (Offset>=1); poza zakresem 1..StationCount

43
world/stationnames.cpp Normal file
View File

@@ -0,0 +1,43 @@
/*
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/stationnames.h"
#include "utilities/utilities.h"
#include <algorithm>
namespace timetable {
std::string station_ascii(std::string Name) {
win1250_to_ascii(Name);
return Name;
}
std::string station_key(std::string_view const Name) {
// the same steps the comparison of a W4 with the timetable always took: the marks off, then the case
auto key{ToLower(station_ascii(std::string{Name}))};
std::ranges::replace(key, ' ', '_');
return key;
}
bool same_station(std::string_view const Left, std::string_view const Right) {
return station_key(Left) == station_key(Right);
}
bool stop_point_is_for(std::string_view const Text, std::string_view const Station) {
return Text.starts_with(stop_point_prefix) && same_station(Text.substr(stop_point_prefix.size()), Station);
}
std::string station_caption(std::string const &Name) {
return data_name_to_utf8(Name, true);
}
} // namespace timetable

40
world/stationnames.h Normal file
View File

@@ -0,0 +1,40 @@
/*
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>
#include <string_view>
// the names of the stations (MaSzyna-EU07/maszyna#94): a timetable and the W4 stop points of a scenery name a station
// each in its own file, in windows-1250, and they don't have to spell it the same way (with or without the polish
// letters, in another case). a name has three forms here:
// - as written, with its letters: what the files hold and what the player is shown (station_caption())
// - the ascii one, the polish letters without their marks: what the timetable always kept as the name of a station,
// what the scenery events, the scripts and the file names of the announcements and destination boards go by
// (station_ascii())
// - the key two spellings are the same station by (station_key(), same_station())
namespace timetable {
// what a W4 text starts with: "PassengerStopPoint:<station>". in the scenery a "#<part which makes the name of the
// event unique>" follows; the event cuts it as it's read, a memory cell keeps the whole of its text
inline constexpr std::string_view stop_point_prefix{"PassengerStopPoint:"};
// the name without the marks of the polish letters of windows-1250, the rest as written
std::string station_ascii(std::string Name);
// the key of a name: the ascii form in lower case, spaces as underscores
std::string station_key(std::string_view Name);
// whether the two names are spellings of the same station
bool same_station(std::string_view Left, std::string_view Right);
// whether the W4 text, as an event or a memory cell holds it, is for the station of given name, in any spelling of the two
bool stop_point_is_for(std::string_view Text, std::string_view Station);
// the name for the player: utf-8, with its letters, underscores as spaces
std::string station_caption(std::string const &Name);
} // namespace timetable

View File

@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Logs.h"
#include "utilities/utilities.h"
#include "world/stationnames.h"
namespace Mtable {
@@ -125,8 +126,9 @@ int read_timetable(std::istream &fin, timetable_data &Data) {
break;
}
if (s != "|") {
Data.Relation1 = s;
win1250_to_ascii(Data.Relation1);
// the name is kept as written, for showing; the ascii form is what the rest of the simulator goes by
Data.RelationLabel1 = s;
Data.Relation1 = timetable::station_ascii(s);
}
else
conversionerror = -5;
@@ -138,8 +140,9 @@ int read_timetable(std::istream &fin, timetable_data &Data) {
if (s == "|")
break;
}
fin >> Data.Relation2;
win1250_to_ascii(Data.Relation2);
if (fin >> Data.RelationLabel2) {
Data.Relation2 = timetable::station_ascii(Data.RelationLabel2);
}
while (fin >> s) {
if (s == "Wymagany")
break;
@@ -195,9 +198,11 @@ int read_timetable(std::istream &fin, timetable_data &Data) {
}
while (false == contains(s, "|") && false == fin.fail())
fin >> s;
fin >> record->StationName;
// get rid of non-ascii chars. TODO: run correct version based on locale
win1250_to_ascii(record->StationName);
// the name is kept as written, for showing; the W4 stop points, the announcement files, the scenery
// events and the scripts go by its ascii form, as they always did
if (fin >> record->StationLabel) {
record->StationName = timetable::station_ascii(record->StationLabel);
}
do {
fin >> s;
} while (!(s == "1" || s == "2" || fin.fail()));

View File

@@ -25,7 +25,11 @@ static int const MaxTTableSize = 100; // można by to robić dynamicznie
struct TMTableEntry {
float km{0.f}; // kilometraz linii
float vmax{-1.f}; // predkosc rozkladowa przed przystankiem
std::string StationName{"nowhere"}; // nazwa stacji ('_' zamiast spacji)
// nazwa stacji ('_' zamiast spacji), bez ogonków: the form the station is matched, looked up and handed over by
// (the W4 stop points, the announcement files, the scenery events, the scripts)
std::string StationName{"nowhere"};
// the name as the timetable spells it, in windows-1250 with its letters: for showing (timetable::station_caption())
std::string StationLabel{"nowhere"};
std::string StationWare; // typ i wyposazenie stacji, oddz. przecinkami, bez flag obsługi
int TrackNo{1}; // ilosc torow szlakowych
int Ah{-1};
@@ -45,8 +49,11 @@ struct timetable_data {
std::string TrainName; // the name the file is looked up by, then the one the file gives
std::string TrainCategory;
std::string TrainLabel;
// the first and the last station, in the two forms a station name has (see TMTableEntry)
std::string Relation1;
std::string Relation2;
std::string RelationLabel1;
std::string RelationLabel2;
double BrakeRatio{0.0};
std::string LocSeries;
double LocLoad{0.0};