forked from teamnwah/openmw-tes3coop
AiPursue infinite package updating bug resolved
This commit is contained in:
parent
e4fe78937a
commit
725f6cac5e
5 changed files with 26 additions and 14 deletions
|
@ -730,7 +730,7 @@ namespace MWMechanics
|
||||||
&& MWBase::Environment::get().getWorld()->getLOS(ptr, player)
|
&& MWBase::Environment::get().getWorld()->getLOS(ptr, player)
|
||||||
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, ptr))
|
&& 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);
|
creatureStats.setAlarmed(true);
|
||||||
npcStats.setCrimeId(MWBase::Environment::get().getWorld()->getPlayer().getNewCrimeId());
|
npcStats.setCrimeId(MWBase::Environment::get().getWorld()->getPlayer().getNewCrimeId());
|
||||||
}
|
}
|
||||||
|
@ -759,7 +759,7 @@ namespace MWMechanics
|
||||||
else if (!creatureStats.isHostile())
|
else if (!creatureStats.isHostile())
|
||||||
{
|
{
|
||||||
if (ptr.getClass().isClass(ptr, "Guard"))
|
if (ptr.getClass().isClass(ptr, "Guard"))
|
||||||
creatureStats.getAiSequence().stack(AiPursue(player.getClass().getId(player)), ptr);
|
creatureStats.getAiSequence().stack(AiPursue(player), ptr);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getMechanicsManager()->startCombat(ptr, player);
|
MWBase::Environment::get().getMechanicsManager()->startCombat(ptr, player);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "aipursue.hpp"
|
#include "aipursue.hpp"
|
||||||
|
|
||||||
#include "../mwbase/world.hpp"
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
@ -11,8 +10,8 @@
|
||||||
#include "movement.hpp"
|
#include "movement.hpp"
|
||||||
#include "creaturestats.hpp"
|
#include "creaturestats.hpp"
|
||||||
|
|
||||||
MWMechanics::AiPursue::AiPursue(const std::string &objectId)
|
MWMechanics::AiPursue::AiPursue(const MWWorld::Ptr target)
|
||||||
: mObjectId(objectId)
|
: mTarget(target)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
MWMechanics::AiPursue *MWMechanics::AiPursue::clone() const
|
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)
|
// 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 = mTarget.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;
|
||||||
if(!mPathFinder.isPathConstructed() || cellChange || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
|
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)
|
(pos.pos[2]-targetPos.pos[2])*(pos.pos[2]-targetPos.pos[2]) < 100*100)
|
||||||
{
|
{
|
||||||
movement.mPosition[1] = 0;
|
movement.mPosition[1] = 0;
|
||||||
MWWorld::Ptr target = world->getPtr(mObjectId,false);
|
MWWorld::Class::get(mTarget).activate(mTarget,actor).get()->execute(actor);
|
||||||
MWWorld::Class::get(target).activate(target,actor).get()->execute(actor);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,3 +95,8 @@ int MWMechanics::AiPursue::getTypeId() const
|
||||||
{
|
{
|
||||||
return TypeIdPursue;
|
return TypeIdPursue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWWorld::Ptr MWMechanics::AiPursue::getTarget() const
|
||||||
|
{
|
||||||
|
return mTarget;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#define GAME_MWMECHANICS_AIPURSUE_H
|
#define GAME_MWMECHANICS_AIPURSUE_H
|
||||||
|
|
||||||
#include "aipackage.hpp"
|
#include "aipackage.hpp"
|
||||||
#include <string>
|
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
#include "pathfinding.hpp"
|
#include "pathfinding.hpp"
|
||||||
|
|
||||||
|
@ -12,14 +13,17 @@ namespace MWMechanics
|
||||||
class AiPursue : public AiPackage
|
class AiPursue : public AiPackage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AiPursue(const std::string &objectId);
|
AiPursue(const MWWorld::Ptr target);
|
||||||
virtual AiPursue *clone() const;
|
virtual AiPursue *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?
|
||||||
virtual int getTypeId() const;
|
virtual int getTypeId() const;
|
||||||
|
|
||||||
|
virtual MWWorld::Ptr getTarget() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mObjectId;
|
|
||||||
|
MWWorld::Ptr mTarget;
|
||||||
|
|
||||||
PathFinder mPathFinder;
|
PathFinder mPathFinder;
|
||||||
int mCellX;
|
int mCellX;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "aifollow.hpp"
|
#include "aifollow.hpp"
|
||||||
#include "aiactivate.hpp"
|
#include "aiactivate.hpp"
|
||||||
#include "aicombat.hpp"
|
#include "aicombat.hpp"
|
||||||
|
#include "aipursue.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "creaturestats.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
|
// 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)
|
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));
|
static_cast<AiWander*>(*iter)->setReturnPosition(Ogre::Vector3(actor.getRefData().getPosition().pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,7 +316,7 @@ namespace MWWorld
|
||||||
if(stepMove(colobj, newPosition, velocity, remainingTime, engine))
|
if(stepMove(colobj, newPosition, velocity, remainingTime, engine))
|
||||||
{
|
{
|
||||||
// don't let pure water creatures move out of water after stepMove
|
// 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.z > (waterlevel - halfExtents.z * 0.5))
|
||||||
newPosition = oldPosition;
|
newPosition = oldPosition;
|
||||||
else // Only on the ground if there's gravity
|
else // Only on the ground if there's gravity
|
||||||
|
|
Loading…
Reference in a new issue