1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 03:19:44 +00:00
OpenMW/apps/essimporter/importinventory.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.3 KiB
C++
Raw Normal View History

#include "importinventory.hpp"
#include <stdexcept>
#include <components/esm3/esmreader.hpp>
namespace ESSImport
{
void Inventory::load(ESM::ESMReader& esm)
{
while (esm.isNextSub("NPCO"))
{
ContItem contItem;
2023-12-17 13:03:45 +00:00
esm.getHT(contItem.mCount, contItem.mItem.mData);
InventoryItem item;
item.mId = contItem.mItem.toString();
item.mCount = contItem.mCount;
item.mRelativeEquipmentSlot = -1;
2018-08-01 16:18:37 +00:00
item.mLockLevel = 0;
2023-07-28 10:01:40 +00:00
item.mChargeIntRemainder = 0;
unsigned int itemCount = std::abs(item.mCount);
bool separateStacks = false;
for (unsigned int i = 0; i < itemCount; ++i)
{
bool newStack = esm.isNextSub("XIDX");
if (newStack)
{
2023-12-17 13:03:45 +00:00
uint32_t idx;
esm.getHT(idx);
separateStacks = true;
item.mCount = 1;
}
item.mSCRI.load(esm);
// for XSOL and XCHG seen so far, but probably others too
bool isDeleted = false;
item.ESM::CellRef::loadData(esm, isDeleted);
2023-12-17 13:03:45 +00:00
int32_t charge = -1;
esm.getHNOT(charge, "XHLT");
item.mChargeInt = charge;
if (newStack)
mItems.push_back(item);
}
if (!separateStacks)
mItems.push_back(item);
}
// equipped items
while (esm.isNextSub("WIDX"))
{
// note: same item can be equipped 2 items (e.g. 2 rings)
// and will be *stacked* in the NPCO list, unlike openmw!
// this is currently not handled properly.
esm.getSubHeader();
2023-12-17 13:03:45 +00:00
int32_t itemIndex; // index of the item in the NPCO list
esm.getT(itemIndex);
if (itemIndex < 0 || itemIndex >= int(mItems.size()))
esm.fail("equipment item index out of range");
// appears to be a relative index for only the *possible* slots this item can be equipped in,
// i.e. 0 most of the time
2023-12-17 13:03:45 +00:00
int32_t slotIndex;
esm.getT(slotIndex);
mItems[itemIndex].mRelativeEquipmentSlot = slotIndex;
}
}
}