1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 17:49:55 +00:00
openmw-tes3mp/components/esm/loadlevlist.cpp
scrawl 49d912e5b6 Don't rely on subrecord order part 2
Nice side effects:
 - Subrecord name comparison now uses magic number instead of string (faster)
 - Improves the error message for unknown subrecords: will print the record in question instead of failing to read the next record with a strange error
2015-02-12 05:43:22 +01:00

65 lines
1.9 KiB
C++

#include "loadlevlist.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include "defs.hpp"
namespace ESM
{
void LevelledListBase::load(ESMReader &esm)
{
esm.getHNT(mFlags, "DATA");
esm.getHNT(mChanceNone, "NNAM");
if (esm.isNextSub("INDX"))
{
int len;
esm.getHT(len);
mList.resize(len);
}
else
{
// Original engine ignores rest of the record, even if there are items following
esm.skipRecord();
return;
}
// If this levelled list was already loaded by a previous content file,
// we overwrite the list. Merging lists should probably be left to external tools,
// with the limited amount of information there is in the records, all merging methods
// will be flawed in some way. For a proper fix the ESM format would have to be changed
// to actually track list changes instead of including the whole list for every file
// that does something with that list.
for (size_t i = 0; i < mList.size(); i++)
{
LevelItem &li = mList[i];
li.mId = esm.getHNString(mRecName);
esm.getHNT(li.mLevel, "INTV");
}
}
void LevelledListBase::save(ESMWriter &esm) const
{
esm.writeHNT("DATA", mFlags);
esm.writeHNT("NNAM", mChanceNone);
esm.writeHNT<int>("INDX", mList.size());
for (std::vector<LevelItem>::const_iterator it = mList.begin(); it != mList.end(); ++it)
{
esm.writeHNCString(mRecName, it->mId);
esm.writeHNT("INTV", it->mLevel);
}
}
void LevelledListBase::blank()
{
mFlags = 0;
mChanceNone = 0;
mList.clear();
}
unsigned int CreatureLevList::sRecordId = REC_LEVC;
unsigned int ItemLevList::sRecordId = REC_LEVI;
}