From dbd7c038b28d19bf74a7cbdc7313ade95316b536 Mon Sep 17 00:00:00 2001 From: Allofich Date: Mon, 5 Sep 2016 03:31:48 +0900 Subject: [PATCH] Add loading code for multi-effect projectiles --- apps/openmw/mwmechanics/spellcasting.cpp | 17 +++---- apps/openmw/mwrender/animation.cpp | 5 +- apps/openmw/mwworld/projectilemanager.cpp | 60 ++++++++++++++++++----- apps/openmw/mwworld/projectilemanager.hpp | 4 +- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index cb4e04fa1..8736379f2 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -304,9 +304,7 @@ namespace MWMechanics if (count != 0) speed /= count; - std::string projectileID; std::vector projectileIDs; - std::string sound; std::vector sounds; ESM::EffectList projectileEffects; @@ -321,23 +319,22 @@ namespace MWMechanics const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find ( iter->mEffectID); - projectileID = magicEffect->mBolt; - if (projectileID.empty()) - projectileID = "VFX_DefaultBolt"; - projectileIDs.push_back(projectileID); + if (magicEffect->mBolt.empty()) + projectileIDs.push_back("VFX_DefaultBolt"); + else + projectileIDs.push_back(magicEffect->mBolt); static const std::string schools[] = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; if (!magicEffect->mBoltSound.empty()) - sound = magicEffect->mBoltSound; + sounds.push_back(magicEffect->mBoltSound); else - sound = schools[magicEffect->mData.mSchool] + " bolt"; - sounds.push_back(sound); + sounds.push_back(schools[magicEffect->mData.mSchool] + " bolt"); projectileEffects.mList.push_back(*iter); } - if (projectileEffects.mList.size() > 1) // add a VFX_Multiple projectile if there are multiple projectile effects + if (projectileEffects.mList.size() > 1) // insert a VFX_Multiple projectile if there are multiple projectile effects { std::ostringstream ID; ID << "VFX_Multiple" << projectileEffects.mList.size(); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c65e5bc85..386a4a53b 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1296,14 +1296,13 @@ namespace MWRender void Animation::addEffect (const std::string& model, int effectId, bool loop, const std::string& bonename, std::string texture) { if (!mObjectRoot.get()) - { - std::cout << "no objectroot" << std::endl; return; - } + // Early out if we already have this effect for (std::vector::iterator it = mEffects.begin(); it != mEffects.end(); ++it) if (it->mLoop && loop && it->mEffectId == effectId && it->mBoneName == bonename) return; + EffectParams params; params.mModelName = model; osg::ref_ptr parentNode; diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index d55173ee4..ffb2063c2 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -160,7 +160,7 @@ namespace MWWorld state.mSpeed = speed; state.mStack = stack; state.mIdMagic = projectileIDs; - state.mSoundId = sounds; + state.mSoundIds = sounds; // Should have already had non-projectile effects removed state.mEffects = effects; @@ -173,7 +173,7 @@ namespace MWWorld MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); for (size_t it = 0; it != sounds.size(); it++) { - state.mSound.push_back(sndMgr->playSound3D(pos, sounds.at(it), 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop)); + state.mSounds.push_back(sndMgr->playSound3D(pos, sounds.at(it), 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop)); } mMagicBolts.push_back(state); @@ -217,9 +217,9 @@ namespace MWWorld osg::Vec3f pos(it->mNode->getPosition()); osg::Vec3f newPos = pos + direction * duration * speed; - for (size_t soundIter = 0; soundIter != it->mSound.size(); soundIter++) + for (size_t soundIter = 0; soundIter != it->mSounds.size(); soundIter++) { - it->mSound.at(soundIter)->setPosition(newPos); + it->mSounds.at(soundIter)->setPosition(newPos); } it->mNode->setPosition(newPos); @@ -260,9 +260,9 @@ namespace MWWorld MWBase::Environment::get().getWorld()->explodeSpell(pos, it->mEffects, caster, result.mHitObject, ESM::RT_Target, it->mSpellId, it->mSourceName); - for (size_t soundIter = 0; soundIter != it->mSound.size(); soundIter++) + for (size_t soundIter = 0; soundIter != it->mSounds.size(); soundIter++) { - MWBase::Environment::get().getSoundManager()->stopSound(it->mSound.at(soundIter)); + MWBase::Environment::get().getSoundManager()->stopSound(it->mSounds.at(soundIter)); } mParent->removeChild(it->mNode); @@ -344,9 +344,9 @@ namespace MWWorld for (std::vector::iterator it = mMagicBolts.begin(); it != mMagicBolts.end(); ++it) { mParent->removeChild(it->mNode); - for (size_t soundIter = 0; soundIter != it->mSound.size(); soundIter++) + for (size_t soundIter = 0; soundIter != it->mSounds.size(); soundIter++) { - MWBase::Environment::get().getSoundManager()->stopSound(it->mSound.at(soundIter)); + MWBase::Environment::get().getSoundManager()->stopSound(it->mSounds.at(soundIter)); } } mMagicBolts.clear(); @@ -385,7 +385,7 @@ namespace MWWorld state.mSpellId = it->mSpellId; state.mEffects = it->mEffects; - state.mSound = it->mSoundId.at(0); + state.mSound = it->mSoundIds.at(0); state.mSourceName = it->mSourceName; state.mSpeed = it->mSpeed; state.mStack = it->mStack; @@ -441,10 +441,41 @@ namespace MWWorld state.mStack = esm.mStack; state.mEffects = esm.mEffects; + std::string projectileID; + std::vector projectileIDs; + + if (esm.mEffects.mList.size() > 1) + { + std::ostringstream ID; + ID << "VFX_Multiple" << esm.mEffects.mList.size(); + state.mIdMagic.push_back(ID.str()); + } + + for (std::vector::const_iterator iter (esm.mEffects.mList.begin()); + iter != esm.mEffects.mList.end(); ++iter) + { + const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find ( + iter->mEffectID); + + projectileID = magicEffect->mBolt; + if (projectileID.empty()) + projectileID = "VFX_DefaultBolt"; + state.mIdMagic.push_back(projectileID); + + static const std::string schools[] = { + "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" + }; + + if (!magicEffect->mBoltSound.empty()) + state.mSoundIds.push_back(magicEffect->mBoltSound); + else + state.mSoundIds.push_back(schools[magicEffect->mData.mSchool] + " bolt"); + } + std::string model; try { - MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), esm.mId); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), state.mIdMagic.at(0)); MWWorld::Ptr ptr = ref.getPtr(); model = ptr.getClass().getModel(ptr); } @@ -456,9 +487,12 @@ namespace MWWorld createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true); MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); - state.mSound.push_back(sndMgr->playSound3D(esm.mPosition, esm.mSound, 1.0f, 1.0f, - MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop)); - state.mSoundId.push_back(esm.mSound); + + for (size_t soundIter = 0; soundIter != state.mSoundIds.size(); soundIter++) + { + state.mSounds.push_back(sndMgr->playSound3D(esm.mPosition, state.mSoundIds.at(soundIter), 1.0f, 1.0f, + MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop)); + } mMagicBolts.push_back(state); return true; diff --git a/apps/openmw/mwworld/projectilemanager.hpp b/apps/openmw/mwworld/projectilemanager.hpp index 8d330d5a8..46a6b10de 100644 --- a/apps/openmw/mwworld/projectilemanager.hpp +++ b/apps/openmw/mwworld/projectilemanager.hpp @@ -104,8 +104,8 @@ namespace MWWorld bool mStack; - std::vector mSound; - std::vector mSoundId; + std::vector mSounds; + std::vector mSoundIds; }; struct ProjectileState : public State