diff --git a/src/newgrf/newgrf_act3.cpp b/src/newgrf/newgrf_act3.cpp index 906b60d68f..faaa5660e0 100644 --- a/src/newgrf/newgrf_act3.cpp +++ b/src/newgrf/newgrf_act3.cpp @@ -394,7 +394,7 @@ static void ObjectMapSpriteGroup(ByteReader &buf, uint8_t idcount) continue; } - spec->grf_prop.SetSpriteGroup(OBJECT_SPRITE_GROUP_PURCHASE, _cur_gps.spritegroups[groupid]); + spec->grf_prop.SetSpriteGroup(StandardSpriteGroup::Purchase, _cur_gps.spritegroups[groupid]); } } @@ -414,7 +414,7 @@ static void ObjectMapSpriteGroup(ByteReader &buf, uint8_t idcount) continue; } - spec->grf_prop.SetSpriteGroup(OBJECT_SPRITE_GROUP_DEFAULT, _cur_gps.spritegroups[groupid]); + spec->grf_prop.SetSpriteGroup(StandardSpriteGroup::Default, _cur_gps.spritegroups[groupid]); spec->grf_prop.SetGRFFile(_cur_gps.grffile); spec->grf_prop.local_id = object; } diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index 7be4298a52..7cf7441b24 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -306,9 +306,10 @@ struct GRFFilePropsBase { /** * Fixed-length list of sprite groups for an entity. + * @tparam Tkey Key for indexing spritegroups * @tparam Tcount Number of spritegroups */ -template +template struct FixedGRFFileProps : GRFFilePropsBase { std::array spritegroups{}; ///< pointers to the different sprite groups of the entity @@ -317,14 +318,14 @@ struct FixedGRFFileProps : GRFFilePropsBase { * @param index Index to get. * @returns SpriteGroup at index, or nullptr if not present. */ - const struct SpriteGroup *GetSpriteGroup(size_t index = 0) const { return this->spritegroups[index]; } + const struct SpriteGroup *GetSpriteGroup(Tkey index) const { return this->spritegroups[static_cast(index)]; } /** * Set the SpriteGroup at the specified index. * @param index Index to set. * @param spritegroup SpriteGroup to set. */ - void SetSpriteGroup(size_t index, const struct SpriteGroup *spritegroup) { this->spritegroups[index] = spritegroup; } + void SetSpriteGroup(Tkey index, const struct SpriteGroup *spritegroup) { this->spritegroups[static_cast(index)] = spritegroup; } }; /** @@ -337,6 +338,16 @@ struct SingleGRFFileProps : GRFFilePropsBase { void SetSpriteGroup(const struct SpriteGroup *spritegroup) { this->spritegroup = spritegroup; } }; +/** + * Standard sprite groups. + */ +enum class StandardSpriteGroup { + Default, ///< Default type used when no more-specific group matches. + Purchase, ///< Used before an entity exists. + End +}; +using StandardGRFFileProps = FixedGRFFileProps(StandardSpriteGroup::End)>; + /** * Variable-length list of sprite groups for an entity. * @tparam Tkey Key for indexing spritegroups diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 2369877377..cee3f0e1e8 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -386,8 +386,8 @@ ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, CallbackID callback, uint32_t param1, uint32_t param2) : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view) { - this->root_spritegroup = (obj == nullptr) ? spec->grf_prop.GetSpriteGroup(OBJECT_SPRITE_GROUP_PURCHASE) : nullptr; - if (this->root_spritegroup == nullptr) this->root_spritegroup = spec->grf_prop.GetSpriteGroup(OBJECT_SPRITE_GROUP_DEFAULT); + this->root_spritegroup = (obj == nullptr) ? spec->grf_prop.GetSpriteGroup(StandardSpriteGroup::Purchase) : nullptr; + if (this->root_spritegroup == nullptr) this->root_spritegroup = spec->grf_prop.GetSpriteGroup(StandardSpriteGroup::Default); } /** diff --git a/src/newgrf_object.h b/src/newgrf_object.h index e3c1a33069..7b0aff4938 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -58,8 +58,7 @@ DECLARE_INCREMENT_DECREMENT_OPERATORS(ObjectClassID) * default objects in table/object_land.h */ struct ObjectSpec : NewGRFSpecBase { - /* 2 because of the "normal" and "buy" sprite stacks. */ - FixedGRFFileProps<2> grf_prop; ///< Properties related the the grf file + StandardGRFFileProps grf_prop; ///< Properties related the the grf file /* Animation speed default differs from other features */ AnimationInfo animation{0, AnimationStatus::NoAnimation, 0, {}}; ///< Information about the animation. StringID name; ///< The name for this object. @@ -166,9 +165,6 @@ private: /** Class containing information relating to object classes. */ using ObjectClass = NewGRFClass; -static const size_t OBJECT_SPRITE_GROUP_DEFAULT = 0; -static const size_t OBJECT_SPRITE_GROUP_PURCHASE = 1; - uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view = 0); void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec); diff --git a/src/table/object_land.h b/src/table/object_land.h index 6988af7a72..47199bc0c9 100644 --- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -106,7 +106,7 @@ static const DrawTileSpriteSpan _object_hq[] = { #undef TILE_SPRITE_LINE #undef TILE_SPRITE_LINE_NOTHING -#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, FixedGRFFileProps<2>{}, AnimationInfo{}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, TimerGameCalendar::Date{}, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount, {}} +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, StandardGRFFileProps{}, AnimationInfo{}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, TimerGameCalendar::Date{}, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount, {}} /* Climates * T = Temperate