17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-09 17:12:46 +01:00

whois: consolidate the two lookahead accessors into one

Per review: StationNameAhead()/StationIsStopAhead() duplicated the same
bounds check for no reason. Replaced with a single
TimeTableEntryAhead(Offset) returning the TMTableLine itself; the whois
branch reads .StationName/.Ah off it directly.
This commit is contained in:
Piotr Warszawski
2026-09-04 21:24:01 +02:00
parent 5705062cd2
commit 93463a3850
3 changed files with 13 additions and 23 deletions

View File

@@ -1034,14 +1034,12 @@ whois_event::run_() {
m_activator->Mechanik != nullptr && m_activator->Mechanik->primary() ?
m_activator->Mechanik :
m_activator->ctOwner ) };
auto const aheadname { (
auto const *entry { (
owner != nullptr ?
owner->TrainTimetable().StationNameAhead( 1 ) :
"none" ) };
auto const aheadstop { (
owner != nullptr && owner->TrainTimetable().StationIsStopAhead( 1 ) ?
1 :
0 ) };
&owner->TrainTimetable().TimeTableEntryAhead( 1 ) :
nullptr ) };
auto const aheadname { ( entry != nullptr ? entry->StationName : "none" ) };
auto const aheadstop { ( entry != nullptr && entry->Ah >= 0 ? 1 : 0 ) };
targetcell->UpdateValues(
aheadname, // station after the next one

View File

@@ -77,20 +77,13 @@ bool TTrainParameters::IsLastStop() const {
return StationIndex >= StationCount;
}
std::string TTrainParameters::StationNameAhead( int Offset ) const
{ // nazwa wpisu rozkladu Offset pozycji za aktualnym (bez pomijania przelotow)
TMTableLine const &TTrainParameters::TimeTableEntryAhead( int Offset ) const
{ // wpis rozkladu Offset pozycji za aktualnym (bez pomijania przelotow);
// poza zakresem 1..StationCount zwraca techniczny wpis zerowy
int const idx { StationIndex + Offset };
if( ( idx < 1 ) || ( idx > StationCount ) )
return "none";
return TimeTable[idx].StationName;
}
bool TTrainParameters::StationIsStopAhead( int Offset ) const
{ // czy wpis Offset pozycji za aktualnym to zaplanowany postoj
int const idx { StationIndex + Offset };
if( ( idx < 1 ) || ( idx > StationCount ) )
return false;
return TimeTable[idx].Ah >= 0; //-1 to brak postoju
return TimeTable[0];
return TimeTable[idx];
}

View File

@@ -70,10 +70,9 @@ class TTrainParameters
std::string ShowRelation() const;
double WatchMTable(double DistCounter);
std::string NextStop() const;
// nazwa wpisu rozkladu Offset pozycji za StationIndex (Offset>=1); "none" poza koncem rozkladu
std::string StationNameAhead( int Offset ) const;
// true, gdy ten wpis to zaplanowany postoj (ma godzine przyjazdu), false dla przelotu / poza koncem
bool StationIsStopAhead( int Offset ) const;
// wpis rozkladu Offset pozycji za StationIndex (Offset>=1); poza zakresem 1..StationCount
// zwraca techniczny wpis zerowy (TimeTable[0], StationName=="nowhere", Ah==-1)
TMTableLine const &TimeTableEntryAhead( int Offset ) const;
sound_source next_stop_sound() const;
sound_source last_stop_sound() const;
bool IsStop() const;