forked from teamnwah/openmw-tes3coop
objects scripts are now stopped when they are removed from a container
This commit is contained in:
parent
d4ca954d47
commit
c138e00aa2
6 changed files with 35 additions and 0 deletions
|
@ -45,6 +45,7 @@ namespace MWWorld
|
||||||
class Ptr;
|
class Ptr;
|
||||||
class TimeStamp;
|
class TimeStamp;
|
||||||
class ESMStore;
|
class ESMStore;
|
||||||
|
class RefData;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWBase
|
namespace MWBase
|
||||||
|
@ -138,6 +139,9 @@ namespace MWBase
|
||||||
|
|
||||||
virtual std::string getCurrentCellName() const = 0;
|
virtual std::string getCurrentCellName() const = 0;
|
||||||
|
|
||||||
|
virtual void removeRefScript (MWWorld::RefData *ref) = 0;
|
||||||
|
//< Remove the script attached to ref from mLocalScripts
|
||||||
|
|
||||||
virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0;
|
virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0;
|
||||||
///< Return a pointer to a liveCellRef with the given name.
|
///< Return a pointer to a liveCellRef with the given name.
|
||||||
/// \param activeOnly do non search inactive cells.
|
/// \param activeOnly do non search inactive cells.
|
||||||
|
|
|
@ -146,6 +146,20 @@ void MWWorld::LocalScripts::clearCell (Ptr::CellStore *cell)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MWWorld::LocalScripts::remove (RefData *ref)
|
||||||
|
{
|
||||||
|
for (std::list<std::pair<std::string, Ptr> >::iterator iter = mScripts.begin();
|
||||||
|
iter!=mScripts.end(); ++iter)
|
||||||
|
if (&(iter->second.getRefData()) == ref)
|
||||||
|
{
|
||||||
|
if (iter==mIter)
|
||||||
|
++mIter;
|
||||||
|
|
||||||
|
mScripts.erase (iter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MWWorld::LocalScripts::remove (const Ptr& ptr)
|
void MWWorld::LocalScripts::remove (const Ptr& ptr)
|
||||||
{
|
{
|
||||||
for (std::list<std::pair<std::string, Ptr> >::iterator iter = mScripts.begin();
|
for (std::list<std::pair<std::string, Ptr> >::iterator iter = mScripts.begin();
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
struct ESMStore;
|
struct ESMStore;
|
||||||
class CellStore;
|
class CellStore;
|
||||||
|
class RefData;
|
||||||
|
|
||||||
/// \brief List of active local scripts
|
/// \brief List of active local scripts
|
||||||
class LocalScripts
|
class LocalScripts
|
||||||
|
@ -48,6 +49,8 @@ namespace MWWorld
|
||||||
void clearCell (CellStore *cell);
|
void clearCell (CellStore *cell);
|
||||||
///< Remove all scripts belonging to \a cell.
|
///< Remove all scripts belonging to \a cell.
|
||||||
|
|
||||||
|
void remove (RefData *ref);
|
||||||
|
|
||||||
void remove (const Ptr& ptr);
|
void remove (const Ptr& ptr);
|
||||||
///< Remove script for given reference (ignored if reference does not have a scirpt listed).
|
///< Remove script for given reference (ignored if reference does not have a scirpt listed).
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include "customdata.hpp"
|
#include "customdata.hpp"
|
||||||
#include "cellstore.hpp"
|
#include "cellstore.hpp"
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
void RefData::copy (const RefData& refData)
|
void RefData::copy (const RefData& refData)
|
||||||
|
@ -107,6 +110,9 @@ namespace MWWorld
|
||||||
|
|
||||||
void RefData::setCount (int count)
|
void RefData::setCount (int count)
|
||||||
{
|
{
|
||||||
|
if(count == 0)
|
||||||
|
MWBase::Environment::get().getWorld()->removeRefScript(this);
|
||||||
|
|
||||||
mCount = count;
|
mCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,6 +341,11 @@ namespace MWWorld
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::removeRefScript (MWWorld::RefData *ref)
|
||||||
|
{
|
||||||
|
mLocalScripts.remove (ref);
|
||||||
|
}
|
||||||
|
|
||||||
Ptr World::getPtr (const std::string& name, bool activeOnly)
|
Ptr World::getPtr (const std::string& name, bool activeOnly)
|
||||||
{
|
{
|
||||||
// the player is always in an active cell.
|
// the player is always in an active cell.
|
||||||
|
|
|
@ -173,6 +173,9 @@ namespace MWWorld
|
||||||
|
|
||||||
virtual std::string getCurrentCellName () const;
|
virtual std::string getCurrentCellName () const;
|
||||||
|
|
||||||
|
virtual void removeRefScript (MWWorld::RefData *ref);
|
||||||
|
//< Remove the script attached to ref from mLocalScripts
|
||||||
|
|
||||||
virtual Ptr getPtr (const std::string& name, bool activeOnly);
|
virtual Ptr getPtr (const std::string& name, bool activeOnly);
|
||||||
///< Return a pointer to a liveCellRef with the given name.
|
///< Return a pointer to a liveCellRef with the given name.
|
||||||
/// \param activeOnly do non search inactive cells.
|
/// \param activeOnly do non search inactive cells.
|
||||||
|
|
Loading…
Reference in a new issue