mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
A timetable can now tell the AI how the train is served, for trams, underground trains and the like. The whole train gets them from a new row of the first box of the header: [ Flagi AI | drzwi_centralne=tak,stopien=nie,kierownik=nie,proba_hamulca=nie ] and a station changes them from there on with entries of its station ware (the second line of the station, next to R2, ph, @): [ | | po,kierownik=nie 1 12.54 | ] - drzwi_centralne=tak: the driver opens all the doors from the cab, those of mixed control too (otherwise left to the passengers) - stopien=tak/nie: the doorsteps switched on/off before the doors open (the AI didn't touch them before; new driver hints for it) - kierownik=nie: no conductor, so no departure signal (direct or by radio) and no first door kept open for him before the departure - proba_hamulca=nie: no running brake test A flag left out keeps today's behaviour, so a timetable without flags drives as before. Old builds skip the header row and keep the station entries as station ware text (none starts with R or holds @, po, pt). The reader moves out of TTrainParameters::LoadTTfile into world/timetablereader.cpp (eu07_core) unchanged, so the tests can run it; the flags come out of the station ware there. It now ends at the end of the file with an error where the old one spun forever (a truncated file, a missing number), and stops at 100 stations instead of writing past the table. Every .txt of the game's sceneries and of the SVN data reads the same as with the old reader (compared field by field against a verbatim copy of it); EU07_UNIT_TESTS_TIMETABLES=<scenery folder> reads them in the unit tests and EU07_UNIT_TESTS_TIMETABLES_DUMP writes what was read.
104 lines
2.4 KiB
C++
104 lines
2.4 KiB
C++
/*
|
|
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/timetableflags.h"
|
|
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/utilities.h"
|
|
|
|
namespace timetable {
|
|
|
|
namespace {
|
|
|
|
void apply_one(tristate &Flag, tristate const Other) {
|
|
if (Other != tristate::unset) {
|
|
Flag = Other;
|
|
}
|
|
}
|
|
|
|
tristate *flag_named(std::string_view const Key, service_flags &Flags) {
|
|
if (Key == "drzwi_centralne") {
|
|
return &Flags.central_doors;
|
|
}
|
|
if (Key == "stopien") {
|
|
return &Flags.doorstep;
|
|
}
|
|
if (Key == "kierownik") {
|
|
return &Flags.conductor;
|
|
}
|
|
if (Key == "proba_hamulca") {
|
|
return &Flags.brake_test;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void service_flags::apply(service_flags const &Other) {
|
|
apply_one(central_doors, Other.central_doors);
|
|
apply_one(doorstep, Other.doorstep);
|
|
apply_one(conductor, Other.conductor);
|
|
apply_one(brake_test, Other.brake_test);
|
|
}
|
|
|
|
bool read_flag(std::string_view const Entry, service_flags &Flags) {
|
|
auto const separator{Entry.find('=')};
|
|
if (separator == std::string_view::npos) {
|
|
return false;
|
|
}
|
|
auto const key{ToLower(std::string{Entry.substr(0, separator)})};
|
|
auto *flag{flag_named(key, Flags)};
|
|
if (flag == nullptr) {
|
|
return false;
|
|
}
|
|
auto const value{ToLower(std::string{Entry.substr(separator + 1)})};
|
|
if (value == "tak" || value == "1") {
|
|
*flag = tristate::yes;
|
|
}
|
|
else if (value == "nie" || value == "0") {
|
|
*flag = tristate::no;
|
|
}
|
|
else {
|
|
ErrorLog("Bad timetable: unknown value of " + key + " in \"" + std::string{Entry} + "\", expected tak or nie");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::string extract_flags(std::string const &Ware, service_flags &Flags) {
|
|
if (false == contains(Ware, '=')) {
|
|
// no flags, the list as it was
|
|
return Ware;
|
|
}
|
|
std::string rest;
|
|
for (auto const &entry : Split(Ware, ',')) {
|
|
if (read_flag(entry, Flags)) {
|
|
continue;
|
|
}
|
|
if (contains(entry, '=')) {
|
|
ErrorLog("Bad timetable: unknown flag \"" + entry + "\" in station ware \"" + Ware + "\"");
|
|
}
|
|
if (false == rest.empty()) {
|
|
rest += ',';
|
|
}
|
|
rest += entry;
|
|
}
|
|
return rest;
|
|
}
|
|
|
|
int stop_flags_entry(int const StationIndex, int const StationCount) {
|
|
return std::clamp(StationIndex, 0, std::max(StationCount, 0));
|
|
}
|
|
|
|
int run_flags_entry(int const StationIndex, int const StationCount) {
|
|
return std::clamp(StationIndex - 1, 0, std::max(StationCount, 0));
|
|
}
|
|
|
|
} // namespace timetable
|