Make saving of deleted ESM records more consistent

openmw-38
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) void ESM::CellRef::load (ESMReader& esm, bool &isDeleted, bool wideRefNum)
{ {
loadId(esm, wideRefNum); loadId(esm, wideRefNum);
@ -67,6 +40,8 @@ void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum)
if (esm.isNextSub ("NAM0")) if (esm.isNextSub ("NAM0"))
esm.skipHSub(); esm.skipHSub();
blank();
mRefNum.load (esm, wideRefNum); mRefNum.load (esm, wideRefNum);
mRefID = esm.getHNString ("NAME"); mRefID = esm.getHNString ("NAME");
@ -76,8 +51,6 @@ void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted)
{ {
isDeleted = false; isDeleted = false;
clearData();
bool isLoaded = false; bool isLoaded = false;
while (!isLoaded && esm.hasMoreSubs()) while (!isLoaded && esm.hasMoreSubs())
{ {
@ -154,6 +127,11 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool
esm.writeHNCString("NAME", mRefID); esm.writeHNCString("NAME", mRefID);
if (isDeleted) {
esm.writeHNCString("DELE", "");
return;
}
if (mScale != 1.0) { if (mScale != 1.0) {
esm.writeHNT("XSCL", mScale); esm.writeHNT("XSCL", mScale);
} }
@ -198,18 +176,35 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool
if (!inInventory) if (!inInventory)
esm.writeHNT("DATA", mPos, 24); esm.writeHNT("DATA", mPos, 24);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
}
} }
void ESM::CellRef::blank() void ESM::CellRef::blank()
{ {
mRefNum.unset(); mRefNum.unset();
mRefID.clear(); mRefID.clear();
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;
}
} }
bool ESM::operator== (const RefNum& left, const RefNum& right) bool ESM::operator== (const RefNum& left, const RefNum& right)

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save