From f6c3a62b3e592d62fdf35515d4527cae8c03a3c2 Mon Sep 17 00:00:00 2001 From: Allofich Date: Wed, 31 Aug 2016 19:50:27 +0900 Subject: [PATCH] Use average speed for multiple spell projectiles --- apps/openmw/mwmechanics/spellcasting.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index df6d2c600..a9c0bb9f7 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -286,9 +286,26 @@ namespace MWMechanics /// If \a model is empty, the spell has no ranged effects and should not spawn a projectile. void CastSpell::getProjectileInfoAndLaunch (const ESM::EffectList& effects) { + // All projectiles should use the same speed. From observations in the + // original engine, this seems to be the average of the constituent effects. + // First we get this average speed. + float speed = 0; + int count = 0; + for (std::vector::const_iterator iter (effects.mList.begin()); + iter!=effects.mList.end(); ++iter) + { + const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find ( + iter->mEffectID); + speed += magicEffect->mData.mSpeed; + count++; + } + + if (count != 0) + speed /= count; + std::string model; std::string sound; - float speed = 0; + osg::Vec3f fallbackDirection (0,1,0); for (std::vector::const_iterator iter (effects.mList.begin()); iter!=effects.mList.end(); ++iter) @@ -311,8 +328,6 @@ namespace MWMechanics else sound = schools[magicEffect->mData.mSchool] + " bolt"; - speed = magicEffect->mData.mSpeed; - // Fall back to a "caster to target" direction if we have no other means of determining it // (e.g. when cast by a non-actor) if (!mTarget.isEmpty()) @@ -320,8 +335,7 @@ namespace MWMechanics osg::Vec3f(mTarget.getRefData().getPosition().asVec3())- osg::Vec3f(mCaster.getRefData().getPosition().asVec3()); - if (!model.empty()) - MWBase::Environment::get().getWorld()->launchMagicBolt(model, sound, mId, speed, + MWBase::Environment::get().getWorld()->launchMagicBolt(model, sound, mId, speed, false, effects, mCaster, mSourceName, fallbackDirection); } }