diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 1f5f986282..1dc9f22d8f 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -22,6 +22,7 @@ #include "command_func.h" #include "window_func.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "vehicle_func.h" #include "sound_func.h" #include "cheat_type.h" @@ -338,7 +339,7 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine * v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_aircraft); - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->build_year = u->build_year = TimerGameCalendar::year; @@ -1555,7 +1556,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass * if (_settings_game.order.serviceathelipad) { if (v->subtype == AIR_HELICOPTER && apc->num_helipads > 0) { /* an excerpt of ServiceAircraft, without the invisibility stuff */ - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->breakdowns_since_last_service = 0; v->reliability = v->GetEngine()->reliability; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 80869d9c03..7dfa8863c0 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -21,6 +21,7 @@ #include "strings_func.h" #include "tunnelbridge_map.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "vehicle_func.h" #include "sound_func.h" #include "ai/ai.hpp" @@ -299,7 +300,7 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engin v->SetServiceInterval(Company::Get(v->owner)->settings.vehicle.servint_roadveh); - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->build_year = TimerGameCalendar::year; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 3a4467add4..54a73cd193 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1441,7 +1441,7 @@ bool AfterLoadGame() 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; } } @@ -3266,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(); } } diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 2e0186d714..a77b96fa6a 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -23,6 +23,7 @@ #include "strings_func.h" #include "window_func.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "vehicle_func.h" #include "sound_func.h" #include "ai/ai.hpp" @@ -902,7 +903,7 @@ CommandCost CmdBuildShip(DoCommandFlag flags, TileIndex tile, const Engine *e, V v->state = TRACK_BIT_DEPOT; v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships); - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->build_year = TimerGameCalendar::year; v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); diff --git a/src/timer/timer_game_calendar.cpp b/src/timer/timer_game_calendar.cpp index a30ff2bc8d..bcbef27820 100644 --- a/src/timer/timer_game_calendar.cpp +++ b/src/timer/timer_game_calendar.cpp @@ -114,7 +114,6 @@ void TimerManager::Elapsed([[maybe_unused]] TimerGameCalendar TimerGameCalendar::year--; days_this_year = TimerGameCalendar::IsLeapYear(TimerGameCalendar::year) ? CalendarTime::DAYS_IN_LEAP_YEAR : CalendarTime::DAYS_IN_YEAR; TimerGameCalendar::date -= days_this_year; - for (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year); for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year); } } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 848a1bad4e..5d847c5d8f 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -38,6 +38,7 @@ #include "train_cmd.h" #include "misc_cmd.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "table/strings.h" #include "table/train_sprites.h" @@ -653,7 +654,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlag flags, TileIndex tile, const v->railtype = rvi->railtype; - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->build_year = TimerGameCalendar::year; v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); @@ -787,7 +788,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engin v->railtype = rvi->railtype; v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_trains); - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->build_year = TimerGameCalendar::year; v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 0bf1e4a163..5f01b96aff 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -170,7 +170,7 @@ void VehicleServiceInDepot(Vehicle *v) SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated do { - v->date_of_last_service = TimerGameCalendar::date; + v->date_of_last_service = TimerGameEconomy::date; v->date_of_last_service_newgrf = TimerGameCalendar::date; v->breakdowns_since_last_service = 0; v->reliability = v->GetEngine()->reliability; @@ -197,7 +197,7 @@ bool Vehicle::NeedsServicing() const const Company *c = Company::Get(this->owner); if (this->ServiceIntervalIsPercent() ? (this->reliability >= this->GetEngine()->reliability * (100 - this->GetServiceInterval()) / 100) : - (this->date_of_last_service + this->GetServiceInterval() >= TimerGameCalendar::date)) { + (this->date_of_last_service + this->GetServiceInterval() >= TimerGameEconomy::date)) { return false; } @@ -767,9 +767,9 @@ uint32_t Vehicle::GetGRFID() const * This is useful if the date has been modified with the cheat menu. * @param interval Number of days to be added or substracted. */ -void Vehicle::ShiftDates(TimerGameCalendar::Date interval) +void Vehicle::ShiftDates(TimerGameEconomy::Date interval) { - this->date_of_last_service = std::max(this->date_of_last_service + interval, TimerGameCalendar::Date(0)); + this->date_of_last_service = std::max(this->date_of_last_service + interval, TimerGameEconomy::Date(0)); /* date_of_last_service_newgrf is not updated here as it must stay stable * for vehicles outside of a depot. */ } diff --git a/src/vehicle_base.h b/src/vehicle_base.h index cd0ac70aae..b2b27e324b 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -287,8 +287,8 @@ public: TimerGameCalendar::Year build_year; ///< Year the vehicle has been built. TimerGameCalendar::Date age; ///< Age in days TimerGameCalendar::Date max_age; ///< Maximum age - TimerGameCalendar::Date date_of_last_service; ///< Last date the vehicle had a service at a depot. - TimerGameCalendar::Date date_of_last_service_newgrf; ///< Last date the vehicle had a service at a depot, unchanged by the date cheat to protect against unsafe NewGRF behavior. + TimerGameEconomy::Date date_of_last_service; ///< Last economy date the vehicle had a service at a depot. + TimerGameCalendar::Date date_of_last_service_newgrf; ///< Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect against unsafe NewGRF behavior. uint16_t reliability; ///< Reliability. uint16_t reliability_spd_dec; ///< Reliability decrease speed. byte breakdown_ctr; ///< Counter for managing breakdown events. @see Vehicle::HandleBreakdown @@ -571,7 +571,7 @@ public: */ virtual void OnNewDay() {}; - void ShiftDates(TimerGameCalendar::Date interval); + void ShiftDates(TimerGameEconomy::Date interval); /** * Crash the (whole) vehicle chain. diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index de7bdb479a..4226d99ef6 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2431,7 +2431,7 @@ struct VehicleDetailsWindow : Window { case WID_VD_SERVICING_INTERVAL: SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval - SetDParamMaxValue(1, TimerGameCalendar::DateAtStartOfYear(CalendarTime::MAX_YEAR)); // Roughly the maximum year + SetDParamMaxValue(1, TimerGameEconomy::DateAtStartOfYear(EconomyTime::MAX_YEAR)); // Roughly the maximum year size->width = std::max( GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width, GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width