(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.

This commit is contained in:
frosch 2011-01-23 14:58:54 +00:00
parent 3f103c35a6
commit 9a1c0f139a
3 changed files with 21 additions and 22 deletions

View File

@ -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) {
/* Only include whole vehicles, so start with the first articulated part */
u = u->GetFirstEnginePart();
/* 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);
u = u->GetNextArticulatedPart();
}
}
for (;u != NULL && num_vehicles > 0; num_vehicles--, u = u->Next()) {
/* 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());
}
}
}

View File

@ -245,7 +245,7 @@ static CommandCost GetRefitCost(EngineID engine_type)
* 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 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
* - 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
*/

View File

@ -758,9 +758,14 @@ struct RefitWindow : public Window {
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;
}
}