mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Merge remote-tracking branch 'gus/AIFix2'
This commit is contained in:
		
						commit
						c7f2cfeca0
					
				
					 4 changed files with 41 additions and 26 deletions
				
			
		|  | @ -543,6 +543,8 @@ namespace MWMechanics | |||
|                         ref.getPtr().getCellRef().mPos = ipos; | ||||
| 
 | ||||
|                         // TODO: Add AI to follow player and fight for him
 | ||||
|                         AiFollow package(ptr.getRefData().getHandle()); | ||||
|                         MWWorld::Class::get (ref.getPtr()).getCreatureStats (ref.getPtr()).getAiSequence().stack(package); | ||||
|                         // TODO: VFX_SummonStart, VFX_SummonEnd
 | ||||
|                         creatureStats.mSummonedCreatures.insert(std::make_pair(it->first, | ||||
|                             MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,ipos).getRefData().getHandle())); | ||||
|  |  | |||
|  | @ -49,7 +49,9 @@ bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration) | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     MWWorld::Ptr target = world->getPtr(mObjectId,false); | ||||
|     MWWorld::Ptr target = world->searchPtr(mObjectId,false); | ||||
|     if(target == MWWorld::Ptr()) return true; | ||||
| 
 | ||||
|     ESM::Position targetPos = target.getRefData().getPosition(); | ||||
| 
 | ||||
|     bool cellChange = cell->mData.mX != mCellX || cell->mData.mY != mCellY; | ||||
|  |  | |||
|  | @ -1,28 +1,34 @@ | |||
| #include "aifollow.hpp" | ||||
| #include <iostream> | ||||
| #include "../mwbase/world.hpp" | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwworld/class.hpp" | ||||
| #include "../mwworld/cellstore.hpp" | ||||
| #include "movement.hpp" | ||||
| 
 | ||||
| #include <OgreMath.h> | ||||
| 
 | ||||
| #include "../mwbase/world.hpp" | ||||
| #include "../mwbase/environment.hpp" | ||||
| 
 | ||||
| #include "../mwworld/class.hpp" | ||||
| #include "../mwworld/cellstore.hpp" | ||||
| 
 | ||||
| #include "movement.hpp" | ||||
| #include "steering.hpp" | ||||
| 
 | ||||
| MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z) | ||||
| : mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(""), mTimer(0), mStuckTimer(0) | ||||
| : mAlwaysFollow(false), mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(""), mTimer(0), mStuckTimer(0) | ||||
| { | ||||
| } | ||||
| MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z) | ||||
| : mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId), mTimer(0), mStuckTimer(0) | ||||
| : mAlwaysFollow(false), mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId), mTimer(0), mStuckTimer(0) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| MWMechanics::AiFollow::AiFollow(const std::string &actorId) | ||||
| : mAlwaysFollow(true), mDuration(0), mX(0), mY(0), mZ(0), mActorId(actorId), mCellId(""), mTimer(0), mStuckTimer(0) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) | ||||
| { | ||||
|     const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mActorId, false); | ||||
|     const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(mActorId, false); | ||||
|      | ||||
|     if(target == MWWorld::Ptr()) return true; | ||||
| 
 | ||||
|     mTimer = mTimer + duration; | ||||
|     mStuckTimer = mStuckTimer + duration; | ||||
|  | @ -30,22 +36,25 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) | |||
| 
 | ||||
|     ESM::Position pos = actor.getRefData().getPosition(); | ||||
| 
 | ||||
|     if(mTotalTime > mDuration && mDuration != 0) | ||||
|         return true; | ||||
| 
 | ||||
|     if((pos.pos[0]-mX)*(pos.pos[0]-mX) + | ||||
|         (pos.pos[1]-mY)*(pos.pos[1]-mY) + | ||||
|         (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < 100*100) | ||||
|     if(!mAlwaysFollow) | ||||
|     { | ||||
|         if(actor.getCell()->isExterior()) | ||||
|         if(mTotalTime > mDuration && mDuration != 0) | ||||
|             return true; | ||||
| 
 | ||||
|         if((pos.pos[0]-mX)*(pos.pos[0]-mX) + | ||||
|             (pos.pos[1]-mY)*(pos.pos[1]-mY) + | ||||
|             (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < 100*100)  | ||||
|         { | ||||
|             if(mCellId == "") | ||||
|                 return true; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if(mCellId == actor.getCell()->getCell()->mName) | ||||
|                 return true; | ||||
|             if(actor.getCell()->isExterior()) | ||||
|             { | ||||
|                 if(mCellId == "")  | ||||
|                     return true; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if(mCellId == actor.getCell()->getCell()->mName) | ||||
|                     return true; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ namespace MWMechanics | |||
|         public: | ||||
|             AiFollow(const std::string &ActorId,float duration, float X, float Y, float Z); | ||||
|             AiFollow(const std::string &ActorId,const std::string &CellId,float duration, float X, float Y, float Z); | ||||
|             AiFollow(const std::string &ActorId); | ||||
|             virtual AiFollow *clone() const; | ||||
|             virtual bool execute (const MWWorld::Ptr& actor,float duration); | ||||
|                     ///< \return Package completed?
 | ||||
|  | @ -22,6 +23,7 @@ namespace MWMechanics | |||
|             std::string getFollowedActor(); | ||||
| 
 | ||||
|         private: | ||||
|             bool mAlwaysFollow; //this will make the actor always follow, thus ignoring mDuration and mX,mY,mZ (used for summoned creatures).
 | ||||
|             float mDuration; | ||||
|             float mX; | ||||
|             float mY; | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue