mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 00:45:34 +00:00
parent
7aeafd3bb9
commit
d3b76b7006
6 changed files with 101 additions and 63 deletions
|
@ -26,6 +26,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
virtual unsigned int getPriority() const;
|
virtual unsigned int getPriority() const;
|
||||||
|
|
||||||
|
virtual bool canCancel() const { return false; }
|
||||||
|
virtual bool shouldCancelPreviousAi() const { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float mDuration;
|
float mDuration;
|
||||||
MWWorld::ConstPtr mDoorPtr;
|
MWWorld::ConstPtr mDoorPtr;
|
||||||
|
|
|
@ -53,6 +53,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const;
|
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const;
|
||||||
|
|
||||||
|
virtual bool canCancel() const { return false; }
|
||||||
|
virtual bool shouldCancelPreviousAi() const { return false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell);
|
virtual bool doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,16 @@ bool MWMechanics::AiPackage::followTargetThroughDoors() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MWMechanics::AiPackage::canCancel() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MWMechanics::AiPackage::shouldCancelPreviousAi() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
MWMechanics::AiPackage::AiPackage() : mTimer(0.26f) { //mTimer starts at .26 to force initial pathbuild
|
MWMechanics::AiPackage::AiPackage() : mTimer(0.26f) { //mTimer starts at .26 to force initial pathbuild
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ namespace MWMechanics
|
||||||
TypeIdEscort = 2,
|
TypeIdEscort = 2,
|
||||||
TypeIdFollow = 3,
|
TypeIdFollow = 3,
|
||||||
TypeIdActivate = 4,
|
TypeIdActivate = 4,
|
||||||
|
|
||||||
|
// These 3 are not really handled as Ai Packages in the MW engine
|
||||||
TypeIdCombat = 5,
|
TypeIdCombat = 5,
|
||||||
TypeIdPursue = 6,
|
TypeIdPursue = 6,
|
||||||
TypeIdAvoidDoor = 7
|
TypeIdAvoidDoor = 7
|
||||||
|
@ -78,6 +80,12 @@ namespace MWMechanics
|
||||||
/// Return true if the actor should follow the target through teleport doors (default false)
|
/// Return true if the actor should follow the target through teleport doors (default false)
|
||||||
virtual bool followTargetThroughDoors() const;
|
virtual bool followTargetThroughDoors() const;
|
||||||
|
|
||||||
|
/// Can this Ai package be canceled? (default true)
|
||||||
|
virtual bool canCancel() const;
|
||||||
|
|
||||||
|
/// Upon adding this Ai package, should the Ai Sequence attempt to cancel previous Ai packages (default true)?
|
||||||
|
virtual bool shouldCancelPreviousAi() const;
|
||||||
|
|
||||||
bool isTargetMagicallyHidden(const MWWorld::Ptr& target);
|
bool isTargetMagicallyHidden(const MWWorld::Ptr& target);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -38,6 +38,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
virtual void writeState (ESM::AiSequence::AiSequence& sequence) const;
|
virtual void writeState (ESM::AiSequence::AiSequence& sequence) const;
|
||||||
|
|
||||||
|
virtual bool canCancel() const { return false; }
|
||||||
|
virtual bool shouldCancelPreviousAi() const { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int mTargetActorId; // The actor to pursue
|
int mTargetActorId; // The actor to pursue
|
||||||
|
|
|
@ -153,8 +153,12 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
|
||||||
{
|
{
|
||||||
if(actor != getPlayer())
|
if(actor != getPlayer())
|
||||||
{
|
{
|
||||||
if (!mPackages.empty())
|
if (mPackages.empty())
|
||||||
{
|
{
|
||||||
|
mLastAiPackage = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MWMechanics::AiPackage* package = mPackages.front();
|
MWMechanics::AiPackage* package = mPackages.front();
|
||||||
mLastAiPackage = package->getTypeId();
|
mLastAiPackage = package->getTypeId();
|
||||||
|
|
||||||
|
@ -230,7 +234,6 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
|
||||||
mDone = false;
|
mDone = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AiSequence::clear()
|
void AiSequence::clear()
|
||||||
|
@ -251,11 +254,6 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor)
|
||||||
// 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::TypeIdPursue && package.getTypeId() == AiPackage::TypeIdPursue
|
|
||||||
&& static_cast<const AiPursue*>(*iter)->getTarget() == static_cast<const AiPursue*>(&package)->getTarget())
|
|
||||||
{
|
|
||||||
return; // target is already pursued
|
|
||||||
}
|
|
||||||
if((*iter)->getTypeId() == AiPackage::TypeIdCombat && package.getTypeId() == AiPackage::TypeIdCombat
|
if((*iter)->getTypeId() == AiPackage::TypeIdCombat && package.getTypeId() == AiPackage::TypeIdCombat
|
||||||
&& static_cast<const AiCombat*>(*iter)->getTarget() == static_cast<const AiCombat*>(&package)->getTarget())
|
&& static_cast<const AiCombat*>(*iter)->getTarget() == static_cast<const AiCombat*>(&package)->getTarget())
|
||||||
{
|
{
|
||||||
|
@ -266,6 +264,19 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove previous packages if required
|
||||||
|
if (package.shouldCancelPreviousAi())
|
||||||
|
{
|
||||||
|
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end();)
|
||||||
|
{
|
||||||
|
if((*it)->canCancel())
|
||||||
|
it = mPackages.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert new package in correct place depending on priority
|
||||||
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
||||||
{
|
{
|
||||||
if((*it)->getPriority() <= package.getPriority())
|
if((*it)->getPriority() <= package.getPriority())
|
||||||
|
|
Loading…
Reference in a new issue