2014-05-03 10:23:22 +00:00
|
|
|
#include "aipursue.hpp"
|
2014-04-02 04:18:22 +00:00
|
|
|
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/action.hpp"
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
|
|
|
|
#include "steering.hpp"
|
|
|
|
#include "movement.hpp"
|
|
|
|
#include "creaturestats.hpp"
|
|
|
|
|
2014-05-16 10:11:34 +00:00
|
|
|
MWMechanics::AiPursue::AiPursue(const std::string &objectId)
|
|
|
|
: mObjectId(objectId)
|
2014-04-02 04:18:22 +00:00
|
|
|
{
|
|
|
|
}
|
2014-05-03 10:23:22 +00:00
|
|
|
MWMechanics::AiPursue *MWMechanics::AiPursue::clone() const
|
2014-04-02 04:18:22 +00:00
|
|
|
{
|
2014-05-03 10:23:22 +00:00
|
|
|
return new AiPursue(*this);
|
2014-04-02 04:18:22 +00:00
|
|
|
}
|
2014-05-03 10:23:22 +00:00
|
|
|
bool MWMechanics::AiPursue::execute (const MWWorld::Ptr& actor, float duration)
|
2014-04-02 04:18:22 +00:00
|
|
|
{
|
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
ESM::Position pos = actor.getRefData().getPosition(); //position of the actor
|
2014-05-16 10:11:34 +00:00
|
|
|
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(mObjectId, false); //The target to follow
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
if(target == MWWorld::Ptr())
|
|
|
|
return true; //Target doesn't exist
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
//Set the target desition from the actor
|
|
|
|
ESM::Pathgrid::Point dest = target.getRefData().getPosition().pos;
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
if(distance(dest, pos.pos[0], pos.pos[1], pos.pos[2]) < 100) { //Stop when you get close
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
|
2014-05-16 10:11:34 +00:00
|
|
|
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mObjectId,false);
|
|
|
|
MWWorld::Class::get(target).activate(target,actor).get()->execute(actor); //Arrest player
|
2014-04-02 04:18:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-13 07:58:32 +00:00
|
|
|
else {
|
|
|
|
pathTo(actor, dest, duration); //Go to the destination
|
|
|
|
}
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
actor.getClass().getCreatureStats(actor).setMovementFlag(MWMechanics::CreatureStats::Flag_Run, true); //Make NPC run
|
2014-04-02 04:18:22 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:23:22 +00:00
|
|
|
int MWMechanics::AiPursue::getTypeId() const
|
2014-04-02 04:18:22 +00:00
|
|
|
{
|
2014-05-03 10:23:22 +00:00
|
|
|
return TypeIdPursue;
|
2014-04-02 04:18:22 +00:00
|
|
|
}
|