diff options
author | rubidium <rubidium@openttd.org> | 2011-10-30 20:24:00 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-10-30 20:24:00 +0000 |
commit | c6b2145da65e9553e190f33fc569217ca95f5e57 (patch) | |
tree | 59cf0d64b4b0647469a6400eebc1ae70db756d43 | |
parent | a561dadb49b61be81c262b41b24671d4f3a79e7e (diff) | |
download | openttd-c6b2145da65e9553e190f33fc569217ca95f5e57.tar.xz |
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
-rw-r--r-- | src/economy.cpp | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index 78d271242..84b1bc4c5 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -389,11 +389,6 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } { - FreeUnitIDGenerator unitidgen[] = { - FreeUnitIDGenerator(VEH_TRAIN, new_owner), FreeUnitIDGenerator(VEH_ROAD, new_owner), - FreeUnitIDGenerator(VEH_SHIP, new_owner), FreeUnitIDGenerator(VEH_AIRCRAFT, new_owner) - }; - Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) { @@ -402,21 +397,48 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } else { if (v->IsEngineCountable()) GroupStatistics::CountEngine(v, -1); if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, -1); + } + } + } + } + + /* In all cases clear replace engine rules. + * Even if it was copied, it could interfere with new owner's rules */ + RemoveAllEngineReplacementForCompany(Company::Get(old_owner)); - v->owner = new_owner; - v->colourmap = PAL_NONE; + if (new_owner == INVALID_OWNER) { + RemoveAllGroupsForCompany(old_owner); + } else { + Group *g; + FOR_ALL_GROUPS(g) { + if (g->owner == old_owner) g->owner = new_owner; + } + } - if (v->IsEngineCountable()) { - GroupStatistics::CountEngine(v, 1); - } - if (v->IsPrimaryVehicle()) { - GroupStatistics::CountVehicle(v, 1); - v->unitnumber = unitidgen[v->type].NextID(); - } + { + FreeUnitIDGenerator unitidgen[] = { + FreeUnitIDGenerator(VEH_TRAIN, new_owner), FreeUnitIDGenerator(VEH_ROAD, new_owner), + FreeUnitIDGenerator(VEH_SHIP, new_owner), FreeUnitIDGenerator(VEH_AIRCRAFT, new_owner) + }; + + Vehicle *v; + FOR_ALL_VEHICLES(v) { + if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) { + assert(new_owner != INVALID_OWNER); + + v->owner = new_owner; + v->colourmap = PAL_NONE; - /* Invalidate the vehicle's cargo payment "owner cache". */ - if (v->cargo_payment != NULL) v->cargo_payment->owner = NULL; + if (v->IsEngineCountable()) { + GroupStatistics::CountEngine(v, 1); } + if (v->IsPrimaryVehicle()) { + GroupStatistics::CountVehicle(v, 1); + v->unitnumber = unitidgen[v->type].NextID(); + } + + /* Invalidate the vehicle's cargo payment "owner cache". */ + if (v->cargo_payment != NULL) v->cargo_payment->owner = NULL; } } @@ -472,19 +494,6 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } } - /* In all cases clear replace engine rules. - * Even if it was copied, it could interfere with new owner's rules */ - RemoveAllEngineReplacementForCompany(Company::Get(old_owner)); - - if (new_owner == INVALID_OWNER) { - RemoveAllGroupsForCompany(old_owner); - } else { - Group *g; - FOR_ALL_GROUPS(g) { - if (g->owner == old_owner) g->owner = new_owner; - } - } - Sign *si; FOR_ALL_SIGNS(si) { if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner; |