OpenMW
|
00001 #ifndef GAME_MWWORLD_MANUALREF_H 00002 #define GAME_MWWORLD_MANUALREF_H 00003 00004 #include <boost/any.hpp> 00005 00006 #include "esmstore.hpp" 00007 #include "ptr.hpp" 00008 #include "cellstore.hpp" 00009 00010 namespace MWWorld 00011 { 00013 class ManualRef 00014 { 00015 boost::any mRef; 00016 Ptr mPtr; 00017 00018 ManualRef (const ManualRef&); 00019 ManualRef& operator= (const ManualRef&); 00020 00021 template<typename T> 00022 bool create (const MWWorld::Store<T>& list, const std::string& name) 00023 { 00024 if (const T *instance = list.search (name)) 00025 { 00026 LiveCellRef<T> ref; 00027 ref.mBase = instance; 00028 00029 mRef = ref; 00030 mPtr = Ptr (&boost::any_cast<LiveCellRef<T>&> (mRef), 0); 00031 00032 return true; 00033 } 00034 00035 return false; 00036 } 00037 00038 public: 00039 00040 ManualRef (const MWWorld::ESMStore& store, const std::string& name, const int count=1) 00041 { 00042 // create 00043 if (!create (store.get<ESM::Activator>(), name) && 00044 !create (store.get<ESM::Potion>(), name) && 00045 !create (store.get<ESM::Apparatus>(), name) && 00046 !create (store.get<ESM::Armor>(), name) && 00047 !create (store.get<ESM::Book>(), name) && 00048 !create (store.get<ESM::Clothing>(), name) && 00049 !create (store.get<ESM::Container>(), name) && 00050 !create (store.get<ESM::Creature>(), name) && 00051 !create (store.get<ESM::Door>(), name) && 00052 !create (store.get<ESM::Ingredient>(), name) && 00053 !create (store.get<ESM::CreatureLevList>(), name) && 00054 !create (store.get<ESM::ItemLevList>(), name) && 00055 !create (store.get<ESM::Light>(), name) && 00056 !create (store.get<ESM::Lockpick>(), name) && 00057 !create (store.get<ESM::Miscellaneous>(), name) && 00058 !create (store.get<ESM::NPC>(), name) && 00059 !create (store.get<ESM::Probe>(), name) && 00060 !create (store.get<ESM::Repair>(), name) && 00061 !create (store.get<ESM::Static>(), name) && 00062 !create (store.get<ESM::Weapon>(), name)) 00063 throw std::logic_error ("failed to create manual cell ref for " + name); 00064 00065 // initialise 00066 ESM::CellRef& cellRef = mPtr.getCellRef(); 00067 cellRef.mRefID = name; 00068 cellRef.mRefnum = -1; 00069 cellRef.mScale = 1; 00070 cellRef.mFactIndex = 0; 00071 cellRef.mCharge = -1; 00072 cellRef.mGoldValue = 1; 00073 cellRef.mEnchantmentCharge = -1; 00074 cellRef.mTeleport = false; 00075 cellRef.mLockLevel = 0; 00076 cellRef.mReferenceBlocked = 0; 00077 mPtr.getRefData().setCount(count); 00078 } 00079 00080 const Ptr& getPtr() const 00081 { 00082 return mPtr; 00083 } 00084 }; 00085 } 00086 00087 #endif