diff --git a/src/date_type.h b/src/date_type.h index 505b289605..c7d8d72488 100644 --- a/src/date_type.h +++ b/src/date_type.h @@ -16,6 +16,7 @@ typedef int32 Date; ///< The type to store our dates in typedef uint16 DateFract; ///< The fraction of a date we're in, i.e. the number of ticks since the last date changeover typedef int32 Ticks; ///< The type to store ticks in typedef int32 DateTicks; ///< The type to store dates in when tick-precision is required +typedef int64 DateTicksScaled; ///< The type to store dates scaled by the day length factor in when tick-precision is required typedef int32 Minutes; ///< The type to store minutes in typedef int32 Year; ///< Type for the year, note: 0 based, i.e. starts at the year 0. @@ -32,7 +33,9 @@ static const int DAY_TICKS = 74; ///< ticks per day static const int DAYS_IN_YEAR = 365; ///< days per year static const int DAYS_IN_LEAP_YEAR = 366; ///< sometimes, you need one day more... -#define DATE_UNIT_SIZE (_settings_client.gui.time_in_minutes ? _settings_client.gui.ticks_per_minute : DAY_TICKS) +#define CURRENT_SCALED_TICKS (((((DateTicksScaled)_date * DAY_TICKS) + _date_fract) * _settings_game.economy.day_length_factor) + _tick_skip_counter) + +#define DATE_UNIT_SIZE (_settings_client.gui.time_in_minutes ? _settings_client.gui.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 @@ -111,7 +114,7 @@ static const Year MAX_YEAR = 5000000; #define MINUTES_DATE(day, hour, minute) ((day * 1440) + (hour * 60) + minute) /** Get the current date in minutes */ -#define CURRENT_MINUTE ((((DateTicks)_date * DAY_TICKS) + _date_fract) / _settings_client.gui.ticks_per_minute) +#define CURRENT_MINUTE (CURRENT_SCALED_TICKS / _settings_client.gui.ticks_per_minute) /** * Data structure to convert between Date and triplet (year, month, and day). diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 820869ee02..26e47a2f4d 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -139,7 +139,7 @@ struct StatusBarWindow : Window { switch (widget) { case WID_S_LEFT: /* Draw the date */ - SetDParam(0, ((DateTicks)_date * DAY_TICKS) + _date_fract); + SetDParam(0, CURRENT_SCALED_TICKS); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_WHITE_DATE_WALLCLOCK_LONG, TC_FROMSTRING, SA_HOR_CENTER); break; diff --git a/src/strings.cpp b/src/strings.cpp index 1e41363cb6..9cd544243b 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1229,7 +1229,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg if (_settings_client.gui.time_in_minutes) { buff = FormatWallClockString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_LONG), last, _settings_client.gui.date_with_time, next_substr_case_index); } else { - buff = FormatYmdString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_LONG) / DAY_TICKS, last, next_substr_case_index); + buff = FormatYmdString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_LONG) / (DAY_TICKS * _settings_game.economy.day_length_factor), last, next_substr_case_index); } break; } @@ -1238,7 +1238,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg if (_settings_client.gui.time_in_minutes) { buff = FormatWallClockString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_SHORT), last, _settings_client.gui.date_with_time, next_substr_case_index); } else { - buff = FormatYmdString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_SHORT) / DAY_TICKS, last, next_substr_case_index); + buff = FormatYmdString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_SHORT) / (DAY_TICKS * _settings_game.economy.day_length_factor), last, next_substr_case_index); } break; } @@ -1247,7 +1247,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg if (_settings_client.gui.time_in_minutes) { buff = FormatWallClockString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_TINY), last, false, next_substr_case_index); } else { - buff = FormatTinyOrISODate(buff, args->GetInt64(SCC_DATE_WALLCLOCK_TINY) / DAY_TICKS, STR_FORMAT_DATE_TINY, last); + buff = FormatTinyOrISODate(buff, args->GetInt64(SCC_DATE_WALLCLOCK_TINY) / (DAY_TICKS * _settings_game.economy.day_length_factor), STR_FORMAT_DATE_TINY, last); } break; } @@ -1256,7 +1256,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg if (_settings_client.gui.time_in_minutes) { buff = FormatWallClockString(buff, args->GetInt64(SCC_DATE_WALLCLOCK_ISO), last, false, next_substr_case_index); } else { - buff = FormatTinyOrISODate(buff, args->GetInt64(SCC_DATE_WALLCLOCK_ISO) / DAY_TICKS, STR_FORMAT_DATE_ISO, last); + buff = FormatTinyOrISODate(buff, args->GetInt64(SCC_DATE_WALLCLOCK_ISO) / (DAY_TICKS * _settings_game.economy.day_length_factor), STR_FORMAT_DATE_ISO, last); } break; }