Mercurial > hg > openttd
changeset 17164:bfc7b87f4672 draft
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
author | frosch <frosch@openttd.org> |
---|---|
date | Sun, 23 Jan 2011 14:58:54 +0000 |
parents | 5cdb72b33b97 |
children | 3c9baf898829 |
files | src/vehicle.cpp src/vehicle_cmd.cpp src/vehicle_gui.cpp |
diffstat | 3 files changed, 21 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2359,7 +2359,7 @@ * 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 @@ { 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()); } } }
--- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -245,7 +245,7 @@ * This is the vehicle-type independent part of the CmdRefitXXX functions. * @param v The vehicle to refit. * @param only_this Whether to only refit this vehicle, or to check the rest of them. - * @param num_vehicles Number of vehicles to refit. Zero means the whole chain. + * @param num_vehicles Number of vehicles to refit (not counting articulated parts). Zero means the whole chain. * @param new_cid Cargotype to refit to * @param new_subtype Cargo subtype to refit to * @param flags Command flags @@ -319,7 +319,8 @@ * - p2 = (bit 0-4) - New cargo type to refit to. * - p2 = (bit 7) - Refit only this vehicle. Used only for cloning vehicles. * - p2 = (bit 8-15) - New cargo subtype to refit to. - * - p2 = (bit 16-23) - Number of vehicles to refit. Zero means all vehicles. Only used if "refit only this vehicle" is false. + * - p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). Zero means all vehicles. + * Only used if "refit only this vehicle" is false. * @param text unused * @return the cost of this operation or an error */
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -758,9 +758,14 @@ if (left_x < 0 && !start_counting) { this->selected_vehicle = u->index; start_counting = true; + + /* Count the first vehicle, even if articulated part */ + this->num_vehicles++; + } else if (start_counting && !u->IsArticulatedPart()) { + /* Do not count articulated parts */ + this->num_vehicles++; } - if (start_counting) this->num_vehicles++; if (right_x < 0) break; } }