1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 18:45:33 +00:00
openmw/components/esm3/loadclas.cpp

106 lines
2.9 KiB
C++
Raw Normal View History

#include "loadclas.hpp"
#include <stdexcept>
2022-09-22 18:26:05 +00:00
#include "components/esm/defs.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
2012-09-17 07:37:50 +00:00
namespace ESM
{
2022-09-22 18:26:05 +00:00
const Class::Specialization Class::sSpecializationIds[3] = { Class::Combat, Class::Magic, Class::Stealth };
const char* Class::sGmstSpecializationIds[3]
= { "sSpecializationCombat", "sSpecializationMagic", "sSpecializationStealth" };
int& Class::CLDTstruct::getSkill(int index, bool major)
{
2022-09-22 18:26:05 +00:00
if (index < 0 || index >= 5)
throw std::logic_error("skill index out of range");
return mSkills[index][major ? 1 : 0];
}
2022-09-22 18:26:05 +00:00
int Class::CLDTstruct::getSkill(int index, bool major) const
{
2022-09-22 18:26:05 +00:00
if (index < 0 || index >= 5)
throw std::logic_error("skill index out of range");
return mSkills[index][major ? 1 : 0];
}
2022-09-22 18:26:05 +00:00
void Class::load(ESMReader& esm, bool& isDeleted)
{
isDeleted = false;
mRecordFlags = esm.getRecordFlags();
bool hasName = false;
bool hasData = false;
while (esm.hasMoreSubs())
{
esm.getSubName();
switch (esm.retSubName().toInt())
{
case SREC_NAME:
mId = esm.getHString();
hasName = true;
break;
case fourCC("FNAM"):
mName = esm.getHString();
break;
case fourCC("CLDT"):
esm.getHTSized<60>(mData);
if (mData.mIsPlayable > 1)
esm.fail("Unknown bool value");
hasData = true;
break;
case fourCC("DESC"):
mDescription = esm.getHString();
break;
case SREC_DELE:
esm.skipHSub();
isDeleted = true;
break;
default:
esm.fail("Unknown subrecord");
break;
}
}
if (!hasName)
esm.fail("Missing NAME subrecord");
if (!hasData && !isDeleted)
esm.fail("Missing CLDT subrecord");
}
2022-09-22 18:26:05 +00:00
void Class::save(ESMWriter& esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNString("DELE", "", 3);
return;
}
esm.writeHNOCString("FNAM", mName);
esm.writeHNT("CLDT", mData, 60);
esm.writeHNOString("DESC", mDescription);
}
2013-03-25 12:22:06 +00:00
void Class::blank()
{
2022-05-29 20:12:30 +00:00
mRecordFlags = 0;
2013-03-25 12:22:06 +00:00
mName.clear();
mDescription.clear();
mData.mAttribute[0] = mData.mAttribute[1] = 0;
mData.mSpecialization = 0;
mData.mIsPlayable = 0;
mData.mCalc = 0;
2022-09-22 18:26:05 +00:00
for (int i = 0; i < 5; ++i)
for (int i2 = 0; i2 < 2; ++i2)
2013-03-25 12:22:06 +00:00
mData.mSkills[i][i2] = 0;
}
}