From 9a1c0f139aeafd3ff550d0689e3a4c227927f0e5 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 23 Jan 2011 14:58:54 +0000 Subject: (svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits. --- src/vehicle.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src/vehicle.cpp') 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()); } } } -- cgit v1.2.3-54-g00ecf