Issue #28: implemented access to references outside of the active cells

actorid
Marc Zinnschlag 13 years ago
parent f0dd38b431
commit af4f48fd3f

@ -1,5 +1,34 @@
#include "cells.hpp"
MWWorld::Ptr::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell)
{
if (cell->data.flags & ESM::Cell::Interior)
{
std::map<std::string, Ptr::CellStore>::iterator result = mInteriors.find (cell->name);
if (result==mInteriors.end())
{
result = mInteriors.insert (std::make_pair (cell->name, Ptr::CellStore (cell))).first;
}
return &result->second;
}
else
{
std::map<std::pair<int, int>, Ptr::CellStore>::iterator result =
mExteriors.find (std::make_pair (cell->data.gridX, cell->data.gridY));
if (result==mExteriors.end())
{
result = mExteriors.insert (std::make_pair (
std::make_pair (cell->data.gridX, cell->data.gridY), Ptr::CellStore (cell))).first;
}
return &result->second;
}
}
MWWorld::Cells::Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader)
: mStore (store), mReader (reader) {}
@ -103,3 +132,49 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& ce
return Ptr();
}
MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name)
{
// First check cells that are already listed
for (std::map<std::string, Ptr::CellStore>::iterator iter = mInteriors.begin();
iter!=mInteriors.end(); ++iter)
{
Ptr ptr = getPtr (name, iter->second);
if (!ptr.isEmpty())
return ptr;
}
for (std::map<std::pair<int, int>, Ptr::CellStore>::iterator iter = mExteriors.begin();
iter!=mExteriors.end(); ++iter)
{
Ptr ptr = getPtr (name, iter->second);
if (!ptr.isEmpty())
return ptr;
}
// Now try the other cells
for (ESMS::CellList::IntCells::const_iterator iter = mStore.cells.intCells.begin();
iter!=mStore.cells.intCells.end(); ++iter)
{
Ptr::CellStore *cellStore = getCellStore (iter->second);
Ptr ptr = getPtr (name, *cellStore);
if (!ptr.isEmpty())
return ptr;
}
for (ESMS::CellList::ExtCells::const_iterator iter = mStore.cells.extCells.begin();
iter!=mStore.cells.extCells.end(); ++iter)
{
Ptr::CellStore *cellStore = getCellStore (iter->second);
Ptr ptr = getPtr (name, *cellStore);
if (!ptr.isEmpty())
return ptr;
}
// giving up
return Ptr();
}

@ -29,6 +29,8 @@ namespace MWWorld
Cells (const Cells&);
Cells& operator= (const Cells&);
Ptr::CellStore *getCellStore (const ESM::Cell *cell);
public:
Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader);
@ -38,6 +40,8 @@ namespace MWWorld
Ptr::CellStore *getInterior (const std::string& name);
Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore);
Ptr getPtr (const std::string& name);
};
}

@ -351,7 +351,10 @@ namespace MWWorld
if (!activeOnly)
{
// TODO: inactive cells
Ptr ptr = mCells.getPtr (name);
if (!ptr.isEmpty())
return ptr;
}
throw std::runtime_error ("unknown ID: " + name);

Loading…
Cancel
Save