From 10842462c7020e11aa54274d4e6c848d42b5fa93 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sun, 4 Sep 2016 01:54:09 +0900 Subject: [PATCH] Send lists of models and sounds to launchMagicBolt --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwmechanics/spellcasting.cpp | 26 +++++-------- apps/openmw/mwworld/projectilemanager.cpp | 47 +++++++++++------------ apps/openmw/mwworld/projectilemanager.hpp | 11 ++++-- apps/openmw/mwworld/worldimp.cpp | 4 +- apps/openmw/mwworld/worldimp.hpp | 2 +- 6 files changed, 44 insertions(+), 48 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 549931b9a8..8dda90b642 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -486,7 +486,7 @@ namespace MWBase virtual void castSpell (const MWWorld::Ptr& actor) = 0; - virtual void launchMagicBolt (const std::string& model, const std::string& sound, const std::string& spellId, + virtual void launchMagicBolt (const std::vector& models, const std::vector& sounds, const std::string& spellId, float speed, bool stack, const ESM::EffectList& effects, const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection) = 0; virtual void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile, diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 9fcd488cad..734509b6b9 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -304,11 +304,12 @@ namespace MWMechanics speed /= count; std::string model; + std::vector models; std::string sound; + std::vector sounds; + ESM::EffectList projectileEffects; - osg::Vec3f fallbackDirection (0,1,0); - - bool isFirstProjectile = true; + osg::Vec3f fallbackDirection (0,1,0); for (std::vector::const_iterator iter (effects.mList.begin()); iter!=effects.mList.end(); ++iter) @@ -322,6 +323,7 @@ namespace MWMechanics model = magicEffect->mBolt; if (model.empty()) model = "VFX_DefaultBolt"; + models.push_back(model); static const std::string schools[] = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" @@ -330,6 +332,9 @@ namespace MWMechanics sound = magicEffect->mBoltSound; else sound = schools[magicEffect->mData.mSchool] + " bolt"; + sounds.push_back(sound); + projectileEffects.mList.push_back(*iter); + } // 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) @@ -338,19 +343,8 @@ namespace MWMechanics osg::Vec3f(mTarget.getRefData().getPosition().asVec3())- osg::Vec3f(mCaster.getRefData().getPosition().asVec3()); - // Only send the effects data with the first projectile, so we don't have the impact sounds - // playing multiple times. - if (isFirstProjectile) - MWBase::Environment::get().getWorld()->launchMagicBolt(model, sound, mId, speed, - false, effects, mCaster, mSourceName, fallbackDirection); - else - { - ESM::EffectList empty; - MWBase::Environment::get().getWorld()->launchMagicBolt(model, sound, mId, speed, - false, empty, mCaster, mSourceName, fallbackDirection); - } - isFirstProjectile = false; - } + MWBase::Environment::get().getWorld()->launchMagicBolt(models, sounds, mId, speed, + false, projectileEffects, mCaster, mSourceName, fallbackDirection); } void CastSpell::inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 90fba827f9..0825be3c39 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -112,7 +112,7 @@ namespace MWWorld state.mEffectAnimationTime->addTime(duration); } - void ProjectileManager::launchMagicBolt(const std::string &model, const std::string &sound, + void ProjectileManager::launchMagicBolt(const std::vector &models, const std::vector &sounds, const std::string &spellId, float speed, bool stack, const ESM::EffectList &effects, const Ptr &caster, const std::string &sourceName, const osg::Vec3f& fallbackDirection) @@ -137,7 +137,6 @@ namespace MWWorld MagicBoltState state; state.mSourceName = sourceName; - state.mId = model; state.mSpellId = spellId; state.mCasterHandle = caster; if (caster.getClass().isActor()) @@ -146,24 +145,24 @@ namespace MWWorld state.mActorId = -1; state.mSpeed = speed; state.mStack = stack; - state.mSoundId = sound; + state.mIdMagic = models; + state.mSoundId = sounds; - // Only interested in "on target" effects - for (std::vector::const_iterator iter (effects.mList.begin()); - iter!=effects.mList.end(); ++iter) + // Should have already had non-projectile effects removed + state.mEffects = effects; + + for (int iter = 0; iter != models.size(); ++iter) { - if (iter->mRange == ESM::RT_Target) - state.mEffects.mList.push_back(*iter); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), models.at(iter)); + MWWorld::Ptr ptr = ref.getPtr(); + + createModel(state, ptr.getClass().getModel(ptr), pos, orient, true); + + MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); + if (iter < sounds.size()) + state.mSound = sndMgr->playSound3D(pos, sounds.at(iter), 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop); } - MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), model); - MWWorld::Ptr ptr = ref.getPtr(); - - createModel(state, ptr.getClass().getModel(ptr), pos, orient, true); - - MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); - state.mSound = sndMgr->playSound3D(pos, sound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop); - mMagicBolts.push_back(state); } @@ -173,7 +172,7 @@ namespace MWWorld state.mActorId = actor.getClass().getCreatureStats(actor).getActorId(); state.mBowId = bow.getCellRef().getRefId(); state.mVelocity = orient * osg::Vec3f(0,1,0) * speed; - state.mId = projectile.getCellRef().getRefId(); + state.mIdArrow = projectile.getCellRef().getRefId(); state.mCasterHandle = actor; state.mAttackStrength = attackStrength; @@ -286,7 +285,7 @@ namespace MWWorld { if (result.mHit) { - MWWorld::ManualRef projectileRef(MWBase::Environment::get().getWorld()->getStore(), it->mId); + MWWorld::ManualRef projectileRef(MWBase::Environment::get().getWorld()->getStore(), it->mIdArrow); // Try to get a Ptr to the bow that was used. It might no longer exist. MWWorld::Ptr bow = projectileRef.getPtr(); @@ -338,7 +337,7 @@ namespace MWWorld writer.startRecord(ESM::REC_PROJ); ESM::ProjectileState state; - state.mId = it->mId; + state.mId = it->mIdArrow; state.mPosition = ESM::Vector3(osg::Vec3f(it->mNode->getPosition())); state.mOrientation = ESM::Quaternion(osg::Quat(it->mNode->getAttitude())); state.mActorId = it->mActorId; @@ -357,14 +356,14 @@ namespace MWWorld writer.startRecord(ESM::REC_MPRJ); ESM::MagicBoltState state; - state.mId = it->mId; + state.mId = it->mIdMagic.at(0); state.mPosition = ESM::Vector3(osg::Vec3f(it->mNode->getPosition())); state.mOrientation = ESM::Quaternion(osg::Quat(it->mNode->getAttitude())); state.mActorId = it->mActorId; state.mSpellId = it->mSpellId; state.mEffects = it->mEffects; - state.mSound = it->mSoundId; + state.mSound = it->mSoundId.at(0); state.mSourceName = it->mSourceName; state.mSpeed = it->mSpeed; state.mStack = it->mStack; @@ -386,7 +385,7 @@ namespace MWWorld state.mActorId = esm.mActorId; state.mBowId = esm.mBowId; state.mVelocity = esm.mVelocity; - state.mId = esm.mId; + state.mIdArrow = esm.mId; state.mAttackStrength = esm.mAttackStrength; std::string model; @@ -413,7 +412,7 @@ namespace MWWorld MagicBoltState state; state.mSourceName = esm.mSourceName; - state.mId = esm.mId; + state.mIdMagic.push_back(esm.mId); state.mSpellId = esm.mSpellId; state.mActorId = esm.mActorId; state.mSpeed = esm.mSpeed; @@ -437,7 +436,7 @@ namespace MWWorld MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); state.mSound = sndMgr->playSound3D(esm.mPosition, esm.mSound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop); - state.mSoundId = esm.mSound; + state.mSoundId.push_back(esm.mSound); mMagicBolts.push_back(state); return true; diff --git a/apps/openmw/mwworld/projectilemanager.hpp b/apps/openmw/mwworld/projectilemanager.hpp index 74d4c1dc53..709beb7cf8 100644 --- a/apps/openmw/mwworld/projectilemanager.hpp +++ b/apps/openmw/mwworld/projectilemanager.hpp @@ -49,7 +49,7 @@ namespace MWWorld MWRender::RenderingManager* rendering, MWPhysics::PhysicsSystem* physics); /// If caster is an actor, the actor's facing orientation is used. Otherwise fallbackDirection is used. - void launchMagicBolt (const std::string& model, const std::string &sound, const std::string &spellId, + void launchMagicBolt (const std::vector& models, const std::vector &sounds, const std::string &spellId, float speed, bool stack, const ESM::EffectList& effects, const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection); @@ -84,8 +84,11 @@ namespace MWWorld MWWorld::Ptr getCaster(); - // MW-id of this projectile - std::string mId; + // MW-ids of a magic projectile + std::vector mIdMagic; + + // MW-id of an arrow projectile + std::string mIdArrow; }; struct MagicBoltState : public State @@ -102,7 +105,7 @@ namespace MWWorld bool mStack; MWBase::SoundPtr mSound; - std::string mSoundId; + std::vector mSoundId; }; struct ProjectileState : public State diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 4448a9c178..7b27137e73 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2705,11 +2705,11 @@ namespace MWWorld mProjectileManager->launchProjectile(actor, projectile, worldPos, orient, bow, speed, attackStrength); } - void World::launchMagicBolt (const std::string& model, const std::string &sound, const std::string &spellId, + void World::launchMagicBolt (const std::vector &models, const std::vector &sounds, const std::string &spellId, float speed, bool stack, const ESM::EffectList& effects, const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection) { - mProjectileManager->launchMagicBolt(model, sound, spellId, speed, stack, effects, caster, sourceName, fallbackDirection); + mProjectileManager->launchMagicBolt(models, sounds, spellId, speed, stack, effects, caster, sourceName, fallbackDirection); } const std::vector& World::getContentFiles() const diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index da665e27cd..eb1ed24584 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -594,7 +594,7 @@ namespace MWWorld */ virtual void castSpell (const MWWorld::Ptr& actor); - virtual void launchMagicBolt (const std::string& model, const std::string& sound, const std::string& spellId, + virtual void launchMagicBolt (const std::vector& models, const std::vector& sounds, const std::string& spellId, float speed, bool stack, const ESM::EffectList& effects, const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection); virtual void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,