forked from teamnwah/openmw-tes3coop
ESSImport: inventory loading works, equipment slots need more work
This commit is contained in:
parent
f7e32a24c9
commit
a7b82e5107
10 changed files with 98 additions and 5 deletions
|
@ -12,6 +12,8 @@ set(ESSIMPORTER_FILES
|
||||||
converter.cpp
|
converter.cpp
|
||||||
convertacdt.cpp
|
convertacdt.cpp
|
||||||
convertnpcc.cpp
|
convertnpcc.cpp
|
||||||
|
convertinventory.cpp
|
||||||
|
convertcrec.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(openmw-essimporter
|
add_executable(openmw-essimporter
|
||||||
|
|
13
apps/essimporter/convertcrec.cpp
Normal file
13
apps/essimporter/convertcrec.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
apps/essimporter/convertcrec.hpp
Normal file
15
apps/essimporter/convertcrec.hpp
Normal file
|
@ -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 <components/esm/creaturestate.hpp>
|
||||||
|
|
||||||
|
#include "convertcrec.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -197,6 +199,7 @@ namespace ESSImport
|
||||||
ESM::CreatureState objstate;
|
ESM::CreatureState objstate;
|
||||||
objstate.blank();
|
objstate.blank();
|
||||||
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
||||||
|
convertCREC(crecIt->second, objstate);
|
||||||
objstate.mEnabled = cellref.mEnabled;
|
objstate.mEnabled = cellref.mEnabled;
|
||||||
objstate.mPosition = cellref.mPos;
|
objstate.mPosition = cellref.mPos;
|
||||||
objstate.mRef = out;
|
objstate.mRef = out;
|
||||||
|
@ -215,6 +218,7 @@ namespace ESSImport
|
||||||
objstate.blank();
|
objstate.blank();
|
||||||
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
||||||
convertNpcData(cellref.mActorData, objstate.mNpcStats);
|
convertNpcData(cellref.mActorData, objstate.mNpcStats);
|
||||||
|
convertNPCC(npccIt->second, objstate);
|
||||||
objstate.mEnabled = cellref.mEnabled;
|
objstate.mEnabled = cellref.mEnabled;
|
||||||
objstate.mPosition = cellref.mPos;
|
objstate.mPosition = cellref.mPos;
|
||||||
objstate.mRef = out;
|
objstate.mRef = out;
|
||||||
|
|
23
apps/essimporter/convertinventory.cpp
Normal file
23
apps/essimporter/convertinventory.cpp
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
apps/essimporter/convertinventory.hpp
Normal file
15
apps/essimporter/convertinventory.hpp
Normal file
|
@ -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 "convertnpcc.hpp"
|
||||||
|
|
||||||
|
#include "convertinventory.hpp"
|
||||||
|
|
||||||
namespace ESSImport
|
namespace ESSImport
|
||||||
{
|
{
|
||||||
|
|
||||||
void convertNPCC(const NPCC &npcc, ESM::NpcState &npcState)
|
void convertNPCC(const NPCC &npcc, ESM::NpcState &npcState)
|
||||||
{
|
{
|
||||||
npcState.mNpcStats.mReputation = npcc.mNPDT.mReputation;
|
npcState.mNpcStats.mReputation = npcc.mNPDT.mReputation;
|
||||||
|
|
||||||
|
convertInventory(npcc.mInventory, npcState.mInventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <components/esm/esmreader.hpp>
|
#include <components/esm/esmreader.hpp>
|
||||||
|
|
||||||
|
#include <components/esm/loadcont.hpp>
|
||||||
|
|
||||||
namespace ESSImport
|
namespace ESSImport
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -9,8 +11,12 @@ namespace ESSImport
|
||||||
{
|
{
|
||||||
while (esm.isNextSub("NPCO"))
|
while (esm.isNextSub("NPCO"))
|
||||||
{
|
{
|
||||||
|
ESM::ContItem contItem;
|
||||||
|
esm.getHT(contItem);
|
||||||
|
|
||||||
InventoryItem item;
|
InventoryItem item;
|
||||||
item.mId = esm.getHString();
|
item.mId = contItem.mItem.toString();
|
||||||
|
item.mCount = contItem.mCount;
|
||||||
|
|
||||||
if (esm.isNextSub("XIDX"))
|
if (esm.isNextSub("XIDX"))
|
||||||
esm.skipHSub();
|
esm.skipHSub();
|
||||||
|
@ -32,14 +38,24 @@ namespace ESSImport
|
||||||
item.ESM::CellRef::loadData(esm);
|
item.ESM::CellRef::loadData(esm);
|
||||||
|
|
||||||
item.mCondition = -1;
|
item.mCondition = -1;
|
||||||
|
// FIXME: for Lights, this is actually a float
|
||||||
esm.getHNOT(item.mCondition, "XHLT");
|
esm.getHNOT(item.mCondition, "XHLT");
|
||||||
mItems.push_back(item);
|
mItems.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// equipped items
|
||||||
while (esm.isNextSub("WIDX"))
|
while (esm.isNextSub("WIDX"))
|
||||||
{
|
{
|
||||||
// equipping?
|
// note: same item can be equipped 2 items (e.g. 2 rings)
|
||||||
esm.skipHSub();
|
// 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
|
struct InventoryItem : public ESM::CellRef
|
||||||
{
|
{
|
||||||
std::string mId;
|
std::string mId;
|
||||||
|
int mCount;
|
||||||
int mCondition;
|
int mCondition;
|
||||||
};
|
};
|
||||||
std::vector<InventoryItem> mItems;
|
std::vector<InventoryItem> mItems;
|
||||||
|
|
|
@ -142,8 +142,8 @@ void ESM::CellRef::blank()
|
||||||
mSoul.clear();
|
mSoul.clear();
|
||||||
mFaction.clear();
|
mFaction.clear();
|
||||||
mFactionRank = -2;
|
mFactionRank = -2;
|
||||||
mCharge = 0;
|
mCharge = -1;
|
||||||
mEnchantmentCharge = 0;
|
mEnchantmentCharge = -1;
|
||||||
mGoldValue = 0;
|
mGoldValue = 0;
|
||||||
mDestCell.clear();
|
mDestCell.clear();
|
||||||
mLockLevel = 0;
|
mLockLevel = 0;
|
||||||
|
|
Loading…
Reference in a new issue