mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Improve performance of exclusive preview engine test.
Check group statistics to test if a company has built an exclusive preview engine. This improves performance by avoiding iterating the vehicle pool.pull/14270/head
parent
9f190aa534
commit
f9d0877f36
|
@ -1085,22 +1085,13 @@ static void NewVehicleAvailable(Engine *e)
|
||||||
* prevent that company from getting future intro periods for a while. */
|
* prevent that company from getting future intro periods for a while. */
|
||||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) {
|
if (e->flags.Test(EngineFlag::ExclusivePreview)) {
|
||||||
for (Company *c : Company::Iterate()) {
|
for (Company *c : Company::Iterate()) {
|
||||||
uint block_preview = c->block_preview;
|
|
||||||
|
|
||||||
if (!e->company_avail.Test(c->index)) continue;
|
if (!e->company_avail.Test(c->index)) continue;
|
||||||
|
|
||||||
/* We assume the user did NOT build it.. prove me wrong ;) */
|
/* Check the company's 'ALL_GROUP' group statistics. This only includes countable vehicles, which is fine
|
||||||
c->block_preview = 20;
|
* as those are the only engines that can be given exclusive previews. */
|
||||||
|
if (GetGroupNumEngines(c->index, ALL_GROUP, e->index) == 0) {
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
/* The company did not build this engine during preview. */
|
||||||
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
|
c->block_preview = 20;
|
||||||
(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
|
|
||||||
if (v->owner == c->index && v->engine_type == index) {
|
|
||||||
/* The user did prove me wrong, so restore old value */
|
|
||||||
c->block_preview = block_preview;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue