1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-29 17:06:43 +00:00

consider skills when auto equipping

This commit is contained in:
Marc Zinnschlag 2012-04-08 12:26:21 +02:00
parent 34a02fef45
commit dcab6737e5
3 changed files with 39 additions and 8 deletions

View file

@ -19,7 +19,7 @@ namespace MWMechanics
{ {
if (!paused) if (!paused)
MWWorld::Class::get (ptr).getInventoryStore (ptr).autoEquip ( 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) {} Actors::Actors (MWWorld::Environment& environment) : mEnvironment (environment), mDuration (0) {}

View file

@ -4,6 +4,8 @@
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include "../mwmechanics/npcstats.hpp"
#include "class.hpp" #include "class.hpp"
#include <iostream> /// \todo remove after rendering is implemented #include <iostream> /// \todo remove after rendering is implemented
@ -94,7 +96,8 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
return mSlots[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; TSlots slots;
initSlots (slots); initSlots (slots);
@ -102,6 +105,7 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats)
for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter) for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
{ {
Ptr test = *iter; Ptr test = *iter;
int testSkill = MWWorld::Class::get (test).getEquipmentSkill (test, environment);
std::pair<std::vector<int>, bool> itemsSlots = std::pair<std::vector<int>, bool> itemsSlots =
MWWorld::Class::get (*iter).getEquipmentSlots (*iter); MWWorld::Class::get (*iter).getEquipmentSlots (*iter);
@ -109,15 +113,40 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats)
for (std::vector<int>::const_iterator iter2 (itemsSlots.first.begin()); for (std::vector<int>::const_iterator iter2 (itemsSlots.first.begin());
iter2!=itemsSlots.first.end(); ++iter2) 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); Ptr old = *slots.at (*iter2);
// check value if (!use)
if (MWWorld::Class::get (old).getValue (old)>=MWWorld::Class::get (test).getValue (test))
{ {
/// \todo check skill // check skill
continue; 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()<stats.mSkill[testSkill].getModified())
use = true;
}
}
if (!use)
{
// check value
if (MWWorld::Class::get (old).getValue (old)>=
MWWorld::Class::get (test).getValue (test))
{
continue;
}
use = true;
} }
} }

View file

@ -10,6 +10,8 @@ namespace MWMechanics
namespace MWWorld namespace MWWorld
{ {
struct Environment;
///< \brief Variant of the ContainerStore for NPCs ///< \brief Variant of the ContainerStore for NPCs
class InventoryStore : public ContainerStore class InventoryStore : public ContainerStore
{ {
@ -62,7 +64,7 @@ namespace MWWorld
ContainerStoreIterator getSlot (int slot); 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. ///< Auto equip items according to stats and item value.
}; };
} }