From 37f07f74353905201c77347c9f0e09e9551493e9 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sun, 4 Sep 2016 17:39:14 +0900 Subject: [PATCH] Combine into one multi-effect magic projectile --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwmechanics/spellcasting.cpp | 40 +++++++++++++++-------- apps/openmw/mwrender/animation.cpp | 5 +-- apps/openmw/mwworld/projectilemanager.cpp | 30 ++++++++++------- apps/openmw/mwworld/projectilemanager.hpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 4 +-- apps/openmw/mwworld/worldimp.hpp | 2 +- 7 files changed, 53 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 8dda90b64..4737a0e22 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::vector& models, const std::vector& sounds, const std::string& spellId, + virtual void launchMagicBolt (const std::vector& projectileIDs, 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 734509b6b..654e4b51b 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -303,8 +303,8 @@ namespace MWMechanics if (count != 0) speed /= count; - std::string model; - std::vector models; + std::string projectileID; + std::vector projectileIDs; std::string sound; std::vector sounds; ESM::EffectList projectileEffects; @@ -320,10 +320,10 @@ namespace MWMechanics const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find ( iter->mEffectID); - model = magicEffect->mBolt; - if (model.empty()) - model = "VFX_DefaultBolt"; - models.push_back(model); + projectileID = magicEffect->mBolt; + if (projectileID.empty()) + projectileID = "VFX_DefaultBolt"; + projectileIDs.push_back(projectileID); static const std::string schools[] = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" @@ -335,16 +335,28 @@ namespace MWMechanics sounds.push_back(sound); projectileEffects.mList.push_back(*iter); } + + if (projectileEffects.mList.size() > 1) // add a VFX_Multiple projectile if there are multiple projectile effects + { + std::vector::iterator it; + it = projectileIDs.begin(); + char numstr[8]; + sprintf(numstr, "%zd", (effects.mList.size())); + std::string ID = "VFX_Multiple"; + ID = ID + numstr; + it = projectileIDs.insert(it, ID); + } - // 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()) - fallbackDirection = - osg::Vec3f(mTarget.getRefData().getPosition().asVec3())- - osg::Vec3f(mCaster.getRefData().getPosition().asVec3()); + // 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()) + fallbackDirection = + osg::Vec3f(mTarget.getRefData().getPosition().asVec3())- + osg::Vec3f(mCaster.getRefData().getPosition().asVec3()); - MWBase::Environment::get().getWorld()->launchMagicBolt(models, sounds, mId, speed, - false, projectileEffects, mCaster, mSourceName, fallbackDirection); + if (!projectileEffects.mList.empty()) + MWBase::Environment::get().getWorld()->launchMagicBolt(projectileIDs, sounds, mId, speed, + false, projectileEffects, mCaster, mSourceName, fallbackDirection); } void CastSpell::inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 386a4a53b..c65e5bc85 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1296,13 +1296,14 @@ 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 0825be3c3..1e7b82836 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -94,6 +94,17 @@ namespace MWWorld mResourceSystem->getSceneManager()->getInstance(model, attachTo); + if (state.mIdMagic.size() > 1) + for (size_t iter = 1; iter != state.mIdMagic.size(); ++iter) + { + char numstr[8]; + sprintf(numstr, "%zd", iter); + std::string node = "Dummy0"; + node = node + numstr; + const ESM::Weapon* weapon = MWBase::Environment::get().getWorld()->getStore().get().find (state.mIdMagic.at(iter)); + mResourceSystem->getSceneManager()->getInstance("meshes\\" + weapon->mModel, attachTo); + } + SceneUtil::DisableFreezeOnCullVisitor disableFreezeOnCullVisitor; state.mNode->accept(disableFreezeOnCullVisitor); @@ -112,7 +123,7 @@ namespace MWWorld state.mEffectAnimationTime->addTime(duration); } - void ProjectileManager::launchMagicBolt(const std::vector &models, const std::vector &sounds, + void ProjectileManager::launchMagicBolt(const std::vector &projectileIDs, 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) @@ -145,23 +156,20 @@ namespace MWWorld state.mActorId = -1; state.mSpeed = speed; state.mStack = stack; - state.mIdMagic = models; + state.mIdMagic = projectileIDs; state.mSoundId = sounds; // Should have already had non-projectile effects removed state.mEffects = effects; - for (int iter = 0; iter != models.size(); ++iter) - { - MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), models.at(iter)); - MWWorld::Ptr ptr = ref.getPtr(); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectileIDs.at(0)); + MWWorld::Ptr ptr = ref.getPtr(); - createModel(state, ptr.getClass().getModel(ptr), pos, orient, true); + 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); - } + MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); + if (projectileIDs.size() == 1) + state.mSound = sndMgr->playSound3D(pos, sounds.at(0), 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop); mMagicBolts.push_back(state); } diff --git a/apps/openmw/mwworld/projectilemanager.hpp b/apps/openmw/mwworld/projectilemanager.hpp index 709beb7cf..63bcb70b9 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::vector& models, const std::vector &sounds, const std::string &spellId, + void launchMagicBolt (const std::vector& projectileIDs, 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); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7b27137e7..cf5845adf 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::vector &models, const std::vector &sounds, const std::string &spellId, + void World::launchMagicBolt (const std::vector &projectileIDs, 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(models, sounds, spellId, speed, stack, effects, caster, sourceName, fallbackDirection); + mProjectileManager->launchMagicBolt(projectileIDs, 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 eb1ed2458..f26e2b9c0 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::vector& models, const std::vector& sounds, const std::string& spellId, + virtual void launchMagicBolt (const std::vector& projectileIDs, 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,