mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use economy dates for vehicle service dates
parent
89eedf49aa
commit
7ab048195d
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -114,7 +114,6 @@ void TimerManager<TimerGameCalendar>::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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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. */
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue