AiWander: resume moving to destination after combat

pull/456/head
Andrei Kortunov 7 years ago
parent 18ff097e4a
commit 81f29d8dcd

@ -79,6 +79,9 @@ namespace MWMechanics
/// Get the target actor the AI is targeted at (not applicable to all AI packages, default return empty Ptr)
virtual MWWorld::Ptr getTarget() const;
/// Get the destination point of the AI package (not applicable to all AI packages, default return (0, 0, 0))
virtual osg::Vec3f getDestination(const MWWorld::Ptr& actor) const { return osg::Vec3f(0, 0, 0); };
/// Return true if having this AiPackage makes the actor side with the target in fights (default false)
virtual bool sideWithTarget() const;

@ -338,6 +338,15 @@ namespace MWMechanics
return mRepeat;
}
osg::Vec3f AiWander::getDestination(const MWWorld::Ptr& actor) const
{
if (mHasDestination)
return mDestination;
const ESM::Pathgrid::Point currentPosition = actor.getRefData().getPosition().pos;
const osg::Vec3f currentPositionVec3f = osg::Vec3f(currentPosition.mX, currentPosition.mY, currentPosition.mZ);
return currentPositionVec3f;
}
bool AiWander::isPackageCompleted(const MWWorld::Ptr& actor, AiWanderStorage& storage)
{

@ -50,6 +50,8 @@ namespace MWMechanics
bool getRepeat() const;
osg::Vec3f getDestination(const MWWorld::Ptr& actor) const;
enum GreetingState {
Greet_None,
Greet_InProgress,

@ -1605,12 +1605,22 @@ namespace MWMechanics
return;
// we should return a wandering actor back after combat
// TODO: only for stationary wander?
if (!aiSequence.isInCombat() && aiSequence.getLastRunTypeId() == MWMechanics::AiPackage::TypeIdWander)
// the same thing for actors without AI packages
if (!aiSequence.isInCombat() && aiSequence.getTypeId() <= MWMechanics::AiPackage::TypeIdWander)
{
osg::Vec3f pos = ptr.getRefData().getPosition().asVec3();
int typeId = aiSequence.getTypeId();
osg::Vec3f dest;
if (typeId == MWMechanics::AiPackage::TypeIdNone)
{
dest = ptr.getRefData().getPosition().asVec3();
}
else if (typeId == MWMechanics::AiPackage::TypeIdWander)
{
AiPackage* activePackage = aiSequence.getActivePackage();
dest = activePackage->getDestination(ptr);
}
MWMechanics::AiTravel travelPackage(pos.x(), pos.y(), pos.z());
MWMechanics::AiTravel travelPackage(dest.x(), dest.y(), dest.z());
aiSequence.stack(travelPackage, ptr, false);
}

Loading…
Cancel
Save