From 4cddb3a38d539d4ecc3210694496054310f97cc3 Mon Sep 17 00:00:00 2001 From: Ivan Pravdin Date: Sat, 20 Jul 2024 18:56:04 -0400 Subject: [PATCH] Fix 12860, 2bada59: Timetable does not show vehicles as early Timetable does not show vehicles as early, only as on time. Fix this by changing 'VehicleIsAboveLatenessThreshold()' to accept number of ticks the vehicle is late. This allows to use it with absolute value. Codefix #12860: Update comments Co-authored-by: Tyler Trahan --- src/timetable_gui.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 4749477bf8..629620241b 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -86,20 +86,20 @@ static inline TimerGameTick::Ticks TicksPerTimetableUnit() } /** - * Determine if a vehicle should be shown as late, depending on the timetable display setting. - * @param v The vehicle in question. + * Determine if a vehicle should be shown as late or early, using a threshold depending on the timetable display setting. + * @param ticks The number of ticks that the vehicle is late or early. * @param round_to_day When using ticks, if we should round up to the nearest day. - * @return True if the vehicle is later than the threshold. + * @return True if the vehicle is outside the "on time" threshold, either early or late. */ -bool VehicleIsAboveLatenessThreshold(const Vehicle *v, bool round_to_day) +bool VehicleIsAboveLatenessThreshold(TimerGameTick::Ticks ticks, bool round_to_day) { switch (_settings_client.gui.timetable_mode) { case TimetableMode::Days: - return v->lateness_counter > Ticks::DAY_TICKS; + return ticks > Ticks::DAY_TICKS; case TimetableMode::Seconds: - return v->lateness_counter > Ticks::TICKS_PER_SECOND; + return ticks > Ticks::TICKS_PER_SECOND; case TimetableMode::Ticks: - return v->lateness_counter > (round_to_day ? Ticks::DAY_TICKS : 0); + return ticks > (round_to_day ? Ticks::DAY_TICKS : 0); default: NOT_REACHED(); } @@ -501,7 +501,7 @@ struct TimetableWindow : Window { int selected = this->sel_index; Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); - bool show_late = this->show_expected && VehicleIsAboveLatenessThreshold(v, true); + bool show_late = this->show_expected && VehicleIsAboveLatenessThreshold(v->lateness_counter, true); TimerGameTick::Ticks offset = show_late ? 0 : -v->lateness_counter; for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop @@ -586,7 +586,7 @@ struct TimetableWindow : Window { } else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) { /* We aren't running on a timetable yet. */ DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED); - } else if (!VehicleIsAboveLatenessThreshold(v, false)) { + } else if (!VehicleIsAboveLatenessThreshold(abs(v->lateness_counter), false)) { /* We are on time. */ DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME); } else {