diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 1ca452efe..31b8a1515 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -497,9 +497,11 @@ namespace MWWorld // List moved references, from separately tracked list. for (ESM::CellRefTracker::const_iterator it = mCell->mLeasedRefs.begin(); it != mCell->mLeasedRefs.end(); ++it) { - const ESM::CellRef &ref = *it; + const ESM::CellRef &ref = it->first; + bool deleted = it->second; - mIds.push_back(Misc::StringUtils::lowerCase(ref.mRefID)); + if (!deleted) + mIds.push_back(Misc::StringUtils::lowerCase(ref.mRefID)); } std::sort (mIds.begin(), mIds.end()); @@ -549,9 +551,10 @@ namespace MWWorld // Load moved references, from separately tracked list. for (ESM::CellRefTracker::const_iterator it = mCell->mLeasedRefs.begin(); it != mCell->mLeasedRefs.end(); ++it) { - ESM::CellRef &ref = const_cast(*it); + ESM::CellRef &ref = const_cast(it->first); + bool deleted = it->second; - loadRef (ref, false); + loadRef (ref, deleted); } updateMergedRefs(); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 4cddbcdfb..fbe94b7d0 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -513,19 +513,16 @@ namespace MWWorld bool deleted = false; cell->getNextRef(esm, ref, deleted); - if (!deleted) - { - // Add data required to make reference appear in the correct cell. - // We should not need to test for duplicates, as this part of the code is pre-cell merge. - cell->mMovedRefs.push_back(cMRef); - - // But there may be duplicates here! - ESM::CellRefTracker::iterator iter = std::find(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ref.mRefNum); - if (iter == cellAlt->mLeasedRefs.end()) - cellAlt->mLeasedRefs.push_back(ref); - else - *iter = ref; - } + // Add data required to make reference appear in the correct cell. + // We should not need to test for duplicates, as this part of the code is pre-cell merge. + cell->mMovedRefs.push_back(cMRef); + + // But there may be duplicates here! + ESM::CellRefTracker::iterator iter = std::find_if(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(ref.mRefNum)); + if (iter == cellAlt->mLeasedRefs.end()) + cellAlt->mLeasedRefs.push_back(std::make_pair(ref, deleted)); + else + *iter = std::make_pair(ref, deleted); } } const ESM::Cell *Store::search(const std::string &id) const @@ -681,7 +678,7 @@ namespace MWWorld if (itold != oldcell->mMovedRefs.end()) { ESM::MovedCellRef target0 = *itold; ESM::Cell *wipecell = const_cast(search(target0.mTarget[0], target0.mTarget[1])); - ESM::CellRefTracker::iterator it_lease = std::find(wipecell->mLeasedRefs.begin(), wipecell->mLeasedRefs.end(), it->mRefNum); + ESM::CellRefTracker::iterator it_lease = std::find_if(wipecell->mLeasedRefs.begin(), wipecell->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(it->mRefNum)); if (it_lease != wipecell->mLeasedRefs.end()) wipecell->mLeasedRefs.erase(it_lease); else diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 549ed7309..249d812b1 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -43,7 +43,15 @@ bool operator==(const MovedCellRef& ref, const RefNum& refNum); bool operator==(const CellRef& ref, const RefNum& refNum); typedef std::list MovedCellRefTracker; -typedef std::list CellRefTracker; +typedef std::list > CellRefTracker; + +struct CellRefTrackerPredicate +{ + RefNum mRefNum; + + CellRefTrackerPredicate(const RefNum& refNum) : mRefNum(refNum) {} + bool operator() (const std::pair& refdelPair) { return refdelPair.first == mRefNum; } +}; /* Cells hold data about objects, creatures, statics (rocks, walls, buildings) and landscape (for exterior cells). Cells frequently