diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 14589f8c51..a331f35972 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -480,7 +480,7 @@ void Aircraft::OnNewDay() if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this); - AgeVehicle(this); + if (!EconTime::UsingWallclockUnits()) AgeVehicle(this); } void Aircraft::OnPeriodic() diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index c2701d1c79..0e1e20f901 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -2302,7 +2302,7 @@ static void CheckIfRoadVehNeedsService(RoadVehicle *v) void RoadVehicle::OnNewDay() { - AgeVehicle(this); + if (!EconTime::UsingWallclockUnits()) AgeVehicle(this); if (!this->IsFrontEngine()) return; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index ba755bf0cc..91853f619e 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -290,7 +290,7 @@ void Ship::OnNewDay() if ((++this->day_counter & 7) == 0) { DecreaseVehicleValue(this); } - AgeVehicle(this); + if (!EconTime::UsingWallclockUnits()) AgeVehicle(this); } void Ship::OnPeriodic() diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index fba6eb4e98..d0ab5e0a5e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -6889,7 +6889,7 @@ static void CheckIfTrainNeedsService(Train *v) /** Update day counters of the train vehicle. */ void Train::OnNewDay() { - AgeVehicle(this); + if (!EconTime::UsingWallclockUnits()) AgeVehicle(this); if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 155f14fe0a..1f539f24e0 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1369,6 +1369,41 @@ static void RunVehicleDayProc() } } +/** + * Increases the day counter for all vehicles and calls 1-day and 32-day handlers. + * Each tick, it processes vehicles with "index % DAY_TICKS == _date_fract", + * so each day, all vehicles are processes in DAY_TICKS steps. + */ +static void RunVehicleCalendarDayProc() +{ + if (_game_mode != GM_NORMAL) return; + + Vehicle *v = nullptr; + SCOPE_INFO_FMT([&v], "RunVehicleCalendarDayProc: %s", scope_dumper().VehicleInfo(v)); + for (size_t i = CalTime::CurDateFract(); i < Vehicle::GetPoolSize(); i += DAY_TICKS) { + v = Vehicle::Get(i); + if (v == nullptr) continue; + + /* This is called once per day for each vehicle, but not in the first tick of the day */ + switch (v->type) { + case VEH_TRAIN: + AgeVehicle(v); + break; + case VEH_ROAD: + if (v->IsFrontEngine()) AgeVehicle(v); + break; + case VEH_SHIP: + if (static_cast(v)->IsPrimaryVehicle()) AgeVehicle(v); + break; + case VEH_AIRCRAFT: + if (static_cast(v)->IsNormalAircraft()) AgeVehicle(v); + break; + default: + break; + } + } +} + static void ShowAutoReplaceAdviceMessage(const CommandCost &res, const Vehicle *v) { StringID error_message = res.GetErrorMessage(); @@ -1530,6 +1565,10 @@ void CallVehicleTicks() if (TickSkipCounter() == 0) RunVehicleDayProc(); + if (EconTime::UsingWallclockUnits() && _settings_game.economy.minutes_per_calendar_year != CalTime::FROZEN_MINUTES_PER_YEAR && CalTime::Detail::now.sub_date_fract == 0) { + RunVehicleCalendarDayProc(); + } + if (DayLengthFactor() >= 8 && _game_mode == GM_NORMAL) { /* * Vehicle::OnPeriodic is decoupled from Vehicle::OnNewDay at day lengths >= 8