|
@@ -2260,18 +2260,37 @@ const GroundVehicleCache *Vehicle::GetGr
|
|
|
|
|
|
/**
|
|
|
* 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.
|
|
|
* @pre \c set must be empty.
|
|
|
* @post \c set will contain the vehicles that will be refitted.
|
|
|
*/
|
|
|
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
|
|
|
{
|
|
|
if (v->type == VEH_TRAIN) {
|
|
|
for (Train *u = Train::From(v); u != NULL && num_vehicles > 0; num_vehicles--, u = u->Next()) {
|
|
|
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->GetNextArticPart();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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 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();
|
|
|
}
|
|
|
}
|
|
|
}
|