Stop combat between AI when canFight is false

pull/124/head
Allofich 8 years ago
parent e8c7ad2f4b
commit e10c4d8814

@ -19,6 +19,7 @@
#include "aicombataction.hpp" #include "aicombataction.hpp"
#include "combat.hpp" #include "combat.hpp"
#include "coordinateconverter.hpp" #include "coordinateconverter.hpp"
#include "actorutil.hpp"
namespace namespace
{ {
@ -210,13 +211,14 @@ namespace MWMechanics
else else
{ {
timerReact = 0; timerReact = 0;
attack(actor, target, storage, characterController); if (attack(actor, target, storage, characterController))
return true;
} }
return false; return false;
} }
void AiCombat::attack(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, AiCombatStorage& storage, CharacterController& characterController) bool AiCombat::attack(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, AiCombatStorage& storage, CharacterController& characterController)
{ {
const MWWorld::CellStore*& currentCell = storage.mCell; const MWWorld::CellStore*& currentCell = storage.mCell;
bool cellChange = currentCell && (actor.getCell() != currentCell); bool cellChange = currentCell && (actor.getCell() != currentCell);
@ -231,7 +233,10 @@ namespace MWMechanics
storage.stopAttack(); storage.stopAttack();
characterController.setAttackingOrSpell(false); characterController.setAttackingOrSpell(false);
storage.mActionCooldown = 0.f; storage.mActionCooldown = 0.f;
forceFlee = true; if (target == MWMechanics::getPlayer())
forceFlee = true;
else
return true;
} }
const MWWorld::Class& actorClass = actor.getClass(); const MWWorld::Class& actorClass = actor.getClass();
@ -243,7 +248,7 @@ namespace MWMechanics
if (!forceFlee) if (!forceFlee)
{ {
if (actionCooldown > 0) if (actionCooldown > 0)
return; return false;
if (characterController.readyToPrepareAttack()) if (characterController.readyToPrepareAttack())
{ {
@ -258,7 +263,7 @@ namespace MWMechanics
} }
if (!currentAction) if (!currentAction)
return; return false;
if (storage.isFleeing() != currentAction->isFleeing()) if (storage.isFleeing() != currentAction->isFleeing())
{ {
@ -266,7 +271,7 @@ namespace MWMechanics
{ {
storage.startFleeing(); storage.startFleeing();
MWBase::Environment::get().getDialogueManager()->say(actor, "flee"); MWBase::Environment::get().getDialogueManager()->say(actor, "flee");
return; return false;
} }
else else
storage.stopFleeing(); storage.stopFleeing();
@ -311,6 +316,7 @@ namespace MWMechanics
storage.mMovement.mRotation[2] = getZAngleToDir((vTargetPos-vActorPos)); // using vAimDir results in spastic movements since the head is animated storage.mMovement.mRotation[2] = getZAngleToDir((vTargetPos-vActorPos)); // using vAimDir results in spastic movements since the head is animated
} }
} }
return false;
} }
void MWMechanics::AiCombat::updateLOS(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, float duration, MWMechanics::AiCombatStorage& storage) void MWMechanics::AiCombat::updateLOS(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, float duration, MWMechanics::AiCombatStorage& storage)

@ -59,7 +59,8 @@ namespace MWMechanics
int mTargetActorId; int mTargetActorId;
void attack(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, AiCombatStorage& storage, CharacterController& characterController); /// Returns true if combat should end
bool attack(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, AiCombatStorage& storage, CharacterController& characterController);
void updateLOS(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, float duration, AiCombatStorage& storage); void updateLOS(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, float duration, AiCombatStorage& storage);

Loading…
Cancel
Save