1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 18:19:55 +00:00
openmw-tes3mp/components/esm/loadrace.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

81 lines
1.9 KiB
C++

#include "loadrace.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include "defs.hpp"
namespace ESM
{
unsigned int Race::sRecordId = REC_RACE;
int Race::MaleFemale::getValue (bool male) const
{
return male ? mMale : mFemale;
}
int Race::MaleFemaleF::getValue (bool male) const
{
return male ? mMale : mFemale;
}
void Race::load(ESMReader &esm)
{
mPowers.mList.clear();
bool hasData = false;
while (esm.hasMoreSubs())
{
esm.getSubName();
uint32_t name = esm.retSubName().val;
switch (name)
{
case ESM::FourCC<'F','N','A','M'>::value:
mName = esm.getHString();
break;
case ESM::FourCC<'R','A','D','T'>::value:
esm.getHT(mData, 140);
hasData = true;
break;
case ESM::FourCC<'D','E','S','C'>::value:
mDescription = esm.getHString();
break;
case ESM::FourCC<'N','P','C','S'>::value:
mPowers.add(esm);
break;
default:
esm.fail("Unknown subrecord");
}
}
if (!hasData)
esm.fail("Missing RADT subrecord");
}
void Race::save(ESMWriter &esm) const
{
esm.writeHNOCString("FNAM", mName);
esm.writeHNT("RADT", mData, 140);
mPowers.save(esm);
esm.writeHNOString("DESC", mDescription);
}
void Race::blank()
{
mName.clear();
mDescription.clear();
mPowers.mList.clear();
for (int i=0; i<7; ++i)
{
mData.mBonus[i].mSkill = -1;
mData.mBonus[i].mBonus = 0;
}
for (int i=0; i<8; ++i)
mData.mAttributeValues[i].mMale = mData.mAttributeValues[i].mFemale = 1;
mData.mHeight.mMale = mData.mHeight.mFemale = 1;
mData.mWeight.mMale = mData.mWeight.mFemale = 1;
mData.mFlags = 0;
}
}