diff --git a/src/openrct2/object/ObjectList.cpp b/src/openrct2/object/ObjectList.cpp index 27ebb3c8d9..858cdbbac0 100644 --- a/src/openrct2/object/ObjectList.cpp +++ b/src/openrct2/object/ObjectList.cpp @@ -170,12 +170,27 @@ void ObjectList::SetObject(ObjectType type, ObjectEntryIndex index, std::string_ SetObject(index, entry); } -ObjectEntryIndex ObjectList::Find(ObjectType type, std::string_view identifier) +ObjectEntryIndex ObjectList::Find(ObjectType type, std::string_view identifier) const { auto& subList = GetList(type); for (size_t i = 0; i < subList.size(); i++) { - if (subList[i].Identifier == identifier) + if (subList[i].Generation == ObjectGeneration::JSON && subList[i].Identifier == identifier) + { + return static_cast(i); + } + } + return OBJECT_ENTRY_INDEX_NULL; +} + +// Intended to be used to find non-custom legacy objects. For internal use only. +ObjectEntryIndex ObjectList::FindLegacy(ObjectType type, std::string_view identifier) const +{ + auto& subList = GetList(type); + for (size_t i = 0; i < subList.size(); i++) + { + if (subList[i].Generation == ObjectGeneration::DAT && subList[i].Entry.GetName() == identifier + && subList[i].Entry.GetSourceGame() != ObjectSourceGame::Custom) { return static_cast(i); } diff --git a/src/openrct2/object/ObjectList.h b/src/openrct2/object/ObjectList.h index 3cc725cf10..476c694e4e 100644 --- a/src/openrct2/object/ObjectList.h +++ b/src/openrct2/object/ObjectList.h @@ -25,7 +25,8 @@ public: const ObjectEntryDescriptor& GetObject(ObjectType type, ObjectEntryIndex index) const; void SetObject(ObjectEntryIndex index, const ObjectEntryDescriptor& entry); void SetObject(ObjectType type, ObjectEntryIndex index, std::string_view identifier); - ObjectEntryIndex Find(ObjectType type, std::string_view identifier); + ObjectEntryIndex Find(ObjectType type, std::string_view identifier) const; + ObjectEntryIndex FindLegacy(ObjectType type, std::string_view identifier) const; struct const_iterator {