mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-10 06:44:29 +00:00
added action interface
This commit is contained in:
parent
239498bcd4
commit
c38b02bd5c
@ -88,6 +88,8 @@ set(GAMEWORLD_HEADER
|
|||||||
mwworld/environment.hpp
|
mwworld/environment.hpp
|
||||||
mwworld/globals.hpp
|
mwworld/globals.hpp
|
||||||
mwworld/class.hpp
|
mwworld/class.hpp
|
||||||
|
mwworld/action.hpp
|
||||||
|
mwworld/nullaction.hpp
|
||||||
)
|
)
|
||||||
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
||||||
|
|
||||||
|
25
apps/openmw/mwworld/action.hpp
Normal file
25
apps/openmw/mwworld/action.hpp
Normal file
@ -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 <stdexcept>
|
||||||
|
|
||||||
#include "ptr.hpp"
|
#include "ptr.hpp"
|
||||||
|
#include "nullaction.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
@ -28,6 +29,16 @@ namespace MWWorld
|
|||||||
throw std::runtime_error ("class does not have item health");
|
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)
|
const Class& Class::get (const std::string& key)
|
||||||
{
|
{
|
||||||
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (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 <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include "action.hpp"
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
struct CreatureStats;
|
struct CreatureStats;
|
||||||
@ -47,6 +49,13 @@ namespace MWWorld
|
|||||||
///< Return item max health or throw an exception, if class does not have item health
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
/// (default implementation: throw an exceoption)
|
/// (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);
|
static const Class& get (const std::string& key);
|
||||||
///< If there is no class for this \a key, an exception is thrown.
|
///< If there is no class for this \a key, an exception is thrown.
|
||||||
|
|
||||||
|
17
apps/openmw/mwworld/nullaction.hpp
Normal file
17
apps/openmw/mwworld/nullaction.hpp
Normal file
@ -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…
x
Reference in New Issue
Block a user