Fix non-percentage servicing interval when using wallclock mode
This commit is contained in:
@@ -237,12 +237,23 @@ bool Vehicle::NeedsServicing() const
|
|||||||
* vehicles to go for service is lame. */
|
* vehicles to go for service is lame. */
|
||||||
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
|
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? */
|
/* Are we ready for the next service cycle? */
|
||||||
bool needs_service = true;
|
bool needs_service = true;
|
||||||
const Company *c = Company::Get(this->owner);
|
const Company *c = Company::Get(this->owner);
|
||||||
if ((this->ServiceIntervalIsPercent() ?
|
if (service_not_due
|
||||||
(this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) :
|
|
||||||
(this->date_of_last_service + this->service_interval >= EconTime::CurDate()))
|
|
||||||
&& !(this->type == VEH_TRAIN && HasBit(Train::From(this)->flags, VRF_CONSIST_BREAKDOWN) && Train::From(this)->ConsistNeedsRepair())
|
&& !(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_ROAD && RoadVehicle::From(this)->critical_breakdown_count > 0)
|
||||||
&& !(this->type == VEH_SHIP && Ship::From(this)->critical_breakdown_count > 0)) {
|
&& !(this->type == VEH_SHIP && Ship::From(this)->critical_breakdown_count > 0)) {
|
||||||
|
Reference in New Issue
Block a user