You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/components/esm/loadnpc.cpp

88 lines
2.0 KiB
C++

#include "loadnpc.hpp"
#include "esm_reader.hpp"
#include "esm_writer.hpp"
namespace ESM
{
void NPC::load(ESMReader &esm)
{
mNpdt52.mGold = -10;
mModel = esm.getHNOString("MODL");
mName = esm.getHNOString("FNAM");
mRace = esm.getHNString("RNAM");
mClass = esm.getHNString("CNAM");
mFaction = esm.getHNString("ANAM");
mHead = esm.getHNString("BNAM");
mHair = esm.getHNString("KNAM");
mScript = esm.getHNOString("SCRI");
esm.getSubNameIs("NPDT");
esm.getSubHeader();
if (esm.getSubSize() == 52)
{
mNpdtType = 52;
esm.getExact(&mNpdt52, 52);
}
else if (esm.getSubSize() == 12)
{
mNpdtType = 12;
esm.getExact(&mNpdt12, 12);
}
else
esm.fail("NPC_NPDT must be 12 or 52 bytes long");
esm.getHNT(mFlags, "FLAG");
mInventory.load(esm);
mSpells.load(esm);
if (esm.isNextSub("AIDT"))
{
13 years ago
esm.getHExact(&mAiData, sizeof(mAiData));
mHasAI= true;
}
else
13 years ago
mHasAI = false;
13 years ago
while (esm.isNextSub("DODT") || esm.isNextSub("DNAM")) {
if (esm.retSubName() == 0x54444f44) { // DODT struct
Dest dodt;
13 years ago
esm.getHExact(&dodt.mPos, 24);
mTransport.push_back(dodt);
13 years ago
} else if (esm.retSubName() == 0x4d414e44) { // DNAM struct
13 years ago
mTransport.back().mCellName = esm.getHString();
13 years ago
}
}
13 years ago
mAiPackage.load(esm);
esm.skipRecord();
}
void NPC::save(ESMWriter &esm)
{
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);
if (mNpdtType == 52)
esm.writeHNT("NPDT", mNpdt52, 52);
else if (mNpdtType == 12)
esm.writeHNT("NPDT", mNpdt12, 12);
esm.writeHNT("FLAG", mFlags);
mInventory.save(esm);
mSpells.save(esm);
mAiPackage.save(esm);
}
}