2011-04-06 20:11:08 +04:00
|
|
|
#include "loadbook.hpp"
|
|
|
|
|
2012-09-23 22:41:41 +04:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2022-01-22 15:58:41 +01:00
|
|
|
#include "components/esm/defs.hpp"
|
2012-09-17 11:37:50 +04:00
|
|
|
|
2011-04-06 20:11:08 +04:00
|
|
|
namespace ESM
|
|
|
|
{
|
2013-09-24 13:17:28 +02:00
|
|
|
unsigned int Book::sRecordId = REC_BOOK;
|
2011-04-06 20:11:08 +04:00
|
|
|
|
2015-07-20 17:23:14 +03:00
|
|
|
void Book::load(ESMReader &esm, bool &isDeleted)
|
2015-02-10 23:16:25 +01:00
|
|
|
{
|
2015-07-20 17:23:14 +03:00
|
|
|
isDeleted = false;
|
2021-06-29 23:25:26 +10:00
|
|
|
mRecordFlags = esm.getRecordFlags();
|
2015-07-07 15:37:42 +03:00
|
|
|
|
2015-07-16 19:52:31 +03:00
|
|
|
bool hasName = false;
|
2015-02-10 23:16:25 +01:00
|
|
|
bool hasData = false;
|
|
|
|
while (esm.hasMoreSubs())
|
|
|
|
{
|
|
|
|
esm.getSubName();
|
2021-10-17 02:52:22 +02:00
|
|
|
switch (esm.retSubName().toInt())
|
2015-02-10 23:16:25 +01:00
|
|
|
{
|
2022-04-12 00:18:39 +02:00
|
|
|
case SREC_NAME:
|
2015-07-16 19:52:31 +03:00
|
|
|
mId = esm.getHString();
|
|
|
|
hasName = true;
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("MODL"):
|
2015-02-10 23:16:25 +01:00
|
|
|
mModel = esm.getHString();
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("FNAM"):
|
2015-02-10 23:16:25 +01:00
|
|
|
mName = esm.getHString();
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("BKDT"):
|
2022-04-10 13:35:00 +02:00
|
|
|
esm.getHTSized<20>(mData);
|
2015-02-10 23:16:25 +01:00
|
|
|
hasData = true;
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("SCRI"):
|
2015-02-10 23:16:25 +01:00
|
|
|
mScript = esm.getHString();
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("ITEX"):
|
2015-02-10 23:16:25 +01:00
|
|
|
mIcon = esm.getHString();
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("ENAM"):
|
2015-02-10 23:16:25 +01:00
|
|
|
mEnchant = esm.getHString();
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("TEXT"):
|
2015-02-10 23:16:25 +01:00
|
|
|
mText = esm.getHString();
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case SREC_DELE:
|
2015-07-20 17:23:14 +03:00
|
|
|
esm.skipHSub();
|
|
|
|
isDeleted = true;
|
|
|
|
break;
|
2015-02-10 23:16:25 +01:00
|
|
|
default:
|
|
|
|
esm.fail("Unknown subrecord");
|
2015-07-16 19:52:31 +03:00
|
|
|
break;
|
2015-02-10 23:16:25 +01:00
|
|
|
}
|
|
|
|
}
|
2015-07-16 19:52:31 +03:00
|
|
|
|
|
|
|
if (!hasName)
|
|
|
|
esm.fail("Missing NAME subrecord");
|
2015-07-20 17:23:14 +03:00
|
|
|
if (!hasData && !isDeleted)
|
2015-02-10 23:16:25 +01:00
|
|
|
esm.fail("Missing BKDT subrecord");
|
|
|
|
}
|
2015-07-20 17:23:14 +03:00
|
|
|
void Book::save(ESMWriter &esm, bool isDeleted) const
|
2015-02-10 23:16:25 +01:00
|
|
|
{
|
2015-07-07 15:37:42 +03:00
|
|
|
esm.writeHNCString("NAME", mId);
|
2015-07-16 19:52:31 +03:00
|
|
|
|
2015-07-20 17:23:14 +03:00
|
|
|
if (isDeleted)
|
2015-07-07 15:37:42 +03:00
|
|
|
{
|
2021-07-06 14:57:58 +10:00
|
|
|
esm.writeHNString("DELE", "", 3);
|
2015-07-07 15:37:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-10 23:16:25 +01:00
|
|
|
esm.writeHNCString("MODL", mModel);
|
|
|
|
esm.writeHNOCString("FNAM", mName);
|
|
|
|
esm.writeHNT("BKDT", mData, 20);
|
|
|
|
esm.writeHNOCString("SCRI", mScript);
|
|
|
|
esm.writeHNOCString("ITEX", mIcon);
|
|
|
|
esm.writeHNOString("TEXT", mText);
|
|
|
|
esm.writeHNOCString("ENAM", mEnchant);
|
|
|
|
}
|
2011-04-06 20:11:08 +04:00
|
|
|
|
2013-05-06 14:10:43 +02:00
|
|
|
void Book::blank()
|
|
|
|
{
|
|
|
|
mData.mWeight = 0;
|
|
|
|
mData.mValue = 0;
|
|
|
|
mData.mIsScroll = 0;
|
2017-02-12 13:53:10 +01:00
|
|
|
mData.mSkillId = 0;
|
2013-05-06 14:10:43 +02:00
|
|
|
mData.mEnchant = 0;
|
|
|
|
mName.clear();
|
|
|
|
mModel.clear();
|
|
|
|
mIcon.clear();
|
|
|
|
mScript.clear();
|
|
|
|
mEnchant.clear();
|
|
|
|
mText.clear();
|
|
|
|
}
|
2011-04-06 20:11:08 +04:00
|
|
|
}
|