2011-04-06 16:11:08 +00:00
|
|
|
#include "loadarmo.hpp"
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2022-01-22 14:58:41 +00:00
|
|
|
#include "components/esm/defs.hpp"
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2011-04-06 16:11:08 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
2015-02-10 22:16:25 +00:00
|
|
|
void PartReferenceList::add(ESMReader &esm)
|
2011-04-06 16:11:08 +00:00
|
|
|
{
|
|
|
|
PartReference pr;
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getHT(pr.mPart); // The INDX byte
|
|
|
|
pr.mMale = esm.getHNOString("BNAM");
|
|
|
|
pr.mFemale = esm.getHNOString("CNAM");
|
|
|
|
mParts.push_back(pr);
|
2015-02-10 22:16:25 +00:00
|
|
|
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-10 22:16:25 +00:00
|
|
|
void PartReferenceList::load(ESMReader &esm)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2015-02-10 22:16:25 +00:00
|
|
|
mParts.clear();
|
|
|
|
while (esm.isNextSub("INDX"))
|
|
|
|
{
|
|
|
|
add(esm);
|
|
|
|
}
|
2011-04-06 16:11:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-10 22:16:25 +00:00
|
|
|
void PartReferenceList::save(ESMWriter &esm) const
|
|
|
|
{
|
|
|
|
for (std::vector<PartReference>::const_iterator it = mParts.begin(); it != mParts.end(); ++it)
|
|
|
|
{
|
|
|
|
esm.writeHNT("INDX", it->mPart);
|
|
|
|
esm.writeHNOString("BNAM", it->mMale);
|
|
|
|
esm.writeHNOString("CNAM", it->mFemale);
|
|
|
|
}
|
|
|
|
}
|
2013-09-24 11:17:28 +00:00
|
|
|
|
2015-02-10 22:16:25 +00:00
|
|
|
unsigned int Armor::sRecordId = REC_ARMO;
|
2011-04-06 16:11:08 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void Armor::load(ESMReader &esm, bool &isDeleted)
|
2015-02-10 22:16:25 +00:00
|
|
|
{
|
2015-07-20 14:23:14 +00:00
|
|
|
isDeleted = false;
|
2021-06-29 13:25:26 +00:00
|
|
|
mRecordFlags = esm.getRecordFlags();
|
2015-07-20 14:23:14 +00:00
|
|
|
|
2015-02-10 22:16:25 +00:00
|
|
|
mParts.mParts.clear();
|
2015-07-07 12:37:42 +00:00
|
|
|
|
2015-07-16 16:52:31 +00:00
|
|
|
bool hasName = false;
|
2015-02-10 22:16:25 +00:00
|
|
|
bool hasData = false;
|
|
|
|
while (esm.hasMoreSubs())
|
|
|
|
{
|
|
|
|
esm.getSubName();
|
2021-10-17 00:52:22 +00:00
|
|
|
switch (esm.retSubName().toInt())
|
2015-02-10 22:16:25 +00:00
|
|
|
{
|
2015-11-13 17:07:18 +00:00
|
|
|
case ESM::SREC_NAME:
|
2015-07-16 16:52:31 +00:00
|
|
|
mId = esm.getHString();
|
|
|
|
hasName = true;
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("MODL"):
|
2015-02-10 22:16:25 +00:00
|
|
|
mModel = esm.getHString();
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("FNAM"):
|
2015-02-10 22:16:25 +00:00
|
|
|
mName = esm.getHString();
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("AODT"):
|
2022-04-10 11:35:00 +00:00
|
|
|
esm.getHTSized<24>(mData);
|
2015-02-10 22:16:25 +00:00
|
|
|
hasData = true;
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("SCRI"):
|
2015-02-10 22:16:25 +00:00
|
|
|
mScript = esm.getHString();
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("ITEX"):
|
2015-02-10 22:16:25 +00:00
|
|
|
mIcon = esm.getHString();
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("ENAM"):
|
2015-02-10 22:16:25 +00:00
|
|
|
mEnchant = esm.getHString();
|
|
|
|
break;
|
2022-03-07 16:05:24 +00:00
|
|
|
case ESM::fourCC("INDX"):
|
2015-02-10 22:16:25 +00:00
|
|
|
mParts.add(esm);
|
|
|
|
break;
|
2015-11-13 17:07:18 +00:00
|
|
|
case ESM::SREC_DELE:
|
2015-07-20 14:23:14 +00:00
|
|
|
esm.skipHSub();
|
|
|
|
isDeleted = true;
|
|
|
|
break;
|
2015-02-10 22:16:25 +00:00
|
|
|
default:
|
|
|
|
esm.fail("Unknown subrecord");
|
2015-07-16 16:52:31 +00:00
|
|
|
break;
|
2015-02-10 22:16:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-16 16:52:31 +00:00
|
|
|
|
|
|
|
if (!hasName)
|
|
|
|
esm.fail("Missing NAME subrecord");
|
2015-07-20 14:23:14 +00:00
|
|
|
if (!hasData && !isDeleted)
|
2021-05-17 22:36:59 +00:00
|
|
|
esm.fail("Missing AODT subrecord");
|
2015-02-10 22:16:25 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void Armor::save(ESMWriter &esm, bool isDeleted) const
|
2015-02-10 22:16:25 +00:00
|
|
|
{
|
2015-07-07 12:37:42 +00:00
|
|
|
esm.writeHNCString("NAME", mId);
|
2015-07-16 16:52:31 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
if (isDeleted)
|
2015-07-07 12:37:42 +00:00
|
|
|
{
|
2021-07-06 04:57:58 +00:00
|
|
|
esm.writeHNString("DELE", "", 3);
|
2015-07-07 12:37:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-10 22:16:25 +00:00
|
|
|
esm.writeHNCString("MODL", mModel);
|
|
|
|
esm.writeHNOCString("FNAM", mName);
|
|
|
|
esm.writeHNOCString("SCRI", mScript);
|
|
|
|
esm.writeHNT("AODT", mData, 24);
|
|
|
|
esm.writeHNOCString("ITEX", mIcon);
|
|
|
|
mParts.save(esm);
|
|
|
|
esm.writeHNOCString("ENAM", mEnchant);
|
|
|
|
}
|
2011-04-06 16:11:08 +00:00
|
|
|
|
2013-05-06 12:10:43 +00:00
|
|
|
void Armor::blank()
|
|
|
|
{
|
|
|
|
mData.mType = 0;
|
|
|
|
mData.mWeight = 0;
|
|
|
|
mData.mValue = 0;
|
|
|
|
mData.mHealth = 0;
|
|
|
|
mData.mEnchant = 0;
|
|
|
|
mData.mArmor = 0;
|
|
|
|
mParts.mParts.clear();
|
|
|
|
mName.clear();
|
|
|
|
mModel.clear();
|
|
|
|
mIcon.clear();
|
|
|
|
mScript.clear();
|
|
|
|
mEnchant.clear();
|
|
|
|
}
|
2011-04-06 16:11:08 +00:00
|
|
|
}
|