diff --git a/src/base_consist.cpp b/src/base_consist.cpp index c7fcdec..2005127 100644 --- a/src/base_consist.cpp +++ b/src/base_consist.cpp @@ -44,4 +44,8 @@ void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src) if (HasBit(src->vehicle_flags, VF_TIMETABLE_STARTED)) SetBit(this->vehicle_flags, VF_TIMETABLE_STARTED); if (HasBit(src->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(this->vehicle_flags, VF_AUTOFILL_TIMETABLE); if (HasBit(src->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) SetBit(this->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); + if (HasBit(src->vehicle_flags, VF_SERVINT_IS_PERCENT) != HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT)) { + ToggleBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); + } + if (HasBit(src->vehicle_flags, VF_SERVINT_IS_CUSTOM)) SetBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); } diff --git a/src/economy.cpp b/src/economy.cpp index 37a89b3..1d338d6 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -436,6 +436,21 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) { assert(new_owner != INVALID_OWNER); + /* Verify the service interval settings for mismatching defaults */ + Company *old_company = Company::Get(old_owner); + Company *new_company = Company::Get(new_owner); + + if (old_company->settings.vehicle.servint_ispercent != new_company->settings.vehicle.servint_ispercent) { + /* If the service interval types (day/percent) the value gets interpeted incorrectly. + * When the vehicle gets auto replaced this value will get accepted for whatever the setting happens to be. + * This could cause 150% intervals which is normally not valid. + * Forcibly adjust the vehicle to the same settings but with the VF_SERVINT_IS_CUSTOM enabled + */ + + uint16 interval = GetServiceIntervalClamped(v->GetServiceInterval(), old_company->settings.vehicle.servint_ispercent); + DoCommand(v->tile, v->index, interval | (1 << 16) | (old_company->settings.vehicle.servint_ispercent << 17), DC_EXEC | DC_BANKRUPT, CMD_CHANGE_SERVICE_INT); + } + v->owner = new_owner; /* Owner changes, clear cache */