Commit 725f6cac authored by mrcheko's avatar mrcheko

AiPursue infinite package updating bug resolved

parent e4fe7893
......@@ -730,7 +730,7 @@ namespace MWMechanics
&& MWBase::Environment::get().getWorld()->getLOS(ptr, player)
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, ptr))
{
creatureStats.getAiSequence().stack(AiPursue(player.getClass().getId(player)), ptr);
creatureStats.getAiSequence().stack(AiPursue(player), ptr);
creatureStats.setAlarmed(true);
npcStats.setCrimeId(MWBase::Environment::get().getWorld()->getPlayer().getNewCrimeId());
}
......@@ -759,7 +759,7 @@ namespace MWMechanics
else if (!creatureStats.isHostile())
{
if (ptr.getClass().isClass(ptr, "Guard"))
creatureStats.getAiSequence().stack(AiPursue(player.getClass().getId(player)), ptr);
creatureStats.getAiSequence().stack(AiPursue(player), ptr);
else
{
MWBase::Environment::get().getMechanicsManager()->startCombat(ptr, player);
......
#include "aipursue.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwworld/class.hpp"
......@@ -11,8 +10,8 @@
#include "movement.hpp"
#include "creaturestats.hpp"
MWMechanics::AiPursue::AiPursue(const std::string &objectId)
: mObjectId(objectId)
MWMechanics::AiPursue::AiPursue(const MWWorld::Ptr target)
: mTarget(target)
{
}
MWMechanics::AiPursue *MWMechanics::AiPursue::clone() const
......@@ -54,8 +53,7 @@ bool MWMechanics::AiPursue::execute (const MWWorld::Ptr& actor, float duration)
// Big TODO: Sync this with current AiFollow. Move common code to a shared base class or helpers (applies to all AI packages, way too much duplicated code)
MWWorld::Ptr target = world->getPtr(mObjectId,false);
ESM::Position targetPos = target.getRefData().getPosition();
ESM::Position targetPos = mTarget.getRefData().getPosition();
bool cellChange = cell->mData.mX != mCellX || cell->mData.mY != mCellY;
if(!mPathFinder.isPathConstructed() || cellChange || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
......@@ -81,8 +79,7 @@ bool MWMechanics::AiPursue::execute (const MWWorld::Ptr& actor, float duration)
(pos.pos[2]-targetPos.pos[2])*(pos.pos[2]-targetPos.pos[2]) < 100*100)
{
movement.mPosition[1] = 0;
MWWorld::Ptr target = world->getPtr(mObjectId,false);
MWWorld::Class::get(target).activate(target,actor).get()->execute(actor);
MWWorld::Class::get(mTarget).activate(mTarget,actor).get()->execute(actor);
return true;
}
......@@ -98,3 +95,8 @@ int MWMechanics::AiPursue::getTypeId() const
{
return TypeIdPursue;
}
MWWorld::Ptr MWMechanics::AiPursue::getTarget() const
{
return mTarget;
}
......@@ -2,7 +2,8 @@
#define GAME_MWMECHANICS_AIPURSUE_H
#include "aipackage.hpp"
#include <string>
#include "../mwbase/world.hpp"
#include "pathfinding.hpp"
......@@ -12,14 +13,17 @@ namespace MWMechanics
class AiPursue : public AiPackage
{
public:
AiPursue(const std::string &objectId);
AiPursue(const MWWorld::Ptr target);
virtual AiPursue *clone() const;
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;
virtual MWWorld::Ptr getTarget() const;
private:
std::string mObjectId;
MWWorld::Ptr mTarget;
PathFinder mPathFinder;
int mCellX;
......
......@@ -9,6 +9,7 @@
#include "aifollow.hpp"
#include "aiactivate.hpp"
#include "aicombat.hpp"
#include "aipursue.hpp"
#include "../mwworld/class.hpp"
#include "creaturestats.hpp"
......@@ -128,7 +129,12 @@ void MWMechanics::AiSequence::stack (const AiPackage& package, const MWWorld::Pt
// Notify AiWander of our current position so we can return to it after combat finished
for (std::list<AiPackage *>::const_iterator iter (mPackages.begin()); iter!=mPackages.end(); ++iter)
{
if ((*iter)->getTypeId() == AiPackage::TypeIdWander)
if((*iter)->getTypeId() == AiPackage::TypeIdPursue && package.getTypeId() == AiPackage::TypeIdPursue
&& static_cast<const AiPursue*>(*iter)->getTarget() == static_cast<const AiPursue*>(&package)->getTarget())
{
return; // target is already pursued
}
else if ((*iter)->getTypeId() == AiPackage::TypeIdWander)
static_cast<AiWander*>(*iter)->setReturnPosition(Ogre::Vector3(actor.getRefData().getPosition().pos));
}
}
......
......@@ -316,7 +316,7 @@ namespace MWWorld
if(stepMove(colobj, newPosition, velocity, remainingTime, engine))
{
// don't let pure water creatures move out of water after stepMove
if((ptr.getClass().canSwim(ptr) && !canWalk)
if((ptr.getClass().canSwim(ptr) && !ptr.getClass().canWalk(ptr))
&& newPosition.z > (waterlevel - halfExtents.z * 0.5))
newPosition = oldPosition;
else // Only on the ground if there's gravity
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment