diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index dd3c2ab42..27a34fb88 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -73,6 +73,8 @@ namespace MWMechanics MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats (ptr); MWMechanics::NpcStats& npcStats = ptr.getClass().getNpcStats (ptr); + npcStats.setNeedRecalcDynamicStats(true); + const ESM::NPC *player = ptr.get()->mBase; // reset diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 798ae00dd..58cd46c40 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -158,7 +158,8 @@ namespace MWScript if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item)) itemName = iter->getClass().getName(*iter); - int numRemoved = store.remove(item, count, ptr); + // Actors should not equip a replacement when items are removed with RemoveItem + int numRemoved = store.remove(item, count, ptr, false); // Spawn a messagebox (only for items removed from player's inventory) if ((numRemoved > 0) @@ -213,7 +214,8 @@ namespace MWScript else { boost::shared_ptr action = it->getClass().use(*it); - action->execute(ptr); + // No equip sound for actors other than the player + action->execute(ptr, true); } } }; diff --git a/apps/openmw/mwworld/action.cpp b/apps/openmw/mwworld/action.cpp index 5663ba38f..92e959e41 100644 --- a/apps/openmw/mwworld/action.cpp +++ b/apps/openmw/mwworld/action.cpp @@ -22,9 +22,9 @@ MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSo MWWorld::Action::~Action() {} -void MWWorld::Action::execute (const Ptr& actor) +void MWWorld::Action::execute (const Ptr& actor, bool noSound) { - if(!mSoundId.empty()) + if(!mSoundId.empty() && !noSound) { if(mKeepSound && actor == MWMechanics::getPlayer()) MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0, diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp index 6b4dff6aa..2f9804053 100644 --- a/apps/openmw/mwworld/action.hpp +++ b/apps/openmw/mwworld/action.hpp @@ -37,7 +37,7 @@ namespace MWWorld virtual bool isNullAction() { return false; } ///< Is running this action a no-op? (default false) - void execute (const Ptr& actor); + void execute (const Ptr& actor, bool noSound = false); void setSound (const std::string& id); void setSoundOffset(float offset); diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index d9fddf7a9..a4154e125 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -398,13 +398,13 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addNewStack (const Cons return it; } -int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor) +int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement) { int toRemove = count; for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter) if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId)) - toRemove -= remove(*iter, toRemove, actor); + toRemove -= remove(*iter, toRemove, actor, equipReplacement); flagAsModified(); @@ -412,7 +412,7 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const return count - toRemove; } -int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor) +int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement) { assert(this == item.getContainerStore()); diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 9849dbf26..21e126a32 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -142,12 +142,12 @@ namespace MWWorld ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr); ///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true) - int remove(const std::string& itemId, int count, const Ptr& actor); + int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement = true); ///< Remove \a count item(s) designated by \a itemId from this container. /// /// @return the number of items actually removed - virtual int remove(const Ptr& item, int count, const Ptr& actor); + virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = true); ///< Remove \a count item(s) designated by \a item from this inventory. /// /// @return the number of items actually removed diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index cf295af6e..f60d630e5 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -660,7 +660,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSelectedEnchantItem( return mSelectedEnchantItem; } -int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor) +int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement) { int retCount = ContainerStore::remove(item, count, actor); @@ -682,8 +682,9 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor } // If an armor/clothing item is removed, try to find a replacement, - // but not for the player nor werewolves. - if (wasEquipped && (actor != MWMechanics::getPlayer()) + // but not for the player nor werewolves, and not if the RemoveItem script command + // was used (equipReplacement is false) + if (equipReplacement && wasEquipped && (actor != MWMechanics::getPlayer()) && actor.getClass().isNpc() && !actor.getClass().getNpcStats(actor).isWerewolf()) { std::string type = item.getTypeName(); diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 05f21370a..90f7f7788 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -177,7 +177,7 @@ namespace MWWorld virtual bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2) const; ///< @return true if the two specified objects can stack with each other - virtual int remove(const Ptr& item, int count, const Ptr& actor); + virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = true); ///< Remove \a count item(s) designated by \a item from this inventory. /// /// @return the number of items actually removed