From a69eba31fe2c1409be3f99c3762d9fb0e51d9978 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 14 Feb 2022 00:26:52 +0000 Subject: [PATCH] Implement NewGRF road stop root sprite group selection --- src/newgrf.cpp | 2 +- src/newgrf_roadstop.cpp | 27 +++++++++++++++++++++++++-- src/newgrf_roadstop.h | 9 +++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 3c54e88fca..d5279a7dad 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5849,7 +5849,7 @@ static CargoID TranslateCargo(uint8 feature, uint8 ctype) } } /* Special cargo types for purchase list and stations */ - if (feature == GSF_STATIONS && ctype == 0xFE) return CT_DEFAULT_NA; + if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return CT_DEFAULT_NA; if (ctype == 0xFF) return CT_PURCHASE; if (_cur.grffile->cargo_list.size() == 0) { diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index 86684e4d8b..2f511c600f 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -112,8 +112,31 @@ RoadStopResolverObject::RoadStopResolverObject(const RoadStopSpec *roadstopspec, { this->town_scope = nullptr; - this->root_spritegroup = (st == nullptr && roadstopspec->grf_prop.spritegroup[CT_DEFAULT] != nullptr) - ? roadstopspec->grf_prop.spritegroup[CT_DEFAULT] : roadstopspec->grf_prop.spritegroup[CT_DEFAULT]; + + CargoID ctype = CT_DEFAULT_NA; + + if (st == nullptr) { + /* No station, so we are in a purchase list */ + ctype = CT_PURCHASE; + } 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()].cargo.TotalCount() > 0) { + ctype = cs->Index(); + break; + } + } + } + + if (roadstopspec->grf_prop.spritegroup[ctype] == nullptr) { + ctype = CT_DEFAULT; + } + + /* Remember the cargo type we've picked */ + this->roadstop_scope.cargo_type = ctype; + this->root_spritegroup = roadstopspec->grf_prop.spritegroup[ctype]; } RoadStopResolverObject::~RoadStopResolverObject() diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index e4e8a1d035..bbcd9190ac 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -110,8 +110,13 @@ struct RoadStopResolverObject : public ResolverObject { /** Road stop specification. */ struct RoadStopSpec { - // We'll have a default and a fence "cargo". Or maybe just a default one? - GRFFilePropsBase grf_prop; + /** + * Properties related the the grf file. + * NUM_CARGO real cargo plus three pseudo cargo sprite groups. + * Used for obtaining the sprite offset of custom sprites, and for + * evaluating callbacks. + */ + GRFFilePropsBase grf_prop; RoadStopClassID cls_id; ///< The class to which this spec belongs. int spec_id; ///< The ID of this spec inside the class. StringID name; ///< Name of this stop