added action interface

pull/7/head
Marc Zinnschlag 15 years ago
parent 239498bcd4
commit c38b02bd5c

@ -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})

@ -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

@ -4,6 +4,7 @@
#include <stdexcept>
#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<Action> Class::activate (const Ptr& ptr) const
{
return boost::shared_ptr<Action> (new NullAction);
}
boost::shared_ptr<Action> Class::use (const Ptr& ptr) const
{
return boost::shared_ptr<Action> (new NullAction);
}
const Class& Class::get (const std::string& key)
{
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);

@ -6,6 +6,8 @@
#include <boost/shared_ptr.hpp>
#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<Action> activate (const Ptr& ptr) const;
///< Generate action for activation (default implementation: return a null action).
virtual boost::shared_ptr<Action> 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.

@ -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
Loading…
Cancel
Save