mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-12 04:51:35 +00:00
[General] Combine CellStore's exact object searches
This commit is contained in:
parent
6875c3422f
commit
cc8c222d18
4 changed files with 16 additions and 87 deletions
|
@ -365,14 +365,7 @@ void ObjectList::activateObjects(MWWorld::CellStore* cellStore)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Activated object is %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
|
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Activated object is %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
|
||||||
if (baseObject.refId.empty())
|
ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum, baseObject.refId);
|
||||||
{
|
|
||||||
ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ptrFound = cellStore->searchExactPlus(baseObject.refId, baseObject.refNum, baseObject.mpNum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptrFound)
|
if (ptrFound)
|
||||||
|
@ -1014,16 +1007,8 @@ void ObjectList::makeDialogueChoices(MWWorld::CellStore* cellStore)
|
||||||
for (const auto& baseObject : baseObjects)
|
for (const auto& baseObject : baseObjects)
|
||||||
{
|
{
|
||||||
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
|
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
|
||||||
MWWorld::Ptr ptrFound;
|
|
||||||
|
|
||||||
if (baseObject.refId.empty())
|
MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum, baseObject.refId);
|
||||||
{
|
|
||||||
ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ptrFound = cellStore->searchExactPlus(baseObject.refId, baseObject.refNum, baseObject.mpNum);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ptrFound)
|
if (ptrFound)
|
||||||
{
|
{
|
||||||
|
|
|
@ -605,8 +605,9 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
const unsigned int mRefNumToFind;
|
const unsigned int mRefNumToFind;
|
||||||
const unsigned int mMpNumToFind;
|
const unsigned int mMpNumToFind;
|
||||||
|
const std::string mRefIdToFind;
|
||||||
public:
|
public:
|
||||||
SearchExactVisitor(const unsigned int refNum, const unsigned int mpNum) : mRefNumToFind(refNum), mMpNumToFind(mpNum) {}
|
SearchExactVisitor(const unsigned int refNum, const unsigned int mpNum, const std::string refId) : mRefNumToFind(refNum), mMpNumToFind(mpNum), mRefIdToFind(refId) {}
|
||||||
|
|
||||||
Ptr mFound;
|
Ptr mFound;
|
||||||
|
|
||||||
|
@ -614,39 +615,12 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind)
|
if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind)
|
||||||
{
|
{
|
||||||
mFound = ptr;
|
if (mRefIdToFind.empty() || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), mRefIdToFind))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
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;
|
mFound = ptr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -659,33 +633,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)
|
Ptr CellStore::searchExact (const unsigned int refNum, const unsigned int mpNum, const std::string refId)
|
||||||
{
|
{
|
||||||
// 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);
|
SearchExactVisitor searchVisitor(refNum, mpNum, refId);
|
||||||
forEach(searchVisitor);
|
|
||||||
return searchVisitor.mFound;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
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);
|
forEach(searchVisitor);
|
||||||
return searchVisitor.mFound;
|
return searchVisitor.mFound;
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,20 +262,10 @@ namespace MWWorld
|
||||||
/*
|
/*
|
||||||
Start of tes3mp addition
|
Start of tes3mp addition
|
||||||
|
|
||||||
Allow the searching of objects by their reference numbers
|
Allow the searching of objects by their reference numbers and, optionally,
|
||||||
|
their refIds
|
||||||
*/
|
*/
|
||||||
Ptr searchExact (unsigned int refNum, unsigned int mpNum);
|
Ptr searchExact (unsigned int refNum, unsigned int mpNum, std::string refId = "");
|
||||||
/*
|
|
||||||
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
|
End of tes3mp addition
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace mwmp
|
||||||
|
|
||||||
struct BaseObject
|
struct BaseObject
|
||||||
{
|
{
|
||||||
std::string refId;
|
std::string refId = "";
|
||||||
unsigned int refNum;
|
unsigned int refNum;
|
||||||
unsigned int mpNum;
|
unsigned int mpNum;
|
||||||
int count;
|
int count;
|
||||||
|
|
Loading…
Reference in a new issue