mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 21:45:32 +00:00
handle moved references on load
This commit is contained in:
parent
ba7b74217b
commit
e32402a040
3 changed files with 27 additions and 2 deletions
|
@ -1,8 +1,18 @@
|
|||
|
||||
#include "ref.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
CSMWorld::CellRef::CellRef()
|
||||
{
|
||||
mRefNum.mIndex = 0;
|
||||
mRefNum.mContentFile = 0;
|
||||
}
|
||||
|
||||
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
|
||||
{
|
||||
const int cellSize = 8192;
|
||||
|
||||
return std::make_pair (
|
||||
std::floor (mPos.pos[0]/cellSize), std::floor (mPos.pos[1]/cellSize));
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef CSM_WOLRD_REF_H
|
||||
#define CSM_WOLRD_REF_H
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <components/esm/cellref.hpp>
|
||||
|
||||
namespace CSMWorld
|
||||
|
@ -15,6 +17,9 @@ namespace CSMWorld
|
|||
std::string mOriginalCell;
|
||||
|
||||
CellRef();
|
||||
|
||||
/// Calculate cell index based on coordinates (x and y)
|
||||
std::pair<int, int> getCellIndex() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,19 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
|||
while (ESM::Cell::getNextRef (reader, ref, deleted))
|
||||
{
|
||||
ref.mOriginalCell = cell2.mId;
|
||||
ref.mCell = cell2.mId;
|
||||
|
||||
/// \todo handle moved references
|
||||
if (cell.get().isExterior())
|
||||
{
|
||||
// ignoring moved references sub-record; instead calculate cell from coordinates
|
||||
std::pair<int, int> index = ref.getCellIndex();
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << "#" << index.first << " " << index.second;
|
||||
|
||||
ref.mCell = stream.str();
|
||||
}
|
||||
else
|
||||
ref.mCell = cell2.mId;
|
||||
|
||||
std::map<ESM::RefNum, std::string>::iterator iter = cache.find (ref.mRefNum);
|
||||
|
||||
|
|
Loading…
Reference in a new issue