forked from mirror/OpenTTD
Codechange: Split dates and timers into Economy and Calendar time (#10700)
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
#include "../water.h"
|
||||
#include "../timer/timer.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../timer/timer_game_economy.h"
|
||||
#include "../timer/timer_game_tick.h"
|
||||
|
||||
#include "saveload_internal.h"
|
||||
@@ -260,8 +261,8 @@ static void InitializeWindowsAndCaches()
|
||||
/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
|
||||
* accordingly if it is not the case. No need to set it on companies that are not been used already,
|
||||
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
|
||||
if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != CalendarTime::MIN_YEAR) {
|
||||
c->inaugurated_year = TimerGameCalendar::year;
|
||||
if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != EconomyTime::MIN_YEAR) {
|
||||
c->inaugurated_year = TimerGameEconomy::year;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,6 +735,13 @@ bool AfterLoadGame()
|
||||
* must be done before loading sprites as some newgrfs check it */
|
||||
TimerGameCalendar::SetDate(TimerGameCalendar::date, TimerGameCalendar::date_fract);
|
||||
|
||||
/* Update economy year. If we don't have a separate economy date saved, follow the calendar date. */
|
||||
if (IsSavegameVersionBefore(SLV_ECONOMY_DATE)) {
|
||||
TimerGameEconomy::SetDate(TimerGameCalendar::date.base(), TimerGameCalendar::date_fract);
|
||||
} else {
|
||||
TimerGameEconomy::SetDate(TimerGameEconomy::date, TimerGameEconomy::date_fract);
|
||||
}
|
||||
|
||||
/*
|
||||
* Force the old behaviour for compatibility reasons with old savegames. As new
|
||||
* settings can only be loaded from new savegames loading old savegames with new
|
||||
@@ -1429,11 +1437,11 @@ bool AfterLoadGame()
|
||||
for (Station *st : Station::Iterate()) st->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
for (Engine *e : Engine::Iterate()) e->intro_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
for (Company *c : Company::Iterate()) c->inaugurated_year += CalendarTime::ORIGINAL_BASE_YEAR;
|
||||
for (Industry *i : Industry::Iterate()) i->last_prod_year += CalendarTime::ORIGINAL_BASE_YEAR;
|
||||
for (Company *c : Company::Iterate()) c->inaugurated_year += EconomyTime::ORIGINAL_BASE_YEAR;
|
||||
for (Industry *i : Industry::Iterate()) i->last_prod_year += EconomyTime::ORIGINAL_BASE_YEAR;
|
||||
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
v->date_of_last_service += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
v->date_of_last_service += EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
v->build_year += CalendarTime::ORIGINAL_BASE_YEAR;
|
||||
}
|
||||
}
|
||||
@@ -3258,7 +3266,7 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(SLV_NEWGRF_LAST_SERVICE)) {
|
||||
/* Set service date provided to NewGRF. */
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
v->date_of_last_service_newgrf = v->date_of_last_service;
|
||||
v->date_of_last_service_newgrf = v->date_of_last_service.base();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user