From a25903b075a567b9c6eef47874b42433a5312150 Mon Sep 17 00:00:00 2001 From: glbwsk Date: Fri, 13 Oct 2017 14:39:44 +0200 Subject: [PATCH 1/4] fixed autoequiping rings by npc - now checks if right hand is free --- .gitignore | 1 + apps/openmw/mwworld/inventorystore.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 9fbb82dba..e9e518c7d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ Makefile makefile build* prebuilt +cmake-build-debug/ ##windows build process /deps diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 77141f269..7c3271cc2 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -315,6 +315,14 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) } else if (iter.getType() == ContainerStore::Type_Clothing) { + if (*iter2 == MWWorld::InventoryStore::Slot_LeftRing) + { + if (slots_.at(MWWorld::InventoryStore::Slot_RightRing) == end()) + { + continue; + } + } + if (old.getTypeName() == typeid(ESM::Clothing).name()) { // check value From e6e482ea9890ef8d4b5a2d89d6b00f9d80f99670 Mon Sep 17 00:00:00 2001 From: glbwsk Date: Fri, 13 Oct 2017 14:47:26 +0200 Subject: [PATCH 2/4] added some comments for autoEquip --- apps/openmw/mwworld/inventorystore.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 7c3271cc2..c28e6a109 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -266,6 +266,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) // Autoequip clothing, armor and weapons. // Equipping lights is handled in Actors::updateEquippedLight based on environment light. + // the main loop iterating through all items in inventory for (ContainerStoreIterator iter (begin(ContainerStore::Type_Clothing | ContainerStore::Type_Armor)); iter!=end(); ++iter) { Ptr test = *iter; @@ -290,9 +291,13 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) std::pair, bool> itemsSlots = iter->getClass().getEquipmentSlots (*iter); + // nested loop for iterating through avialable NPC slots for equipped items + // and checking if current item poited by iter can be placed there for (std::vector::const_iterator iter2 (itemsSlots.first.begin()); iter2!=itemsSlots.first.end(); ++iter2) { + // if true then it means slot is equipped already + // check if slot may require swapping if current item is more valueable if (slots_.at (*iter2)!=end()) { Ptr old = *slots_.at (*iter2); @@ -315,8 +320,10 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) } else if (iter.getType() == ContainerStore::Type_Clothing) { + // if left ring is equipped if (*iter2 == MWWorld::InventoryStore::Slot_LeftRing) { + // if there is a place for right ring dont swap left leaving right hand empty if (slots_.at(MWWorld::InventoryStore::Slot_RightRing) == end()) { continue; @@ -345,6 +352,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) } } + // if we are here it means item can be equipped or swapped slots_[*iter2] = iter; break; } From ff9cb22a58fc9dbb233b223a15e93b3914ed428e Mon Sep 17 00:00:00 2001 From: glbwsk Date: Fri, 13 Oct 2017 15:16:07 +0200 Subject: [PATCH 3/4] npc swap cheaper ring during auto equip --- apps/openmw/mwworld/inventorystore.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index c28e6a109..40f9c741a 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -321,13 +321,23 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) else if (iter.getType() == ContainerStore::Type_Clothing) { // if left ring is equipped - if (*iter2 == MWWorld::InventoryStore::Slot_LeftRing) + if (*iter2 == Slot_LeftRing) { // if there is a place for right ring dont swap left leaving right hand empty - if (slots_.at(MWWorld::InventoryStore::Slot_RightRing) == end()) + if (slots_.at(Slot_RightRing) == end()) { continue; } + else // if right ring is equipped too + { + Ptr rightRing = *slots_.at(Slot_RightRing); + + // we want to swap cheaper ring only if both are equipped + if (rightRing.getClass().getValue(rightRing) < old.getClass().getValue(old)) + { + continue; + } + } } if (old.getTypeName() == typeid(ESM::Clothing).name()) From 83a5c7c3d87f4e5740b67f271c6007ad16f73d8f Mon Sep 17 00:00:00 2001 From: glbwsk Date: Fri, 13 Oct 2017 20:32:52 +0200 Subject: [PATCH 4/4] removed unnecessary comments, added gitignore for clion cmake --- .gitignore | 2 +- apps/openmw/mwworld/inventorystore.cpp | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e9e518c7d..672c3ec18 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ Makefile makefile build* prebuilt -cmake-build-debug/ ##windows build process /deps @@ -27,6 +26,7 @@ Doxygen .settings .directory .idea +cmake-build-* files/windows/*.aps ## qt-creator CMakeLists.txt.user* diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 40f9c741a..50ee97d1c 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -265,8 +265,6 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) // Autoequip clothing, armor and weapons. // Equipping lights is handled in Actors::updateEquippedLight based on environment light. - - // the main loop iterating through all items in inventory for (ContainerStoreIterator iter (begin(ContainerStore::Type_Clothing | ContainerStore::Type_Armor)); iter!=end(); ++iter) { Ptr test = *iter; @@ -291,8 +289,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) std::pair, bool> itemsSlots = iter->getClass().getEquipmentSlots (*iter); - // nested loop for iterating through avialable NPC slots for equipped items - // and checking if current item poited by iter can be placed there + // checking if current item poited by iter can be equipped for (std::vector::const_iterator iter2 (itemsSlots.first.begin()); iter2!=itemsSlots.first.end(); ++iter2) { @@ -323,7 +320,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) // if left ring is equipped if (*iter2 == Slot_LeftRing) { - // if there is a place for right ring dont swap left leaving right hand empty + // if there is a place for right ring dont swap it if (slots_.at(Slot_RightRing) == end()) { continue;