1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 22:45:33 +00:00

Add a searchPtr method as required for getting an owner, which may already be dead and disposed of.

This commit is contained in:
scrawl 2014-01-11 03:33:17 +01:00
parent bf6d302fba
commit 9127839cc1
4 changed files with 19 additions and 6 deletions

View file

@ -157,6 +157,10 @@ namespace MWBase
///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells.
virtual MWWorld::Ptr searchPtr (const std::string& name, bool activeOnly) = 0;
///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells.
virtual MWWorld::Ptr getPtrViaHandle (const std::string& handle) = 0;
///< Return a pointer to a liveCellRef with the given Ogre handle.

View file

@ -34,7 +34,7 @@ namespace
}
if (!item.getCellRef().mOwner.empty())
victim = MWBase::Environment::get().getWorld()->getPtr(item.getCellRef().mOwner, true);
victim = MWBase::Environment::get().getWorld()->searchPtr(item.getCellRef().mOwner, true);
return (!isOwned && !isFactionOwned);
}

View file

@ -485,8 +485,9 @@ namespace MWWorld
mLocalScripts.remove (ref);
}
Ptr World::getPtr (const std::string& name, bool activeOnly)
Ptr World::searchPtr (const std::string& name, bool activeOnly)
{
Ptr ret;
// the player is always in an active cell.
if (name=="player")
{
@ -514,12 +515,16 @@ namespace MWWorld
if (!activeOnly)
{
Ptr ptr = mCells.getPtr (lowerCaseName);
if (!ptr.isEmpty())
return ptr;
ret = mCells.getPtr (lowerCaseName);
}
return ret;
}
Ptr World::getPtr (const std::string& name, bool activeOnly)
{
Ptr ret = searchPtr(name, activeOnly);
if (!ret.isEmpty())
return ret;
throw std::runtime_error ("unknown ID: " + name);
}

View file

@ -232,6 +232,10 @@ namespace MWWorld
///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells.
virtual Ptr searchPtr (const std::string& name, bool activeOnly);
///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells.
virtual Ptr getPtrViaHandle (const std::string& handle);
///< Return a pointer to a liveCellRef with the given Ogre handle.