1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:49:55 +00:00
openmw-tes3mp/apps/openmw/mwworld/manualref.hpp

86 lines
2.9 KiB
C++
Raw Normal View History

2010-08-07 13:11:31 +00:00
#ifndef GAME_MWWORLD_MANUALREF_H
#define GAME_MWWORLD_MANUALREF_H
#include <boost/any.hpp>
2012-10-01 15:17:04 +00:00
#include "esmstore.hpp"
2010-08-07 13:11:31 +00:00
#include "ptr.hpp"
#include "cellstore.hpp"
2010-08-07 13:11:31 +00:00
namespace MWWorld
{
/// \brief Manually constructed live cell ref
class ManualRef
{
boost::any mRef;
Ptr mPtr;
ManualRef (const ManualRef&);
ManualRef& operator= (const ManualRef&);
template<typename T>
bool create (const MWWorld::Store<T>& list, const std::string& name)
{
if (const T *instance = list.search (name))
{
LiveCellRef<T> ref;
2012-11-05 12:07:59 +00:00
ref.mBase = instance;
mRef = ref;
mPtr = Ptr (&boost::any_cast<LiveCellRef<T>&> (mRef), 0);
2010-08-07 13:11:31 +00:00
return true;
}
return false;
}
public:
2012-10-01 15:17:04 +00:00
ManualRef (const MWWorld::ESMStore& store, const std::string& name)
2010-08-07 13:11:31 +00:00
{
// create
if (!create (store.get<ESM::Activator>(), name) &&
!create (store.get<ESM::Potion>(), name) &&
!create (store.get<ESM::Apparatus>(), name) &&
!create (store.get<ESM::Armor>(), name) &&
!create (store.get<ESM::Book>(), name) &&
!create (store.get<ESM::Clothing>(), name) &&
!create (store.get<ESM::Container>(), name) &&
!create (store.get<ESM::Creature>(), name) &&
!create (store.get<ESM::Door>(), name) &&
!create (store.get<ESM::Ingredient>(), name) &&
!create (store.get<ESM::CreatureLevList>(), name) &&
!create (store.get<ESM::ItemLevList>(), name) &&
!create (store.get<ESM::Light>(), name) &&
2013-03-22 04:50:54 +00:00
!create (store.get<ESM::Lockpick>(), name) &&
!create (store.get<ESM::Miscellaneous>(), name) &&
!create (store.get<ESM::NPC>(), name) &&
!create (store.get<ESM::Probe>(), name) &&
!create (store.get<ESM::Repair>(), name) &&
!create (store.get<ESM::Static>(), name) &&
!create (store.get<ESM::Weapon>(), name))
2010-08-07 13:11:31 +00:00
throw std::logic_error ("failed to create manual cell ref for " + name);
// initialise
ESM::CellRef& cellRef = mPtr.getCellRef();
2012-09-17 07:37:50 +00:00
cellRef.mRefID = name;
cellRef.mRefnum = -1;
cellRef.mScale = 1;
cellRef.mFactIndex = 0;
cellRef.mCharge = -1;
2012-09-17 07:37:50 +00:00
cellRef.mNam9 = 0;
cellRef.mTeleport = false;
cellRef.mLockLevel = 0;
cellRef.mUnam = 0;
2010-08-07 13:11:31 +00:00
}
const Ptr& getPtr() const
{
return mPtr;
}
};
}
#endif