2011-04-08 13:58:21 +00:00
|
|
|
#include "loaddial.hpp"
|
|
|
|
|
2014-02-20 15:59:20 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2013-09-24 11:17:28 +00:00
|
|
|
#include "defs.hpp"
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2013-09-24 11:17:28 +00:00
|
|
|
unsigned int Dialogue::sRecordId = REC_DIAL;
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
void Dialogue::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
esm.getSubNameIs("DATA");
|
|
|
|
esm.getSubHeader();
|
|
|
|
int si = esm.getSubSize();
|
|
|
|
if (si == 1)
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getT(mType);
|
2011-04-08 13:58:21 +00: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 07:37:50 +00:00
|
|
|
mType = Deleted;
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
esm.fail("Unknown sub record size");
|
|
|
|
}
|
|
|
|
|
2013-09-16 10:32:35 +00:00
|
|
|
void Dialogue::save(ESMWriter &esm) const
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
if (mType != Deleted)
|
|
|
|
esm.writeHNT("DATA", mType);
|
2012-04-06 19:04:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
esm.writeHNT("DATA", (int)1);
|
|
|
|
esm.writeHNT("DELE", (int)1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 22:36:37 +00:00
|
|
|
void Dialogue::blank()
|
|
|
|
{
|
|
|
|
mInfo.clear();
|
|
|
|
}
|
2013-10-20 15:13:31 +00:00
|
|
|
|
2014-05-30 22:36:37 +00:00
|
|
|
void Dialogue::readInfo(ESMReader &esm, bool merge)
|
2014-02-20 15:59:20 +00:00
|
|
|
{
|
2014-05-30 22:36:37 +00:00
|
|
|
const std::string& id = esm.getHNOString("INAM");
|
|
|
|
|
|
|
|
if (!merge || mInfo.empty())
|
2014-02-20 15:59:20 +00:00
|
|
|
{
|
2014-05-30 22:36:37 +00:00
|
|
|
ESM::DialInfo info;
|
|
|
|
info.mId = id;
|
|
|
|
info.load(esm);
|
|
|
|
mLookup[id] = mInfo.insert(mInfo.end(), info);
|
2014-02-20 15:59:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-05-18 13:59:45 +00:00
|
|
|
|
|
|
|
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
|
|
|
|
|
|
|
|
std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
|
2014-05-18 16:58:32 +00:00
|
|
|
|
2014-05-30 22:36:37 +00:00
|
|
|
lookup = mLookup.find(id);
|
2014-11-30 21:02:25 +00:00
|
|
|
|
|
|
|
ESM::DialInfo info;
|
2014-05-18 13:59:45 +00:00
|
|
|
if (lookup != mLookup.end())
|
|
|
|
{
|
|
|
|
it = lookup->second;
|
2014-05-30 22:36:37 +00:00
|
|
|
|
|
|
|
// Merge with existing record. Only the subrecords that are present in
|
|
|
|
// the new record will be overwritten.
|
|
|
|
it->load(esm);
|
2014-11-30 21:02:25 +00:00
|
|
|
info = *it;
|
2014-05-30 22:36:37 +00:00
|
|
|
|
2014-11-30 21:02:25 +00:00
|
|
|
// Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record
|
|
|
|
mInfo.erase(it);
|
|
|
|
mLookup.erase(lookup);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info.mId = id;
|
|
|
|
info.load(esm);
|
|
|
|
}
|
2014-05-30 22:36:37 +00:00
|
|
|
|
|
|
|
if (info.mNext.empty())
|
|
|
|
{
|
|
|
|
mLookup[id] = mInfo.insert(mInfo.end(), info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (info.mPrev.empty())
|
|
|
|
{
|
|
|
|
mLookup[id] = mInfo.insert(mInfo.begin(), info);
|
2014-05-18 13:59:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-18 16:58:32 +00:00
|
|
|
lookup = mLookup.find(info.mPrev);
|
2014-05-18 13:59:45 +00:00
|
|
|
if (lookup != mLookup.end())
|
2014-02-20 15:59:20 +00:00
|
|
|
{
|
2014-05-18 13:59:45 +00:00
|
|
|
it = lookup->second;
|
|
|
|
|
2014-05-30 22:36:37 +00:00
|
|
|
mLookup[id] = mInfo.insert(++it, info);
|
2014-05-18 13:59:45 +00:00
|
|
|
return;
|
2014-02-20 15:59:20 +00:00
|
|
|
}
|
2014-05-18 13:59:45 +00:00
|
|
|
|
2014-05-18 16:58:32 +00:00
|
|
|
lookup = mLookup.find(info.mNext);
|
2014-05-18 13:59:45 +00:00
|
|
|
if (lookup != mLookup.end())
|
|
|
|
{
|
|
|
|
it = lookup->second;
|
2014-05-18 16:58:32 +00:00
|
|
|
|
2014-05-30 22:36:37 +00:00
|
|
|
mLookup[id] = mInfo.insert(it, info);
|
2014-05-18 13:59:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-30 22:36:37 +00:00
|
|
|
std::cerr << "Failed to insert info " << id << std::endl;
|
2014-02-20 15:59:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 15:45:18 +00:00
|
|
|
void Dialogue::clearDeletedInfos()
|
|
|
|
{
|
|
|
|
for (InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); )
|
|
|
|
{
|
|
|
|
if (it->mQuestStatus == DialInfo::QS_Deleted)
|
|
|
|
it = mInfo.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|