fixed ref num saving in non-wide format

moveref
Marc Zinnschlag 10 years ago
parent 764c155cec
commit a97f599e65

@ -231,8 +231,18 @@ void CSMDoc::CollectionReferencesStage::perform (int stage, Messages& messages)
record.mState==CSMWorld::RecordBase::State_Modified || record.mState==CSMWorld::RecordBase::State_Modified ||
record.mState==CSMWorld::RecordBase::State_ModifiedOnly) record.mState==CSMWorld::RecordBase::State_ModifiedOnly)
{ {
mState.getSubRecords()[Misc::StringUtils::lowerCase (record.get().mCell)] std::string cellId = record.get().mOriginalCell.empty() ?
.push_back (i); record.get().mCell : record.get().mOriginalCell;
std::deque<int>& indices =
mState.getSubRecords()[Misc::StringUtils::lowerCase (cellId)];
// collect moved references at the end of the container
if (!record.get().mOriginalCell.empty() &&
record.get().mOriginalCell!=record.get().mCell)
indices.push_back (i);
else
indices.push_front (i);
} }
} }
} }
@ -253,7 +263,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
const CSMWorld::Record<CSMWorld::Cell>& cell = const CSMWorld::Record<CSMWorld::Cell>& cell =
mDocument.getData().getCells().getRecord (stage); mDocument.getData().getCells().getRecord (stage);
std::map<std::string, std::vector<int> >::const_iterator references = std::map<std::string, std::deque<int> >::const_iterator references =
mState.getSubRecords().find (Misc::StringUtils::lowerCase (cell.get().mId)); mState.getSubRecords().find (Misc::StringUtils::lowerCase (cell.get().mId));
if (cell.mState==CSMWorld::RecordBase::State_Modified || if (cell.mState==CSMWorld::RecordBase::State_Modified ||
@ -284,7 +294,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
// write references // write references
if (references!=mState.getSubRecords().end()) if (references!=mState.getSubRecords().end())
{ {
for (std::vector<int>::const_iterator iter (references->second.begin()); for (std::deque<int>::const_iterator iter (references->second.begin());
iter!=references->second.end(); ++iter) iter!=references->second.end(); ++iter)
{ {
const CSMWorld::Record<CSMWorld::CellRef>& ref = const CSMWorld::Record<CSMWorld::CellRef>& ref =
@ -293,6 +303,24 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
if (ref.mState==CSMWorld::RecordBase::State_Modified || if (ref.mState==CSMWorld::RecordBase::State_Modified ||
ref.mState==CSMWorld::RecordBase::State_ModifiedOnly) ref.mState==CSMWorld::RecordBase::State_ModifiedOnly)
{ {
if (!ref.get().mOriginalCell.empty() &&
ref.get().mOriginalCell!=ref.get().mCell)
{
ESM::MovedCellRef moved;
moved.mRefNum = ref.get().mRefNum;
std::istringstream stream (ref.get().mCell.c_str());
char ignore;
stream >> ignore >> moved.mTarget[0] >> moved.mTarget[1];
mState.getWriter().startSubRecord ("MVRF");
mState.getWriter().endRecord ("MVRF");
mState.getWriter().writeHNT ("FRMR", moved.mRefNum.mIndex, 4);
mState.getWriter().writeHNT ("CNDT", moved.mTarget, 8);
}
ref.get().save (mState.getWriter()); ref.get().save (mState.getWriter());
} }
else if (ref.mState==CSMWorld::RecordBase::State_Deleted) else if (ref.mState==CSMWorld::RecordBase::State_Deleted)

@ -64,7 +64,7 @@ bool CSMDoc::SavingState::isProjectFile() const
return mProjectFile; return mProjectFile;
} }
std::map<std::string, std::vector<int> >& CSMDoc::SavingState::getSubRecords() std::map<std::string, std::deque<int> >& CSMDoc::SavingState::getSubRecords()
{ {
return mSubRecords; return mSubRecords;
} }

@ -3,6 +3,7 @@
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <deque>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -26,7 +27,7 @@ namespace CSMDoc
ESM::ESMWriter mWriter; ESM::ESMWriter mWriter;
boost::filesystem::path mProjectPath; boost::filesystem::path mProjectPath;
bool mProjectFile; bool mProjectFile;
std::map<std::string, std::vector<int> > mSubRecords; // record ID, list of subrecords std::map<std::string, std::deque<int> > mSubRecords; // record ID, list of subrecords
public: public:
@ -49,7 +50,7 @@ namespace CSMDoc
bool isProjectFile() const; bool isProjectFile() const;
///< Currently saving project file? (instead of content file) ///< Currently saving project file? (instead of content file)
std::map<std::string, std::vector<int> >& getSubRecords(); std::map<std::string, std::deque<int> >& getSubRecords();
}; };

@ -17,7 +17,11 @@ void ESM::RefNum::save (ESMWriter &esm, bool wide) const
if (wide) if (wide)
esm.writeHNT ("FRMR", *this, 8); esm.writeHNT ("FRMR", *this, 8);
else else
esm.writeHNT ("FRMR", mIndex, 4); {
int refNum = (mIndex & 0xffffff) | ((mContentFile==-1 ? 0xff : mContentFile)<<24);
esm.writeHNT ("FRMR", refNum, 4);
}
} }

Loading…
Cancel
Save