Saveload: Fix recalculation of _state_ticks
For XSLFI_VARIABLE_DAY_LENGTH versions 1 to 3
This commit is contained in:
@@ -110,14 +110,14 @@ EconTime::State EconTime::Detail::NewState(EconTime::Year year)
|
||||
return state;
|
||||
}
|
||||
|
||||
StateTicks GetStateTicksFromCurrentDateWithoutOffset()
|
||||
StateTicks GetStateTicksFromDateWithoutOffset(EconTime::Date date, EconTime::DateFract date_fract)
|
||||
{
|
||||
return ((int64_t)(EconTime::DateToDateTicks(EconTime::CurDate(), EconTime::CurDateFract()).base()) * DayLengthFactor()) + TickSkipCounter();
|
||||
return ((int64_t)(EconTime::DateToDateTicks(date, date_fract).base()) * DayLengthFactor()) + TickSkipCounter();
|
||||
}
|
||||
|
||||
void RecalculateStateTicksOffset()
|
||||
{
|
||||
DateDetail::_state_ticks_offset = _state_ticks - GetStateTicksFromCurrentDateWithoutOffset();
|
||||
DateDetail::_state_ticks_offset = _state_ticks - GetStateTicksFromDateWithoutOffset(EconTime::CurDate(), EconTime::CurDateFract());
|
||||
}
|
||||
|
||||
void UpdateEffectiveDayLengthFactor()
|
||||
|
@@ -24,7 +24,7 @@ namespace DateDetail {
|
||||
extern uint8_t _effective_day_length;
|
||||
};
|
||||
|
||||
StateTicks GetStateTicksFromCurrentDateWithoutOffset();
|
||||
StateTicks GetStateTicksFromDateWithoutOffset(EconTime::Date date, EconTime::DateFract date_fract);
|
||||
void RecalculateStateTicksOffset();
|
||||
|
||||
inline uint8_t TickSkipCounter()
|
||||
|
@@ -667,7 +667,12 @@ bool AfterLoadGame()
|
||||
|
||||
TileIndex map_size = MapSize();
|
||||
|
||||
/* Only new games can use wallclock units. */
|
||||
if (SlXvIsFeatureMissing(XSLFI_VARIABLE_DAY_LENGTH, 5) && IsSavegameVersionBefore(SLV_ECONOMY_MODE_TIMEKEEPING_UNITS)) {
|
||||
_settings_game.economy.timekeeping_units = TKU_CALENDAR;
|
||||
}
|
||||
UpdateEffectiveDayLengthFactor();
|
||||
|
||||
SetupTickRate();
|
||||
|
||||
extern TileIndex _cur_tileloop_tile; // From landscape.cpp.
|
||||
@@ -865,18 +870,15 @@ bool AfterLoadGame()
|
||||
_scaled_tick_counter = (uint64_t)((_tick_counter * DayLengthFactor()) + TickSkipCounter());
|
||||
}
|
||||
if (SlXvIsFeaturePresent(XSLFI_VARIABLE_DAY_LENGTH, 1, 3)) {
|
||||
_state_ticks = GetStateTicksFromCurrentDateWithoutOffset() + DateDetail::_state_ticks_offset;
|
||||
/* CalTime is used here because EconTime hasn't been set yet, but this needs to be done before setting EconTime::Detail::SetDate,
|
||||
* because that calls RecalculateStateTicksOffset which overwrites DateDetail::_state_ticks_offset which is an input here */
|
||||
_state_ticks = GetStateTicksFromDateWithoutOffset(CalTime::CurDate().base(), CalTime::CurDateFract()) + DateDetail::_state_ticks_offset;
|
||||
}
|
||||
|
||||
/* Update current year
|
||||
* must be done before loading sprites as some newgrfs check it */
|
||||
CalTime::Detail::SetDate(CalTime::CurDate(), CalTime::CurDateFract());
|
||||
|
||||
/* Only new games can use wallclock units. */
|
||||
if (SlXvIsFeatureMissing(XSLFI_VARIABLE_DAY_LENGTH, 5) && IsSavegameVersionBefore(SLV_ECONOMY_MODE_TIMEKEEPING_UNITS)) {
|
||||
_settings_game.economy.timekeeping_units = TKU_CALENDAR;
|
||||
}
|
||||
|
||||
if (SlXvIsFeaturePresent(XSLFI_VARIABLE_DAY_LENGTH, 5) || !IsSavegameVersionBefore(SLV_ECONOMY_DATE)) {
|
||||
EconTime::Detail::SetDate(EconTime::CurDate(), EconTime::CurDateFract());
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user