Implement and use getDistanceToFacedObject()

coverity_scan^2
Allofich 9 years ago
parent 0e5c3f781f
commit 4e54338ce0

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

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

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

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

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

@ -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<MWWorld::Action> action = (object.getClass().activate(object, actor));
action->execute (actor, mDistanceToFacedObject);
action->execute (actor);
}
}

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

Loading…
Cancel
Save