mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:56:43 +00:00 
			
		
		
		
	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;
 | 
					            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
 | 
					            ///< 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
 | 
					            /// \todo enable reference in the OGRE scene
 | 
				
			||||||
            virtual void enable (const MWWorld::Ptr& ptr) = 0;
 | 
					            virtual void enable (const MWWorld::Ptr& ptr) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace MWMechanics
 | 
					namespace MWMechanics
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    int CreatureStats::sActorId = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CreatureStats::CreatureStats()
 | 
					    CreatureStats::CreatureStats()
 | 
				
			||||||
        : mLevel (0), mDead (false), mDied (false), mFriendlyHits (0),
 | 
					        : mLevel (0), mDead (false), mDied (false), mFriendlyHits (0),
 | 
				
			||||||
          mTalkedTo (false), mAlarmed (false),
 | 
					          mTalkedTo (false), mAlarmed (false),
 | 
				
			||||||
| 
						 | 
					@ -18,7 +20,8 @@ namespace MWMechanics
 | 
				
			||||||
          mAttackingOrSpell(false),
 | 
					          mAttackingOrSpell(false),
 | 
				
			||||||
          mIsWerewolf(false),
 | 
					          mIsWerewolf(false),
 | 
				
			||||||
          mFallHeight(0), mRecalcDynamicStats(false), mKnockdown(false), mKnockdownOneFrame(false), mKnockdownOverOneFrame(false), mHitRecovery(false), mBlock(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)
 | 
					        for (int i=0; i<4; ++i)
 | 
				
			||||||
            mAiSettings[i] = 0;
 | 
					            mAiSettings[i] = 0;
 | 
				
			||||||
| 
						 | 
					@ -516,4 +519,17 @@ namespace MWMechanics
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return mGoldPool;
 | 
					        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
 | 
					    class CreatureStats
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        static int sActorId;
 | 
				
			||||||
        DrawState_ mDrawState;
 | 
					        DrawState_ mDrawState;
 | 
				
			||||||
        AttributeValue mAttributes[8];
 | 
					        AttributeValue mAttributes[8];
 | 
				
			||||||
        DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
 | 
					        DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
 | 
				
			||||||
| 
						 | 
					@ -60,6 +61,7 @@ namespace MWMechanics
 | 
				
			||||||
        MWWorld::TimeStamp mTradeTime; // Relates to NPC gold reset delay
 | 
					        MWWorld::TimeStamp mTradeTime; // Relates to NPC gold reset delay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        int mGoldPool; // the pool of merchant gold not in inventory
 | 
					        int mGoldPool; // the pool of merchant gold not in inventory
 | 
				
			||||||
 | 
					        int mActorId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected:
 | 
					    protected:
 | 
				
			||||||
        bool mIsWerewolf;
 | 
					        bool mIsWerewolf;
 | 
				
			||||||
| 
						 | 
					@ -239,6 +241,13 @@ namespace MWMechanics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void setGoldPool(int pool);
 | 
					        void setGoldPool(int pool);
 | 
				
			||||||
        int getGoldPool() const;
 | 
					        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/environment.hpp"
 | 
				
			||||||
#include "../mwbase/world.hpp"
 | 
					#include "../mwbase/world.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "../mwmechanics/creaturestats.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "ptr.hpp"
 | 
					#include "ptr.hpp"
 | 
				
			||||||
#include "esmstore.hpp"
 | 
					#include "esmstore.hpp"
 | 
				
			||||||
#include "class.hpp"
 | 
					#include "class.hpp"
 | 
				
			||||||
| 
						 | 
					@ -40,6 +42,22 @@ namespace
 | 
				
			||||||
        return MWWorld::Ptr();
 | 
					        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>
 | 
					    template<typename RecordType, typename T>
 | 
				
			||||||
    void writeReferenceCollection (ESM::ESMWriter& writer,
 | 
					    void writeReferenceCollection (ESM::ESMWriter& writer,
 | 
				
			||||||
        const MWWorld::CellRefList<T>& collection)
 | 
					        const MWWorld::CellRefList<T>& collection)
 | 
				
			||||||
| 
						 | 
					@ -319,6 +337,17 @@ namespace MWWorld
 | 
				
			||||||
        return Ptr();
 | 
					        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
 | 
					    float CellStore::getWaterLevel() const
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return mWaterLevel;
 | 
					        return mWaterLevel;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,6 +80,9 @@ namespace MWWorld
 | 
				
			||||||
            Ptr searchViaHandle (const std::string& handle);
 | 
					            Ptr searchViaHandle (const std::string& handle);
 | 
				
			||||||
            ///< Will return an empty Ptr if cell is not loaded.
 | 
					            ///< 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;
 | 
					            float getWaterLevel() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            void setWaterLevel (float level);
 | 
					            void setWaterLevel (float level);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -496,4 +496,14 @@ namespace MWWorld
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return false;
 | 
					        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.
 | 
					            ///< Remove an object from the scene, but not from the world model.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            bool isCellActive(const CellStore &cell);
 | 
					            bool isCellActive(const CellStore &cell);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Ptr searchPtrViaActorId (int actorId);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -549,6 +549,11 @@ namespace MWWorld
 | 
				
			||||||
        return MWWorld::Ptr();
 | 
					        return MWWorld::Ptr();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ptr World::searchPtrViaActorId (int actorId)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return mWorldScene->searchPtrViaActorId (actorId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void World::addContainerScripts(const Ptr& reference, CellStore * cell)
 | 
					    void World::addContainerScripts(const Ptr& reference, CellStore * cell)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if( reference.getTypeName()==typeid (ESM::Container).name() ||
 | 
					        if( reference.getTypeName()==typeid (ESM::Container).name() ||
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -287,6 +287,9 @@ namespace MWWorld
 | 
				
			||||||
            virtual Ptr searchPtrViaHandle (const std::string& handle);
 | 
					            virtual Ptr searchPtrViaHandle (const std::string& handle);
 | 
				
			||||||
            ///< Return a pointer to a liveCellRef with the given Ogre handle or Ptr() if not found
 | 
					            ///< 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);
 | 
					            virtual void adjustPosition (const Ptr& ptr);
 | 
				
			||||||
            ///< Adjust position after load to be on ground. Must be called after model load.
 | 
					            ///< Adjust position after load to be on ground. Must be called after model load.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue