1
0
Fork 0

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 <tyler@tylertrahan.com>
pull/12883/head
Ivan Pravdin 2024-07-20 18:56:04 -04:00 committed by rubidium42
parent 7a698c7f1c
commit 4cddb3a38d
1 changed files with 9 additions and 9 deletions

View File

@ -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 {