added containerstore

pull/7/head
Marc Zinnschlag 15 years ago
parent e0a3b1b1db
commit ee7570f7e7

@ -92,6 +92,7 @@ set(GAMEWORLD_HEADER
mwworld/action.hpp
mwworld/nullaction.hpp
mwworld/actionteleport.hpp
mwworld/containerstore.hpp
)
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})

@ -17,6 +17,22 @@ namespace MWClass
return ref->base->name;
}
MWWorld::ContainerStore<MWWorld::RefData>& Container::getContainerStore (const MWWorld::Ptr& ptr)
const
{
if (!ptr.getRefData().getContainerStore().get())
{
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
new MWWorld::ContainerStore<MWWorld::RefData>);
// TODO add initial content
ptr.getRefData().getContainerStore() = store;
}
return *ptr.getRefData().getContainerStore();
}
void Container::registerSelf()
{
boost::shared_ptr<Class> instance (new Container);

@ -13,6 +13,10 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual MWWorld::ContainerStore<MWWorld::RefData>& getContainerStore (
const MWWorld::Ptr& ptr) const;
///< Return container store
static void registerSelf();
};
}

@ -44,6 +44,22 @@ namespace MWClass
return *ptr.getRefData().getCreatureStats();
}
MWWorld::ContainerStore<MWWorld::RefData>& Creature::getContainerStore (const MWWorld::Ptr& ptr)
const
{
if (!ptr.getRefData().getContainerStore().get())
{
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
new MWWorld::ContainerStore<MWWorld::RefData>);
// TODO add initial content
ptr.getRefData().getContainerStore() = store;
}
return *ptr.getRefData().getContainerStore();
}
void Creature::registerSelf()
{
boost::shared_ptr<Class> instance (new Creature);

@ -16,6 +16,10 @@ namespace MWClass
virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const;
///< Return creature stats
virtual MWWorld::ContainerStore<MWWorld::RefData>& getContainerStore (
const MWWorld::Ptr& ptr) const;
///< Return container store
static void registerSelf();
};
}

@ -44,6 +44,21 @@ namespace MWClass
return *ptr.getRefData().getCreatureStats();
}
MWWorld::ContainerStore<MWWorld::RefData>& Npc::getContainerStore (const MWWorld::Ptr& ptr) const
{
if (!ptr.getRefData().getContainerStore().get())
{
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
new MWWorld::ContainerStore<MWWorld::RefData>);
// TODO add initial content
ptr.getRefData().getContainerStore() = store;
}
return *ptr.getRefData().getContainerStore();
}
void Npc::registerSelf()
{
boost::shared_ptr<Class> instance (new Npc);

@ -16,6 +16,10 @@ namespace MWClass
virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const;
///< Return creature stats
virtual MWWorld::ContainerStore<MWWorld::RefData>& getContainerStore (
const MWWorld::Ptr& ptr) const;
///< Return container store
static void registerSelf();
};
}

@ -41,6 +41,11 @@ namespace MWWorld
return boost::shared_ptr<Action> (new NullAction);
}
ContainerStore<RefData>& Class::getContainerStore (const Ptr& ptr) const
{
throw std::runtime_error ("class does not have a container store");
}
const Class& Class::get (const std::string& key)
{
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);

@ -7,6 +7,8 @@
#include <boost/shared_ptr.hpp>
#include "action.hpp"
#include "containerstore.hpp"
#include "refdata.hpp"
namespace MWMechanics
{
@ -58,6 +60,10 @@ namespace MWWorld
///< Generate action for using via inventory menu (default implementation: return a
/// null action).
virtual ContainerStore<RefData>& getContainerStore (const Ptr& ptr) const;
///< Return container store or throw an exception, if class does not have a
/// container store (default implementation: throw an exceoption)
static const Class& get (const std::string& key);
///< If there is no class for this \a key, an exception is thrown.

@ -0,0 +1,26 @@
#ifndef GAME_MWWORLD_CONTAINERSTORE_H
#define GAME_MWWORLD_CONTAINERSTORE_H
#include <components/esm_store/cell_store.hpp>
namespace MWWorld
{
template<typename D>
struct ContainerStore
{
ESMS::CellRefList<ESM::Potion, D> potions;
ESMS::CellRefList<ESM::Apparatus, D> appas;
ESMS::CellRefList<ESM::Armor, D> armors;
ESMS::CellRefList<ESM::Book, D> books;
ESMS::CellRefList<ESM::Clothing, D> clothes;
ESMS::CellRefList<ESM::Ingredient, D> ingreds;
ESMS::CellRefList<ESM::Light, D> lights;
ESMS::CellRefList<ESM::Tool, D> lockpicks;
ESMS::CellRefList<ESM::Misc, D> miscItems;
ESMS::CellRefList<ESM::Probe, D> probes;
ESMS::CellRefList<ESM::Repair, D> repairs;
ESMS::CellRefList<ESM::Weapon, D> weapons;
};
}
#endif

@ -7,6 +7,8 @@
#include "../mwscript/locals.hpp"
#include "containerstore.hpp"
namespace ESM
{
class Script;
@ -36,6 +38,8 @@ namespace MWWorld
// are never copied outside of container operations.
boost::shared_ptr<MWMechanics::CreatureStats> mCreatureStats;
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
public:
RefData() : mHasLocals (false), mEnabled (true), mCount (1) {}
@ -93,6 +97,11 @@ namespace MWWorld
{
return mCreatureStats;
}
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore()
{
return mContainerStore;
}
};
}

Loading…
Cancel
Save