#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; ref.mRef.mRefNum.mIndex = 0; ref.mRef.mRefNum.mContentFile = -1; mRef = ref; mPtr = Ptr (&boost::any_cast&> (mRef), 0); return true; } return false; } public: ManualRef (const MWWorld::ESMStore& store, const std::string& name, const int count=1) { // 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 = Misc::StringUtils::lowerCase (name); cellRef.mRefNum.mIndex = 0; cellRef.mRefNum.mContentFile = -1; cellRef.mScale = 1; cellRef.mFactIndex = 0; cellRef.mCharge = -1; cellRef.mGoldValue = 1; cellRef.mEnchantmentCharge = -1; cellRef.mTeleport = false; cellRef.mLockLevel = 0; cellRef.mReferenceBlocked = 0; mPtr.getRefData().setCount(count); } const Ptr& getPtr() const { return mPtr; } }; } #endif