1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 06:45:33 +00:00

add AIfollow to summoned creatures

This commit is contained in:
gus 2014-03-05 11:24:39 +01:00
parent 95ff869163
commit f4879dacd5
3 changed files with 28 additions and 16 deletions

View file

@ -539,6 +539,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()));

View file

@ -10,11 +10,16 @@
#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)
{
}
@ -30,22 +35,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()->mCell->mName)
return true;
if(actor.getCell()->isExterior())
{
if(mCellId == "")
return true;
}
else
{
if(mCellId == actor.getCell()->mCell->mName)
return true;
}
}
}

View file

@ -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;