From 4e54338ce083d91ded1145341c3cc44a9456cd0d Mon Sep 17 00:00:00 2001 From: Allofich Date: Fri, 8 Jul 2016 23:07:07 +0900 Subject: [PATCH] Implement and use getDistanceToFacedObject() --- apps/openmw/mwbase/world.hpp | 2 ++ apps/openmw/mwworld/action.cpp | 8 +++----- apps/openmw/mwworld/action.hpp | 6 ++---- apps/openmw/mwworld/actiontrap.cpp | 5 ++--- apps/openmw/mwworld/actiontrap.hpp | 4 ++-- apps/openmw/mwworld/worldimp.cpp | 7 ++++++- apps/openmw/mwworld/worldimp.hpp | 2 ++ 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 7376e6b51..82d5ddd5e 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -250,6 +250,8 @@ namespace MWBase virtual MWWorld::Ptr getFacedObject() = 0; ///< Return pointer to the object the player is looking at, if it is within activation range + virtual float getDistanceToFacedObject() = 0; + virtual float getMaxActivationDistance() = 0; /// Returns a pointer to the object the provided object would hit (if within the diff --git a/apps/openmw/mwworld/action.cpp b/apps/openmw/mwworld/action.cpp index e76ff8105..c29377ecb 100644 --- a/apps/openmw/mwworld/action.cpp +++ b/apps/openmw/mwworld/action.cpp @@ -17,7 +17,7 @@ MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSo MWWorld::Action::~Action() {} -void MWWorld::Action::execute (const Ptr& actor, float distanceToFacedObject) +void MWWorld::Action::execute (const Ptr& actor) { if(!mSoundId.empty()) { @@ -41,10 +41,8 @@ void MWWorld::Action::execute (const Ptr& actor, float distanceToFacedObject) ); } } - if (mTarget.getCellRef().getTrap() != "") - executeImp(actor, distanceToFacedObject); - else - executeImp(actor); + + executeImp (actor); } void MWWorld::Action::setSound (const std::string& id) diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp index d61e72551..38907cf44 100644 --- a/apps/openmw/mwworld/action.hpp +++ b/apps/openmw/mwworld/action.hpp @@ -19,9 +19,7 @@ namespace MWWorld Action (const Action& action); Action& operator= (const Action& action); - virtual void executeImp (const Ptr& actor) { return; } - virtual void executeImp (const Ptr& actor, float distanceToObject) { return; } - + virtual void executeImp (const Ptr& actor) = 0; protected: @@ -37,7 +35,7 @@ namespace MWWorld virtual bool isNullAction() { return false; } ///< Is running this action a no-op? (default false) - void execute (const Ptr& actor, float distanceToObject = -1); + void execute (const Ptr& actor); void setSound (const std::string& id); void setSoundOffset(float offset); diff --git a/apps/openmw/mwworld/actiontrap.cpp b/apps/openmw/mwworld/actiontrap.cpp index 1ddf86bf6..cdabaf8c8 100644 --- a/apps/openmw/mwworld/actiontrap.cpp +++ b/apps/openmw/mwworld/actiontrap.cpp @@ -1,14 +1,13 @@ #include "actiontrap.hpp" #include "../mwmechanics/spellcasting.hpp" -#include "../mwmechanics/actorutil.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" namespace MWWorld { - void ActionTrap::executeImp(const Ptr &actor, float distance) + void ActionTrap::executeImp(const Ptr &actor) { osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3()); osg::Vec3f trapPosition(mTrapSource.getRefData().getPosition().asVec3()); @@ -18,7 +17,7 @@ namespace MWWorld // radius, because for most trap spells this is 1 foot, much less than the activation distance. // Using activation distance as the trap range. - if (distance > trapRange && actor == MWMechanics::getPlayer()) // player activated object outside range of trap + if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr() && MWBase::Environment::get().getWorld()->getDistanceToFacedObject() > trapRange) // player activated object outside range of trap { MWMechanics::CastSpell cast(mTrapSource, mTrapSource); cast.mHitPosition = trapPosition; diff --git a/apps/openmw/mwworld/actiontrap.hpp b/apps/openmw/mwworld/actiontrap.hpp index 6a0820381..4c2f4139f 100644 --- a/apps/openmw/mwworld/actiontrap.hpp +++ b/apps/openmw/mwworld/actiontrap.hpp @@ -13,7 +13,7 @@ namespace MWWorld std::string mSpellId; MWWorld::Ptr mTrapSource; - virtual void executeImp (const Ptr& actor, float distanceToObject); + virtual void executeImp (const Ptr& actor); public: @@ -21,7 +21,7 @@ namespace MWWorld /// @param actor Actor that activated the trap /// @param trapSource ActionTrap (const Ptr& actor, const std::string& spellId, const Ptr& trapSource) - : Action(false, trapSource), mSpellId(spellId), mTrapSource(trapSource) {} + : Action(false, actor), mSpellId(spellId), mTrapSource(trapSource) {} }; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 05b060bce..4aa249a6d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1033,6 +1033,11 @@ namespace MWWorld return facedObject; } + float World::getDistanceToFacedObject() + { + return mDistanceToFacedObject; + } + osg::Matrixf World::getActorHeadTransform(const MWWorld::ConstPtr& actor) const { const MWRender::Animation *anim = mRendering->getAnimation(actor); @@ -3204,7 +3209,7 @@ namespace MWWorld if (object.getRefData().activate()) { boost::shared_ptr action = (object.getClass().activate(object, actor)); - action->execute (actor, mDistanceToFacedObject); + action->execute (actor); } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 64160018f..411dbc103 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -348,6 +348,8 @@ namespace MWWorld virtual MWWorld::Ptr getFacedObject(); ///< Return pointer to the object the player is looking at, if it is within activation range + virtual float getDistanceToFacedObject(); + /// Returns a pointer to the object the provided object would hit (if within the /// specified distance), and the point where the hit occurs. This will attempt to /// use the "Head" node as a basis.