17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-12 09:24:12 +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 != nullptr && m_activator->Mechanik->primary() ?
m_activator->Mechanik : m_activator->Mechanik :
m_activator->ctOwner ) }; m_activator->ctOwner ) };
auto const aheadname { ( auto const *entry { (
owner != nullptr ? owner != nullptr ?
owner->TrainTimetable().StationNameAhead( 1 ) : &owner->TrainTimetable().TimeTableEntryAhead( 1 ) :
"none" ) }; nullptr ) };
auto const aheadstop { ( auto const aheadname { ( entry != nullptr ? entry->StationName : "none" ) };
owner != nullptr && owner->TrainTimetable().StationIsStopAhead( 1 ) ? auto const aheadstop { ( entry != nullptr && entry->Ah >= 0 ? 1 : 0 ) };
1 :
0 ) };
targetcell->UpdateValues( targetcell->UpdateValues(
aheadname, // station after the next one aheadname, // station after the next one

View File

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

View File

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