Changing day length or date no longer changes time in minutes

Add offset variables for scaled date ticks.
Adjust offset when changing day length or date, such that scaled
date ticks remain the same.
Store _scaled_tick_counter and scaled date ticks offset in the savagame.
This commit is contained in:
Jonathan G Rennison 2022-12-15 22:54:42 +00:00
parent 9038c849ab
commit 3877bb31ef
18 changed files with 127 additions and 48 deletions

View File

@ -33,6 +33,7 @@ uint64 _tick_counter; ///< Ever incrementing tick counter for setting off vario
uint8 _tick_skip_counter; ///< Counter for ticks, when only vehicles are moving and nothing else happens
uint64 _scaled_tick_counter; ///< Tick counter in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks; ///< Date as ticks in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks_offset; ///< Offset to add when generating _scaled_date_ticks
uint32 _quit_after_days; ///< Quit after this many days of run time
YearMonthDay _game_load_cur_date_ymd;
@ -41,12 +42,48 @@ uint8 _game_load_tick_skip_counter;
extern void ClearOutOfDateSignalSpeedRestrictions();
void CheckScaledDateTicksWrap()
{
DateTicksScaled tick_adjust = 0;
auto get_tick_adjust = [&](DateTicksScaled target) {
int32 rounding = _settings_time.time_in_minutes * 1440;
return target - (target % rounding);
};
if (_scaled_date_ticks >= ((int64)1 << 60)) {
tick_adjust = get_tick_adjust(_scaled_date_ticks);
} else if (_scaled_date_ticks <= -((int64)1 << 60)) {
tick_adjust = -get_tick_adjust(-_scaled_date_ticks);
} else {
return;
}
_scaled_date_ticks_offset -= tick_adjust;
_scaled_date_ticks -= tick_adjust;
extern void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaled delta);
AdjustAllSignalSpeedRestrictionTickValues(-tick_adjust);
extern void AdjustVehicleScaledTickBase(int64 delta);
AdjustVehicleScaledTickBase(-tick_adjust);
}
void RebaseScaledDateTicksBase()
{
DateTicksScaled old_scaled_date_ticks = _scaled_date_ticks;
SetScaledTickVariables();
_scaled_date_ticks_offset += (old_scaled_date_ticks - _scaled_date_ticks);
SetScaledTickVariables();
assert(old_scaled_date_ticks == _scaled_date_ticks);
CheckScaledDateTicksWrap();
}
/**
* Set the date.
* @param date New date
* @param fract The number of ticks that have passed on this date.
*/
void SetDate(Date date, DateFract fract)
void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks)
{
assert(fract < DAY_TICKS);
@ -56,14 +93,17 @@ void SetDate(Date date, DateFract fract)
_date_fract = fract;
ConvertDateToYMD(date, &ymd);
_cur_date_ymd = ymd;
SetScaledTickVariables();
if (preserve_scaled_ticks) {
RebaseScaledDateTicksBase();
} else {
SetScaledTickVariables();
}
UpdateCachedSnowLine();
}
void SetScaledTickVariables()
{
_scaled_date_ticks = ((((DateTicksScaled)_date * DAY_TICKS) + _date_fract) * _settings_game.economy.day_length_factor) + _tick_skip_counter;
_scaled_tick_counter = (uint64)((_tick_counter * _settings_game.economy.day_length_factor) + _tick_skip_counter);
_scaled_date_ticks = ((((DateTicksScaled)_date * DAY_TICKS) + _date_fract) * _settings_game.economy.day_length_factor) + _tick_skip_counter + _scaled_date_ticks_offset;
}
#define M(a, b) ((a << 5) | b)
@ -236,12 +276,15 @@ static void OnNewYear()
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
ShiftOrderDates(-days_this_year);
ShiftVehicleDates(-days_this_year);
_scaled_date_ticks_offset += ((int64)days_this_year) * (DAY_TICKS * _settings_game.economy.day_length_factor);
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
* all of them if the date is set back, else those messages will hang for ever */
NetworkInitChatMessage();
}
CheckScaledDateTicksWrap();
if (_settings_client.gui.auto_euro) CheckSwitchToEuro();
IConsoleCmdExec("exec scripts/on_newyear.scr 0");
}

