An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.
C++
#include "action.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwmp/Hooks.hpp"
#include "../mwmechanics/actorutil.hpp"
const MWWorld::Ptr& MWWorld::Action::getTarget() const
{
return mTarget;
}
void MWWorld::Action::setTarget(const MWWorld::Ptr& target)
{
mTarget = target;
}
MWWorld::Action::Action(bool keepSound, const Ptr& target)
: mKeepSound(keepSound)
, mSoundOffset(0)
, mTarget(target)
{
}
MWWorld::Action::~Action() {}
void MWWorld::Action::execute(const Ptr& actor, bool noSound)
{
if (!mSoundId.empty() && !noSound)
{
MWSound::PlayMode envType = MWSound::PlayMode::Normal;
// 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())
{
envType = MWSound::PlayMode::NoEnv;
}
if (mKeepSound && actor == MWMechanics::getPlayer())
{
MWBase::Environment::get().getSoundManager()->playSound(
mSoundId, 1.0, 1.0, MWSound::Type::Sfx, envType, mSoundOffset);
// Isowind multiplayer: other players hear it from the player
mwmp::hooks::sendObjectSound(actor, mSoundId);
}
else
{
bool local = mTarget.isEmpty() || !mTarget.isInCell(); // no usable target
// Isowind multiplayer: other players hear the sounds of NPCs this client has authority over
if (mwmp::hooks::isLocalActor(actor))
mwmp::hooks::sendObjectSound(local ? actor : mTarget, mSoundId);
if (mKeepSound)
MWBase::Environment::get().getSoundManager()->playSound3D(
(local ? actor : mTarget).getRefData().getPosition().asVec3(), mSoundId, 1.0, 1.0,
MWSound::Type::Sfx, envType, mSoundOffset);
else
MWBase::Environment::get().getSoundManager()->playSound3D(
local ? actor : mTarget, mSoundId, 1.0, 1.0, MWSound::Type::Sfx, envType, mSoundOffset);
}
}
executeImp(actor);
}
void MWWorld::Action::setSound(const ESM::RefId& id)
{
mSoundId = id;
}
void MWWorld::Action::setSoundOffset(float offset)
{
mSoundOffset = offset;
}