2011-04-08 17:58:21 +04:00
|
|
|
#include "loaddial.hpp"
|
|
|
|
|
2014-02-20 16:59:20 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2012-09-23 22:41:41 +04:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2013-09-24 13:17:28 +02:00
|
|
|
#include "defs.hpp"
|
2012-09-17 11:37:50 +04:00
|
|
|
|
2011-04-08 17:58:21 +04:00
|
|
|
namespace ESM
|
|
|
|
{
|
2013-09-24 13:17:28 +02:00
|
|
|
unsigned int Dialogue::sRecordId = REC_DIAL;
|
2011-04-08 17:58:21 +04:00
|
|
|
|
|
|
|
void Dialogue::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
esm.getSubNameIs("DATA");
|
|
|
|
esm.getSubHeader();
|
|
|
|
int si = esm.getSubSize();
|
|
|
|
if (si == 1)
|
2012-09-17 11:37:50 +04:00
|
|
|
esm.getT(mType);
|
2011-04-08 17:58:21 +04:00
|
|
|
else if (si == 4)
|
|
|
|
{
|
|
|
|
// These are just markers, their values are not used.
|
|
|
|
int i;
|
|
|
|
esm.getT(i);
|
|
|
|
esm.getHNT(i, "DELE");
|
2012-09-17 11:37:50 +04:00
|
|
|
mType = Deleted;
|
2011-04-08 17:58:21 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
esm.fail("Unknown sub record size");
|
|
|
|
}
|
|
|
|
|
2013-09-16 12:32:35 +02:00
|
|
|
void Dialogue::save(ESMWriter &esm) const
|
2012-04-06 21:04:30 +02:00
|
|
|
{
|
2012-09-17 11:37:50 +04:00
|
|
|
if (mType != Deleted)
|
|
|
|
esm.writeHNT("DATA", mType);
|
2012-04-06 21:04:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
esm.writeHNT("DATA", (int)1);
|
|
|
|
esm.writeHNT("DELE", (int)1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 17:13:31 +02:00
|
|
|
void Dialogue::blank()
|
|
|
|
{
|
|
|
|
mInfo.clear();
|
|
|
|
}
|
|
|
|
|
2014-02-20 16:59:20 +01:00
|
|
|
void Dialogue::addInfo(const ESM::DialInfo& info, bool merge)
|
|
|
|
{
|
|
|
|
// TODO: use std::move
|
|
|
|
if (!merge || mInfo.empty() || info.mNext.empty())
|
|
|
|
{
|
|
|
|
mInfo.push_back(info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (info.mPrev.empty())
|
|
|
|
{
|
|
|
|
mInfo.push_front(info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int i=0;
|
|
|
|
for (ESM::Dialogue::InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ++it)
|
|
|
|
{
|
|
|
|
if (info.mPrev == it->mId)
|
|
|
|
{
|
|
|
|
mInfo.insert(++it, info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (info.mNext == it->mId)
|
|
|
|
{
|
|
|
|
mInfo.insert(it, info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (info.mId == it->mId)
|
|
|
|
{
|
|
|
|
*it = info;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
std::cerr << "Failed to insert info " << info.mId << std::endl;
|
|
|
|
}
|
|
|
|
|
2011-04-08 17:58:21 +04:00
|
|
|
}
|