1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 21:40:03 +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 11:37:50 +04: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 20:32:51 +03:00
{
esm.getSubHeader();
SoundRef sr;
sr.mSound.assign(esm.getString(32));
esm.getT(sr.mChance);
mSoundList.push_back(sr);
break;
2016-05-07 20:32:51 +03:00
}
case SREC_DELE:
esm.skipHSub();
isDeleted = true;
2015-07-26 13:54:36 +03: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 16:32:06 +02:00
if (esm.getVersion() == VER_12)
esm.writeHNT("WEAT", mData, sizeof(mData) - 2);
else
esm.writeHNT("WEAT", mData);
2013-04-07 16:32:06 +02:00
esm.writeHNOCString("BNAM", mSleepList);
2013-04-07 16:32:06 +02: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 15:45:22 +02:00
esm.endRecord("SNAM");
}
}
2013-04-07 16:32:06 +02:00
void Region::blank()
{
2022-05-29 22:12:30 +02:00
mRecordFlags = 0;
2013-04-07 16:32:06 +02: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 16:32:06 +02:00
mMapColor = 0;
mName.clear();
mSleepList.clear();
mSoundList.clear();
}
}