1
0
Fork 0

Codechange: Iterate group vehicle lists for WhoCanServiceIndustry

pull/10548/head
SamuXarick 2023-12-30 21:37:34 +00:00
parent e1f07a56ee
commit becb273ed4
1 changed files with 29 additions and 30 deletions

View File

@ -2684,22 +2684,19 @@ int WhoCanServiceIndustry(Industry *ind)
if (ind->stations_near.empty()) return 0; // No stations found at all => nobody services if (ind->stations_near.empty()) return 0; // No stations found at all => nobody services
int result = 0; int result = 0;
for (const Vehicle *v : Vehicle::Iterate()) { for (const Company *c : Company::Iterate()) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
const VehicleList &vehicle_list = c->group_all[type].vehicle_list;
for (const Vehicle *v : vehicle_list) {
/* Is it worthwhile to try this vehicle? */ /* Is it worthwhile to try this vehicle? */
if (v->owner != _local_company && result != 0) continue; if (v->owner != _local_company && result != 0) continue;
/* Check whether it accepts the right kind of cargo */ /* Check whether it accepts the right kind of cargo */
bool c_accepts = false; bool c_accepts = false;
bool c_produces = false; bool c_produces = false;
if (v->type == VEH_TRAIN && v->IsFrontEngine()) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) { for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces); CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces);
} }
} else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) {
CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces);
} else {
continue;
}
if (!c_accepts && !c_produces) continue; // Wrong cargo if (!c_accepts && !c_produces) continue; // Wrong cargo
/* Check orders of the vehicle. /* Check orders of the vehicle.
@ -2722,6 +2719,8 @@ int WhoCanServiceIndustry(Industry *ind)
} }
} }
} }
}
}
return result; return result;
} }