From 0b663f709d60fd95254ec6549cf08763c841787f Mon Sep 17 00:00:00 2001 From: PeterN Date: Fri, 2 Jun 2023 09:25:13 +0100 Subject: [PATCH] Codechange: Sprite mapping for objects doesn't involve cargo types. (#10905) Objects have a default sprite group and an optional purchase list sprite group. There is no need to pretend that these are cargo IDs. --- src/newgrf.cpp | 24 +++++++++--------------- src/newgrf_object.cpp | 4 ++-- src/newgrf_object.h | 4 ++-- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 9d4d14e072..2f311c8bd5 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5504,15 +5504,6 @@ static void NewSpriteGroup(ByteReader *buf) static CargoID TranslateCargo(uint8 feature, uint8 ctype) { - if (feature == GSF_OBJECTS) { - switch (ctype) { - case 0: return 0; - case 0xFF: return CT_PURCHASE_OBJECT; - default: - GrfMsg(1, "TranslateCargo: Invalid cargo bitnum {} for objects, skipping.", ctype); - return CT_INVALID; - } - } /* Special cargo types for purchase list and stations */ if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return CT_DEFAULT_NA; if (ctype == 0xFF) return CT_PURCHASE; @@ -5878,8 +5869,11 @@ static void ObjectMapSpriteGroup(ByteReader *buf, uint8 idcount) uint16 groupid = buf->ReadWord(); if (!IsValidGroupID(groupid, "ObjectMapSpriteGroup")) continue; - ctype = TranslateCargo(GSF_OBJECTS, ctype); - if (!IsValidCargoID(ctype)) continue; + /* The only valid option here is purchase list sprite groups. */ + if (ctype != 0xFF) { + GrfMsg(1, "ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype); + continue; + } for (auto &object : objects) { ObjectSpec *spec = object >= _cur.grffile->objectspec.size() ? nullptr : _cur.grffile->objectspec[object].get(); @@ -5889,7 +5883,7 @@ static void ObjectMapSpriteGroup(ByteReader *buf, uint8 idcount) continue; } - spec->grf_prop.spritegroup[ctype] = _cur.spritegroups[groupid]; + spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_PURCHASE] = _cur.spritegroups[groupid]; } } @@ -5909,9 +5903,9 @@ static void ObjectMapSpriteGroup(ByteReader *buf, uint8 idcount) continue; } - spec->grf_prop.spritegroup[0] = _cur.spritegroups[groupid]; - spec->grf_prop.grffile = _cur.grffile; - spec->grf_prop.local_id = object; + spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_DEFAULT] = _cur.spritegroups[groupid]; + spec->grf_prop.grffile = _cur.grffile; + spec->grf_prop.local_id = object; } } diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 60c0684303..cc418df29b 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -378,8 +378,8 @@ ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view) { this->town_scope = nullptr; - this->root_spritegroup = (obj == nullptr && spec->grf_prop.spritegroup[CT_PURCHASE_OBJECT] != nullptr) ? - spec->grf_prop.spritegroup[CT_PURCHASE_OBJECT] : spec->grf_prop.spritegroup[0]; + this->root_spritegroup = (obj == nullptr && spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_PURCHASE] != nullptr) ? + spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_PURCHASE] : spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_DEFAULT]; } ObjectResolverObject::~ObjectResolverObject() diff --git a/src/newgrf_object.h b/src/newgrf_object.h index ad0ebd3702..e82f916cb8 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -166,8 +166,8 @@ private: /** Struct containing information relating to object classes. */ typedef NewGRFClass ObjectClass; -/** Mapping of purchase for objects. */ -static const CargoID CT_PURCHASE_OBJECT = 1; +static const size_t OBJECT_SPRITE_GROUP_DEFAULT = 0; +static const size_t OBJECT_SPRITE_GROUP_PURCHASE = 1; uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0);