2011-04-08 13:58:21 +00:00
|
|
|
#include "loadnpc.hpp"
|
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
#include "esm_reader.hpp"
|
|
|
|
#include "esm_writer.hpp"
|
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
2012-04-08 09:51:52 +00:00
|
|
|
void NPC::load(ESMReader &esm)
|
2011-04-08 13:58:21 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
mNpdt52.mGold = -10;
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
mModel = esm.getHNOString("MODL");
|
|
|
|
mName = esm.getHNOString("FNAM");
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
mRace = esm.getHNString("RNAM");
|
|
|
|
mClass = esm.getHNString("CNAM");
|
|
|
|
mFaction = esm.getHNString("ANAM");
|
|
|
|
mHead = esm.getHNString("BNAM");
|
|
|
|
mHair = esm.getHNString("KNAM");
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
mScript = esm.getHNOString("SCRI");
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
esm.getSubNameIs("NPDT");
|
|
|
|
esm.getSubHeader();
|
|
|
|
if (esm.getSubSize() == 52)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
mNpdtType = 52;
|
|
|
|
esm.getExact(&mNpdt52, 52);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
else if (esm.getSubSize() == 12)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
mNpdtType = 12;
|
|
|
|
esm.getExact(&mNpdt12, 12);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
else
|
|
|
|
esm.fail("NPC_NPDT must be 12 or 52 bytes long");
|
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getHNT(mFlags, "FLAG");
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
mInventory.load(esm);
|
|
|
|
mSpells.load(esm);
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
if (esm.isNextSub("AIDT"))
|
|
|
|
{
|
2012-08-29 17:35:06 +00:00
|
|
|
esm.getHExact(&mAiData, sizeof(mAiData));
|
|
|
|
mHasAI= true;
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
else
|
2012-08-29 17:35:06 +00:00
|
|
|
mHasAI = false;
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2012-08-29 10:01:10 +00:00
|
|
|
while (esm.isNextSub("DODT") || esm.isNextSub("DNAM")) {
|
|
|
|
if (esm.retSubName() == 0x54444f44) { // DODT struct
|
|
|
|
Dest dodt;
|
2012-08-29 17:35:06 +00:00
|
|
|
esm.getHExact(&dodt.mPos, 24);
|
|
|
|
mTransport.push_back(dodt);
|
2012-08-29 10:01:10 +00:00
|
|
|
} else if (esm.retSubName() == 0x4d414e44) { // DNAM struct
|
2012-08-29 17:35:06 +00:00
|
|
|
mTransport.back().mCellName = esm.getHString();
|
2012-08-29 10:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-29 17:35:06 +00:00
|
|
|
mAiPackage.load(esm);
|
2011-04-08 13:58:21 +00:00
|
|
|
esm.skipRecord();
|
|
|
|
}
|
2012-04-06 19:04:30 +00:00
|
|
|
void NPC::save(ESMWriter &esm)
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.writeHNOCString("MODL", mModel);
|
|
|
|
esm.writeHNOCString("FNAM", mName);
|
|
|
|
esm.writeHNCString("RNAM", mRace);
|
|
|
|
esm.writeHNCString("CNAM", mClass);
|
|
|
|
esm.writeHNCString("ANAM", mFaction);
|
|
|
|
esm.writeHNCString("BNAM", mHead);
|
|
|
|
esm.writeHNCString("KNAM", mHair);
|
|
|
|
esm.writeHNOCString("SCRI", mScript);
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
if (mNpdtType == 52)
|
|
|
|
esm.writeHNT("NPDT", mNpdt52, 52);
|
|
|
|
else if (mNpdtType == 12)
|
|
|
|
esm.writeHNT("NPDT", mNpdt12, 12);
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.writeHNT("FLAG", mFlags);
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
mInventory.save(esm);
|
|
|
|
mSpells.save(esm);
|
|
|
|
mAiPackage.save(esm);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
}
|