[Client] Add actorsOnly argument to CellStore's exact object search

This commit is contained in:
David Cernat 2022-03-23 09:49:57 +02:00
parent a6dd76776f
commit 17715933b5
2 changed files with 12 additions and 7 deletions

View File

@ -606,8 +606,10 @@ namespace MWWorld
const unsigned int mRefNumToFind; const unsigned int mRefNumToFind;
const unsigned int mMpNumToFind; const unsigned int mMpNumToFind;
const std::string mRefIdToFind; const std::string mRefIdToFind;
const bool mActorsOnly;
public: public:
SearchExactVisitor(const unsigned int refNum, const unsigned int mpNum, const std::string refId) : mRefNumToFind(refNum), mMpNumToFind(mpNum), mRefIdToFind(refId) {} SearchExactVisitor(const unsigned int refNum, const unsigned int mpNum, const std::string refId, const bool actorsOnly) :
mRefNumToFind(refNum), mMpNumToFind(mpNum), mRefIdToFind(refId), mActorsOnly(actorsOnly) {}
Ptr mFound; Ptr mFound;
@ -615,10 +617,13 @@ namespace MWWorld
{ {
if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind) if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind)
{ {
if (mRefIdToFind.empty() || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), mRefIdToFind)) if (!mActorsOnly || ptr.getClass().isActor())
{ {
mFound = ptr; if (mRefIdToFind.empty() || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), mRefIdToFind))
return false; {
mFound = ptr;
return false;
}
} }
} }
return true; return true;
@ -633,13 +638,13 @@ namespace MWWorld
Allow the searching of objects by their reference numbers Allow the searching of objects by their reference numbers
*/ */
Ptr CellStore::searchExact (const unsigned int refNum, const unsigned int mpNum, const std::string refId) Ptr CellStore::searchExact (const unsigned int refNum, const unsigned int mpNum, const std::string refId, bool actorsOnly)
{ {
// Ensure that all objects searched for have a valid reference number // Ensure that all objects searched for have a valid reference number
if (refNum == 0 && mpNum == 0) if (refNum == 0 && mpNum == 0)
return 0; return 0;
SearchExactVisitor searchVisitor(refNum, mpNum, refId); SearchExactVisitor searchVisitor(refNum, mpNum, refId, actorsOnly);
forEach(searchVisitor); forEach(searchVisitor);
return searchVisitor.mFound; return searchVisitor.mFound;
} }

View File

@ -265,7 +265,7 @@ namespace MWWorld
Allow the searching of objects by their reference numbers and, optionally, Allow the searching of objects by their reference numbers and, optionally,
their refIds their refIds
*/ */
Ptr searchExact (unsigned int refNum, unsigned int mpNum, std::string refId = ""); Ptr searchExact (unsigned int refNum, unsigned int mpNum, std::string refId = "", bool actorsOnly = false);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */