|
|
|
@ -3,12 +3,15 @@
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
|
|
|
|
|
#include "ref.hpp"
|
|
|
|
|
#include "cell.hpp"
|
|
|
|
|
#include "universalid.hpp"
|
|
|
|
|
#include "record.hpp"
|
|
|
|
|
|
|
|
|
|
void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base)
|
|
|
|
|
void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base,
|
|
|
|
|
std::map<ESM::CellRef::RefNum, std::string>& cache)
|
|
|
|
|
{
|
|
|
|
|
Record<Cell> cell = mCells.getRecord (cellIndex);
|
|
|
|
|
|
|
|
|
@ -17,19 +20,48 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
|
|
|
|
CellRef ref;
|
|
|
|
|
|
|
|
|
|
bool deleted = false;
|
|
|
|
|
while (cell2.getNextRef (reader, ref, deleted))
|
|
|
|
|
|
|
|
|
|
while (ESM::Cell::getNextRef (reader, ref, deleted))
|
|
|
|
|
{
|
|
|
|
|
/// \todo handle deleted and moved references
|
|
|
|
|
ref.load (reader, cell2, getNewId());
|
|
|
|
|
ref.mCell = cell2.mId;
|
|
|
|
|
|
|
|
|
|
Record<CellRef> record2;
|
|
|
|
|
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
|
|
|
|
(base ? record2.mBase : record2.mModified) = ref;
|
|
|
|
|
/// \todo handle moved references
|
|
|
|
|
|
|
|
|
|
appendRecord (record2);
|
|
|
|
|
}
|
|
|
|
|
if (deleted)
|
|
|
|
|
{
|
|
|
|
|
/// \todo handle deleted references
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::map<ESM::CellRef::RefNum, std::string>::iterator iter = cache.find (ref.mRefNum);
|
|
|
|
|
|
|
|
|
|
if (iter==cache.end())
|
|
|
|
|
{
|
|
|
|
|
// new reference
|
|
|
|
|
ref.mId = getNewId();
|
|
|
|
|
|
|
|
|
|
Record<CellRef> record;
|
|
|
|
|
record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
|
|
|
|
(base ? record.mBase : record.mModified) = ref;
|
|
|
|
|
|
|
|
|
|
mCells.setRecord (cellIndex, cell);
|
|
|
|
|
appendRecord (record);
|
|
|
|
|
|
|
|
|
|
cache.insert (std::make_pair (ref.mRefNum, ref.mId));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// old reference -> merge
|
|
|
|
|
ref.mId = iter->second;
|
|
|
|
|
|
|
|
|
|
int index = getIndex (ref.mId);
|
|
|
|
|
|
|
|
|
|
Record<CellRef> record = getRecord (index);
|
|
|
|
|
record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
|
|
|
|
|
(base ? record.mBase : record.mModified) = ref;
|
|
|
|
|
|
|
|
|
|
setRecord (index, record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string CSMWorld::RefCollection::getNewId()
|
|
|
|
|