mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Iterate group vehicle lists for WhoCanServiceIndustry
parent
e1f07a56ee
commit
becb273ed4
|
@ -2684,22 +2684,19 @@ int WhoCanServiceIndustry(Industry *ind)
|
|||
if (ind->stations_near.empty()) return 0; // No stations found at all => nobody services
|
||||
|
||||
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? */
|
||||
if (v->owner != _local_company && result != 0) continue;
|
||||
|
||||
/* Check whether it accepts the right kind of cargo */
|
||||
bool c_accepts = false;
|
||||
bool c_produces = false;
|
||||
if (v->type == VEH_TRAIN && v->IsFrontEngine()) {
|
||||
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||
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
|
||||
|
||||
/* Check orders of the vehicle.
|
||||
|
@ -2722,6 +2719,8 @@ int WhoCanServiceIndustry(Industry *ind)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue