From 1051611ffaba6fcf7dbb09830ecd2f7786fa50af Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 9 Nov 2013 07:59:17 +0100 Subject: [PATCH] Added spell failure sound --- apps/openmw/mwworld/worldimp.cpp | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 2c8236f3b..5b7eb7bb1 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1996,24 +1996,47 @@ namespace MWWorld const ESM::Spell* spell = getStore().get().search(selectedSpell); // Check mana + bool fail = false; MWMechanics::DynamicStat magicka = stats.getMagicka(); if (magicka.getCurrent() < spell->mData.mCost) { MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientSP}"); - return; + fail = true; } // Reduce mana - magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost); - stats.setMagicka(magicka); + if (!fail) + { + magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost); + stats.setMagicka(magicka); + } // Check success int successChance = MWMechanics::getSpellSuccessChance(selectedSpell, actor); int roll = std::rand()/ (static_cast (RAND_MAX) + 1) * 100; // [0, 99] - if (roll >= successChance) + if (!fail && roll >= successChance) { MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}"); - // TODO sound: "Spell Failure " + fail = true; + } + + if (fail) + { + // Failure sound + for (std::vector::const_iterator iter (spell->mEffects.mList.begin()); + iter!=spell->mEffects.mList.end(); ++iter) + { + const ESM::MagicEffect *magicEffect = getStore().get().find ( + iter->mEffectID); + + static const std::string schools[] = { + "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" + }; + + MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); + sndMgr->playSound3D(actor, "Spell Failure " + schools[magicEffect->mData.mSchool], 1.0f, 1.0f); + break; + } return; }