forked from teamnwah/openmw-tes3coop
basic auto-equipping (picks the first matching item
This commit is contained in:
parent
0892df0ad3
commit
751e7d2199
3 changed files with 73 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <components/esm/loadnpc.hpp>
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
|
@ -16,7 +17,9 @@ namespace MWMechanics
|
|||
|
||||
void Actors::updateNpc (const MWWorld::Ptr& ptr, float duration, bool paused)
|
||||
{
|
||||
|
||||
if (!paused)
|
||||
MWWorld::Class::get (ptr).getInventoryStore (ptr).autoEquip (
|
||||
MWWorld::Class::get (ptr).getNpcStats (ptr));
|
||||
}
|
||||
|
||||
Actors::Actors (MWWorld::Environment& environment) : mEnvironment (environment), mDuration (0) {}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "class.hpp"
|
||||
|
||||
#include <iostream> /// \todo remove after rendering is implemented
|
||||
|
||||
void MWWorld::InventoryStore::copySlots (const InventoryStore& store)
|
||||
{
|
||||
// some const-trickery, required because of a flaw in the handling of MW-references and the
|
||||
|
@ -24,10 +26,15 @@ void MWWorld::InventoryStore::copySlots (const InventoryStore& store)
|
|||
}
|
||||
}
|
||||
|
||||
MWWorld::InventoryStore::InventoryStore()
|
||||
void MWWorld::InventoryStore::initSlots (TSlots& slots)
|
||||
{
|
||||
for (int i=0; i<Slots; ++i)
|
||||
mSlots.push_back (end());
|
||||
slots.push_back (end());
|
||||
}
|
||||
|
||||
MWWorld::InventoryStore::InventoryStore()
|
||||
{
|
||||
initSlots (mSlots);
|
||||
}
|
||||
|
||||
MWWorld::InventoryStore::InventoryStore (const InventoryStore& store)
|
||||
|
@ -86,3 +93,50 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
|||
|
||||
return mSlots[slot];
|
||||
}
|
||||
|
||||
void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats)
|
||||
{
|
||||
TSlots slots;
|
||||
initSlots (slots);
|
||||
|
||||
for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
|
||||
{
|
||||
std::pair<std::vector<int>, bool> itemsSlots =
|
||||
MWWorld::Class::get (*iter).getEquipmentSlots (*iter);
|
||||
|
||||
for (std::vector<int>::const_iterator iter2 (itemsSlots.first.begin());
|
||||
iter2!=itemsSlots.first.end(); ++iter2)
|
||||
{
|
||||
/// \todo comapre item with item in slot
|
||||
if (slots.at (*iter2)==end())
|
||||
{
|
||||
/// \todo unstack, if reqquired (itemsSlots.second)
|
||||
|
||||
slots[*iter2] = iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
for (std::size_t i=0; i<slots.size(); ++i)
|
||||
if (slots[i]!=mSlots[i])
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
mSlots.swap (slots);
|
||||
flagAsModified();
|
||||
|
||||
/// \todo remove the following line after rendering is implemented
|
||||
for (std::size_t i=0; i<mSlots.size(); ++i)
|
||||
if (mSlots[i]!=end())
|
||||
{
|
||||
std::cout<<"NPC is equipping " << MWWorld::Class::get (*mSlots[i]).getName (*mSlots[i])
|
||||
<< " in slot " << i << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include "containerstore.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
struct NpcStats;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
///< \brief Variant of the ContainerStore for NPCs
|
||||
|
@ -36,10 +41,14 @@ namespace MWWorld
|
|||
|
||||
private:
|
||||
|
||||
mutable std::vector<ContainerStoreIterator> mSlots;
|
||||
typedef std::vector<ContainerStoreIterator> TSlots;
|
||||
|
||||
mutable TSlots mSlots;
|
||||
|
||||
void copySlots (const InventoryStore& store);
|
||||
|
||||
void initSlots (TSlots& slots);
|
||||
|
||||
public:
|
||||
|
||||
InventoryStore();
|
||||
|
@ -52,6 +61,9 @@ namespace MWWorld
|
|||
///< \note \a iteartor can be an end-iterator
|
||||
|
||||
ContainerStoreIterator getSlot (int slot);
|
||||
|
||||
void autoEquip (const MWMechanics::NpcStats& stats);
|
||||
///< Auto equip items according to stats and item value.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue