forked from teamnwah/openmw-tes3coop
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;
|
ref.getPtr().getCellRef().mPos = ipos;
|
||||||
|
|
||||||
// TODO: Add AI to follow player and fight for him
|
// 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
|
// TODO: VFX_SummonStart, VFX_SummonEnd
|
||||||
creatureStats.mSummonedCreatures.insert(std::make_pair(it->first,
|
creatureStats.mSummonedCreatures.insert(std::make_pair(it->first,
|
||||||
MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,ipos).getRefData().getHandle()));
|
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();
|
ESM::Position targetPos = target.getRefData().getPosition();
|
||||||
|
|
||||||
bool cellChange = cell->mData.mX != mCellX || cell->mData.mY != mCellY;
|
bool cellChange = cell->mData.mX != mCellX || cell->mData.mY != mCellY;
|
||||||
|
|
|
@ -1,28 +1,34 @@
|
||||||
#include "aifollow.hpp"
|
#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 <OgreMath.h>
|
||||||
|
|
||||||
#include "../mwbase/world.hpp"
|
|
||||||
#include "../mwbase/environment.hpp"
|
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
|
||||||
#include "../mwworld/cellstore.hpp"
|
|
||||||
|
|
||||||
#include "movement.hpp"
|
|
||||||
#include "steering.hpp"
|
#include "steering.hpp"
|
||||||
|
|
||||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z)
|
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)
|
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)
|
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;
|
mTimer = mTimer + duration;
|
||||||
mStuckTimer = mStuckTimer + duration;
|
mStuckTimer = mStuckTimer + duration;
|
||||||
|
@ -30,6 +36,8 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration)
|
||||||
|
|
||||||
ESM::Position pos = actor.getRefData().getPosition();
|
ESM::Position pos = actor.getRefData().getPosition();
|
||||||
|
|
||||||
|
if(!mAlwaysFollow)
|
||||||
|
{
|
||||||
if(mTotalTime > mDuration && mDuration != 0)
|
if(mTotalTime > mDuration && mDuration != 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -48,6 +56,7 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ESM::Pathgrid::Point dest;
|
ESM::Pathgrid::Point dest;
|
||||||
dest.mX = target.getRefData().getPosition().pos[0];
|
dest.mX = target.getRefData().getPosition().pos[0];
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace MWMechanics
|
||||||
public:
|
public:
|
||||||
AiFollow(const std::string &ActorId,float duration, float X, float Y, float Z);
|
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,const std::string &CellId,float duration, float X, float Y, float Z);
|
||||||
|
AiFollow(const std::string &ActorId);
|
||||||
virtual AiFollow *clone() const;
|
virtual AiFollow *clone() const;
|
||||||
virtual bool execute (const MWWorld::Ptr& actor,float duration);
|
virtual bool execute (const MWWorld::Ptr& actor,float duration);
|
||||||
///< \return Package completed?
|
///< \return Package completed?
|
||||||
|
@ -22,6 +23,7 @@ namespace MWMechanics
|
||||||
std::string getFollowedActor();
|
std::string getFollowedActor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool mAlwaysFollow; //this will make the actor always follow, thus ignoring mDuration and mX,mY,mZ (used for summoned creatures).
|
||||||
float mDuration;
|
float mDuration;
|
||||||
float mX;
|
float mX;
|
||||||
float mY;
|
float mY;
|
||||||
|
|
Loading…
Reference in a new issue