1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 06:49:55 +00:00
openmw-tes3mp/apps/openmw/mwworld/actiontrap.cpp
dteviot 8d7de7d1ec Telekinesis allows safe opening of traps (Fixes #1916)
When trap activated at beyond normal activation distance, assume telekinesis used and detonate trap at trapped object's location.
Also some minor code refactoring of spellcasting.
1. Corrected parameter passed to explodeSpell().
2. For loop now correctly does an early exit.
3. Removed duplicated tests.
2015-02-17 22:14:25 +13:00

40 lines
1.5 KiB
C++

#include "actiontrap.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
namespace MWWorld
{
void ActionTrap::executeImp(const Ptr &actor)
{
Ogre::Vector3 actorPosition(actor.getRefData().getPosition().pos);
Ogre::Vector3 trapPosition(mTrapSource.getRefData().getPosition().pos);
float activationDistance = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
// GUI calcs if object in activation distance include object and player geometry
const float fudgeFactor = 1.25f;
// Hack: if actor is beyond activation range, then assume actor is using telekinesis
// to open door/container.
// Note, can't just detonate the trap at the trapped object's location and use the blast
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
if (trapPosition.distance(actorPosition) < (activationDistance * fudgeFactor))
{
// assume actor touched trap
MWMechanics::CastSpell cast(mTrapSource, actor);
cast.mHitPosition = actorPosition;
cast.cast(mSpellId);
}
else
{
// assume telekinesis used
MWMechanics::CastSpell cast(mTrapSource, mTrapSource);
cast.mHitPosition = trapPosition;
cast.cast(mSpellId);
}
mTrapSource.getCellRef().setTrap("");
}
}