mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-27 14:14:27 +01:00
Codechange: Use variable storage for GrfProps with cargo-type groups. (#13557)
Slots are only allocated when used instead of being reserved. Array-based GrfProps are still used when the number of options is more limited.
This commit is contained in:
@@ -227,25 +227,31 @@ RoadStopResolverObject::RoadStopResolverObject(const RoadStopSpec *roadstopspec,
|
||||
if (st == nullptr) {
|
||||
/* No station, so we are in a purchase list */
|
||||
ctype = SpriteGroupCargo::SG_PURCHASE;
|
||||
this->root_spritegroup = roadstopspec->grf_prop.GetSpriteGroup(ctype);
|
||||
} else if (Station::IsExpected(st)) {
|
||||
const Station *station = Station::From(st);
|
||||
/* Pick the first cargo that we have waiting */
|
||||
for (const CargoSpec *cs : CargoSpec::Iterate()) {
|
||||
if (roadstopspec->grf_prop.spritegroup[cs->Index()] != nullptr &&
|
||||
station->goods[cs->Index()].HasData() && station->goods[cs->Index()].GetData().cargo.TotalCount() > 0) {
|
||||
ctype = cs->Index();
|
||||
for (const auto &[cargo, spritegroup] : roadstopspec->grf_prop.spritegroups) {
|
||||
if (cargo < NUM_CARGO && station->goods[cargo].HasData() && station->goods[cargo].GetData().cargo.TotalCount() > 0) {
|
||||
ctype = cargo;
|
||||
this->root_spritegroup = spritegroup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->root_spritegroup == nullptr) {
|
||||
ctype = SpriteGroupCargo::SG_DEFAULT_NA;
|
||||
this->root_spritegroup = roadstopspec->grf_prop.GetSpriteGroup(ctype);
|
||||
}
|
||||
}
|
||||
|
||||
if (roadstopspec->grf_prop.spritegroup[ctype] == nullptr) {
|
||||
if (this->root_spritegroup == nullptr) {
|
||||
ctype = SpriteGroupCargo::SG_DEFAULT;
|
||||
this->root_spritegroup = roadstopspec->grf_prop.GetSpriteGroup(ctype);
|
||||
}
|
||||
|
||||
/* Remember the cargo type we've picked */
|
||||
this->roadstop_scope.cargo_type = ctype;
|
||||
this->root_spritegroup = roadstopspec->grf_prop.spritegroup[ctype];
|
||||
}
|
||||
|
||||
TownScopeResolver *RoadStopResolverObject::GetTown()
|
||||
|
||||
Reference in New Issue
Block a user