diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 41392def0c..466f7570f7 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 0000000000..1558193355 --- /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 e5840b96d8..9a6a73a87f 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 ceaf142923..8287284c07 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 0000000000..820fc45388 --- /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