mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Implement and use getDistanceToFacedObject()
This commit is contained in:
parent
0e5c3f781f
commit
4e54338ce0
7 changed files with 19 additions and 15 deletions
|
@ -250,6 +250,8 @@ namespace MWBase
|
||||||
virtual MWWorld::Ptr getFacedObject() = 0;
|
virtual MWWorld::Ptr getFacedObject() = 0;
|
||||||
///< Return pointer to the object the player is looking at, if it is within activation range
|
///< Return pointer to the object the player is looking at, if it is within activation range
|
||||||
|
|
||||||
|
virtual float getDistanceToFacedObject() = 0;
|
||||||
|
|
||||||
virtual float getMaxActivationDistance() = 0;
|
virtual float getMaxActivationDistance() = 0;
|
||||||
|
|
||||||
/// Returns a pointer to the object the provided object would hit (if within the
|
/// 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() {}
|
MWWorld::Action::~Action() {}
|
||||||
|
|
||||||
void MWWorld::Action::execute (const Ptr& actor, float distanceToFacedObject)
|
void MWWorld::Action::execute (const Ptr& actor)
|
||||||
{
|
{
|
||||||
if(!mSoundId.empty())
|
if(!mSoundId.empty())
|
||||||
{
|
{
|
||||||
|
@ -41,10 +41,8 @@ void MWWorld::Action::execute (const Ptr& actor, float distanceToFacedObject)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mTarget.getCellRef().getTrap() != "")
|
|
||||||
executeImp(actor, distanceToFacedObject);
|
executeImp (actor);
|
||||||
else
|
|
||||||
executeImp(actor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWWorld::Action::setSound (const std::string& id)
|
void MWWorld::Action::setSound (const std::string& id)
|
||||||
|
|
|
@ -19,9 +19,7 @@ namespace MWWorld
|
||||||
Action (const Action& action);
|
Action (const Action& action);
|
||||||
Action& operator= (const Action& action);
|
Action& operator= (const Action& action);
|
||||||
|
|
||||||
virtual void executeImp (const Ptr& actor) { return; }
|
virtual void executeImp (const Ptr& actor) = 0;
|
||||||
virtual void executeImp (const Ptr& actor, float distanceToObject) { return; }
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ namespace MWWorld
|
||||||
virtual bool isNullAction() { return false; }
|
virtual bool isNullAction() { return false; }
|
||||||
///< Is running this action a no-op? (default 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 setSound (const std::string& id);
|
||||||
void setSoundOffset(float offset);
|
void setSoundOffset(float offset);
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
#include "actiontrap.hpp"
|
#include "actiontrap.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/spellcasting.hpp"
|
#include "../mwmechanics/spellcasting.hpp"
|
||||||
#include "../mwmechanics/actorutil.hpp"
|
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
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 actorPosition(actor.getRefData().getPosition().asVec3());
|
||||||
osg::Vec3f trapPosition(mTrapSource.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.
|
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
|
||||||
// Using activation distance as the trap range.
|
// 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);
|
MWMechanics::CastSpell cast(mTrapSource, mTrapSource);
|
||||||
cast.mHitPosition = trapPosition;
|
cast.mHitPosition = trapPosition;
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace MWWorld
|
||||||
std::string mSpellId;
|
std::string mSpellId;
|
||||||
MWWorld::Ptr mTrapSource;
|
MWWorld::Ptr mTrapSource;
|
||||||
|
|
||||||
virtual void executeImp (const Ptr& actor, float distanceToObject);
|
virtual void executeImp (const Ptr& actor);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ namespace MWWorld
|
||||||
/// @param actor Actor that activated the trap
|
/// @param actor Actor that activated the trap
|
||||||
/// @param trapSource
|
/// @param trapSource
|
||||||
ActionTrap (const Ptr& actor, const std::string& spellId, const Ptr& 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;
|
return facedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float World::getDistanceToFacedObject()
|
||||||
|
{
|
||||||
|
return mDistanceToFacedObject;
|
||||||
|
}
|
||||||
|
|
||||||
osg::Matrixf World::getActorHeadTransform(const MWWorld::ConstPtr& actor) const
|
osg::Matrixf World::getActorHeadTransform(const MWWorld::ConstPtr& actor) const
|
||||||
{
|
{
|
||||||
const MWRender::Animation *anim = mRendering->getAnimation(actor);
|
const MWRender::Animation *anim = mRendering->getAnimation(actor);
|
||||||
|
@ -3204,7 +3209,7 @@ namespace MWWorld
|
||||||
if (object.getRefData().activate())
|
if (object.getRefData().activate())
|
||||||
{
|
{
|
||||||
boost::shared_ptr<MWWorld::Action> action = (object.getClass().activate(object, actor));
|
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();
|
virtual MWWorld::Ptr getFacedObject();
|
||||||
///< Return pointer to the object the player is looking at, if it is within activation range
|
///< 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
|
/// 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
|
/// specified distance), and the point where the hit occurs. This will attempt to
|
||||||
/// use the "Head" node as a basis.
|
/// use the "Head" node as a basis.
|
||||||
|
|
Loading…
Reference in a new issue