1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-12 15:43:06 +00:00

Merge branch 'cattlethief' into 'master'

Fix AI issues with Command spells

Closes #5331

See merge request OpenMW/openmw!4599
This commit is contained in:
psi29a 2025-07-01 21:18:09 +00:00
commit 59eb7b9888
5 changed files with 22 additions and 14 deletions

View file

@ -119,6 +119,7 @@ namespace MWMechanics
/// Reset pathfinding state
void reset();
virtual void resetInitialPosition() {}
/// Return if actor's rotation speed is sufficient to rotate to the destination pathpoint on the run. Otherwise
/// actor should rotate while standing.

View file

@ -400,7 +400,7 @@ namespace MWMechanics
const auto newTypeId = package.getTypeId();
if (currentTypeId <= MWMechanics::AiPackageTypeId::Wander
&& !hasPackage(MWMechanics::AiPackageTypeId::InternalTravel)
&& (newTypeId <= MWMechanics::AiPackageTypeId::Combat || newTypeId == MWMechanics::AiPackageTypeId::Pursue
&& (newTypeId == MWMechanics::AiPackageTypeId::Combat || newTypeId == MWMechanics::AiPackageTypeId::Pursue
|| newTypeId == MWMechanics::AiPackageTypeId::Cast))
{
osg::Vec3f dest;
@ -444,8 +444,15 @@ namespace MWMechanics
if ((*it)->getPriority() <= package.getPriority())
{
if (cancelOther && isActualAiPackage((*it)->getTypeId()))
mAiState.reset();
onPackageAdded(package);
mPackages.insert(it, package.clone());
it = mPackages.insert(it, package.clone());
if (newTypeId == MWMechanics::AiPackageTypeId::Follow)
{
for (++it; it != mPackages.end(); ++it)
(*it)->resetInitialPosition();
}
return;
}
}
@ -455,11 +462,7 @@ namespace MWMechanics
// Make sure that temporary storage is empty
if (cancelOther)
{
mAiState.moveIn(std::make_unique<AiCombatStorage>());
mAiState.moveIn(std::make_unique<AiFollowStorage>());
mAiState.moveIn(std::make_unique<AiWanderStorage>());
}
mAiState.reset();
}
bool MWMechanics::AiSequence::isEmpty() const

View file

@ -59,12 +59,7 @@ namespace MWMechanics
mStorage = std::make_unique<Derived>(payload);
}
/// \brief takes ownership of the passed object
template <class Derived>
void moveIn(std::unique_ptr<Derived>&& storage)
{
mStorage = std::move(storage);
}
void reset() { mStorage.reset(); }
};
}

View file

@ -676,6 +676,13 @@ namespace MWMechanics
stopMovement(actor);
}
void AiWander::resetInitialPosition()
{
mStoredInitialActorPosition = false;
mPathFinder.clearPath();
mHasDestination = false;
}
bool AiWander::playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect)
{
if ((GroupIndex_MinIdle <= idleSelect) && (idleSelect <= GroupIndex_MaxIdle))
@ -804,7 +811,7 @@ namespace MWMechanics
converter.toWorld(dest);
state.moveIn(std::make_unique<AiWanderStorage>());
state.reset();
osg::Vec3f pos(static_cast<float>(dest.mX), static_cast<float>(dest.mY), static_cast<float>(dest.mZ));
MWBase::Environment::get().getWorld()->moveObject(actor, pos);

View file

@ -122,6 +122,8 @@ namespace MWMechanics
static std::string_view getIdleGroupName(size_t index) { return sIdleSelectToGroupName[index]; }
void resetInitialPosition() override;
private:
void stopWalking(const MWWorld::Ptr& actor);