1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 20:19:57 +00:00

ESSImport: convert other references (non-creature/npc/container)

This commit is contained in:
scrawl 2015-01-19 23:51:43 +01:00
parent 9014dc48ee
commit 40c29abe20
5 changed files with 95 additions and 57 deletions

View file

@ -26,6 +26,17 @@ namespace
objstate.mPosition = cellref.mPos;
objstate.mRef.mRefNum = cellref.mRefNum;
}
bool isIndexedRefId(const std::string& indexedRefId)
{
if (indexedRefId.size() <= 8)
return false;
std::string index = indexedRefId.substr(indexedRefId.size()-8);
if(index.find_first_not_of("0123456789ABCDEF") == std::string::npos )
return true;
return false;
}
}
namespace ESSImport
@ -191,65 +202,87 @@ namespace ESSImport
ESM::CellRef out;
out.blank();
if (cellref.mIndexedRefId.size() < 8)
if (!isIndexedRefId(cellref.mIndexedRefId))
{
std::cerr << "CellRef with no index?" << std::endl;
continue;
}
std::stringstream stream;
stream << cellref.mIndexedRefId.substr(cellref.mIndexedRefId.size()-8,8);
int refIndex;
stream >> refIndex;
// non-indexed RefNum, i.e. no CREC/NPCC/CNTC record associated with it
// this could be any type of object really (even creatures/npcs too)
out.mRefID = cellref.mIndexedRefId;
std::string idLower = Misc::StringUtils::lowerCase(out.mRefID);
out.mRefID = cellref.mIndexedRefId.substr(0,cellref.mIndexedRefId.size()-8);
std::map<std::pair<int, std::string>, CREC>::const_iterator crecIt = mContext->mCreatureChanges.find(
std::make_pair(refIndex, out.mRefID));
if (crecIt != mContext->mCreatureChanges.end())
{
ESM::CreatureState objstate;
ESM::ObjectState objstate;
objstate.blank();
objstate.mRef = out;
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
convertCREC(crecIt->second, objstate);
objstate.mRef.mRefID = idLower;
objstate.mHasCustomState = false;
convertCellRef(cellref, objstate);
// FIXME: change save format to not require object type, instead look up it up using the RefId
esm.writeHNT ("OBJE", ESM::REC_CREA);
esm.writeHNT ("OBJE", 0);
objstate.save(esm);
continue;
}
std::map<std::pair<int, std::string>, NPCC>::const_iterator npccIt = mContext->mNpcChanges.find(
std::make_pair(refIndex, out.mRefID));
if (npccIt != mContext->mNpcChanges.end())
else
{
ESM::NpcState objstate;
objstate.blank();
objstate.mRef = out;
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
convertNpcData(cellref.mActorData, objstate.mNpcStats);
convertNPCC(npccIt->second, objstate);
convertCellRef(cellref, objstate);
esm.writeHNT ("OBJE", ESM::REC_NPC_);
objstate.save(esm);
continue;
}
std::stringstream stream;
stream << std::hex << cellref.mIndexedRefId.substr(cellref.mIndexedRefId.size()-8,8);
int refIndex;
stream >> refIndex;
std::map<std::pair<int, std::string>, CNTC>::const_iterator cntcIt = mContext->mContainerChanges.find(
std::make_pair(refIndex, out.mRefID));
if (cntcIt != mContext->mContainerChanges.end())
{
ESM::ContainerState objstate;
objstate.blank();
objstate.mRef = out;
convertCNTC(cntcIt->second, objstate);
convertCellRef(cellref, objstate);
esm.writeHNT ("OBJE", ESM::REC_CONT);
objstate.save(esm);
continue;
}
out.mRefID = cellref.mIndexedRefId.substr(0,cellref.mIndexedRefId.size()-8);
std::string idLower = Misc::StringUtils::lowerCase(out.mRefID);
std::cerr << "Can't find type for " << refIndex << " " << out.mRefID << std::endl;
std::map<std::pair<int, std::string>, NPCC>::const_iterator npccIt = mContext->mNpcChanges.find(
std::make_pair(refIndex, out.mRefID));
if (npccIt != mContext->mNpcChanges.end())
{
ESM::NpcState objstate;
objstate.blank();
objstate.mRef = out;
objstate.mRef.mRefID = idLower;
// probably need more micromanagement here so we don't overwrite values
// from the ESM with default values
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
convertNpcData(cellref.mActorData, objstate.mNpcStats);
convertNPCC(npccIt->second, objstate);
convertCellRef(cellref, objstate);
esm.writeHNT ("OBJE", ESM::REC_NPC_);
objstate.save(esm);
continue;
}
std::map<std::pair<int, std::string>, CNTC>::const_iterator cntcIt = mContext->mContainerChanges.find(
std::make_pair(refIndex, out.mRefID));
if (cntcIt != mContext->mContainerChanges.end())
{
ESM::ContainerState objstate;
objstate.blank();
objstate.mRef = out;
objstate.mRef.mRefID = idLower;
convertCNTC(cntcIt->second, objstate);
convertCellRef(cellref, objstate);
esm.writeHNT ("OBJE", ESM::REC_CONT);
objstate.save(esm);
continue;
}
std::map<std::pair<int, std::string>, CREC>::const_iterator crecIt = mContext->mCreatureChanges.find(
std::make_pair(refIndex, out.mRefID));
if (crecIt != mContext->mCreatureChanges.end())
{
ESM::CreatureState objstate;
objstate.blank();
objstate.mRef = out;
objstate.mRef.mRefID = idLower;
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
// probably need more micromanagement here so we don't overwrite values
// from the ESM with default values
convertCREC(crecIt->second, objstate);
convertCellRef(cellref, objstate);
esm.writeHNT ("OBJE", ESM::REC_CREA);
objstate.save(esm);
continue;
}
std::cerr << "Can't find type for " << cellref.mIndexedRefId << std::endl;
}
}
esm.endRecord(ESM::REC_CSTA);

View file

@ -167,8 +167,14 @@ public:
convertNPCC(npcc, mContext->mPlayer.mObject);
}
else
mContext->mNpcChanges.insert(std::make_pair(std::make_pair(npcc.mIndex,id), npcc));
{
int index = mIndexCounter[id]++;
mContext->mNpcChanges.insert(std::make_pair(std::make_pair(index,id), npcc)).second;
}
}
private:
std::map<std::string, int> mIndexCounter;
};
class ConvertREFR : public Converter
@ -230,7 +236,6 @@ public:
std::string id = esm.getHNString("NAME");
CREC crec;
crec.load(esm);
mContext->mCreatureChanges.insert(std::make_pair(std::make_pair(crec.mIndex,id), crec));
}
};

View file

@ -18,8 +18,13 @@ namespace ESSImport
mIndexedRefId = esm.getHNString("NAME");
if (esm.isNextSub("LVCR"))
esm.skipHSub();
{
// occurs on leveled creature spawner references
// probably some identifier for the the creature that has been spawned?
unsigned char lvcr;
esm.getHT(lvcr);
//std::cout << "LVCR: " << (int)lvcr << std::endl;
}
mActorData.load(esm);
mEnabled = true;

View file

@ -7,9 +7,6 @@ namespace ESSImport
void NPCC::load(ESM::ESMReader &esm)
{
mIndex = 0;
esm.getHNOT(mIndex, "INDX");
esm.getHNT(mNPDT, "NPDT");
if (esm.isNextSub("AI_E"))

View file

@ -26,8 +26,6 @@ namespace ESSImport
Inventory mInventory;
int mIndex;
void load(ESM::ESMReader &esm);
};