From 3190f287100ed1a152bd8203ceaaec1d88ed59de Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 9 Jun 2017 10:23:46 +0400 Subject: [PATCH 1/2] Spell priority: make AI do not cast target spells under water --- apps/openmw/mwbase/world.hpp | 1 + apps/openmw/mwmechanics/aicombataction.cpp | 7 +++++++ apps/openmw/mwworld/worldimp.hpp | 4 +--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 86d26d3a7..691891486 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -383,6 +383,7 @@ namespace MWBase ///Is the head of the creature underwater? virtual bool isSubmerged(const MWWorld::ConstPtr &object) const = 0; virtual bool isUnderwater(const MWWorld::CellStore* cell, const osg::Vec3f &pos) const = 0; + virtual bool isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const = 0; virtual bool isWaterWalkingCastableOnTarget(const MWWorld::ConstPtr &target) const = 0; virtual bool isOnGround(const MWWorld::Ptr &ptr) const = 0; diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index 37b67c9b2..358e04d6b 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -545,6 +545,13 @@ namespace MWMechanics const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find(effect.mEffectID); + // Underwater casting not possible + if (effect.mRange == ESM::RT_Target) + { + if (MWBase::Environment::get().getWorld()->isUnderwater(MWWorld::ConstPtr(actor), 0.75f)) + return 0; + } + rating *= magicEffect->mData.mBaseCost; if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index ce6e27672..eb35ad031 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -168,9 +168,6 @@ namespace MWWorld float mDistanceToFacedObject; - bool isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const; - ///< helper function for implementing isSwimming(), isSubmerged(), isWading() - bool mTeleportEnabled; bool mLevitationEnabled; bool mGoToJail; @@ -490,6 +487,7 @@ namespace MWWorld virtual bool isSubmerged(const MWWorld::ConstPtr &object) const; virtual bool isSwimming(const MWWorld::ConstPtr &object) const; virtual bool isUnderwater(const MWWorld::CellStore* cell, const osg::Vec3f &pos) const; + virtual bool isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const; virtual bool isWading(const MWWorld::ConstPtr &object) const; virtual bool isWaterWalkingCastableOnTarget(const MWWorld::ConstPtr &target) const; virtual bool isOnGround(const MWWorld::Ptr &ptr) const; From 9fdfb2a83f488fec895461d1f24b153533effe69 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 11 Jun 2017 10:13:00 +0400 Subject: [PATCH 2/2] Spell priority: make AI do not cast target spells when enemy is under water --- apps/openmw/mwmechanics/aicombataction.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index 358e04d6b..f9b793f94 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -549,7 +549,13 @@ namespace MWMechanics if (effect.mRange == ESM::RT_Target) { if (MWBase::Environment::get().getWorld()->isUnderwater(MWWorld::ConstPtr(actor), 0.75f)) - return 0; + return 0.f; + + if (enemy.isEmpty()) + return 0.f; + + if (MWBase::Environment::get().getWorld()->isUnderwater(MWWorld::ConstPtr(enemy), 0.75f)) + return 0.f; } rating *= magicEffect->mData.mBaseCost;