Fix non-percentage servicing interval when using wallclock mode

This commit is contained in:
Jonathan G Rennison
2024-05-18 15:00:43 +01:00
parent 89902c8ab1
commit 6d1f3b673e

View File

@@ -237,12 +237,23 @@ bool Vehicle::NeedsServicing() const
* vehicles to go for service is lame. */
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
bool service_not_due;
/* Service intervals can be measured in different units, which we handle individually. */
if (this->ServiceIntervalIsPercent()) {
/* Service interval is in percents. */
service_not_due = (this->reliability >= this->GetEngine()->reliability * (100 - this->GetServiceInterval()) / 100);
} else if (EconTime::UsingWallclockUnits()) {
/* Service interval is in minutes. */
service_not_due = (this->date_of_last_service + (this->GetServiceInterval() * EconTime::DAYS_IN_ECONOMY_WALLCLOCK_MONTH) >= EconTime::CurDate());
} else {
/* Service interval is in days. */
service_not_due = (this->date_of_last_service + this->GetServiceInterval() >= EconTime::CurDate());
}
/* Are we ready for the next service cycle? */
bool needs_service = true;
const Company *c = Company::Get(this->owner);
if ((this->ServiceIntervalIsPercent() ?
(this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) :
(this->date_of_last_service + this->service_interval >= EconTime::CurDate()))
if (service_not_due
&& !(this->type == VEH_TRAIN && HasBit(Train::From(this)->flags, VRF_CONSIST_BREAKDOWN) && Train::From(this)->ConsistNeedsRepair())
&& !(this->type == VEH_ROAD && RoadVehicle::From(this)->critical_breakdown_count > 0)
&& !(this->type == VEH_SHIP && Ship::From(this)->critical_breakdown_count > 0)) {