diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index c4269670b2..f75a11d51c 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -256,13 +256,20 @@ void CSMDoc::CollectionReferencesStage::perform(int stage, Messages& messages) if (record.isModified() || record.mState == CSMWorld::RecordBase::State_Deleted) { - const ESM::RefId cellId - = record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell; + ESM::RefId cellId = record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell; std::deque& indices = mState.getOrInsertSubRecord(cellId); // collect moved references at the end of the container - const bool interior = !cellId.is(); + + const bool interior = !cellId.startsWith("#"); + std::ostringstream stream; + if (!interior) + { + // recalculate the ref's cell location + std::pair index = record.get().getCellIndex(); + cellId = ESM::RefId::stringRefId(ESM::RefId::esm3ExteriorCell(index.first, index.second).toString()); + } // An empty mOriginalCell is meant to indicate that it is the same as // the current cell. It is possible that a moved ref is moved again. @@ -351,7 +358,7 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages) std::deque tempRefs; std::deque persistentRefs; - const std::deque* references = mState.findSubRecord(static_cast(cell.get()).mId); + const std::deque* references = mState.findSubRecord(cell.get().mId); if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted || references != nullptr) { diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 125a684f86..1afa9027a9 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -73,7 +73,7 @@ void CSMWorld::RefCollection::load(ESM::ESMReader& reader, int cellIndex, bool b // Autocalculate the cell index from coordinates first std::pair index = ref.getCellIndex(); - ref.mCell = ESM::RefId::esm3ExteriorCell(index.first, index.second); + ref.mCell = ESM::RefId::stringRefId(ESM::RefId::esm3ExteriorCell(index.first, index.second).toString()); // Handle non-base moved references if (!base && isMoved) @@ -89,7 +89,8 @@ void CSMWorld::RefCollection::load(ESM::ESMReader& reader, int cellIndex, bool b if (index.first != mref.mTarget[0] || index.second != mref.mTarget[1]) { ESM::RefId indexCell = ref.mCell; - ref.mCell = ESM::RefId::esm3ExteriorCell(mref.mTarget[0], mref.mTarget[1]); + ref.mCell = ESM::RefId::stringRefId( + ESM::RefId::esm3ExteriorCell(mref.mTarget[0], mref.mTarget[1]).toString()); CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Cell, mCells.getId(cellIndex)); messages.add(id, "The position of the moved reference " + ref.mRefID.toDebugString() + " (cell " + indexCell.toDebugString() + ")"