1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 05:39:42 +00:00

Exclude deleted actors, prevent copies, and try to avoid a second getActorsSidingWith call

This commit is contained in:
Evil Eye 2024-01-29 22:08:00 +01:00
parent a8ee3dfae8
commit 8ed7a5319d
2 changed files with 6 additions and 5 deletions

View file

@ -606,8 +606,7 @@ namespace MWMechanics
// Get actors allied with actor1. Includes those following or escorting actor1, actors following or escorting
// those actors, (recursive) and any actor currently being followed or escorted by actor1
const std::set<MWWorld::Ptr> allies1 = cachedAllies.getActorsSidingWith(actor1);
const std::set<MWWorld::Ptr> allies2 = cachedAllies.getActorsSidingWith(actor2);
const std::set<MWWorld::Ptr>& allies1 = cachedAllies.getActorsSidingWith(actor1);
const auto mechanicsManager = MWBase::Environment::get().getMechanicsManager();
// If an ally of actor1 has been attacked by actor2 or has attacked actor2, start combat between actor1 and
@ -619,7 +618,7 @@ namespace MWMechanics
if (creatureStats2.matchesActorId(ally.getClass().getCreatureStats(ally).getHitAttemptActorId()))
{
mechanicsManager->startCombat(actor1, actor2, &allies2);
mechanicsManager->startCombat(actor1, actor2, &cachedAllies.getActorsSidingWith(actor2));
// Also set the same hit attempt actor. Otherwise, if fighting the player, they may stop combat
// if the player gets out of reach, while the ally would continue combat with the player
creatureStats1.setHitAttemptActorId(ally.getClass().getCreatureStats(ally).getHitAttemptActorId());
@ -644,6 +643,7 @@ namespace MWMechanics
// Check that actor2 is in combat with actor1
if (creatureStats2.getAiSequence().isInCombat(actor1))
{
const std::set<MWWorld::Ptr>& allies2 = cachedAllies.getActorsSidingWith(actor2);
// Check that an ally of actor2 is also in combat with actor1
for (const MWWorld::Ptr& ally2 : allies2)
{
@ -741,7 +741,7 @@ namespace MWMechanics
bool LOS = world->getLOS(actor1, actor2) && mechanicsManager->awarenessCheck(actor2, actor1);
if (LOS)
mechanicsManager->startCombat(actor1, actor2, &allies2);
mechanicsManager->startCombat(actor1, actor2, &cachedAllies.getActorsSidingWith(actor2));
}
}

View file

@ -507,7 +507,8 @@ namespace MWScript
runtime.pop();
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false);
if (!target.isEmpty() && !target.getClass().getCreatureStats(target).isDead())
if (!target.isEmpty() && !target.getBase()->isDeleted()
&& !target.getClass().getCreatureStats(target).isDead())
MWBase::Environment::get().getMechanicsManager()->startCombat(actor, target, nullptr);
}
};