From 48765f2ff28a1634d7a994d8b71f0b1ebc3b1a05 Mon Sep 17 00:00:00 2001 From: mrcheko Date: Mon, 19 Sep 2016 23:43:26 +0300 Subject: [PATCH 1/2] fix using potion as weapon --- apps/openmw/mwmechanics/aicombat.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index c821eac0d..298a3024e 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -229,7 +229,8 @@ namespace MWMechanics osg::Vec3f vAimDir = MWBase::Environment::get().getWorld()->aimToTarget(actor, target); float distToTarget = MWBase::Environment::get().getWorld()->getHitDistance(actor, target); - storage.mReadyToAttack = (distToTarget <= rangeAttack); + bool isPotion = (dynamic_cast(currentAction.get()) != NULL); + storage.mReadyToAttack = (!isPotion && distToTarget <= rangeAttack); // can't fight if attacker can't go where target is. E.g. A fish can't attack person on land. if (distToTarget > rangeAttack From 229cb4b386d91e6da058d3ca8dc1aac9255f3aca Mon Sep 17 00:00:00 2001 From: mrcheko Date: Tue, 20 Sep 2016 23:00:00 +0300 Subject: [PATCH 2/2] remove dynamic_cast to ActionPotion --- apps/openmw/mwmechanics/aicombat.cpp | 3 +-- apps/openmw/mwmechanics/aicombataction.hpp | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 298a3024e..68bcae695 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -229,8 +229,7 @@ namespace MWMechanics osg::Vec3f vAimDir = MWBase::Environment::get().getWorld()->aimToTarget(actor, target); float distToTarget = MWBase::Environment::get().getWorld()->getHitDistance(actor, target); - bool isPotion = (dynamic_cast(currentAction.get()) != NULL); - storage.mReadyToAttack = (!isPotion && distToTarget <= rangeAttack); + storage.mReadyToAttack = (currentAction->isAttackingOrSpell() && distToTarget <= rangeAttack); // can't fight if attacker can't go where target is. E.g. A fish can't attack person on land. if (distToTarget > rangeAttack diff --git a/apps/openmw/mwmechanics/aicombataction.hpp b/apps/openmw/mwmechanics/aicombataction.hpp index c280d3c11..b36413587 100644 --- a/apps/openmw/mwmechanics/aicombataction.hpp +++ b/apps/openmw/mwmechanics/aicombataction.hpp @@ -19,6 +19,7 @@ namespace MWMechanics virtual float getCombatRange (bool& isRanged) const = 0; virtual float getActionCooldown() { return 0.f; } virtual const ESM::Weapon* getWeapon() const { return NULL; }; + virtual bool isAttackingOrSpell() const { return true; } }; class ActionSpell : public Action @@ -53,6 +54,7 @@ namespace MWMechanics /// Drinks the given potion. virtual void prepare(const MWWorld::Ptr& actor); virtual float getCombatRange (bool& isRanged) const; + virtual bool isAttackingOrSpell() const { return false; } /// Since this action has no animation, apply a small cool down for using it virtual float getActionCooldown() { return 1.f; }