diff --git a/apps/openmw/mwgui/containeritemmodel.cpp b/apps/openmw/mwgui/containeritemmodel.cpp index 5d23744b2..e23b4f77f 100644 --- a/apps/openmw/mwgui/containeritemmodel.cpp +++ b/apps/openmw/mwgui/containeritemmodel.cpp @@ -76,7 +76,7 @@ void ContainerItemModel::copyItem (const ItemStack& item, size_t count) const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1]; int origCount = item.mBase.getRefData().getCount(); item.mBase.getRefData().setCount(count); - MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase); + MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase, source); if (*it != item.mBase) item.mBase.getRefData().setCount(origCount); else diff --git a/apps/openmw/mwgui/inventoryitemmodel.cpp b/apps/openmw/mwgui/inventoryitemmodel.cpp index c78bc2c00..30269cd9c 100644 --- a/apps/openmw/mwgui/inventoryitemmodel.cpp +++ b/apps/openmw/mwgui/inventoryitemmodel.cpp @@ -42,7 +42,7 @@ void InventoryItemModel::copyItem (const ItemStack& item, size_t count) { int origCount = item.mBase.getRefData().getCount(); item.mBase.getRefData().setCount(count); - MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase); + MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase, mActor); if (*it != item.mBase) item.mBase.getRefData().setCount(origCount); else diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 7ad17fab0..3b848f2e0 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -304,7 +304,7 @@ namespace MWGui int origCount = ptr.getRefData().getCount(); ptr.getRefData().setCount(mDragAndDrop->mDraggedCount); - it = invStore.add(ptr); + it = invStore.add(ptr, mPtr); ptr.getRefData().setCount(origCount); mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount); @@ -481,7 +481,7 @@ namespace MWGui // add to player inventory // can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object); + MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object, player); // remove from world MWBase::Environment::get().getWorld()->deleteObject (object); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 498fbace8..a073a2899 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -225,7 +225,7 @@ namespace MWGui assert(amount > 0); MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); ref.getPtr().getRefData().setCount(amount); - playerStore.add(ref.getPtr()); + playerStore.add(ref.getPtr(), player); } } diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 718200372..1d992be41 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -287,7 +287,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name) } MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); - MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr()); + MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr(), mAlchemist); } void MWMechanics::Alchemy::increaseSkill() diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index e1b416efb..4e26b5027 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -65,7 +65,7 @@ namespace MWMechanics if(boost::iequals(mSoulGemPtr.get()->mBase->mId, "Misc_SoulGem_Azura")) { MWWorld::ManualRef azura (MWBase::Environment::get().getWorld()->getStore(), "Misc_SoulGem_Azura"); - MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr()); + MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr(), player); } if(mSelfEnchanting) @@ -93,7 +93,7 @@ namespace MWMechanics MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId); ref.getPtr().getRefData().setCount (mOldItemCount-1); - MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr()); + MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr(), player); if(!mSelfEnchanting) payForEnchantment(); diff --git a/apps/openmw/mwmechanics/repair.cpp b/apps/openmw/mwmechanics/repair.cpp index 8ed449885..66c492bf8 100644 --- a/apps/openmw/mwmechanics/repair.cpp +++ b/apps/openmw/mwmechanics/repair.cpp @@ -32,7 +32,7 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) if (mTool.getRefData().getCount() > 1 && uses == ref->mBase->mData.mUses) { MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); - MWWorld::ContainerStoreIterator it = store.add(mTool); + MWWorld::ContainerStoreIterator it = store.add(mTool, player); it->getRefData().setCount(mTool.getRefData().getCount()-1); it->getCellRef().mCharge = -1; diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 3a46f62d6..c1efc55eb 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -64,7 +64,7 @@ namespace MWScript ref.getPtr().getRefData().setLocals(*esmscript); } - MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr()); + MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr); // Spawn a messagebox (only for items added to player's inventory and if player is talking to someone) if (ptr == MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer() ) diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 6b1adc938..b16d6e0a9 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -346,7 +346,7 @@ namespace MWScript ref.getPtr().getCellRef().mSoul = creature; - MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr()); + MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr); } }; diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index cdd19b46e..d3c4aa2f6 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -17,7 +17,7 @@ namespace MWWorld // insert into player's inventory MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPtr ("player", true); - MWWorld::Class::get (player).getContainerStore (player).add (getTarget()); + MWWorld::Class::get (player).getContainerStore (player).add (getTarget(), player); MWBase::Environment::get().getWorld()->deleteObject (getTarget()); } diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index a9d57c128..cd30f1ac0 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -74,9 +74,9 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2) return false; } -MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr, const Ptr& actorPtr) { - MWWorld::ContainerStoreIterator it = addImp(ptr); + MWWorld::ContainerStoreIterator it = addImp(itemPtr); MWWorld::Ptr item = *it; std::string script = MWWorld::Class::get(item).getScript(item); diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 559463d46..bdf6d28e4 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -65,7 +65,7 @@ namespace MWWorld ContainerStoreIterator end(); - ContainerStoreIterator add (const Ptr& ptr); + virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr); ///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed) /// /// \note The item pointed to is not required to exist beyond this function call. diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index db45dbf54..e737ab827 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -64,6 +64,22 @@ MWWorld::InventoryStore& MWWorld::InventoryStore::operator= (const InventoryStor return *this; } +MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr, const Ptr& actorPtr) +{ + const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, actorPtr); + + // Auto-equip items if an armor/clothing item is added, but not for the player nor werewolves + if ((actorPtr.getRefData().getHandle() != "player") + && !(MWWorld::Class::get(actorPtr).getNpcStats(actorPtr).isWerewolf())) + { + std::string type = itemPtr.getTypeName(); + if ((type == typeid(ESM::Armor).name()) || (type == typeid(ESM::Clothing).name())) + autoEquip(actorPtr); + } + + return retVal; +} + void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& iterator) { if (slot<0 || slot>=static_cast (mSlots.size())) diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 713c72955..f0cba0f9f 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -65,6 +65,17 @@ namespace MWWorld InventoryStore& operator= (const InventoryStore& store); + virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr); + ///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed) + /// Auto-equip items if specific conditions are fulfilled (see the implementation). + /// + /// \note The item pointed to is not required to exist beyond this function call. + /// + /// \attention Do not add items to an existing stack by increasing the count instead of + /// calling this function! + /// + /// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item. + void equip (int slot, const ContainerStoreIterator& iterator); ///< \note \a iterator can be an end-iterator