Merge commit 'd8170c932b448ba6888e702746b5ae22632062d8' into sim

This commit is contained in:
milek7
2022-01-05 01:02:56 +01:00
76 changed files with 9277 additions and 5749 deletions

View File

@@ -183,10 +183,10 @@ bool TTrainParameters::IsTimeToGo(double hh, double mm)
// returns: difference between specified time and scheduled departure from current stop, in seconds
double TTrainParameters::seconds_until_departure( double const Hour, double const Minute ) const {
if( ( TimeTable[ StationIndex ].Ah < 0 ) ) { // passthrough
if( ( TimeTable[ StationStart ].Ah < 0 ) ) { // passthrough
return 0;
}
return ( 60.0 * CompareTime( Hour, Minute, TimeTable[ StationIndex ].Dh, TimeTable[ StationIndex ].Dm ) );
return ( 60.0 * CompareTime( Hour, Minute, TimeTable[ StationStart ].Dh, TimeTable[ StationStart ].Dm ) );
}
std::string TTrainParameters::ShowRelation() const
@@ -211,6 +211,7 @@ void TTrainParameters::NewName(std::string const &NewTrainName)
TrainName = NewTrainName;
StationCount = 0;
StationIndex = 0;
StationStart = 0;
NextStationName = "nowhere";
LastStationLatency = 0;
Direction = 1;
@@ -288,7 +289,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
while (fin.good() && !((ConversionError != 0) || EndTable))
{
std::getline(fin, lines); /*wczytanie linii*/
if (lines.find("___________________") != std::string::npos) /*linia pozioma górna*/
if (contains( lines, "___________________") ) /*linia pozioma górna*/
{
fin >> s;
if (s == "[") /*lewy pion*/
@@ -311,14 +312,33 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
// pliku}
// ConversionError:=-7 {błąd niezgodności}
TrainName = s; // nadanie nazwy z pliku TXT (bez ścieżki do pliku)
while (fin >> s || fin.bad())
{
if (contains( s,"_______|") )
{
break;
}
if (s == "Kategoria")
{
do
{
fin >> s;
} while (!((s == "|") || (fin.bad())));
fin >> TrainCategory;
continue;
}
if (s == "Nazwa")
{
do
{
fin >> s;
} while (!((s == "|") || (fin.bad())));
fin >> TrainLabel;
continue;
}
} // while (!(s == "Seria"));
// else
{ /*czytaj naglowek*/
while (fin >> s || !fin.bad())
{
if (s.find("_______|") != std::string::npos)
break;
// fin >> s;
} // while (!(s.find("_______|") != std::string::npos) || fin.eof());
while (fin >> s || !fin.bad())
{
if (s == "[")
@@ -375,7 +395,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
do
{
fin >> s;
} while (!(s.find("[______________") != std::string::npos || fin.bad()));
} while (!(contains( s,"[______________" ) || fin.bad()));
auto activeradiochannel{ -1 };
while (!fin.bad() && !EndTable)
{
@@ -390,21 +410,20 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
else
ConversionError = -4;
if (s.find("|") == std::string::npos)
if (false == contains( s,"|") )
{
record->km = atof(s.c_str());
fin >> s;
}
if (s.find("|_____|") !=
std::string::npos) /*zmiana predkosci szlakowej*/
if (contains( s,"|_____|")) /*zmiana predkosci szlakowej*/
UpdateVelocity(StationCount, vActual);
else
{
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains(s,"|"))
vActual = atof(s.c_str());
}
while (s.find("|") == std::string::npos)
while (false == contains( s,"|"))
fin >> s;
fin >> record->StationName;
// get rid of non-ascii chars. TODO: run correct version based on locale
@@ -417,7 +436,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
if (s != "|")
{
if (s.find(hrsd) != std::string::npos)
if (contains( s, hrsd) )
{
record->Ah = atoi( s.substr(0, s.find(hrsd)).c_str()); // godzina przyjazdu
record->Am = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta przyjazdu
@@ -439,7 +458,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
} while (!((s == "[") || fin.bad()));
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains(s,"|"))
{
/*tu s moze byc miejscem zmiany predkosci szlakowej*/
fin >> s;
@@ -450,10 +469,10 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
else
{
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains(s,"|"))
vActual = atof(s.c_str());
}
while (s.find("|") == std::string::npos)
while (false == contains(s,"|"))
fin >> s;
// stationware. added fix for empty entry
fin >> s;
@@ -464,7 +483,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
}
// cache relevant station data
record->is_maintenance = ( s.find( "pt" ) != std::string::npos );
record->is_maintenance = ( contains( s, "pt" ) );
{
auto const stationware { Split( record->StationWare, ',' ) };
for( auto const &entry : stationware ) {
@@ -492,7 +511,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
if (s != "|")
{
if (s.find(hrsd) != std::string::npos)
if (contains( s, hrsd) )
{
record->Dh = atoi(s.substr(0, s.find(hrsd)).c_str()); // godzina odjazdu
record->Dm = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta odjazdu
@@ -517,28 +536,27 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
do
{
fin >> s;
} while (!((s.find("[") != std::string::npos) || fin.bad()));
if (s.find("_|_") == std::string::npos)
} while (!(contains( s, "[" ) || fin.bad()));
if (false == contains( s, "_|_"))
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains( s, "|"))
{
/*tu s moze byc miejscem zmiany predkosci szlakowej*/
fin >> s;
}
if (s.find("|_____|") !=
std::string::npos) /*zmiana predkosci szlakowej*/
if (contains( s, "|_____|") ) /*zmiana predkosci szlakowej*/
UpdateVelocity(StationCount, vActual);
else
{
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains( s, "|"))
vActual = atof(s.c_str());
}
while (s.find("|") == std::string::npos)
while (false == contains( s, "|" ) )
fin >> s;
while ((s.find("]") == std::string::npos))
while ((false == contains( s,"]") ))
fin >> s;
if (s.find("_|_") != std::string::npos)
if (contains( s,"_|_") )
EndTable = true;
} /*timetableline*/
}
@@ -615,7 +633,7 @@ bool TTrainParameters::DirectionChange()
// sprawdzenie, czy po zatrzymaniu wykonać kolejne komendy
{
if ((StationIndex > 0) && (StationIndex < StationCount)) // dla ostatniej stacji nie
if (TimeTable[StationIndex].StationWare.find('@') != std::string::npos)
if (contains( TimeTable[StationIndex].StationWare, '@') )
return true;
return false;
}
@@ -623,6 +641,8 @@ bool TTrainParameters::DirectionChange()
void TTrainParameters::serialize( dictionary_source *Output ) const {
Output->insert( "trainnumber", TrainName );
Output->insert( "traincategory", TrainCategory );
Output->insert( "trainname", TrainLabel );
Output->insert( "train_brakingmassratio", BrakeRatio );
Output->insert( "train_enginetype", LocSeries );
Output->insert( "train_engineload", LocLoad );
@@ -631,6 +651,7 @@ void TTrainParameters::serialize( dictionary_source *Output ) const {
Output->insert( "train_stationto", Relation2 );
Output->insert( "train_stationindex", StationIndex );
Output->insert( "train_stationcount", StationCount );
Output->insert( "train_stationstart", StationStart );
if( StationCount > 0 ) {
// timetable stations data, if there's any
for( auto stationidx = 1; stationidx <= StationCount; ++stationidx ) {