diff --git a/CHANGELOG.md b/CHANGELOG.md index 42db494f3c..facb9df9e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Bug #7557: Terrain::ChunkManager::createChunk is called twice for the same position, lod on initial loading Bug #7573: Drain Fatigue can't bring fatigue below zero by default Bug #7603: Scripts menu size is not updated properly + Bug #7604: Goblins Grunt becomes idle once injured Feature #3537: Shader-based water ripples Feature #5492: Let rain and snow collide with statics Feature #6149: Dehardcode Lua API_REVISION diff --git a/apps/openmw/mwclass/actor.cpp b/apps/openmw/mwclass/actor.cpp index 152a4bbba9..7f60ae5c2c 100644 --- a/apps/openmw/mwclass/actor.cpp +++ b/apps/openmw/mwclass/actor.cpp @@ -3,6 +3,7 @@ #include #include "../mwbase/environment.hpp" +#include "../mwbase/luamanager.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/world.hpp" @@ -14,6 +15,7 @@ #include "../mwphysics/physicssystem.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/worldmodel.hpp" namespace MWClass { @@ -90,4 +92,15 @@ namespace MWClass moveSpeed *= 0.75f; return moveSpeed; } + + bool Actor::consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const + { + MWBase::Environment::get().getWorld()->breakInvisibility(actor); + MWMechanics::CastSpell cast(actor, actor); + const ESM::RefId& recordId = consumable.getCellRef().getRefId(); + MWBase::Environment::get().getWorldModel()->registerPtr(consumable); + MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor); + actor.getClass().getContainerStore(actor).remove(consumable, 1); + return cast.cast(recordId); + } } diff --git a/apps/openmw/mwclass/actor.hpp b/apps/openmw/mwclass/actor.hpp index 5a143c7a7d..41d06cf5bd 100644 --- a/apps/openmw/mwclass/actor.hpp +++ b/apps/openmw/mwclass/actor.hpp @@ -62,6 +62,8 @@ namespace MWClass /// Return current movement speed. float getCurrentSpeed(const MWWorld::Ptr& ptr) const override; + bool consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const override; + // not implemented Actor(const Actor&) = delete; Actor& operator=(const Actor&) = delete; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index f1514a4ffe..dab6dc99ae 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -21,7 +21,6 @@ #include "../mwbase/dialoguemanager.hpp" #include "../mwbase/environment.hpp" -#include "../mwbase/luamanager.hpp" #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/windowmanager.hpp" @@ -1123,17 +1122,6 @@ namespace MWClass return getNpcStats(ptr).isWerewolf() ? 0.0f : Actor::getEncumbrance(ptr); } - bool Npc::consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const - { - MWBase::Environment::get().getWorld()->breakInvisibility(actor); - MWMechanics::CastSpell cast(actor, actor); - const ESM::RefId& recordId = consumable.getCellRef().getRefId(); - MWBase::Environment::get().getWorldModel()->registerPtr(consumable); - MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor); - actor.getClass().getContainerStore(actor).remove(consumable, 1); - return cast.cast(recordId); - } - void Npc::skillUsageSucceeded(const MWWorld::Ptr& ptr, ESM::RefId skill, int usageType, float extraFactor) const { MWMechanics::NpcStats& stats = getNpcStats(ptr); diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 9b53143c4d..eb8cafc9d1 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -114,8 +114,6 @@ namespace MWClass float getArmorRating(const MWWorld::Ptr& ptr) const override; ///< @return combined armor rating of this actor - bool consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const override; - void adjustScale(const MWWorld::ConstPtr& ptr, osg::Vec3f& scale, bool rendering) const override; /// @param rendering Indicates if the scale to adjust is for the rendering mesh, or for the collision mesh diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index a7bcd1a0df..563bd8b8cd 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -176,34 +176,35 @@ namespace MWMechanics return bestAction; } - if (actor.getClass().hasInventoryStore(actor)) + const bool hasInventoryStore = actor.getClass().hasInventoryStore(actor); + MWWorld::ContainerStore& store = actor.getClass().getContainerStore(actor); + for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { - MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor); - - for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) + if (it->getType() == ESM::Potion::sRecordId) { - if (it->getType() == ESM::Potion::sRecordId) + float rating = ratePotion(*it, actor); + if (rating > bestActionRating) { - float rating = ratePotion(*it, actor); - if (rating > bestActionRating) - { - bestActionRating = rating; - bestAction = std::make_unique(*it); - antiFleeRating = std::numeric_limits::max(); - } - } - else if (!it->getClass().getEnchantment(*it).empty()) - { - float rating = rateMagicItem(*it, actor, enemy); - if (rating > bestActionRating) - { - bestActionRating = rating; - bestAction = std::make_unique(it); - antiFleeRating = std::numeric_limits::max(); - } + bestActionRating = rating; + bestAction = std::make_unique(*it); + antiFleeRating = std::numeric_limits::max(); } } + // TODO remove inventory store check, creatures should be able to use enchanted items they cannot equip + else if (hasInventoryStore && !it->getClass().getEnchantment(*it).empty()) + { + float rating = rateMagicItem(*it, actor, enemy); + if (rating > bestActionRating) + { + bestActionRating = rating; + bestAction = std::make_unique(it); + antiFleeRating = std::numeric_limits::max(); + } + } + } + if (hasInventoryStore) + { MWWorld::Ptr bestArrow; float bestArrowRating = rateAmmo(actor, enemy, bestArrow, ESM::Weapon::Arrow);