From c38b02bd5c031ee7a4deab3ff96a402952f7ff1e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 3 Aug 2010 18:20:15 +0200 Subject: [PATCH] added action interface --- apps/openmw/CMakeLists.txt | 2 ++ apps/openmw/mwworld/action.hpp | 25 +++++++++++++++++++++++++ apps/openmw/mwworld/class.cpp | 11 +++++++++++ apps/openmw/mwworld/class.hpp | 9 +++++++++ apps/openmw/mwworld/nullaction.hpp | 17 +++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 apps/openmw/mwworld/action.hpp create mode 100644 apps/openmw/mwworld/nullaction.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 41392def0..466f7570f 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -88,6 +88,8 @@ set(GAMEWORLD_HEADER mwworld/environment.hpp mwworld/globals.hpp mwworld/class.hpp + mwworld/action.hpp + mwworld/nullaction.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp new file mode 100644 index 000000000..155819335 --- /dev/null +++ b/apps/openmw/mwworld/action.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_MWWORLD_ACTION_H +#define GAME_MWWORLD_ACTION_H + +namespace MWWorld +{ + class Environment; + + /// \brief Abstract base for actions + class Action + { + // not implemented + Action (const Action& action); + Action& operator= (const Action& action); + + public: + + Action() {} + + virtual ~Action() {} + + virtual void execute (Environment& environment) = 0; + }; +} + +#endif diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index e5840b96d..9a6a73a87 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -4,6 +4,7 @@ #include #include "ptr.hpp" +#include "nullaction.hpp" namespace MWWorld { @@ -28,6 +29,16 @@ namespace MWWorld throw std::runtime_error ("class does not have item health"); } + boost::shared_ptr Class::activate (const Ptr& ptr) const + { + return boost::shared_ptr (new NullAction); + } + + boost::shared_ptr Class::use (const Ptr& ptr) const + { + return boost::shared_ptr (new NullAction); + } + 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 ceaf14292..8287284c0 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -6,6 +6,8 @@ #include +#include "action.hpp" + namespace MWMechanics { struct CreatureStats; @@ -47,6 +49,13 @@ namespace MWWorld ///< Return item max health or throw an exception, if class does not have item health /// (default implementation: throw an exceoption) + virtual boost::shared_ptr activate (const Ptr& ptr) const; + ///< Generate action for activation (default implementation: return a null action). + + virtual boost::shared_ptr use (const Ptr& ptr) const; + ///< Generate action for using via inventory menu (default implementation: return a + /// null action). + 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/nullaction.hpp b/apps/openmw/mwworld/nullaction.hpp new file mode 100644 index 000000000..820fc4538 --- /dev/null +++ b/apps/openmw/mwworld/nullaction.hpp @@ -0,0 +1,17 @@ +#ifndef GAME_MWWORLD_NULLACTION_H +#define GAME_MWWORLD_NULLACTION_H + +#include "action.hpp" + +namespace MWWorld +{ + /// \brief Action: do nothing + class NullAction : public Action + { + public: + + virtual void execute (Environment& environment) {} + }; +} + +#endif