diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8cfc6bfc8..4e4e9062d 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -207,6 +207,7 @@ set(GAMEMECHANICS_HEADER mwmechanics/stat.hpp mwmechanics/creaturestats.hpp mwmechanics/magiceffects.hpp + mwmechanics/movement.hpp ) source_group(apps\\openmw\\mwmechanics FILES ${GAMEMECHANICS} ${GAMEMECHANICS_HEADER}) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index bd7aeb413..82306ab2c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -439,6 +439,33 @@ namespace MWClass return getStance (ptr, Run) ? 600 : 300; // TODO calculate these values from stats } + MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getMovement().get()) + { + boost::shared_ptr movement ( + new MWMechanics::Movement); + } + + return *ptr.getRefData().getMovement(); + } + + Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const + { + Ogre::Vector3 vector (0, 0, 0); + + if (ptr.getRefData().getMovement().get()) + { + vector.x = - ptr.getRefData().getMovement()->mLeftRight * 200; + vector.z = - ptr.getRefData().getMovement()->mForwardBackward * 200; + + if (getStance (ptr, Run, false)) + vector *= 2; + } + + return vector; + } + void Npc::registerSelf() { boost::shared_ptr instance (new Npc); diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 1d9d90c4d..9f29878da 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -56,6 +56,13 @@ namespace MWClass virtual float getSpeed (const MWWorld::Ptr& ptr) const; ///< Return movement speed. + virtual MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const; + ///< Return desired movement. + + virtual Ogre::Vector3 getMovementVector (const MWWorld::Ptr& ptr) const; + ///< Return desired movement vector (determined based on movement settings, + /// stance and stats). + static void registerSelf(); }; } diff --git a/apps/openmw/mwmechanics/movement.hpp b/apps/openmw/mwmechanics/movement.hpp new file mode 100644 index 000000000..a555ac010 --- /dev/null +++ b/apps/openmw/mwmechanics/movement.hpp @@ -0,0 +1,16 @@ +#ifndef GAME_MWMECHANICS_MOVEMENT_H +#define GAME_MWMECHANICS_MOVEMENT_H + +namespace MWMechanics +{ + /// Desired movement for an actor + struct Movement + { + signed char mLeftRight; // 1: wants to move left, -1: wants to move right + signed char mForwardBackward; // 1:wants to move forward, -1: wants to move backward + + Movement() : mLeftRight (0), mForwardBackward (0) {} + }; +} + +#endif diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 837b3b294..670cf90b2 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -3,6 +3,8 @@ #include +#include + #include "ptr.hpp" #include "nullaction.hpp" @@ -112,6 +114,16 @@ namespace MWWorld return 0; } + MWMechanics::Movement& Class::getMovementSettings (const Ptr& ptr) const + { + throw std::runtime_error ("movement settings not supported by class"); + } + + Ogre::Vector3 Class::getMovementVector (const Ptr& ptr) const + { + return Ogre::Vector3 (0, 0, 0); + } + 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 51c727aad..8ad9ba58f 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -10,6 +10,11 @@ #include "containerstore.hpp" #include "refdata.hpp" +namespace Ogre +{ + class Vector3; +} + namespace MWRender { class CellRenderImp; @@ -19,6 +24,7 @@ namespace MWMechanics { struct CreatureStats; struct NpcStats; + struct Movement; } namespace MWWorld @@ -126,6 +132,13 @@ namespace MWWorld virtual float getSpeed (const Ptr& ptr) const; ///< Return movement speed. + virtual MWMechanics::Movement& getMovementSettings (const Ptr& ptr) const; + ///< Return desired movement. + + virtual Ogre::Vector3 getMovementVector (const Ptr& ptr) const; + ///< Return desired movement vector (determined based on movement settings, + /// stance and stats). + 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/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index a8cf3aed8..a9613248e 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -9,6 +9,7 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" +#include "../mwmechanics/movement.hpp" #include "containerstore.hpp" @@ -36,6 +37,7 @@ namespace MWWorld // are never copied outside of container operations. boost::shared_ptr mCreatureStats; boost::shared_ptr mNpcStats; + boost::shared_ptr mMovement; boost::shared_ptr > mContainerStore; @@ -102,6 +104,11 @@ namespace MWWorld return mNpcStats; } + boost::shared_ptr& getMovement() + { + return mMovement; + } + boost::shared_ptr >& getContainerStore() { return mContainerStore;