2012-07-27 12:00:10 +02:00
|
|
|
#include "action.hpp"
|
|
|
|
|
2012-07-27 12:19:25 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-26 11:47:45 -03:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2012-08-09 14:33:21 +02:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2017-07-15 10:59:08 +04:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-27 12:19:25 +02:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2012-09-04 15:14:33 +02:00
|
|
|
const MWWorld::Ptr& MWWorld::Action::getTarget() const
|
|
|
|
{
|
|
|
|
return mTarget;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:57:50 +01:00
|
|
|
void MWWorld::Action::setTarget(const MWWorld::Ptr& target)
|
|
|
|
{
|
|
|
|
mTarget = target;
|
|
|
|
}
|
|
|
|
|
2015-04-30 19:24:27 -05:00
|
|
|
MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSound), mSoundOffset(0), mTarget (target)
|
2012-08-26 18:50:47 +02:00
|
|
|
{}
|
2012-07-27 12:00:10 +02:00
|
|
|
|
|
|
|
MWWorld::Action::~Action() {}
|
|
|
|
|
2017-04-13 22:18:03 +09:00
|
|
|
void MWWorld::Action::execute (const Ptr& actor, bool noSound)
|
2012-07-27 12:00:10 +02:00
|
|
|
{
|
2017-04-13 22:18:03 +09:00
|
|
|
if(!mSoundId.empty() && !noSound)
|
2012-08-19 20:11:50 -03:00
|
|
|
{
|
2017-09-15 01:03:41 -07:00
|
|
|
MWSound::PlayMode envType = MWSound::PlayMode::Normal;
|
2017-07-15 10:59:08 +04:00
|
|
|
|
|
|
|
// Action sounds should not have a distortion in GUI mode
|
|
|
|
// example: take an item or drink a potion underwater
|
|
|
|
if (actor == MWMechanics::getPlayer() && MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
{
|
2017-09-15 01:03:41 -07:00
|
|
|
envType = MWSound::PlayMode::NoEnv;
|
2017-07-15 10:59:08 +04:00
|
|
|
}
|
|
|
|
|
2015-11-24 23:24:42 -08:00
|
|
|
if(mKeepSound && actor == MWMechanics::getPlayer())
|
2013-07-26 18:43:06 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0,
|
2017-09-15 01:03:41 -07:00
|
|
|
MWSound::Type::Sfx, envType, mSoundOffset
|
2015-11-24 23:24:42 -08:00
|
|
|
);
|
2012-08-26 18:50:47 +02:00
|
|
|
else
|
|
|
|
{
|
2012-09-04 15:21:56 +02:00
|
|
|
bool local = mTarget.isEmpty() || !mTarget.isInCell(); // no usable target
|
2015-11-24 23:24:42 -08:00
|
|
|
if(mKeepSound)
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(
|
|
|
|
(local ? actor : mTarget).getRefData().getPosition().asVec3(),
|
2017-09-15 01:03:41 -07:00
|
|
|
mSoundId, 1.0, 1.0, MWSound::Type::Sfx, envType, mSoundOffset
|
2015-11-24 23:24:42 -08:00
|
|
|
);
|
|
|
|
else
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(local ? actor : mTarget,
|
2017-09-15 01:03:41 -07:00
|
|
|
mSoundId, 1.0, 1.0, MWSound::Type::Sfx, envType, mSoundOffset
|
2015-11-24 23:24:42 -08:00
|
|
|
);
|
2012-08-26 18:50:47 +02:00
|
|
|
}
|
2012-08-19 20:11:50 -03:00
|
|
|
}
|
2012-07-27 12:19:25 +02:00
|
|
|
|
2012-07-27 12:00:10 +02:00
|
|
|
executeImp (actor);
|
|
|
|
}
|
2012-07-27 12:19:25 +02:00
|
|
|
|
2012-08-26 11:47:45 -03:00
|
|
|
void MWWorld::Action::setSound (const std::string& id)
|
2012-07-27 12:19:25 +02:00
|
|
|
{
|
|
|
|
mSoundId = id;
|
|
|
|
}
|
2013-07-26 18:43:06 +02:00
|
|
|
|
|
|
|
void MWWorld::Action::setSoundOffset(float offset)
|
|
|
|
{
|
|
|
|
mSoundOffset=offset;
|
|
|
|
}
|