diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index ee1a0ad2d4..cbc940ec79 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -722,4 +722,27 @@ namespace MWWorld return std::make_pair (stream.str(), created); } + + const ESM::Cell *World::createRecord (const ESM::Cell& record) + { + if (record.data.flags & ESM::Cell::Interior) + { + if (mStore.cells.searchInt (record.name)) + throw std::runtime_error ("failed creating interior cell"); + + ESM::Cell *cell = new ESM::Cell (record); + mStore.cells.intCells.insert (std::make_pair (record.name, cell)); + return cell; + } + else + { + if (mStore.cells.searchExt (record.data.gridX, record.data.gridY)) + throw std::runtime_error ("failed creating exterior cell"); + + ESM::Cell *cell = new ESM::Cell (record); + mStore.cells.extCells.insert ( + std::make_pair (std::make_pair (record.data.gridX, record.data.gridY), cell)); + return cell; + } + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 90d6121634..89c6057fa8 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -207,6 +207,10 @@ namespace MWWorld std::pair createRecord (const ESM::Class& record); ///< Create a new recrod (of type class) in the ESM store. /// \return ID, pointer to created record + + const ESM::Cell *createRecord (const ESM::Cell& record); + ///< Create a new recrod (of type cell) in the ESM store. + /// \return ID, pointer to created record }; } diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 7d3afbb96b..20a2e8ff95 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -305,15 +305,24 @@ namespace ESMS delete it->second; } + const ESM::Cell* searchInt(const std::string &id) const + { + IntCells::const_iterator iter = intCells.find(id); + + if (iter!=intCells.end()) + return iter->second; + + return 0; + } const ESM::Cell* findInt(const std::string &id) const { - IntCells::const_iterator it = intCells.find(id); + const ESM::Cell *cell = searchInt (id); - if(it == intCells.end()) + if (!cell) throw std::runtime_error ("Interior cell not found - " + id); - return it->second; + return cell; } const ESM::Cell *searchExt (int x, int y) const