1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-12 03:36:32 +00:00
OpenMW/apps/openmw/mwworld/actiontrap.cpp

35 lines
1.4 KiB
C++
Raw Normal View History

#include "actiontrap.hpp"
#include "../mwmechanics/spellcasting.hpp"
2016-07-04 05:39:44 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
namespace MWWorld
{
void ActionTrap::executeImp(const Ptr &actor)
2016-07-04 10:09:12 +00:00
{
2016-07-06 19:03:56 +00:00
osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3());
2015-06-01 19:41:13 +00:00
osg::Vec3f trapPosition(mTrapSource.getRefData().getPosition().asVec3());
2016-07-06 19:03:56 +00:00
float trapRange = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
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
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
2016-07-04 10:09:12 +00:00
// Using activation distance as the trap range.
2016-07-04 05:39:44 +00:00
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;
2016-07-07 12:46:58 +00:00
cast.cast(mSpellId);
2016-07-06 19:03:56 +00:00
}
else // player activated object within range of trap, or NPC activated trap
2016-07-06 19:03:56 +00:00
{
MWMechanics::CastSpell cast(mTrapSource, actor);
cast.mHitPosition = actorPosition;
cast.cast(mSpellId);
2016-07-04 10:09:12 +00:00
}
2016-07-06 19:03:56 +00:00
mTrapSource.getCellRef().setTrap("");
}
}