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)
|
|
|
|
{
|
|
|
|
if (!merge || mInfo.empty() || info.mNext.empty())
|
|
|
|
{
|
2014-05-18 15:59:45 +02:00
|
|
|
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
|
2014-02-20 16:59:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (info.mPrev.empty())
|
|
|
|
{
|
2014-05-18 15:59:45 +02:00
|
|
|
mLookup[info.mId] = mInfo.insert(mInfo.begin(), info);
|
2014-02-20 16:59:20 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-18 15:59:45 +02:00
|
|
|
|
|
|
|
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
|
|
|
|
|
|
|
|
std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
|
2014-05-18 18:58:32 +02:00
|
|
|
|
|
|
|
lookup = mLookup.find(info.mId);
|
2014-05-18 15:59:45 +02:00
|
|
|
if (lookup != mLookup.end())
|
|
|
|
{
|
|
|
|
it = lookup->second;
|
2014-05-18 18:58:32 +02:00
|
|
|
*it = info;
|
2014-05-18 15:59:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-18 18:58:32 +02:00
|
|
|
lookup = mLookup.find(info.mPrev);
|
2014-05-18 15:59:45 +02:00
|
|
|
if (lookup != mLookup.end())
|
2014-02-20 16:59:20 +01:00
|
|
|
{
|
2014-05-18 15:59:45 +02:00
|
|
|
it = lookup->second;
|
|
|
|
|
2014-05-18 18:58:32 +02:00
|
|
|
mLookup[info.mId] = mInfo.insert(++it, info);
|
2014-05-18 15:59:45 +02:00
|
|
|
return;
|
2014-02-20 16:59:20 +01:00
|
|
|
}
|
2014-05-18 15:59:45 +02:00
|
|
|
|
2014-05-18 18:58:32 +02:00
|
|
|
lookup = mLookup.find(info.mNext);
|
2014-05-18 15:59:45 +02:00
|
|
|
if (lookup != mLookup.end())
|
|
|
|
{
|
|
|
|
it = lookup->second;
|
2014-05-18 18:58:32 +02:00
|
|
|
|
|
|
|
mLookup[info.mId] = mInfo.insert(it, info);
|
2014-05-18 15:59:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-20 16:59:20 +01:00
|
|
|
std::cerr << "Failed to insert info " << info.mId << std::endl;
|
|
|
|
}
|
|
|
|
|
2011-04-08 17:58:21 +04:00
|
|
|
}
|