2012-11-15 21:22:44 +00:00
|
|
|
#include "aiactivate.hpp"
|
2014-02-05 15:12:50 +00:00
|
|
|
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
2014-02-23 19:11:05 +00:00
|
|
|
|
2014-02-05 15:12:50 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2014-02-14 11:55:14 +00:00
|
|
|
#include "../mwworld/action.hpp"
|
2014-02-23 19:11:05 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2014-02-05 15:12:50 +00:00
|
|
|
|
2014-02-17 09:50:10 +00:00
|
|
|
#include "steering.hpp"
|
2014-02-23 19:11:05 +00:00
|
|
|
#include "movement.hpp"
|
2014-02-05 15:12:50 +00:00
|
|
|
|
2014-01-07 00:12:37 +00:00
|
|
|
MWMechanics::AiActivate::AiActivate(const std::string &objectId)
|
2014-02-05 15:12:50 +00:00
|
|
|
: mObjectId(objectId)
|
2014-01-07 00:12:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
MWMechanics::AiActivate *MWMechanics::AiActivate::clone() const
|
|
|
|
{
|
|
|
|
return new AiActivate(*this);
|
|
|
|
}
|
|
|
|
bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration)
|
2014-05-13 07:58:32 +00:00
|
|
|
{
|
|
|
|
ESM::Position pos = actor.getRefData().getPosition(); //position of the actor
|
|
|
|
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(mObjectId, false); //The target to follow
|
|
|
|
|
|
|
|
if(target == MWWorld::Ptr())
|
|
|
|
return true; //Target doesn't exist
|
|
|
|
|
|
|
|
//Set the target desition from the actor
|
|
|
|
ESM::Pathgrid::Point dest = target.getRefData().getPosition().pos;
|
|
|
|
|
|
|
|
if(distance(dest, pos.pos[0], pos.pos[1], pos.pos[2]) < 200 || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2])) { //Stop when you get close
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
|
|
|
|
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mObjectId,false);
|
|
|
|
MWWorld::Class::get(target).activate(target,actor).get()->execute(actor); //Arrest player
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pathTo(actor, dest, duration); //Go to the destination
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[1] = 1;
|
|
|
|
}
|
|
|
|
|
2014-02-05 15:12:50 +00:00
|
|
|
return false;
|
2014-01-07 00:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int MWMechanics::AiActivate::getTypeId() const
|
|
|
|
{
|
|
|
|
return TypeIdActivate;
|
|
|
|
}
|