1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 06:53:53 +00:00
openmw/components/esm3/loadregn.cpp

117 lines
3.3 KiB
C++
Raw Normal View History

#include "loadregn.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
2012-09-17 07:37:50 +00:00
namespace ESM
{
void Region::load(ESMReader &esm, bool &isDeleted)
{
isDeleted = false;
mRecordFlags = esm.getRecordFlags();
bool hasName = false;
while (esm.hasMoreSubs())
{
esm.getSubName();
switch (esm.retSubName().toInt())
{
case SREC_NAME:
mId = esm.getHString();
hasName = true;
break;
case fourCC("FNAM"):
mName = esm.getHString();
break;
case fourCC("WEAT"):
{
esm.getSubHeader();
// Cold weather not included before 1.3
if (esm.getSubSize() == sizeof(mData))
{
esm.getT(mData);
}
else if (esm.getSubSize() == sizeof(mData) - 2)
{
mData.mSnow = 0;
mData.mBlizzard = 0;
esm.getExact(&mData, sizeof(mData) - 2);
}
else
{
esm.fail("Don't know what to do in this version");
}
break;
}
case fourCC("BNAM"):
mSleepList = esm.getHString();
break;
case fourCC("CNAM"):
esm.getHT(mMapColor);
break;
case fourCC("SNAM"):
2016-05-07 17:32:51 +00:00
{
esm.getSubHeader();
SoundRef sr;
sr.mSound.assign(esm.getString(32));
esm.getT(sr.mChance);
mSoundList.push_back(sr);
break;
2016-05-07 17:32:51 +00:00
}
case SREC_DELE:
esm.skipHSub();
isDeleted = true;
2015-07-26 10:54:36 +00:00
break;
default:
esm.fail("Unknown subrecord");
break;
}
}
if (!hasName)
esm.fail("Missing NAME subrecord");
}
void Region::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNString("DELE", "", 3);
return;
}
esm.writeHNOCString("FNAM", mName);
2013-04-07 14:32:06 +00:00
if (esm.getVersion() == VER_12)
esm.writeHNT("WEAT", mData, sizeof(mData) - 2);
else
esm.writeHNT("WEAT", mData);
2013-04-07 14:32:06 +00:00
esm.writeHNOCString("BNAM", mSleepList);
2013-04-07 14:32:06 +00:00
esm.writeHNT("CNAM", mMapColor);
for (std::vector<SoundRef>::const_iterator it = mSoundList.begin(); it != mSoundList.end(); ++it)
{
esm.startSubRecord("SNAM");
esm.writeFixedSizeString(it->mSound, 32);
esm.writeT(it->mChance);
2022-05-01 13:45:22 +00:00
esm.endRecord("SNAM");
}
}
2013-04-07 14:32:06 +00:00
void Region::blank()
{
2022-05-29 20:12:30 +00:00
mRecordFlags = 0;
2013-04-07 14:32:06 +00:00
mData.mClear = mData.mCloudy = mData.mFoggy = mData.mOvercast = mData.mRain =
mData.mThunder = mData.mAsh = mData.mBlight = mData.mSnow = mData.mBlizzard = 0;
2013-04-07 14:32:06 +00:00
mMapColor = 0;
mName.clear();
mSleepList.clear();
mSoundList.clear();
}
}