2013-11-13 13:02:15 +00:00
|
|
|
#include "actiontrap.hpp"
|
|
|
|
|
2013-11-17 22:15:57 +00:00
|
|
|
#include "../mwmechanics/spellcasting.hpp"
|
2016-07-04 05:39:44 +00:00
|
|
|
|
2015-02-17 09:14:25 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2013-11-13 13:02:15 +00:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
2016-07-03 17:23:04 +00:00
|
|
|
void ActionTrap::executeImp(const Ptr &actor, float distance)
|
2013-11-13 13:02:15 +00:00
|
|
|
{
|
2015-06-01 19:41:13 +00:00
|
|
|
osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3());
|
|
|
|
osg::Vec3f trapPosition(mTrapSource.getRefData().getPosition().asVec3());
|
2015-02-17 09:14:25 +00:00
|
|
|
float activationDistance = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
|
2013-11-13 13:02:15 +00:00
|
|
|
|
2016-07-04 05:39:44 +00:00
|
|
|
// Note: can't just detonate the trap at the trapped object's location and use the blast
|
2015-02-17 09:14:25 +00:00
|
|
|
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
|
2016-07-04 05:39:44 +00:00
|
|
|
// Using the activation distance as the trap range.
|
|
|
|
|
2016-07-03 17:23:04 +00:00
|
|
|
if (distance < activationDistance)
|
2015-02-17 09:14:25 +00:00
|
|
|
{
|
2016-07-04 05:39:44 +00:00
|
|
|
// actor activated object within range of trap
|
2015-02-17 09:14:25 +00:00
|
|
|
MWMechanics::CastSpell cast(mTrapSource, actor);
|
|
|
|
cast.mHitPosition = actorPosition;
|
|
|
|
cast.cast(mSpellId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-04 05:39:44 +00:00
|
|
|
// actor activated object outside range of trap
|
2015-02-17 09:14:25 +00:00
|
|
|
MWMechanics::CastSpell cast(mTrapSource, mTrapSource);
|
|
|
|
cast.mHitPosition = trapPosition;
|
|
|
|
cast.cast(mSpellId);
|
|
|
|
}
|
2014-05-25 12:13:07 +00:00
|
|
|
mTrapSource.getCellRef().setTrap("");
|
2013-11-13 13:02:15 +00:00
|
|
|
}
|
|
|
|
}
|