MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetVehicleSet

Function GetVehicleSet

src/vehicle.cpp:3206–3226  ·  view source on GitHub ↗

* Calculates the set of vehicles that will be affected by a given selection. * @param[in,out] set Set of affected vehicles. * @param v First vehicle of the selection. * @param num_vehicles Number of vehicles in the selection (not counting articulated parts). * @pre \a set must be empty. * @post \a set will contain the vehicles that will be refitted. */

Source from the content-addressed store, hash-verified

3204 * @post \a set will contain the vehicles that will be refitted.
3205 */
3206void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles)
3207{
3208 if (v->type == VEH_TRAIN) {
3209 Train *u = Train::From(v);
3210 /* Only include whole vehicles, so start with the first articulated part */
3211 u = u->GetFirstEnginePart();
3212
3213 /* Include num_vehicles vehicles, not counting articulated parts */
3214 for (; u != nullptr && num_vehicles > 0; num_vehicles--) {
3215 do {
3216 /* Include current vehicle in the selection. */
3217 include(set, u->index);
3218
3219 /* If the vehicle is multiheaded, add the other part too. */
3220 if (u->IsMultiheaded()) include(set, u->other_multiheaded_part->index);
3221
3222 u = u->Next();
3223 } while (u != nullptr && u->IsArticulatedPart());
3224 }
3225 }
3226}
3227
3228/**
3229 * Calculates the maximum weight of the ground vehicle when loaded.

Callers 3

RefitVehicleFunction · 0.85
BuildRefitListMethod · 0.85
DrawWidgetMethod · 0.85

Calls 5

includeFunction · 0.85
IsMultiheadedMethod · 0.80
IsArticulatedPartMethod · 0.80
GetFirstEnginePartMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected