Make saving of deleted ESM records more consistent

pull/678/head
Stanislav Bas 10 years ago
parent 9a8ca81907
commit f9b0b7ede5

@ -25,33 +25,6 @@ void ESM::RefNum::save (ESMWriter &esm, bool wide, const std::string& tag) const
}
void ESM::CellRef::clearData()
{
mScale = 1;
mOwner.clear();
mGlobalVariable.clear();
mSoul.clear();
mFaction.clear();
mFactionRank = -2;
mChargeInt = -1;
mEnchantmentCharge = -1;
mGoldValue = 0;
mDestCell.clear();
mLockLevel = 0;
mKey.clear();
mTrap.clear();
mReferenceBlocked = -1;
mTeleport = false;
for (int i=0; i<3; ++i)
{
mDoorDest.pos[i] = 0;
mDoorDest.rot[i] = 0;
mPos.pos[i] = 0;
mPos.rot[i] = 0;
}
}
void ESM::CellRef::load (ESMReader& esm, bool &isDeleted, bool wideRefNum)
{
loadId(esm, wideRefNum);
@ -67,6 +40,8 @@ void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum)
if (esm.isNextSub ("NAM0"))
esm.skipHSub();
blank();
mRefNum.load (esm, wideRefNum);
mRefID = esm.getHNString ("NAME");
@ -76,8 +51,6 @@ void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted)
{
isDeleted = false;
clearData();
bool isLoaded = false;
while (!isLoaded && esm.hasMoreSubs())
{
@ -154,6 +127,11 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool
esm.writeHNCString("NAME", mRefID);
if (isDeleted) {
esm.writeHNCString("DELE", "");
return;
}
if (mScale != 1.0) {
esm.writeHNT("XSCL", mScale);
}
@ -198,18 +176,35 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool
if (!inInventory)
esm.writeHNT("DATA", mPos, 24);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
}
}
void ESM::CellRef::blank()
{
mRefNum.unset();
mRefID.clear();
clearData();
mRefID.clear();
mScale = 1;
mOwner.clear();
mGlobalVariable.clear();
mSoul.clear();
mFaction.clear();
mFactionRank = -2;
mChargeInt = -1;
mEnchantmentCharge = -1;
mGoldValue = 0;
mDestCell.clear();
mLockLevel = 0;
mKey.clear();
mTrap.clear();
mReferenceBlocked = -1;
mTeleport = false;
for (int i=0; i<3; ++i)
{
mDoorDest.pos[i] = 0;
mDoorDest.rot[i] = 0;
mPos.pos[i] = 0;
mPos.rot[i] = 0;
}
}
bool ESM::operator== (const RefNum& left, const RefNum& right)

@ -33,10 +33,7 @@ namespace ESM
class CellRef
{
void clearData();
public:
// Reference number
// Note: Currently unused for items in containers
RefNum mRefNum;

@ -52,12 +52,13 @@ namespace ESM
void BirthSign::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
esm.writeHNCString("NAME", mId);
esm.writeHNOCString("FNAM", mName);
esm.writeHNOCString("TNAM", mTexture);
esm.writeHNOCString("DESC", mDescription);

@ -62,7 +62,8 @@ namespace ESM
{
isDeleted = false;
bool hasName = false;
blank();
bool hasData = false;
bool isLoaded = false;
while (!isLoaded && esm.hasMoreSubs())
@ -72,7 +73,6 @@ namespace ESM
{
case ESM::FourCC<'N','A','M','E'>::value:
mName = esm.getHString();
hasName = true;
break;
case ESM::FourCC<'D','A','T','A'>::value:
esm.getHT(mData, 12);
@ -89,20 +89,12 @@ namespace ESM
}
}
if (!hasName)
esm.fail("Missing NAME subrecord");
if (!hasData)
esm.fail("Missing DATA subrecord");
}
void Cell::loadCell(ESMReader &esm, bool saveContext)
{
mWater = 0.0f;
mWaterInt = false;
mMapColor = 0;
mRegion.clear();
mRefNumCounter = 0;
bool isLoaded = false;
while (!isLoaded && esm.hasMoreSubs())
{
@ -117,6 +109,7 @@ namespace ESM
break;
case ESM::FourCC<'W','H','G','T'>::value:
esm.getHT(mWater);
mWaterInt = false;
break;
case ESM::FourCC<'A','M','B','I'>::value:
esm.getHT(mAmbi);
@ -153,14 +146,15 @@ namespace ESM
void Cell::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mName);
esm.writeHNOCString("NAME", mName);
esm.writeHNT("DATA", mData, 12);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
esm.writeHNT("DATA", mData, 12);
if (mData.mFlags & Interior)
{
if (mWaterInt) {

@ -167,6 +167,7 @@ namespace ESM
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
if (mLandData)

@ -47,14 +47,14 @@ namespace ESM
}
void LandTexture::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
esm.writeHNT("INTV", mIndex);
esm.writeHNCString("DATA", mTexture);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
}
esm.writeHNCString("NAME", mId);
esm.writeHNT("INTV", mIndex);
esm.writeHNCString("DATA", mTexture);
}
void LandTexture::blank()

@ -43,20 +43,18 @@ namespace ESM
int edgeCount = 0;
bool hasData = false;
bool hasName = false;
while (esm.hasMoreSubs())
{
esm.getSubName();
switch (esm.retSubName().val)
{
case ESM::FourCC<'N','A','M','E'>::value:
mCell = esm.getHString();
break;
case ESM::FourCC<'D','A','T','A'>::value:
esm.getHT(mData, 12);
hasData = true;
break;
case ESM::FourCC<'N','A','M','E'>::value:
mCell = esm.getHString();
hasName = true;
break;
case ESM::FourCC<'P','G','R','P'>::value:
{
esm.getSubHeader();
@ -125,14 +123,12 @@ namespace ESM
if (!hasData)
esm.fail("Missing DATA subrecord");
if (!hasName)
esm.fail("Missing NAME subrecord");
}
void Pathgrid::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNT("DATA", mData, 12);
esm.writeHNCString("NAME", mCell);
esm.writeHNT("DATA", mData, 12);
if (isDeleted)
{

@ -81,12 +81,14 @@ namespace ESM
void Region::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
esm.writeHNString("NAME", mId);
esm.writeHNOCString("FNAM", mName);
if (esm.getVersion() == VER_12)

@ -120,6 +120,7 @@ namespace ESM
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
if (!mVarNames.empty())

@ -51,14 +51,17 @@ namespace ESM
void SoundGenerator::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
esm.writeHNT("DATA", mType, 4);
esm.writeHNOCString("CNAM", mCreature);
esm.writeHNOCString("SNAM", mSound);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
esm.writeHNT("DATA", mType, 4);
esm.writeHNOCString("CNAM", mCreature);
esm.writeHNOCString("SNAM", mSound);
}
void SoundGenerator::blank()

@ -19,14 +19,14 @@ namespace ESM
esm.getSubName();
switch (esm.retSubName().val)
{
case ESM::FourCC<'D','A','T','A'>::value:
mData = esm.getHString();
hasData = true;
break;
case ESM::FourCC<'N','A','M','E'>::value:
mId = esm.getHString();
hasName = true;
break;
case ESM::FourCC<'D','A','T','A'>::value:
mData = esm.getHString();
hasData = true;
break;
case ESM::FourCC<'D','E','L','E'>::value:
esm.skipHSub();
isDeleted = true;
@ -37,20 +37,22 @@ namespace ESM
}
}
if (!hasData)
esm.fail("Missing DATA");
if (!hasName)
esm.fail("Missing NAME");
if (!hasData && !isDeleted)
esm.fail("Missing DATA");
}
void StartScript::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNString("DATA", mData);
esm.writeHNString("NAME", mId);
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
}
else
{
esm.writeHNString("DATA", mData);
}
}
void StartScript::blank()

Loading…
Cancel
Save