1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 04:45:33 +00:00

Move ID loading into a separate method for Dialogue and DialInfo records

(cherry picked from commit c8c79dc1ef)

Conflicts:
	apps/openmw/mwworld/store.cpp
This commit is contained in:
Stanislav Bas 2015-07-13 10:53:31 +03:00 committed by cc9cii
parent d518d70212
commit 72152d84ed
4 changed files with 47 additions and 18 deletions

View file

@ -19,9 +19,18 @@ namespace ESM
void Dialogue::load(ESMReader &esm)
{
mIsDeleted = false;
loadId(esm);
loadData(esm);
}
void Dialogue::loadId(ESMReader &esm)
{
mIsDeleted = false;
mId = esm.getHNString("NAME");
}
void Dialogue::loadData(ESMReader &esm)
{
esm.getSubNameIs("DATA");
esm.getSubHeader();
int si = esm.getSubSize();
@ -60,31 +69,28 @@ namespace ESM
void Dialogue::readInfo(ESMReader &esm, bool merge)
{
const std::string& id = esm.getHNOString("INAM");
ESM::DialInfo info;
info.loadId(esm);
if (!merge || mInfo.empty())
{
ESM::DialInfo info;
info.mId = id;
info.load(esm);
mLookup[id] = mInfo.insert(mInfo.end(), info);
info.loadInfo(esm);
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
return;
}
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
lookup = mLookup.find(info.mId);
lookup = mLookup.find(id);
ESM::DialInfo info;
if (lookup != mLookup.end())
{
it = lookup->second;
// Merge with existing record. Only the subrecords that are present in
// the new record will be overwritten.
it->load(esm);
it->loadInfo(esm);
info = *it;
// Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record
@ -93,18 +99,17 @@ namespace ESM
}
else
{
info.mId = id;
info.load(esm);
info.loadInfo(esm);
}
if (info.mNext.empty())
{
mLookup[id] = mInfo.insert(mInfo.end(), info);
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
return;
}
if (info.mPrev.empty())
{
mLookup[id] = mInfo.insert(mInfo.begin(), info);
mLookup[info.mId] = mInfo.insert(mInfo.begin(), info);
return;
}
@ -113,7 +118,7 @@ namespace ESM
{
it = lookup->second;
mLookup[id] = mInfo.insert(++it, info);
mLookup[info.mId] = mInfo.insert(++it, info);
return;
}
@ -122,11 +127,11 @@ namespace ESM
{
it = lookup->second;
mLookup[id] = mInfo.insert(it, info);
mLookup[info.mId] = mInfo.insert(it, info);
return;
}
std::cerr << "Failed to insert info " << id << std::endl;
std::cerr << "Failed to insert info " << info.mId << std::endl;
}
void Dialogue::clearDeletedInfos()

View file

@ -51,6 +51,12 @@ struct Dialogue
Dialogue();
void load(ESMReader &esm);
///< Loads all sub-records of Dialogue record
void loadId(ESMReader &esm);
///< Loads NAME sub-record of Dialogue record
void loadData(ESMReader &esm);
///< Loads all sub-records of Dialogue record, except NAME sub-record
void save(ESMWriter &esm) const;
/// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos.

View file

@ -14,10 +14,21 @@ namespace ESM
{}
void DialInfo::load(ESMReader &esm)
{
loadId(esm);
loadInfo(esm);
}
void DialInfo::loadId(ESMReader &esm)
{
mIsDeleted = false;
mId = esm.getHNString("INAM");
}
void DialInfo::loadInfo(ESMReader &esm)
{
mQuestStatus = QS_None;
mFactionLess = false;
mIsDeleted = false;
mPrev = esm.getHNString("PNAM");
mNext = esm.getHNString("NNAM");
@ -141,6 +152,7 @@ namespace ESM
void DialInfo::save(ESMWriter &esm) const
{
esm.writeHNCString("INAM", mId);
esm.writeHNCString("PNAM", mPrev);
esm.writeHNCString("NNAM", mNext);

View file

@ -111,6 +111,12 @@ struct DialInfo
DialInfo();
void load(ESMReader &esm);
///< Loads all sub-records of Info record
void loadId(ESMReader &esm);
///< Loads only Id of Info record (INAM sub-record)
void loadInfo(ESMReader &esm);
///< Loads all sub-records of Info record, except INAM sub-record
void save(ESMWriter &esm) const;
void blank();