From ee7570f7e7f825a4becd93491dab052441711e41 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 4 Aug 2010 14:37:23 +0200 Subject: [PATCH] added containerstore --- apps/openmw/CMakeLists.txt | 1 + apps/openmw/mwclass/container.cpp | 16 ++++++++++++++++ apps/openmw/mwclass/container.hpp | 4 ++++ apps/openmw/mwclass/creature.cpp | 16 ++++++++++++++++ apps/openmw/mwclass/creature.hpp | 4 ++++ apps/openmw/mwclass/npc.cpp | 15 +++++++++++++++ apps/openmw/mwclass/npc.hpp | 4 ++++ apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 6 ++++++ apps/openmw/mwworld/containerstore.hpp | 26 ++++++++++++++++++++++++++ apps/openmw/mwworld/refdata.hpp | 9 +++++++++ 11 files changed, 106 insertions(+) create mode 100644 apps/openmw/mwworld/containerstore.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 0fe62ea4f..c9112b0ee 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -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}) diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index a6df294e7..1048329be 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -17,6 +17,22 @@ namespace MWClass return ref->base->name; } + MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + void Container::registerSelf() { boost::shared_ptr instance (new Container); diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 0b907b2b7..6f5b872b9 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -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& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 198c0e72f..d7aa2d357 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -44,6 +44,22 @@ namespace MWClass return *ptr.getRefData().getCreatureStats(); } + MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr) + const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + void Creature::registerSelf() { boost::shared_ptr instance (new Creature); diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 5056501c5..4dbbcc386 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -16,6 +16,10 @@ namespace MWClass virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + static void registerSelf(); }; } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index dbb7f2a93..f5547a934 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -44,6 +44,21 @@ namespace MWClass return *ptr.getRefData().getCreatureStats(); } + MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getContainerStore().get()) + { + boost::shared_ptr > store ( + new MWWorld::ContainerStore); + + // TODO add initial content + + ptr.getRefData().getContainerStore() = store; + } + + return *ptr.getRefData().getContainerStore(); + } + void Npc::registerSelf() { boost::shared_ptr instance (new Npc); diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 76c56de40..54536f180 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -16,6 +16,10 @@ namespace MWClass virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats + virtual MWWorld::ContainerStore& getContainerStore ( + const MWWorld::Ptr& ptr) const; + ///< Return container store + static void registerSelf(); }; } diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 9cca8035e..33c5ff114 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -41,6 +41,11 @@ namespace MWWorld return boost::shared_ptr (new NullAction); } + ContainerStore& 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 >::const_iterator iter = sClasses.find (key); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 9535786e2..159ff3c5f 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -7,6 +7,8 @@ #include #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& 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. diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp new file mode 100644 index 000000000..c05bfe156 --- /dev/null +++ b/apps/openmw/mwworld/containerstore.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWWORLD_CONTAINERSTORE_H +#define GAME_MWWORLD_CONTAINERSTORE_H + +#include + +namespace MWWorld +{ + template + struct ContainerStore + { + ESMS::CellRefList potions; + ESMS::CellRefList appas; + ESMS::CellRefList armors; + ESMS::CellRefList books; + ESMS::CellRefList clothes; + ESMS::CellRefList ingreds; + ESMS::CellRefList lights; + ESMS::CellRefList lockpicks; + ESMS::CellRefList miscItems; + ESMS::CellRefList probes; + ESMS::CellRefList repairs; + ESMS::CellRefList weapons; + }; +} + +#endif diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 8f76635f9..b041a06cb 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -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 mCreatureStats; + boost::shared_ptr > mContainerStore; + public: RefData() : mHasLocals (false), mEnabled (true), mCount (1) {} @@ -93,6 +97,11 @@ namespace MWWorld { return mCreatureStats; } + + boost::shared_ptr >& getContainerStore() + { + return mContainerStore; + } }; }