From 7c22e123f4c6fb37f27f874749096a4b9a8b4558 Mon Sep 17 00:00:00 2001 From: Glorf Date: Mon, 8 Apr 2013 22:10:55 +0200 Subject: [PATCH] Bugfix #691 changes --- apps/openmw/mwclass/armor.cpp | 27 +++++------------ apps/openmw/mwclass/armor.hpp | 3 +- apps/openmw/mwclass/clothing.cpp | 24 ++++------------ apps/openmw/mwclass/clothing.hpp | 3 +- apps/openmw/mwclass/weapon.cpp | 40 +++++++------------------- apps/openmw/mwclass/weapon.hpp | 3 +- apps/openmw/mwworld/actionequip.cpp | 11 +++++-- apps/openmw/mwworld/class.cpp | 4 +-- apps/openmw/mwworld/class.hpp | 4 +-- apps/openmw/mwworld/inventorystore.cpp | 13 +++++++-- 10 files changed, 53 insertions(+), 79 deletions(-) diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index f6392941d..ddab6f754 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -292,25 +292,13 @@ namespace MWClass ref->mBase = record; } - bool Armor::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const + int Armor::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const { MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc); // slots that this item can be equipped in std::pair, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item); - // retrieve ContainerStoreIterator to the item - MWWorld::ContainerStoreIterator it = invStore.begin(); - for (; it != invStore.end(); ++it) - { - if (*it == item) - { - break; - } - } - - assert(it != invStore.end()); - std::string npcRace = npc.get()->mBase->mRace; for (std::vector::const_iterator slot=slots.first.begin(); @@ -321,7 +309,7 @@ namespace MWClass const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(npcRace); if(race->mData.mFlags & ESM::Race::Beast) { - std::vector parts = it->get()->mBase->mParts.mParts; + std::vector parts = item.get()->mBase->mParts.mParts; if(*slot == MWWorld::InventoryStore::Slot_Helmet) { @@ -332,7 +320,7 @@ namespace MWClass if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() ) MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}"); - return false; + return 0; } } } @@ -345,7 +333,7 @@ namespace MWClass { if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() ) MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage14}"); - return false; + return 0; } } } @@ -363,13 +351,12 @@ namespace MWClass weapon->get()->mBase->mData.mType == ESM::Weapon::MarksmanBow || weapon->get()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) { - //unequip twohanded item - invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end()); + return 3; } - return true; + return 1; } } - return true; + return 1; } boost::shared_ptr Armor::use (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index bb07e42b0..96c72848c 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -67,7 +67,8 @@ namespace MWClass virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; - virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) const; diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 318515a7b..58c4a2c5c 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -238,25 +238,11 @@ namespace MWClass ref->mBase = record; } - bool Clothing::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const + int Clothing::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const { - MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc); - // slots that this item can be equipped in std::pair, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item); - // retrieve ContainerStoreIterator to the item - MWWorld::ContainerStoreIterator it = invStore.begin(); - for (; it != invStore.end(); ++it) - { - if (*it == item) - { - break; - } - } - - assert(it != invStore.end()); - std::string npcRace = npc.get()->mBase->mRace; for (std::vector::const_iterator slot=slots.first.begin(); @@ -267,7 +253,7 @@ namespace MWClass const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(npcRace); if(race->mData.mFlags & ESM::Race::Beast) { - std::vector parts = it->get()->mBase->mParts.mParts; + std::vector parts = item.get()->mBase->mParts.mParts; if(*slot == MWWorld::InventoryStore::Slot_Helmet) { @@ -278,7 +264,7 @@ namespace MWClass if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() ) MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}"); - return false; + return 0; } } } @@ -294,13 +280,13 @@ namespace MWClass MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage15}"); } - return false; + return 0; } } } } } - return true; + return 1; } boost::shared_ptr Clothing::use (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 4978fa228..eb8d80199 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -61,7 +61,8 @@ namespace MWClass virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; - virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) const; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index a0a8b7e87..a0cacaf6b 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -384,48 +384,30 @@ namespace MWClass ref->mBase = record; } - bool Weapon::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const + int Weapon::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const { - MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc); - - // slots that this item can be equipped in std::pair, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item); - // retrieve ContainerStoreIterator to the item - MWWorld::ContainerStoreIterator it = invStore.begin(); - for (; it != invStore.end(); ++it) - { - if (*it == item) - { - break; - } - } - - assert(it != invStore.end()); - - std::string npcRace = npc.get()->mBase->mRace; - // equip the item in the first free slot for (std::vector::const_iterator slot=slots.first.begin(); slot!=slots.first.end(); ++slot) { if(*slot == MWWorld::InventoryStore::Slot_CarriedRight) { - if(it->get()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand || - it->get()->mBase->mData.mType == ESM::Weapon::BluntTwoClose || - it->get()->mBase->mData.mType == ESM::Weapon::BluntTwoWide || - it->get()->mBase->mData.mType == ESM::Weapon::SpearTwoWide || - it->get()->mBase->mData.mType == ESM::Weapon::AxeTwoHand || - it->get()->mBase->mData.mType == ESM::Weapon::MarksmanBow || - it->get()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) + if(item.get()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand || + item.get()->mBase->mData.mType == ESM::Weapon::BluntTwoClose || + item.get()->mBase->mData.mType == ESM::Weapon::BluntTwoWide || + item.get()->mBase->mData.mType == ESM::Weapon::SpearTwoWide || + item.get()->mBase->mData.mType == ESM::Weapon::AxeTwoHand || + item.get()->mBase->mData.mType == ESM::Weapon::MarksmanBow || + item.get()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) { - //unequip lefthand item - invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end()); + return 2; } - return true; + return 1; } } - return false; + return 0; } boost::shared_ptr Weapon::use (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 922cd165f..01686b09c 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -67,7 +67,8 @@ namespace MWClass virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; - virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) const; diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index c147113fc..51d0de6fe 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -43,8 +43,15 @@ namespace MWWorld for (std::vector::const_iterator slot=slots.first.begin(); slot!=slots.first.end(); ++slot) { - if(!MWWorld::Class::get(getTarget()).canEquip(actor,getTarget())) - break; + switch(MWWorld::Class::get (*it).canBeEquipped (actor, *it)) + { + case 0: + return; + case 2: + invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end()); + case 3: + invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end()); + } // if all slots are occupied, replace the last slot if (slot == --slots.first.end()) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index ee2072cf0..a0067f5d2 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -259,9 +259,9 @@ namespace MWWorld throw std::runtime_error ("class can't be enchanted"); } - bool Class::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const + int Class::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const { - return true; + return 1; } void Class::adjustPosition(const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 4931da7a8..362a8bc9c 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -242,8 +242,8 @@ namespace MWWorld virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; - virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; - ///< Return 0 if player cannot equip item. Unequip twohanded item if neccesary + virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const; + ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. virtual Ptr copyToCell(const Ptr &ptr, CellStore &cell) const; diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 7a5ae38d0..9f51db353 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -131,6 +131,8 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& npc) { const MWMechanics::NpcStats& stats = MWWorld::Class::get(npc).getNpcStats(npc); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc); + TSlots slots; initSlots (slots); @@ -184,8 +186,15 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& npc) } } - if(!MWWorld::Class::get (test).canEquip (npc, test)) - continue; + switch(MWWorld::Class::get (test).canBeEquipped (npc, test)) + { + case 0: + continue; + case 2: + invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end()); + case 3: + invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end()); + } if (!itemsSlots.second) // if itemsSlots.second is true, item can stay stacked when equipped {