View File

@ -11,6 +11,8 @@
#define DATE_FUNC_H
#include "date_type.h"
#include "settings_type.h"
#include <utility>
extern YearMonthDay _cur_date_ymd;
extern Date _date;
@ -19,13 +21,14 @@ extern uint64 _tick_counter;
extern uint8 _tick_skip_counter;
extern uint64 _scaled_tick_counter;
extern DateTicksScaled _scaled_date_ticks;
extern DateTicksScaled _scaled_date_ticks_offset;
extern uint32 _quit_after_days;
extern YearMonthDay _game_load_cur_date_ymd;
extern DateFract _game_load_date_fract;
extern uint8 _game_load_tick_skip_counter;
void SetDate(Date date, DateFract fract);
void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks = true);
void ConvertDateToYMD(Date date, YearMonthDay *ymd);
Date ConvertYMDToDate(Year year, Month month, Day day);
void SetScaledTickVariables();
@ -47,4 +50,37 @@ static inline bool IsLeapYear(Year yr)
return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0);
}
static inline Date ScaledDateTicksToDate(DateTicksScaled ticks)
{
return (ticks - _scaled_date_ticks_offset) / (DAY_TICKS * _settings_game.economy.day_length_factor);
}
static inline DateTicksScaled DateToScaledDateTicks(Date date)
{
return ((int64)date * DAY_TICKS * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset;
}
static inline DateTicks ScaledDateTicksToDateTicks(DateTicksScaled ticks)
{
return (ticks - _scaled_date_ticks_offset) / _settings_game.economy.day_length_factor;
}
static inline DateTicksScaled DateTicksToScaledDateTicks(DateTicks date_ticks)
{
return ((int64)date_ticks * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset;
}
static inline std::pair<DateTicks, uint16> ScaledDateTicksToDateTicksAndSubTicks(DateTicksScaled ticks)
{
ticks -= _scaled_date_ticks_offset;
return std::make_pair<DateTicks, uint16>(ticks / _settings_game.economy.day_length_factor, ticks % _settings_game.economy.day_length_factor);
}
static inline std::pair<Date, uint16> ScaledDateTicksToDateAndFullSubTicks(DateTicksScaled ticks)
{
ticks -= _scaled_date_ticks_offset;
const int full_date = _settings_game.economy.day_length_factor * DAY_TICKS;
return std::make_pair<Date, uint16>(ticks / full_date, ticks % full_date);
}
#endif /* DATE_FUNC_H */

View File

@ -154,8 +154,7 @@ struct SetDateWindow : Window {
break;
case WID_SD_SET_DATE:
if (this->callback != nullptr) {
this->callback(this, ConvertYMDToDate(this->date.year, this->date.month, this->date.day)
* DAY_TICKS * _settings_game.economy.day_length_factor);
this->callback(this, DateToScaledDateTicks(ConvertYMDToDate(this->date.year, this->date.month, this->date.day)));
}
delete this;
break;
@ -372,8 +371,7 @@ void ShowSetDateWindow(Window *parent, int window_number, DateTicksScaled initia
DeleteWindowByClass(WC_SET_DATE);
if (!_settings_time.time_in_minutes) {
new SetDateWindow(&_set_date_desc, window_number, parent, initial_date / (DAY_TICKS * _settings_game.economy.day_length_factor),
min_year, max_year, callback, button_text, button_tooltip);
new SetDateWindow(&_set_date_desc, window_number, parent, ScaledDateTicksToDate(initial_date), min_year, max_year, callback, button_text, button_tooltip);
} else {
new SetMinutesWindow(&_set_minutes_desc, window_number, parent,
initial_date + (_settings_game.economy.day_length_factor * (_settings_time.clock_offset * _settings_time.ticks_per_minute)),

View File

@ -241,7 +241,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* The maximum possible date for departures to be scheduled to occur. */
DateTicksScaled max_date = _settings_client.gui.max_departure_time * DAY_TICKS * _settings_game.economy.day_length_factor;
DateTicksScaled date_only_scaled = ((DateTicksScaled)_date * DAY_TICKS * _settings_game.economy.day_length_factor);
DateTicksScaled date_only_scaled = DateToScaledDateTicks(_date);
DateTicksScaled date_fract_scaled = ((DateTicksScaled)_date_fract * _settings_game.economy.day_length_factor) + _tick_skip_counter;
/* The scheduled order in next_orders with the earliest expected_date field. */

View File

@ -88,6 +88,8 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
_game_speed = 100;
_tick_counter = 0;
_tick_skip_counter = 0;
_scaled_tick_counter = 0;
_scaled_date_ticks_offset = 0;
_cur_tileloop_tile = 1;
_thd.redsq = INVALID_TILE;
_road_layout_change_counter = 0;
@ -107,7 +109,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
_newgrf_profilers.clear();
if (reset_date) {
SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0);
SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0, false);
InitializeOldNames();
} else {
SetScaledTickVariables();

View File

@ -11394,6 +11394,8 @@ void LoadNewGRF(uint load_index, uint num_baseset)
DateFract date_fract = _date_fract;
uint64 tick_counter = _tick_counter;
uint8 tick_skip_counter = _tick_skip_counter;
uint64 scaled_tick_counter = _scaled_tick_counter;
DateTicksScaled scaled_date_ticks_offset = _scaled_date_ticks_offset;
byte display_opt = _display_opt;
if (_networking) {
@ -11402,6 +11404,8 @@ void LoadNewGRF(uint load_index, uint num_baseset)
_date_fract = 0;
_tick_counter = 0;
_tick_skip_counter = 0;
_scaled_tick_counter = 0;
_scaled_date_ticks_offset = 0;
_display_opt = 0;
UpdateCachedSnowLine();
SetScaledTickVariables();
@ -11507,6 +11511,8 @@ void LoadNewGRF(uint load_index, uint num_baseset)
_date_fract = date_fract;
_tick_counter = tick_counter;
_tick_skip_counter = tick_skip_counter;
_scaled_tick_counter = scaled_tick_counter;
_scaled_date_ticks_offset = scaled_date_ticks_offset;
_display_opt = display_opt;
UpdateCachedSnowLine();
SetScaledTickVariables();

View File

@ -1952,8 +1952,8 @@ void StateGameLoop()
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
_tick_skip_counter++;
_scaled_tick_counter++; // This must update in lock-step with _tick_skip_counter, such that it always matches what SetScaledTickVariables would return.
_scaled_date_ticks++; // "
_scaled_tick_counter++;
_scaled_date_ticks++; // This must update in lock-step with _tick_skip_counter, such that it always matches what SetScaledTickVariables would return.
if (_settings_client.gui.autosave == 6 && !(_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) &&
(_scaled_date_ticks % (_settings_client.gui.autosave_custom_minutes * (60000 / MILLISECONDS_PER_TICK))) == 0) {

View File

@ -806,10 +806,13 @@ bool AfterLoadGame()
if (SlXvIsFeatureMissing(XSLFI_VARIABLE_DAY_LENGTH) && SlXvIsFeatureMissing(XSLFI_SPRINGPP) && SlXvIsFeatureMissing(XSLFI_JOKERPP) && SlXvIsFeatureMissing(XSLFI_CHILLPP)) {
_settings_game.economy.day_length_factor = 1;
}
if (SlXvIsFeatureMissing(XSLFI_VARIABLE_DAY_LENGTH, 3)) {
_scaled_tick_counter = (uint64)((_tick_counter * _settings_game.economy.day_length_factor) + _tick_skip_counter);
}
/* Update current year
* must be done before loading sprites as some newgrfs check it */
SetDate(_date, _date_fract);
SetDate(_date, _date_fract, false);
/*
* Force the old behaviour for compatibility reasons with old savegames. As new

View File

@ -97,7 +97,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_VEHICLE_REPAIR_COST, XSCF_NULL, 2, 2, "vehicle_repair_cost", nullptr, nullptr, nullptr },
{ XSLFI_ENH_VIEWPORT_PLANS, XSCF_IGNORABLE_ALL, 4, 4, "enh_viewport_plans", nullptr, nullptr, "PLAN" },
{ XSLFI_INFRA_SHARING, XSCF_NULL, 2, 2, "infra_sharing", nullptr, nullptr, "CPDP" },
{ XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 2, 2, "variable_day_length", nullptr, nullptr, nullptr },
{ XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 3, 3, "variable_day_length", nullptr, nullptr, nullptr },
{ XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 2, 2, "order_occupancy", nullptr, nullptr, nullptr },
{ XSLFI_MORE_COND_ORDERS, XSCF_NULL, 13, 13, "more_cond_orders", nullptr, nullptr, nullptr },
{ XSLFI_EXTRA_LARGE_MAP, XSCF_NULL, 0, 1, "extra_large_map", nullptr, nullptr, nullptr },

View File

@ -79,6 +79,8 @@ static const SaveLoad _date_desc[] = {
SLEG_CONDVAR_X(_tick_counter, SLE_FILE_U16 | SLE_VAR_U64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_U64_TICK_COUNTER, 0, 0)),
SLEG_CONDVAR_X(_tick_counter, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_U64_TICK_COUNTER)),
SLEG_CONDVAR_X(_tick_skip_counter, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH)),
SLEG_CONDVAR_X(_scaled_tick_counter, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)),
SLEG_CONDVAR_X(_scaled_date_ticks_offset, SLE_INT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)),
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_157), // _vehicle_id_ctr_day
SLEG_CONDVAR(_age_cargo_skip_counter, SLE_UINT8, SL_MIN_VERSION, SLV_162),
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_46),
@ -110,6 +112,8 @@ static const SaveLoad _date_check_desc[] = {
SLE_CONDNULL_X(2, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_U64_TICK_COUNTER, 0, 0)), // _tick_counter
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_U64_TICK_COUNTER)), // _tick_counter
SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH)), // _tick_skip_counter
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)), // _scaled_tick_counter
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)), // _scaled_date_ticks_offset
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_157), // _vehicle_id_ctr_day
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_162), // _age_cargo_skip_counter
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_46),

View File

@ -10,7 +10,7 @@
#ifndef SCHDISPATCH_H
#define SCHDISPATCH_H
#include "date_type.h"
#include "date_func.h"
#include "vehicle_type.h"
#include "settings_type.h"
@ -25,7 +25,7 @@ void SchdispatchInvalidateWindows(const Vehicle *v);
*/
inline DateTicksScaled SchdispatchConvertToScaledTick(Date date, uint16 full_date_fract)
{
return ((DateTicksScaled)date * DAY_TICKS) * _settings_game.economy.day_length_factor + full_date_fract;
return DateToScaledDateTicks(date) + full_date_fract;
}
/**
@ -36,9 +36,7 @@ inline DateTicksScaled SchdispatchConvertToScaledTick(Date date, uint16 full_dat
*/
inline void SchdispatchConvertToFullDateFract(DateTicksScaled tick, Date* date, uint16* full_date_fract)
{
const int full_date = _settings_game.economy.day_length_factor * DAY_TICKS;
*date = tick / full_date;
*full_date_fract = tick % full_date;
std::tie(*date, *full_date_fract) = ScaledDateTicksToDateAndFullSubTicks(tick);
}
#endif /* SCHDISPATCH_H */

View File

@ -1711,14 +1711,8 @@ static void ImprovedBreakdownsSettingChanged(int32 new_value)
static void DayLengthChanged(int32 new_value)
{
const DateTicksScaled old_scaled_date_ticks = _scaled_date_ticks;
SetScaledTickVariables();
extern void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaled delta);
AdjustAllSignalSpeedRestrictionTickValues(_scaled_date_ticks - old_scaled_date_ticks);
extern void AdjustVehicleScaledTickBase(int64 delta);
AdjustVehicleScaledTickBase(_scaled_date_ticks - old_scaled_date_ticks);
extern void RebaseScaledDateTicksBase();
RebaseScaledDateTicksBase();
MarkWholeScreenDirty();
}

View File

@ -115,7 +115,7 @@ struct StatusBarWindow : Window {
Dimension d;
switch (widget) {
case WID_S_LEFT:
SetDParam(0, (uint64)MAX_YEAR * (uint64)DAYS_IN_YEAR * (uint64)DAY_TICKS * (uint64)_settings_game.economy.day_length_factor);
SetDParam(0, DateToScaledDateTicks(MAX_YEAR * DAYS_IN_YEAR));
d = GetStringBoundingBox(STR_WHITE_DATE_WALLCLOCK_LONG);
break;

View File

@ -447,7 +447,7 @@ static char *FormatWallClockString(char *buff, DateTicksScaled ticks, const char
seprintf(hour, lastof(hour), "%02i", (int) MINUTES_HOUR(minutes) );
seprintf(minute, lastof(minute), "%02i", (int) MINUTES_MINUTE(minutes));
if (show_date) {
int64 args[3] = { (int64)hour, (int64)minute, (int64)ticks / (DAY_TICKS * _settings_game.economy.day_length_factor) };
int64 args[3] = { (int64)hour, (int64)minute, ScaledDateTicksToDate(ticks) };
if (_settings_client.gui.date_with_time == 1) {
YearMonthDay ymd;
ConvertDateToYMD(args[2], &ymd);
@ -1508,7 +1508,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (_settings_time.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 * _settings_game.economy.day_length_factor), last, next_substr_case_index);
buff = FormatYmdString(buff, ScaledDateTicksToDate(args->GetInt64(SCC_DATE_WALLCLOCK_LONG)), last, next_substr_case_index);
}
break;
}
@ -1517,7 +1517,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (_settings_time.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 * _settings_game.economy.day_length_factor), last, next_substr_case_index);
buff = FormatYmdString(buff, ScaledDateTicksToDate(args->GetInt64(SCC_DATE_WALLCLOCK_SHORT)), last, next_substr_case_index);
}
break;
}
@ -1526,7 +1526,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (_settings_time.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 * _settings_game.economy.day_length_factor), STR_FORMAT_DATE_TINY, last);
buff = FormatTinyOrISODate(buff, ScaledDateTicksToDate(args->GetInt64(SCC_DATE_WALLCLOCK_TINY)), STR_FORMAT_DATE_TINY, last);
}
break;
}
@ -1535,7 +1535,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (_settings_time.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 * _settings_game.economy.day_length_factor), STR_FORMAT_DATE_ISO, last);
buff = FormatTinyOrISODate(buff, ScaledDateTicksToDate(args->GetInt64(SCC_DATE_WALLCLOCK_ISO)), STR_FORMAT_DATE_ISO, last);
}
break;
}

