diff options
author | frosch <frosch@openttd.org> | 2011-01-23 14:58:54 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-01-23 14:58:54 +0000 |
commit | 9a1c0f139aeafd3ff550d0689e3a4c227927f0e5 (patch) | |
tree | 45c8b5f0450ca60560286502972b4c507494a0a5 /src/vehicle.cpp | |
parent | 3f103c35a6af62993cc01d53d9fd4554f353bf60 (diff) | |
download | openttd-9a1c0f139aeafd3ff550d0689e3a4c227927f0e5.tar.xz |
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 19c11eae2..d5b2b5c60 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2359,7 +2359,7 @@ const GroundVehicleCache *Vehicle::GetGroundVehicleCache() const * Calculates the set of vehicles that will be affected by a given selection. * @param set Set of affected vehicles. * @param v First vehicle of the selection. - * @param num_vehicles Number of vehicles in the selection. + * @param num_vehicles Number of vehicles in the selection (not counting articulated parts). * @pre \c set must be empty. * @post \c set will contain the vehicles that will be refitted. */ @@ -2367,27 +2367,20 @@ void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles) { if (v->type == VEH_TRAIN) { Train *u = Train::From(v); - /* If the first vehicle in the selection is part of an articulated vehicle, add the previous parts of the vehicle. */ - if (u->IsArticulatedPart()) { - u = u->GetFirstEnginePart(); - while (u->index != v->index) { - set.Include(u->index); - u = u->GetNextArticulatedPart(); - } - } + /* Only include whole vehicles, so start with the first articulated part */ + u = u->GetFirstEnginePart(); - for (;u != NULL && num_vehicles > 0; num_vehicles--, u = u->Next()) { - /* Include current vehicle in the selection. */ - set.Include(u->index); + /* Include num_vehicles vehicles, not counting articulated parts */ + for (; u != NULL && num_vehicles > 0; num_vehicles--) { + do { + /* Include current vehicle in the selection. */ + set.Include(u->index); - /* If the vehicle is multiheaded, add the other part too. */ - if (u->IsMultiheaded()) set.Include(u->other_multiheaded_part->index); - } + /* If the vehicle is multiheaded, add the other part too. */ + if (u->IsMultiheaded()) set.Include(u->other_multiheaded_part->index); - /* If the last vehicle is part of an articulated vehicle, add the following parts of the vehicle. */ - while (u != NULL && u->IsArticulatedPart()) { - set.Include(u->index); - u = u->Next(); + u = u->Next(); + } while (u != NULL && u->IsArticulatedPart()); } } } |