From af4f48fd3f4f39009eee509caa36581a625de600 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Sep 2011 12:44:17 +0200 Subject: [PATCH] Issue #28: implemented access to references outside of the active cells --- apps/openmw/mwworld/cells.cpp | 75 +++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/cells.hpp | 4 ++ apps/openmw/mwworld/world.cpp | 5 ++- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 57960e3217..a0b434d99e 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -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::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, 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::iterator iter = mInteriors.begin(); + iter!=mInteriors.end(); ++iter) + { + Ptr ptr = getPtr (name, iter->second); + if (!ptr.isEmpty()) + return ptr; + } + + for (std::map, 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(); +} diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index 2e1e6a587a..661969881f 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -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); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 961cda6dfc..ee1a0ad2d4 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -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);