diff --git a/src/date_func.h b/src/date_func.h index 525848fdb8..c9e78a2a4c 100644 --- a/src/date_func.h +++ b/src/date_func.h @@ -101,6 +101,15 @@ inline DateTicks NowDateTicks() return DateToDateTicks(_date, _date_fract); } +inline Ticks TimetableDisplayUnitSize() +{ + if (_settings_time.time_in_minutes) { + return _settings_time.ticks_per_minute; + } else { + return DAY_TICKS * _settings_game.economy.day_length_factor; + } +} + struct debug_date_dumper { const char *HexDate(Date date, DateFract date_fract, uint8_t tick_skip_counter); diff --git a/src/date_type.h b/src/date_type.h index 9d78c9388e..75a3508987 100644 --- a/src/date_type.h +++ b/src/date_type.h @@ -137,8 +137,6 @@ struct TickMinuteOperations { /* The type to store StateTicks-based minutes in */ using TickMinutes = StrongType::Typedef, TickMinuteOperations>; -#define DATE_UNIT_SIZE (_settings_time.time_in_minutes ? _settings_time.ticks_per_minute : (DAY_TICKS * _settings_game.economy.day_length_factor)) - static const int STATION_RATING_TICKS = 185; ///< cycle duration for updating station rating static const int STATION_ACCEPTANCE_TICKS = 250; ///< cycle duration for updating station acceptance static const int STATION_LINKGRAPH_TICKS = 504; ///< cycle duration for cleaning dead links diff --git a/src/departures_gui.cpp b/src/departures_gui.cpp index f294c9a713..0ecdcd80c3 100644 --- a/src/departures_gui.cpp +++ b/src/departures_gui.cpp @@ -928,7 +928,7 @@ void DeparturesWindow::DrawDeparturesListItems(const Rect &r) const /* The vehicle has been cancelled. */ DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED); } else{ - if (d->lateness <= DATE_UNIT_SIZE && d->scheduled_tick > now_date) { + if (d->lateness <= TimetableDisplayUnitSize() && d->scheduled_tick > now_date) { /* We have no evidence that the vehicle is late, so assume it is on time. */ DrawString(status_left, status_right, y + 1, STR_DEPARTURES_ON_TIME); } else { diff --git a/src/departures_type.h b/src/departures_type.h index aa96dce644..09c22929ce 100644 --- a/src/departures_type.h +++ b/src/departures_type.h @@ -92,8 +92,10 @@ struct Departure { if (this->calling_at[i] != d.calling_at[i]) return false; } + const Ticks timetable_unit_size = TimetableDisplayUnitSize(); + return - (this->scheduled_tick.base() / DATE_UNIT_SIZE) == (d.scheduled_tick.base() / DATE_UNIT_SIZE) && + (this->scheduled_tick.base() / timetable_unit_size) == (d.scheduled_tick.base() / timetable_unit_size) && this->vehicle->type == d.vehicle->type && this->via == d.via && this->via2 == d.via2 && diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 8bd7e2add0..383229c668 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -2591,7 +2591,7 @@ public: case OCV_TIMETABLE: value = order->GetXData(); - if (!_settings_client.gui.timetable_in_ticks) value /= DATE_UNIT_SIZE; + if (!_settings_client.gui.timetable_in_ticks) value /= TimetableDisplayUnitSize(); break; case OCV_CARGO_WAITING_AMOUNT: @@ -3191,7 +3191,7 @@ public: case OCV_TIMETABLE: value = order->GetXData(); if (!_settings_client.gui.timetable_in_ticks) { - value /= DATE_UNIT_SIZE; + value /= TimetableDisplayUnitSize(); charset_filter = CS_NUMERAL_DECIMAL; } break; diff --git a/src/schdispatch_gui.cpp b/src/schdispatch_gui.cpp index b3218dd3fd..0c8c96f5a6 100644 --- a/src/schdispatch_gui.cpp +++ b/src/schdispatch_gui.cpp @@ -896,7 +896,7 @@ struct SchdispatchWindow : GeneralVehicleWindow { int32_t ProcessDurationForQueryString(int32_t duration) const { - if (!_settings_client.gui.timetable_in_ticks) duration = RoundDivSU(duration, DATE_UNIT_SIZE); + if (!_settings_client.gui.timetable_in_ticks) duration = RoundDivSU(duration, TimetableDisplayUnitSize()); return duration; } diff --git a/src/strings.cpp b/src/strings.cpp index adb410f46c..7583ae357f 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1587,10 +1587,10 @@ static void FormatString(StringBuilder builder, const char *str_arg, StringParam FormatString(builder, GetStringPtr(STR_UNITS_TICKS), tmp_params); } else { StringID str = _settings_time.time_in_minutes ? STR_TIMETABLE_MINUTES : STR_UNITS_DAYS; - int64_t ticks = args.GetNextParameter(); - int64_t ratio = DATE_UNIT_SIZE; - int64_t units = ticks / ratio; - int64_t leftover = _settings_client.gui.timetable_leftover_ticks ? ticks % ratio : 0; + const int64_t ticks = args.GetNextParameter(); + const int64_t ratio = TimetableDisplayUnitSize(); + const int64_t units = ticks / ratio; + const int64_t leftover = _settings_client.gui.timetable_leftover_ticks ? ticks % ratio : 0; auto tmp_params = MakeParameters(units); FormatString(builder, GetStringPtr(str), tmp_params); if (b == SCC_TT_TICKS_LONG && _settings_time.time_in_minutes && units > 59) { diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 35acbe5ed2..113272bda2 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -73,7 +73,7 @@ Ticks ParseTimetableDuration(const char *str) char tmp_buffer[64]; strecpy(tmp_buffer, str, lastof(tmp_buffer)); str_replace_wchar(tmp_buffer, lastof(tmp_buffer), GetDecimalSeparatorChar(), '.'); - return atof(tmp_buffer) * DATE_UNIT_SIZE; + return atof(tmp_buffer) * TimetableDisplayUnitSize(); } /** @@ -747,7 +747,8 @@ struct TimetableWindow : GeneralVehicleWindow { Dimension lock_d = GetSpriteSize(SPR_LOCK); int line_height = std::max(GetCharacterHeight(FS_NORMAL), lock_d.height); - bool show_late = this->show_expected && v->lateness_counter > DATE_UNIT_SIZE; + const Ticks timetable_unit_size = TimetableDisplayUnitSize(); + bool show_late = this->show_expected && v->lateness_counter >= timetable_unit_size; Ticks offset = show_late ? 0 : -v->lateness_counter; bool rtl = _current_text_dir == TD_RTL; @@ -803,7 +804,7 @@ struct TimetableWindow : GeneralVehicleWindow { /* We aren't running on a timetable yet, so how can we be "on time" * when we aren't even "on service"/"on duty"? */ DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED); - } else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DATE_UNIT_SIZE == 0)) { + } else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / TimetableDisplayUnitSize() == 0)) { DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME); } else { SetTimetableParams(0, abs(v->lateness_counter)); @@ -924,7 +925,7 @@ struct TimetableWindow : GeneralVehicleWindow { if (order != nullptr) { uint time = (selected % 2 != 0) ? order->GetTravelTime() : order->GetWaitTime(); - if (!_settings_client.gui.timetable_in_ticks) time /= DATE_UNIT_SIZE; + if (!_settings_client.gui.timetable_in_ticks) time /= TimetableDisplayUnitSize(); if (time != 0) { SetDParam(0, time); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index b6660cc49c..280a5fd4b1 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1957,7 +1957,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int } case VST_TIMETABLE_DELAY: { - if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DATE_UNIT_SIZE == 0)) { + if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / TimetableDisplayUnitSize() == 0)) { str = STR_VEHICLE_LIST_TIMETABLE_DELAY_ON_TIME; } else { str = v->lateness_counter > 0 ? STR_VEHICLE_LIST_TIMETABLE_DELAY_LATE : STR_VEHICLE_LIST_TIMETABLE_DELAY_EARLY;