View File

@ -461,7 +461,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (timetable_all && !v->orders->IsCompleteTimetable()) return CMD_ERROR;
const DateTicksScaled now = _scaled_date_ticks;
DateTicksScaled start_date_scaled = (_settings_game.economy.day_length_factor * (((DateTicksScaled)_date * DAY_TICKS) + _date_fract + (DateTicksScaled)(int32)p2)) + sub_ticks;
DateTicksScaled start_date_scaled = DateToScaledDateTicks(_date * DAY_TICKS + _date_fract + (int32)p2) + sub_ticks;
if (flags & DC_EXEC) {
std::vector<Vehicle *> vehs;
@ -493,8 +493,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (tt_start < now && idx < 0) {
tt_start += total_duration;
}
w->timetable_start = tt_start / _settings_game.economy.day_length_factor;
w->timetable_start_subticks = tt_start % _settings_game.economy.day_length_factor;
std::tie(w->timetable_start, w->timetable_start_subticks) = ScaledDateTicksToDateTicksAndSubTicks(tt_start);
++idx;
}
@ -863,7 +862,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
if (!set_scheduled_dispatch) just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
if (v->timetable_start != 0) {
v->lateness_counter = _scaled_date_ticks - ((_settings_game.economy.day_length_factor * ((DateTicksScaled) v->timetable_start)) + v->timetable_start_subticks);
v->lateness_counter = _scaled_date_ticks - (DateTicksToScaledDateTicks(v->timetable_start) + v->timetable_start_subticks);
v->timetable_start = 0;
v->timetable_start_subticks = 0;
}

