diff options
author | frosch <frosch@openttd.org> | 2015-05-11 16:58:09 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2015-05-11 16:58:09 +0000 |
commit | 32cb62a242e0cdde9e733f4795d57ae54e967e76 (patch) | |
tree | 3fc1f07536bbb001a7743bcfb9623a613be5a41a /src | |
parent | e686add63a0d663c027672d5ab696a2e940b195e (diff) | |
download | openttd-32cb62a242e0cdde9e733f4795d57ae54e967e76.tar.xz |
(svn r27282) -Fix [FS#6254]: Enforce the company's default service intervals when purchasing another company. (Johnnei)
Diffstat (limited to 'src')
-rw-r--r-- | src/economy.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index 09eec0386..d78d2ccce 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -431,11 +431,38 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) FreeUnitIDGenerator(VEH_SHIP, new_owner), FreeUnitIDGenerator(VEH_AIRCRAFT, new_owner) }; + /* Override company settings to new company defaults in case we need to convert them. + * This is required as the CmdChangeServiceInt doesn't copy the supplied value when it is non-custom + */ + if (new_owner != INVALID_OWNER) { + Company *old_company = Company::Get(old_owner); + Company *new_company = Company::Get(new_owner); + + old_company->settings.vehicle.servint_aircraft = new_company->settings.vehicle.servint_aircraft; + old_company->settings.vehicle.servint_trains = new_company->settings.vehicle.servint_trains; + old_company->settings.vehicle.servint_roadveh = new_company->settings.vehicle.servint_roadveh; + old_company->settings.vehicle.servint_ships = new_company->settings.vehicle.servint_ships; + old_company->settings.vehicle.servint_ispercent = new_company->settings.vehicle.servint_ispercent; + } + Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) { assert(new_owner != INVALID_OWNER); + /* Correct default values of interval settings while maintaining custom set ones. + * This prevents invalid values on mismatching company defaults being accepted. + */ + if (!v->ServiceIntervalIsCustom()) { + Company *new_company = Company::Get(new_owner); + + /* Technically, passing the interval is not needed as the command will query the default value itself. + * However, do not rely on that behaviour. + */ + int interval = CompanyServiceInterval(new_company, v->type); + DoCommand(v->tile, v->index, interval | (new_company->settings.vehicle.servint_ispercent << 17), DC_EXEC | DC_BANKRUPT, CMD_CHANGE_SERVICE_INT); + } + v->owner = new_owner; /* Owner changes, clear cache */ |