diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a5c0adbf1..fcadace15 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -70,7 +70,7 @@ void OMW::Engine::executeLocalScripts() break; } - mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr()); + localScripts.setIgnore (MWWorld::Ptr()); } bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp index 3fa110338..2d90d90e0 100644 --- a/apps/openmw/mwworld/localscripts.cpp +++ b/apps/openmw/mwworld/localscripts.cpp @@ -1,6 +1,26 @@ #include "localscripts.hpp" +namespace +{ + template + void listCellScripts (MWWorld::LocalScripts& localScripts, + ESMS::CellRefList& cellRefList, MWWorld::Ptr::CellStore *cell) + { + for (typename ESMS::CellRefList::List::iterator iter ( + cellRefList.list.begin()); + iter!=cellRefList.list.end(); ++iter) + { + if (!iter->base->script.empty() && iter->mData.getCount()) + { + localScripts.add (iter->base->script, MWWorld::Ptr (&*iter, cell)); + } + } + } +} + +MWWorld::LocalScripts::LocalScripts (const ESMS::ESMStore& store) : mStore (store) {} + void MWWorld::LocalScripts::setIgnore (const Ptr& ptr) { mIgnore = ptr; @@ -39,7 +59,33 @@ std::pair MWWorld::LocalScripts::getNext() void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) { - mScripts.push_back (std::make_pair (scriptName, ptr)); + if (const ESM::Script *script = mStore.scripts.find (scriptName)) + { + ptr.getRefData().setLocals (*script); + + mScripts.push_back (std::make_pair (scriptName, ptr)); + } +} + +void MWWorld::LocalScripts::addCell (Ptr::CellStore *cell) +{ + listCellScripts (*this, cell->activators, cell); + listCellScripts (*this, cell->potions, cell); + listCellScripts (*this, cell->appas, cell); + listCellScripts (*this, cell->armors, cell); + listCellScripts (*this, cell->books, cell); + listCellScripts (*this, cell->clothes, cell); + listCellScripts (*this, cell->containers, cell); + listCellScripts (*this, cell->creatures, cell); + listCellScripts (*this, cell->doors, cell); + listCellScripts (*this, cell->ingreds, cell); + listCellScripts (*this, cell->lights, cell); + listCellScripts (*this, cell->lockpicks, cell); + listCellScripts (*this, cell->miscItems, cell); + listCellScripts (*this, cell->npcs, cell); + listCellScripts (*this, cell->probes, cell); + listCellScripts (*this, cell->repairs, cell); + listCellScripts (*this, cell->weapons, cell); } void MWWorld::LocalScripts::clear() diff --git a/apps/openmw/mwworld/localscripts.hpp b/apps/openmw/mwworld/localscripts.hpp index bc5a7c1f6..1ea2cf4d5 100644 --- a/apps/openmw/mwworld/localscripts.hpp +++ b/apps/openmw/mwworld/localscripts.hpp @@ -6,6 +6,11 @@ #include "ptr.hpp" +namespace ESMS +{ + struct ESMStore; +} + namespace MWWorld { /// \brief List of active local scripts @@ -14,9 +19,12 @@ namespace MWWorld std::list > mScripts; std::list >::iterator mIter; MWWorld::Ptr mIgnore; + const ESMS::ESMStore& mStore; public: + LocalScripts (const ESMS::ESMStore& store); + void setIgnore (const Ptr& ptr); ///< Mark a single reference for ignoring during iteration over local scripts (will revoke /// previous ignores). @@ -33,6 +41,9 @@ namespace MWWorld void add (const std::string& scriptName, const Ptr& ptr); ///< Add script to collection of active local scripts. + void addCell (Ptr::CellStore *cell); + ///< Add all local scripts in a cell. + void clear(); ///< Clear active local scripts collection. diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 9cc432ee6..da9bff6b2 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -68,7 +68,7 @@ namespace MWWorld void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) { // register local scripts - mWorld->insertInteriorScripts (*cell); + mWorld->getLocalScripts().addCell (cell); // This connects the cell data with the rendering scene. std::pair result = diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 62f477bfb..78827f150 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -66,28 +66,6 @@ namespace namespace MWWorld { - - void World::insertInteriorScripts (ESMS::CellStore& cell) - { - listCellScripts (mStore, cell.activators, mLocalScripts, &cell); - listCellScripts (mStore, cell.potions, mLocalScripts, &cell); - listCellScripts (mStore, cell.appas, mLocalScripts, &cell); - listCellScripts (mStore, cell.armors, mLocalScripts, &cell); - listCellScripts (mStore, cell.books, mLocalScripts, &cell); - listCellScripts (mStore, cell.clothes, mLocalScripts, &cell); - listCellScripts (mStore, cell.containers, mLocalScripts, &cell); - listCellScripts (mStore, cell.creatures, mLocalScripts, &cell); - listCellScripts (mStore, cell.doors, mLocalScripts, &cell); - listCellScripts (mStore, cell.ingreds, mLocalScripts, &cell); - listCellScripts (mStore, cell.lights, mLocalScripts, &cell); - listCellScripts (mStore, cell.lockpicks, mLocalScripts, &cell); - listCellScripts (mStore, cell.miscItems, mLocalScripts, &cell); - listCellScripts (mStore, cell.npcs, mLocalScripts, &cell); - listCellScripts (mStore, cell.probes, mLocalScripts, &cell); - listCellScripts (mStore, cell.repairs, mLocalScripts, &cell); - listCellScripts (mStore, cell.weapons, mLocalScripts, &cell); - } - Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) { if (ESMS::LiveCellRef *ref = @@ -198,7 +176,7 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), + : mScene (renderer,physEng), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { mPhysEngine = physEng; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index ea9f5a56f..978f14c8e 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -107,8 +107,6 @@ namespace MWWorld Ptr::CellStore *getInterior (const std::string& name); - void insertInteriorScripts (ESMS::CellStore& cell); - void adjustSky(); MWWorld::Player& getPlayer();