#ifndef GAME_MWWORLD_MANUALREF_H #define GAME_MWWORLD_MANUALREF_H #include #include "esmstore.hpp" #include "ptr.hpp" #include "cellstore.hpp" namespace MWWorld { /// \brief Manually constructed live cell ref class ManualRef { boost::any mRef; Ptr mPtr; ManualRef (const ManualRef&); ManualRef& operator= (const ManualRef&); template bool create (const MWWorld::Store& list, const std::string& name) { if (const T *instance = list.search (name)) { LiveCellRef ref; ref.mBase = instance; mRef = ref; mPtr = Ptr (&boost::any_cast&> (mRef), 0); return true; } return false; } public: ManualRef (const MWWorld::ESMStore& store, const std::string& name) { // create if (!create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name) && !create (store.get(), name)) throw std::logic_error ("failed to create manual cell ref for " + name); // initialise ESM::CellRef& cellRef = mPtr.getCellRef(); cellRef.mRefID = name; cellRef.mRefnum = -1; cellRef.mScale = 1; cellRef.mFactIndex = 0; cellRef.mCharge = 0; cellRef.mIntv = 0; cellRef.mNam9 = 0; cellRef.mTeleport = false; cellRef.mLockLevel = 0; cellRef.mUnam = 0; } const Ptr& getPtr() const { return mPtr; } }; } #endif