View File

@ -251,8 +251,9 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
*/
static void ChangeTimetableStartIntl(uint32 p1, DateTicksScaled date)
{
DateTicks date_part = date / _settings_game.economy.day_length_factor;
uint32 sub_ticks = date % _settings_game.economy.day_length_factor;
DateTicks date_part;
uint16 sub_ticks;
std::tie(date_part, sub_ticks) = ScaledDateTicksToDateTicksAndSubTicks(date);
DoCommandP(0, p1 | (sub_ticks << 21), (Ticks)(date_part - (((DateTicks)_date * DAY_TICKS) + _date_fract)), CMD_SET_TIMETABLE_START | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
}
@ -815,7 +816,7 @@ struct TimetableWindow : GeneralVehicleWindow {
/* We are running towards the first station so we can start the
* timetable at the given time. */
SetDParam(0, STR_JUST_DATE_WALLCLOCK_TINY);
SetDParam(1, (((DateTicksScaled) v->timetable_start) * _settings_game.economy.day_length_factor) + v->timetable_start_subticks);
SetDParam(1, DateTicksToScaledDateTicks(v->timetable_start) + v->timetable_start_subticks);
DrawString(tr, STR_TIMETABLE_STATUS_START_AT);
} else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
/* We aren't running on a timetable yet, so how can we be "on time"

View File

@ -2023,13 +2023,13 @@ int GetTraceRestrictTimeDateValueFromDate(TraceRestrictTimeDateValueField type,
case TRTDVF_DAY: {
YearMonthDay ymd;
ConvertDateToYMD(scaled_date_ticks / (DAY_TICKS * _settings_game.economy.day_length_factor), &ymd);
ConvertDateToYMD(ScaledDateTicksToDate(scaled_date_ticks), &ymd);
return ymd.day;
}
case TRTDVF_MONTH: {
YearMonthDay ymd;
ConvertDateToYMD(scaled_date_ticks / (DAY_TICKS * _settings_game.economy.day_length_factor), &ymd);
ConvertDateToYMD(ScaledDateTicksToDate(scaled_date_ticks), &ymd);
return ymd.month + 1;
}

View File

@ -4575,11 +4575,6 @@ void ShiftVehicleDates(int interval)
for (Vehicle *v : Vehicle::Iterate()) {
v->date_of_last_service += interval;
}
extern void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaled delta);
AdjustAllSignalSpeedRestrictionTickValues(interval * DAY_TICKS * _settings_game.economy.day_length_factor);
AdjustVehicleScaledTickBase(interval * DAY_TICKS * _settings_game.economy.day_length_factor);
}
/**