From dcab6737e50aa122a4189f8083060d4bd352bdb0 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 8 Apr 2012 12:26:21 +0200 Subject: [PATCH] consider skills when auto equipping --- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwworld/inventorystore.cpp | 41 ++++++++++++++++++++++---- apps/openmw/mwworld/inventorystore.hpp | 4 ++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index e68b99597e..c948e00d58 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -19,7 +19,7 @@ namespace MWMechanics { if (!paused) MWWorld::Class::get (ptr).getInventoryStore (ptr).autoEquip ( - MWWorld::Class::get (ptr).getNpcStats (ptr)); + MWWorld::Class::get (ptr).getNpcStats (ptr), mEnvironment); } Actors::Actors (MWWorld::Environment& environment) : mEnvironment (environment), mDuration (0) {} diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 1fe76a0a81..650418201b 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -4,6 +4,8 @@ #include #include +#include "../mwmechanics/npcstats.hpp" + #include "class.hpp" #include /// \todo remove after rendering is implemented @@ -94,7 +96,8 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) return mSlots[slot]; } -void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats) +void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats, + const Environment& environment) { TSlots slots; initSlots (slots); @@ -102,6 +105,7 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats) for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter) { Ptr test = *iter; + int testSkill = MWWorld::Class::get (test).getEquipmentSkill (test, environment); std::pair, bool> itemsSlots = MWWorld::Class::get (*iter).getEquipmentSlots (*iter); @@ -109,15 +113,40 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats) for (std::vector::const_iterator iter2 (itemsSlots.first.begin()); iter2!=itemsSlots.first.end(); ++iter2) { - if (slots.at (*iter2)!=end()) + bool use = false; + + if (slots.at (*iter2)==end()) + use = true; // slot was empty before -> skill all further checks + else { Ptr old = *slots.at (*iter2); - // check value - if (MWWorld::Class::get (old).getValue (old)>=MWWorld::Class::get (test).getValue (test)) + if (!use) { - /// \todo check skill - continue; + // check skill + int oldSkill = + MWWorld::Class::get (old).getEquipmentSkill (old, environment); + + if (testSkill!=-1 || oldSkill!=-1 || testSkill!=oldSkill) + { + if (stats.mSkill[oldSkill].getModified()>stats.mSkill[testSkill].getModified()) + continue; // rejected, because old item better matched the NPC's skills. + + if (stats.mSkill[oldSkill].getModified()= + MWWorld::Class::get (test).getValue (test)) + { + continue; + } + + use = true; } } diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 5eeaf570d0..ca733b0847 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -10,6 +10,8 @@ namespace MWMechanics namespace MWWorld { + struct Environment; + ///< \brief Variant of the ContainerStore for NPCs class InventoryStore : public ContainerStore { @@ -62,7 +64,7 @@ namespace MWWorld ContainerStoreIterator getSlot (int slot); - void autoEquip (const MWMechanics::NpcStats& stats); + void autoEquip (const MWMechanics::NpcStats& stats, const Environment& environment); ///< Auto equip items according to stats and item value. }; }