From 67a0fccfadc95a62d17307e904d6e0303f848ef1 Mon Sep 17 00:00:00 2001 From: felixprigge <61750128+felixprigge@users.noreply.github.com> Date: Thu, 21 Nov 2024 23:27:07 +0100 Subject: [PATCH] Fix: [Timetable] Use days as precision in day mode for accurate timetable syncing (#12683) Co-authored-by: flowprint <61750128+flowprint@users.noreply.github.com> --- src/lang/english.txt | 1 + src/timetable_cmd.cpp | 6 ++++-- src/timetable_gui.cpp | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index cd0992f4bb..94d64986a4 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4747,6 +4747,7 @@ STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED :(travel for {ST STR_TIMETABLE_STAY_FOR :and stay for {STRING1} STR_TIMETABLE_AND_TRAVEL_FOR :and travel for {STRING1} +STR_TIMETABLE_APPROX_TIME :{BLACK}This timetable will take approximately {STRING1} to complete STR_TIMETABLE_TOTAL_TIME :{BLACK}This timetable will take {STRING1} to complete STR_TIMETABLE_TOTAL_TIME_INCOMPLETE :{BLACK}This timetable will take at least {STRING1} to complete (not all timetabled) diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 9ba8936e45..b53d923913 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -519,7 +519,8 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) /* Before modifying waiting times, check whether we want to preserve bigger ones. */ if (!real_current_order->IsType(OT_CONDITIONAL) && (travelling || time_taken > real_current_order->GetWaitTime() || remeasure_wait_time)) { - /* Round up to the smallest unit of time commonly shown in the GUI (seconds) to avoid confusion. + /* Round up to the unit currently shown in the GUI for days and seconds. + * Round up to seconds if currently used display style is ticks. * Players timetabling in Ticks can adjust later. * For trains/aircraft multiple movement cycles are done in one * tick. This makes it possible to leave the station and process @@ -527,7 +528,8 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) * the timetable entry like is done for road vehicles/ships. * Thus always make sure at least one tick is used between the * processing of different orders when filling the timetable. */ - uint time_to_set = CeilDiv(std::max(time_taken, 1), Ticks::TICKS_PER_SECOND) * Ticks::TICKS_PER_SECOND; + uint factor = _settings_client.gui.timetable_mode == TimetableMode::Days ? Ticks::DAY_TICKS : Ticks::TICKS_PER_SECOND; + uint time_to_set = CeilDiv(std::max(time_taken, 1), factor) * factor; if (travelling && (autofilling || !real_current_order->IsTravelTimetabled())) { ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, autofilling); diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 629620241b..f73d0eeb5a 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -565,7 +565,13 @@ struct TimetableWindow : Window { TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0; if (total_time != 0) { SetTimetableParams(0, 1, total_time); - DrawString(tr, v->orders->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE); + if (!v->orders->IsCompleteTimetable()) { + DrawString(tr, STR_TIMETABLE_TOTAL_TIME_INCOMPLETE); + } else if (total_time % TicksPerTimetableUnit() == 0) { + DrawString(tr, STR_TIMETABLE_TOTAL_TIME); + } else { + DrawString(tr, STR_TIMETABLE_APPROX_TIME); + } } tr.top += GetCharacterHeight(FS_NORMAL);