From e8c7ad2f4b2c29d7bbd8769c6d304572700462f7 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sun, 25 Dec 2016 23:31:44 +0900 Subject: [PATCH] Change environment check to canFight check Instead of just checking that combatants are in compatible environments, allow combat if in attack range using canFight. Together with previous commit, fixes #3690. --- apps/openmw/mwmechanics/actors.cpp | 59 +++++++++++++++--------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 8c1a88e3f..2f1c55a2a 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -29,6 +29,7 @@ #include "movement.hpp" #include "character.hpp" #include "aicombat.hpp" +#include "aicombataction.hpp" #include "aifollow.hpp" #include "aipursue.hpp" #include "actor.hpp" @@ -298,41 +299,12 @@ namespace MWMechanics if (sqrDist > sqrAiProcessingDistance) return; - // pure water creatures won't try to fight with the target on the ground - // except that creature is already hostile - if ((againstPlayer || !creatureStats.getAiSequence().isInCombat()) - && !MWMechanics::isEnvironmentCompatible(actor1, actor2)) // creature can't swim to target - { - return; - } - // no combat for totally static creatures (they have no movement or attack animations anyway) if (!actor1.getClass().isMobile(actor1)) return; const std::list& playerFollowersAndEscorters = getActorsSidingWith(getPlayer()); - bool aggressive; - - if (againstPlayer || std::find(playerFollowersAndEscorters.begin(), playerFollowersAndEscorters.end(), actor2) != playerFollowersAndEscorters.end()) - { - // Player followers and escorters with high fight should not initiate combat with the player or with - // other player followers or escorters - if (std::find(playerFollowersAndEscorters.begin(), playerFollowersAndEscorters.end(), actor1) != playerFollowersAndEscorters.end()) - return; - - aggressive = MWBase::Environment::get().getMechanicsManager()->isAggressive(actor1, actor2); - } - else - { - aggressive = false; - - // Make guards fight aggressive creatures - if (!actor1.getClass().isNpc() && actor2.getClass().isClass(actor2, "Guard")) - { - if (creatureStats.getAiSequence().isInCombat() && MWBase::Environment::get().getMechanicsManager()->isAggressive(actor1, actor2)) - aggressive = true; - } - } + bool aggressive = false; // start combat if target actor is in combat with one of our followers const std::list& followers = getActorsSidingWith(actor1); @@ -366,6 +338,33 @@ namespace MWMechanics aggressive = true; } + // pure water creatures won't try to fight with the target on the ground + // except that creature is already hostile + if (!aggressive && (againstPlayer || !creatureStats.getAiSequence().isInCombat()) + && !MWMechanics::canFight(actor1,actor2)) // creature can't swim to target + { + return; + } + + if (!aggressive && againstPlayer || std::find(playerFollowersAndEscorters.begin(), playerFollowersAndEscorters.end(), actor2) != playerFollowersAndEscorters.end()) + { + // Player followers and escorters with high fight should not initiate combat with the player or with + // other player followers or escorters + if (std::find(playerFollowersAndEscorters.begin(), playerFollowersAndEscorters.end(), actor1) != playerFollowersAndEscorters.end()) + return; + + aggressive = MWBase::Environment::get().getMechanicsManager()->isAggressive(actor1, actor2); + } + else + { + // Make guards fight aggressive creatures + if (!actor1.getClass().isNpc() && actor2.getClass().isClass(actor2, "Guard")) + { + if (creatureStats.getAiSequence().isInCombat() && MWBase::Environment::get().getMechanicsManager()->isAggressive(actor1, actor2)) + aggressive = true; + } + } + if(aggressive) { bool LOS = MWBase::Environment::get().getWorld()->getLOS(actor1, actor2);