diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 3da3020c1..46a1dc7a7 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -624,6 +624,36 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + A custom type of search visitor used to find objects by their reference numbers + while ensuring they have a certain refId + */ + class SearchExactPlusVisitor + { + const std::string mRefIdToFind; + const unsigned int mRefNumToFind; + const unsigned int mMpNumToFind; + public: + SearchExactPlusVisitor(const std::string refId, const unsigned int refNum, const unsigned int mpNum) : mRefIdToFind(refId), mRefNumToFind(refNum), mMpNumToFind(mpNum) {} + + Ptr mFound; + + bool operator()(const Ptr& ptr) + { + if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind && Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), mRefIdToFind)) + { + mFound = ptr; + return false; + } + return true; + } + }; + /* + End of tes3mp addition + */ + /* Start of tes3mp addition @@ -643,6 +673,26 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Allow the searching of objects by their reference numbers while ensuring + they have a certain refId + */ + Ptr CellStore::searchExactPlus(const std::string refId, const unsigned int refNum, const unsigned int mpNum) + { + // Ensure that all objects searched for have a valid reference number + if (refNum == 0 && mpNum == 0) + return 0; + + SearchExactPlusVisitor searchVisitor(refId, refNum, mpNum); + forEach(searchVisitor); + return searchVisitor.mFound; + } + /* + End of tes3mp addition + */ + /* Start of tes3mp addition diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index de3c291d0..ba0a78972 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -269,6 +269,17 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Allow the searching of objects by their reference numbers while ensuring + they have a certain refId + */ + Ptr searchExactPlus (std::string refId, unsigned int refNum, unsigned int mpNum); + /* + End of tes3mp addition + */ + /* Start of tes3mp addition