diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index c8c42d17d..8f55bb466 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -1027,19 +1027,19 @@ namespace MWWorld inline RecordId Store::load(ESM::ESMReader &esm) { // The original letter case of a dialogue ID is saved, because it's printed ESM::Dialogue dialogue; - dialogue.load(esm); + dialogue.loadId(esm); std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId); std::map::iterator found = mStatic.find(idLower); if (found == mStatic.end()) { + dialogue.loadData(esm); mStatic.insert(std::make_pair(idLower, dialogue)); } else { - // Update only read fields (don't touching the Info list) - found->second.mIsDeleted = dialogue.mIsDeleted; - found->second.mType = dialogue.mType; + found->second.loadData(esm); + dialogue = found->second; } return RecordId(dialogue.mId, dialogue.mIsDeleted); diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index dfac0ce63..fcdb57c8d 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -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::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() diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index e80a7b0b2..73bf16974 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -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. diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index c1b12e24c..8f5f0f28b 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -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); diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index fbb7e36a5..c243cd50e 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -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();