forked from mirror/openmw-tes3mp
added actor ID
This commit is contained in:
parent
2906ade531
commit
f6a876bc3d
9 changed files with 82 additions and 2 deletions
|
@ -200,6 +200,9 @@ namespace MWBase
|
|||
virtual MWWorld::Ptr searchPtrViaHandle (const std::string& handle) = 0;
|
||||
///< Return a pointer to a liveCellRef with the given Ogre handle or Ptr() if not found
|
||||
|
||||
virtual MWWorld::Ptr searchPtrViaActorId (int actorId) = 0;
|
||||
///< Search is limited to the active cells.
|
||||
|
||||
/// \todo enable reference in the OGRE scene
|
||||
virtual void enable (const MWWorld::Ptr& ptr) = 0;
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
namespace MWMechanics
|
||||
{
|
||||
int CreatureStats::sActorId = 0;
|
||||
|
||||
CreatureStats::CreatureStats()
|
||||
: mLevel (0), mDead (false), mDied (false), mFriendlyHits (0),
|
||||
mTalkedTo (false), mAlarmed (false),
|
||||
|
@ -18,7 +20,8 @@ namespace MWMechanics
|
|||
mAttackingOrSpell(false),
|
||||
mIsWerewolf(false),
|
||||
mFallHeight(0), mRecalcDynamicStats(false), mKnockdown(false), mKnockdownOneFrame(false), mKnockdownOverOneFrame(false), mHitRecovery(false), mBlock(false),
|
||||
mMovementFlags(0), mDrawState (DrawState_Nothing), mAttackStrength(0.f)
|
||||
mMovementFlags(0), mDrawState (DrawState_Nothing), mAttackStrength(0.f),
|
||||
mActorId (-1)
|
||||
{
|
||||
for (int i=0; i<4; ++i)
|
||||
mAiSettings[i] = 0;
|
||||
|
@ -516,4 +519,17 @@ namespace MWMechanics
|
|||
{
|
||||
return mGoldPool;
|
||||
}
|
||||
|
||||
int CreatureStats::getActorId()
|
||||
{
|
||||
if (mActorId==-1)
|
||||
mActorId = sActorId++;
|
||||
|
||||
return mActorId;
|
||||
}
|
||||
|
||||
bool CreatureStats::matchesActorId (int id) const
|
||||
{
|
||||
return mActorId!=-1 && id==mActorId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace MWMechanics
|
|||
///
|
||||
class CreatureStats
|
||||
{
|
||||
static int sActorId;
|
||||
DrawState_ mDrawState;
|
||||
AttributeValue mAttributes[8];
|
||||
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
|
||||
|
@ -60,6 +61,7 @@ namespace MWMechanics
|
|||
MWWorld::TimeStamp mTradeTime; // Relates to NPC gold reset delay
|
||||
|
||||
int mGoldPool; // the pool of merchant gold not in inventory
|
||||
int mActorId;
|
||||
|
||||
protected:
|
||||
bool mIsWerewolf;
|
||||
|
@ -239,6 +241,13 @@ namespace MWMechanics
|
|||
|
||||
void setGoldPool(int pool);
|
||||
int getGoldPool() const;
|
||||
|
||||
int getActorId();
|
||||
///< Will generate an actor ID, if the actor does not have one yet.
|
||||
|
||||
bool matchesActorId (int id) const;
|
||||
///< Check if \a id matches the actor ID of *this (if the actor does not have an ID
|
||||
/// assigned this function will return false).
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
|
||||
#include "ptr.hpp"
|
||||
#include "esmstore.hpp"
|
||||
#include "class.hpp"
|
||||
|
@ -40,6 +42,22 @@ namespace
|
|||
return MWWorld::Ptr();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
MWWorld::Ptr searchViaActorId (MWWorld::CellRefList<T>& actorList, int actorId,
|
||||
MWWorld::CellStore *cell)
|
||||
{
|
||||
for (typename MWWorld::CellRefList<T>::List::iterator iter (actorList.mList.begin());
|
||||
iter!=actorList.mList.end(); ++iter)
|
||||
{
|
||||
MWWorld::Ptr actor (&*iter, cell);
|
||||
|
||||
if (MWWorld::Class::get (actor).getCreatureStats (actor).matchesActorId (actorId))
|
||||
return actor;
|
||||
}
|
||||
|
||||
return MWWorld::Ptr();
|
||||
}
|
||||
|
||||
template<typename RecordType, typename T>
|
||||
void writeReferenceCollection (ESM::ESMWriter& writer,
|
||||
const MWWorld::CellRefList<T>& collection)
|
||||
|
@ -319,6 +337,17 @@ namespace MWWorld
|
|||
return Ptr();
|
||||
}
|
||||
|
||||
Ptr CellStore::searchViaActorId (int id)
|
||||
{
|
||||
if (Ptr ptr = ::searchViaActorId (mNpcs, id, this))
|
||||
return ptr;
|
||||
|
||||
if (Ptr ptr = ::searchViaActorId (mCreatures, id, this))
|
||||
return ptr;
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
float CellStore::getWaterLevel() const
|
||||
{
|
||||
return mWaterLevel;
|
||||
|
|
|
@ -80,6 +80,9 @@ namespace MWWorld
|
|||
Ptr searchViaHandle (const std::string& handle);
|
||||
///< Will return an empty Ptr if cell is not loaded.
|
||||
|
||||
Ptr searchViaActorId (int id);
|
||||
///< Will return an empty Ptr if cell is not loaded.
|
||||
|
||||
float getWaterLevel() const;
|
||||
|
||||
void setWaterLevel (float level);
|
||||
|
|
|
@ -496,4 +496,14 @@ namespace MWWorld
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Ptr Scene::searchPtrViaActorId (int actorId)
|
||||
{
|
||||
for (CellStoreCollection::const_iterator iter (mActiveCells.begin());
|
||||
iter!=mActiveCells.end(); ++iter)
|
||||
if (Ptr ptr = (*iter)->searchViaActorId (actorId))
|
||||
return ptr;
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,8 @@ namespace MWWorld
|
|||
///< Remove an object from the scene, but not from the world model.
|
||||
|
||||
bool isCellActive(const CellStore &cell);
|
||||
|
||||
Ptr searchPtrViaActorId (int actorId);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -549,6 +549,11 @@ namespace MWWorld
|
|||
return MWWorld::Ptr();
|
||||
}
|
||||
|
||||
Ptr World::searchPtrViaActorId (int actorId)
|
||||
{
|
||||
return mWorldScene->searchPtrViaActorId (actorId);
|
||||
}
|
||||
|
||||
void World::addContainerScripts(const Ptr& reference, CellStore * cell)
|
||||
{
|
||||
if( reference.getTypeName()==typeid (ESM::Container).name() ||
|
||||
|
@ -1909,7 +1914,7 @@ namespace MWWorld
|
|||
out.push_back(searchPtrViaHandle(*it));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool World::getLOS(const MWWorld::Ptr& npc,const MWWorld::Ptr& targetNpc)
|
||||
{
|
||||
if (!targetNpc.getRefData().isEnabled() || !npc.getRefData().isEnabled())
|
||||
|
|
|
@ -287,6 +287,9 @@ namespace MWWorld
|
|||
virtual Ptr searchPtrViaHandle (const std::string& handle);
|
||||
///< Return a pointer to a liveCellRef with the given Ogre handle or Ptr() if not found
|
||||
|
||||
virtual Ptr searchPtrViaActorId (int actorId);
|
||||
///< Search is limited to the active cells.
|
||||
|
||||
virtual void adjustPosition (const Ptr& ptr);
|
||||
///< Adjust position after load to be on ground. Must be called after model load.
|
||||
|
||||
|
|
Loading…
Reference in a new issue