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