mirror of https://github.com/OpenTTD/OpenTTD
Change: Iterate group vehicle lists for GetPreviewCompany and NewVehicleAvailable
As a compromise, the result of this change differs from the original. Since the list only contains primary vehicles, free wagons aren't taken into consideration.pull/10548/head
parent
f786477c6d
commit
89c69f991c
|
@ -885,13 +885,18 @@ static CompanyID GetPreviewCompany(Engine *e)
|
||||||
c->old_economy[0].performance_history > best_hist) {
|
c->old_economy[0].performance_history > best_hist) {
|
||||||
|
|
||||||
/* Check whether the company uses similar vehicles */
|
/* Check whether the company uses similar vehicles */
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
bool match = false;
|
||||||
if (v->owner != c->index || v->type != e->type) continue;
|
const VehicleList &vehicle_list = c->group_all[e->type].vehicle_list;
|
||||||
if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue;
|
for (const Vehicle *v : vehicle_list) {
|
||||||
|
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||||
|
if (!u->GetEngine()->CanCarryCargo() || !HasBit(cargomask, u->cargo_type)) continue;
|
||||||
|
|
||||||
best_hist = c->old_economy[0].performance_history;
|
best_hist = c->old_economy[0].performance_history;
|
||||||
best_company = c->index;
|
best_company = c->index;
|
||||||
break;
|
match = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (match) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1052,15 +1057,20 @@ static void NewVehicleAvailable(Engine *e)
|
||||||
/* We assume the user did NOT build it.. prove me wrong ;) */
|
/* We assume the user did NOT build it.. prove me wrong ;) */
|
||||||
c->block_preview = 20;
|
c->block_preview = 20;
|
||||||
|
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
bool match = false;
|
||||||
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
|
const VehicleList &vehicle_list = c->group_all[e->type].vehicle_list;
|
||||||
(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
|
for (const Vehicle *v : vehicle_list) {
|
||||||
if (v->owner == c->index && v->engine_type == index) {
|
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||||
|
if (u->type == VEH_AIRCRAFT && !Aircraft::From(u)->IsNormalAircraft()) continue;
|
||||||
|
|
||||||
|
if (u->engine_type == index) {
|
||||||
/* The user did prove me wrong, so restore old value */
|
/* The user did prove me wrong, so restore old value */
|
||||||
c->block_preview = block_preview;
|
c->block_preview = block_preview;
|
||||||
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (match) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue