ESSImport: inventory loading works, equipment slots need more work

openmw-35
scrawl 9 years ago
parent f7e32a24c9
commit a7b82e5107

@ -12,6 +12,8 @@ set(ESSIMPORTER_FILES
converter.cpp
convertacdt.cpp
convertnpcc.cpp
convertinventory.cpp
convertcrec.cpp
)
add_executable(openmw-essimporter

@ -0,0 +1,13 @@
#include "convertcrec.hpp"
#include "convertinventory.hpp"
namespace ESSImport
{
void convertCREC(const CREC &crec, ESM::CreatureState &state)
{
convertInventory(crec.mInventory, state.mInventory);
}
}

@ -0,0 +1,15 @@
#ifndef OPENMW_ESSIMPORT_CONVERTCREC_H
#define OPENMW_ESSIMPORT_CONVERTCREC_H
#include "importcrec.hpp"
#include <components/esm/creaturestate.hpp>
namespace ESSImport
{
void convertCREC(const CREC& crec, ESM::CreatureState& state);
}
#endif

@ -4,6 +4,8 @@
#include <components/esm/creaturestate.hpp>
#include "convertcrec.hpp"
namespace
{
@ -197,6 +199,7 @@ namespace ESSImport
ESM::CreatureState objstate;
objstate.blank();
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
convertCREC(crecIt->second, objstate);
objstate.mEnabled = cellref.mEnabled;
objstate.mPosition = cellref.mPos;
objstate.mRef = out;
@ -215,6 +218,7 @@ namespace ESSImport
objstate.blank();
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
convertNpcData(cellref.mActorData, objstate.mNpcStats);
convertNPCC(npccIt->second, objstate);
objstate.mEnabled = cellref.mEnabled;
objstate.mPosition = cellref.mPos;
objstate.mRef = out;

@ -0,0 +1,23 @@
#include "convertinventory.hpp"
#include <components/misc/stringops.hpp>
namespace ESSImport
{
void convertInventory(const Inventory &inventory, ESM::InventoryState &state)
{
for (std::vector<Inventory::InventoryItem>::const_iterator it = inventory.mItems.begin();
it != inventory.mItems.end(); ++it)
{
ESM::ObjectState objstate;
objstate.blank();
objstate.mRef.mRefID = Misc::StringUtils::lowerCase(it->mId);
objstate.mCount = std::abs(it->mCount); // restocking items have negative count in the savefile
// openmw handles them differently, so no need to set any flags
objstate.mRef.mCharge = it->mCondition;
state.mItems.push_back(std::make_pair(objstate, -1));
}
}
}

@ -0,0 +1,15 @@
#ifndef OPENMW_ESSIMPORT_CONVERTINVENTORY_H
#define OPENMW_ESSIMPORT_CONVERTINVENTORY_H
#include "importinventory.hpp"
#include <components/esm/inventorystate.hpp>
namespace ESSImport
{
void convertInventory (const Inventory& inventory, ESM::InventoryState& state);
}
#endif

@ -1,10 +1,14 @@
#include "convertnpcc.hpp"
#include "convertinventory.hpp"
namespace ESSImport
{
void convertNPCC(const NPCC &npcc, ESM::NpcState &npcState)
{
npcState.mNpcStats.mReputation = npcc.mNPDT.mReputation;
convertInventory(npcc.mInventory, npcState.mInventory);
}
}

@ -2,6 +2,8 @@
#include <components/esm/esmreader.hpp>
#include <components/esm/loadcont.hpp>
namespace ESSImport
{
@ -9,8 +11,12 @@ namespace ESSImport
{
while (esm.isNextSub("NPCO"))
{
ESM::ContItem contItem;
esm.getHT(contItem);
InventoryItem item;
item.mId = esm.getHString();
item.mId = contItem.mItem.toString();
item.mCount = contItem.mCount;
if (esm.isNextSub("XIDX"))
esm.skipHSub();
@ -32,14 +38,24 @@ namespace ESSImport
item.ESM::CellRef::loadData(esm);
item.mCondition = -1;
// FIXME: for Lights, this is actually a float
esm.getHNOT(item.mCondition, "XHLT");
mItems.push_back(item);
}
// equipped items
while (esm.isNextSub("WIDX"))
{
// equipping?
esm.skipHSub();
// note: same item can be equipped 2 items (e.g. 2 rings)
// and will be *stacked* in the NPCO list, unlike openmw!
esm.getSubHeader();
int itemIndex; // index of the item in the NPCO list
esm.getT(itemIndex);
// appears to be a relative index for only the *possible* slots this item can be equipped in,
// i.e. 0 most of the time, unlike openmw slot enum index
int slotIndex;
esm.getT(slotIndex);
}
}

@ -19,6 +19,7 @@ namespace ESSImport
struct InventoryItem : public ESM::CellRef
{
std::string mId;
int mCount;
int mCondition;
};
std::vector<InventoryItem> mItems;

@ -142,8 +142,8 @@ void ESM::CellRef::blank()
mSoul.clear();
mFaction.clear();
mFactionRank = -2;
mCharge = 0;
mEnchantmentCharge = 0;
mCharge = -1;
mEnchantmentCharge = -1;
mGoldValue = 0;
mDestCell.clear();
mLockLevel = 0;

Loading…
Cancel
Save