mirror of https://github.com/OpenMW/openmw.git
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.
170 lines
5.4 KiB
C++
170 lines
5.4 KiB
C++
14 years ago
|
#include "loadcrea.hpp"
|
||
|
|
||
6 years ago
|
#include <components/debug/debuglog.hpp>
|
||
9 years ago
|
|
||
12 years ago
|
#include "esmreader.hpp"
|
||
|
#include "esmwriter.hpp"
|
||
3 years ago
|
#include "components/esm/defs.hpp"
|
||
12 years ago
|
|
||
14 years ago
|
namespace ESM {
|
||
|
|
||
11 years ago
|
unsigned int Creature::sRecordId = REC_CREA;
|
||
|
|
||
10 years ago
|
void Creature::load(ESMReader &esm, bool &isDeleted)
|
||
13 years ago
|
{
|
||
10 years ago
|
isDeleted = false;
|
||
4 years ago
|
mRecordFlags = esm.getRecordFlags();
|
||
10 years ago
|
|
||
10 years ago
|
mAiPackage.mList.clear();
|
||
|
mInventory.mList.clear();
|
||
|
mSpells.mList.clear();
|
||
10 years ago
|
mTransport.mList.clear();
|
||
14 years ago
|
|
||
10 years ago
|
mScale = 1.f;
|
||
6 years ago
|
mAiData.blank();
|
||
6 years ago
|
mAiData.mFight = 90;
|
||
|
mAiData.mFlee = 20;
|
||
10 years ago
|
|
||
|
bool hasName = false;
|
||
10 years ago
|
bool hasNpdt = false;
|
||
|
bool hasFlags = false;
|
||
|
while (esm.hasMoreSubs())
|
||
|
{
|
||
|
esm.getSubName();
|
||
3 years ago
|
switch (esm.retSubName().toInt())
|
||
10 years ago
|
{
|
||
9 years ago
|
case ESM::SREC_NAME:
|
||
10 years ago
|
mId = esm.getHString();
|
||
|
hasName = true;
|
||
|
break;
|
||
10 years ago
|
case ESM::FourCC<'M','O','D','L'>::value:
|
||
|
mModel = esm.getHString();
|
||
|
break;
|
||
|
case ESM::FourCC<'C','N','A','M'>::value:
|
||
|
mOriginal = esm.getHString();
|
||
|
break;
|
||
|
case ESM::FourCC<'F','N','A','M'>::value:
|
||
|
mName = esm.getHString();
|
||
|
break;
|
||
|
case ESM::FourCC<'S','C','R','I'>::value:
|
||
|
mScript = esm.getHString();
|
||
|
break;
|
||
|
case ESM::FourCC<'N','P','D','T'>::value:
|
||
|
esm.getHT(mData, 96);
|
||
|
hasNpdt = true;
|
||
|
break;
|
||
|
case ESM::FourCC<'F','L','A','G'>::value:
|
||
6 years ago
|
int flags;
|
||
|
esm.getHT(flags);
|
||
|
mFlags = flags & 0xFF;
|
||
|
mBloodType = ((flags >> 8) & 0xFF) >> 2;
|
||
10 years ago
|
hasFlags = true;
|
||
|
break;
|
||
|
case ESM::FourCC<'X','S','C','L'>::value:
|
||
|
esm.getHT(mScale);
|
||
|
break;
|
||
|
case ESM::FourCC<'N','P','C','O'>::value:
|
||
|
mInventory.add(esm);
|
||
|
break;
|
||
|
case ESM::FourCC<'N','P','C','S'>::value:
|
||
|
mSpells.add(esm);
|
||
|
break;
|
||
|
case ESM::FourCC<'A','I','D','T'>::value:
|
||
|
esm.getHExact(&mAiData, sizeof(mAiData));
|
||
|
break;
|
||
10 years ago
|
case ESM::FourCC<'D','O','D','T'>::value:
|
||
|
case ESM::FourCC<'D','N','A','M'>::value:
|
||
|
mTransport.add(esm);
|
||
|
break;
|
||
10 years ago
|
case AI_Wander:
|
||
|
case AI_Activate:
|
||
|
case AI_Escort:
|
||
|
case AI_Follow:
|
||
|
case AI_Travel:
|
||
|
case AI_CNDT:
|
||
|
mAiPackage.add(esm);
|
||
|
break;
|
||
9 years ago
|
case ESM::SREC_DELE:
|
||
10 years ago
|
esm.skipHSub();
|
||
|
isDeleted = true;
|
||
|
break;
|
||
9 years ago
|
case ESM::FourCC<'I','N','D','X'>::value:
|
||
|
// seems to occur only in .ESS files, unsure of purpose
|
||
|
int index;
|
||
|
esm.getHT(index);
|
||
6 years ago
|
Log(Debug::Warning) << "Creature::load: Unhandled INDX " << index;
|
||
9 years ago
|
break;
|
||
10 years ago
|
default:
|
||
|
esm.fail("Unknown subrecord");
|
||
10 years ago
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
if (!hasName)
|
||
|
esm.fail("Missing NAME subrecord");
|
||
10 years ago
|
if (!hasNpdt && !isDeleted)
|
||
10 years ago
|
esm.fail("Missing NPDT subrecord");
|
||
10 years ago
|
if (!hasFlags && !isDeleted)
|
||
10 years ago
|
esm.fail("Missing FLAG subrecord");
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
void Creature::save(ESMWriter &esm, bool isDeleted) const
|
||
10 years ago
|
{
|
||
10 years ago
|
esm.writeHNCString("NAME", mId);
|
||
10 years ago
|
|
||
10 years ago
|
if (isDeleted)
|
||
10 years ago
|
{
|
||
4 years ago
|
esm.writeHNString("DELE", "", 3);
|
||
10 years ago
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
esm.writeHNCString("MODL", mModel);
|
||
|
esm.writeHNOCString("CNAM", mOriginal);
|
||
|
esm.writeHNOCString("FNAM", mName);
|
||
|
esm.writeHNOCString("SCRI", mScript);
|
||
|
esm.writeHNT("NPDT", mData, 96);
|
||
6 years ago
|
esm.writeHNT("FLAG", ((mBloodType << 10) + mFlags));
|
||
10 years ago
|
if (mScale != 1.0) {
|
||
|
esm.writeHNT("XSCL", mScale);
|
||
|
}
|
||
|
|
||
|
mInventory.save(esm);
|
||
|
mSpells.save(esm);
|
||
6 years ago
|
esm.writeHNT("AIDT", mAiData, sizeof(mAiData));
|
||
10 years ago
|
mTransport.save(esm);
|
||
10 years ago
|
mAiPackage.save(esm);
|
||
12 years ago
|
}
|
||
13 years ago
|
|
||
12 years ago
|
void Creature::blank()
|
||
|
{
|
||
|
mData.mType = 0;
|
||
|
mData.mLevel = 0;
|
||
|
mData.mStrength = mData.mIntelligence = mData.mWillpower = mData.mAgility =
|
||
|
mData.mSpeed = mData.mEndurance = mData.mPersonality = mData.mLuck = 0;
|
||
|
mData.mHealth = mData.mMana = mData.mFatigue = 0;
|
||
|
mData.mSoul = 0;
|
||
|
mData.mCombat = mData.mMagic = mData.mStealth = 0;
|
||
|
for (int i=0; i<6; ++i) mData.mAttack[i] = 0;
|
||
|
mData.mGold = 0;
|
||
6 years ago
|
mBloodType = 0;
|
||
12 years ago
|
mFlags = 0;
|
||
9 years ago
|
mScale = 1.f;
|
||
12 years ago
|
mModel.clear();
|
||
|
mName.clear();
|
||
|
mScript.clear();
|
||
|
mOriginal.clear();
|
||
|
mInventory.mList.clear();
|
||
|
mSpells.mList.clear();
|
||
|
mAiData.blank();
|
||
6 years ago
|
mAiData.mFight = 90;
|
||
|
mAiData.mFlee = 20;
|
||
12 years ago
|
mAiPackage.mList.clear();
|
||
10 years ago
|
mTransport.mList.clear();
|
||
|
}
|
||
|
|
||
|
const std::vector<Transport::Dest>& Creature::getTransport() const
|
||
|
{
|
||
|
return mTransport.mList;
|
||
12 years ago
|
}
|
||
14 years ago
|
}
|