Add loading code for multi-effect projectiles

coverity_scan^2
Allofich 8 years ago
parent c6cd1f813b
commit dbd7c038b2

@ -304,9 +304,7 @@ namespace MWMechanics
if (count != 0) if (count != 0)
speed /= count; speed /= count;
std::string projectileID;
std::vector<std::string> projectileIDs; std::vector<std::string> projectileIDs;
std::string sound;
std::vector<std::string> sounds; std::vector<std::string> sounds;
ESM::EffectList projectileEffects; ESM::EffectList projectileEffects;
@ -321,23 +319,22 @@ namespace MWMechanics
const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find ( const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find (
iter->mEffectID); iter->mEffectID);
projectileID = magicEffect->mBolt; if (magicEffect->mBolt.empty())
if (projectileID.empty()) projectileIDs.push_back("VFX_DefaultBolt");
projectileID = "VFX_DefaultBolt"; else
projectileIDs.push_back(projectileID); projectileIDs.push_back(magicEffect->mBolt);
static const std::string schools[] = { static const std::string schools[] = {
"alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration"
}; };
if (!magicEffect->mBoltSound.empty()) if (!magicEffect->mBoltSound.empty())
sound = magicEffect->mBoltSound; sounds.push_back(magicEffect->mBoltSound);
else else
sound = schools[magicEffect->mData.mSchool] + " bolt"; sounds.push_back(schools[magicEffect->mData.mSchool] + " bolt");
sounds.push_back(sound);
projectileEffects.mList.push_back(*iter); 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; std::ostringstream ID;
ID << "VFX_Multiple" << projectileEffects.mList.size(); ID << "VFX_Multiple" << projectileEffects.mList.size();

@ -1296,14 +1296,13 @@ namespace MWRender
void Animation::addEffect (const std::string& model, int effectId, bool loop, const std::string& bonename, std::string texture) void Animation::addEffect (const std::string& model, int effectId, bool loop, const std::string& bonename, std::string texture)
{ {
if (!mObjectRoot.get()) if (!mObjectRoot.get())
{
std::cout << "no objectroot" << std::endl;
return; return;
}
// Early out if we already have this effect // Early out if we already have this effect
for (std::vector<EffectParams>::iterator it = mEffects.begin(); it != mEffects.end(); ++it) for (std::vector<EffectParams>::iterator it = mEffects.begin(); it != mEffects.end(); ++it)
if (it->mLoop && loop && it->mEffectId == effectId && it->mBoneName == bonename) if (it->mLoop && loop && it->mEffectId == effectId && it->mBoneName == bonename)
return; return;
EffectParams params; EffectParams params;
params.mModelName = model; params.mModelName = model;
osg::ref_ptr<osg::Group> parentNode; osg::ref_ptr<osg::Group> parentNode;

@ -160,7 +160,7 @@ namespace MWWorld
state.mSpeed = speed; state.mSpeed = speed;
state.mStack = stack; state.mStack = stack;
state.mIdMagic = projectileIDs; state.mIdMagic = projectileIDs;
state.mSoundId = sounds; state.mSoundIds = sounds;
// Should have already had non-projectile effects removed // Should have already had non-projectile effects removed
state.mEffects = effects; state.mEffects = effects;
@ -173,7 +173,7 @@ namespace MWWorld
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
for (size_t it = 0; it != sounds.size(); it++) 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); mMagicBolts.push_back(state);
@ -217,9 +217,9 @@ namespace MWWorld
osg::Vec3f pos(it->mNode->getPosition()); osg::Vec3f pos(it->mNode->getPosition());
osg::Vec3f newPos = pos + direction * duration * speed; 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); it->mNode->setPosition(newPos);
@ -260,9 +260,9 @@ namespace MWWorld
MWBase::Environment::get().getWorld()->explodeSpell(pos, it->mEffects, caster, result.mHitObject, MWBase::Environment::get().getWorld()->explodeSpell(pos, it->mEffects, caster, result.mHitObject,
ESM::RT_Target, it->mSpellId, it->mSourceName); 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); mParent->removeChild(it->mNode);
@ -344,9 +344,9 @@ namespace MWWorld
for (std::vector<MagicBoltState>::iterator it = mMagicBolts.begin(); it != mMagicBolts.end(); ++it) for (std::vector<MagicBoltState>::iterator it = mMagicBolts.begin(); it != mMagicBolts.end(); ++it)
{ {
mParent->removeChild(it->mNode); 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(); mMagicBolts.clear();
@ -385,7 +385,7 @@ namespace MWWorld
state.mSpellId = it->mSpellId; state.mSpellId = it->mSpellId;
state.mEffects = it->mEffects; state.mEffects = it->mEffects;
state.mSound = it->mSoundId.at(0); state.mSound = it->mSoundIds.at(0);
state.mSourceName = it->mSourceName; state.mSourceName = it->mSourceName;
state.mSpeed = it->mSpeed; state.mSpeed = it->mSpeed;
state.mStack = it->mStack; state.mStack = it->mStack;
@ -441,10 +441,41 @@ namespace MWWorld
state.mStack = esm.mStack; state.mStack = esm.mStack;
state.mEffects = esm.mEffects; state.mEffects = esm.mEffects;
std::string projectileID;
std::vector<std::string> 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<ESM::ENAMstruct>::const_iterator iter (esm.mEffects.mList.begin());
iter != esm.mEffects.mList.end(); ++iter)
{
const ESM::MagicEffect *magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().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; std::string model;
try 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(); MWWorld::Ptr ptr = ref.getPtr();
model = ptr.getClass().getModel(ptr); model = ptr.getClass().getModel(ptr);
} }
@ -456,9 +487,12 @@ namespace MWWorld
createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true); createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true);
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); 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)); for (size_t soundIter = 0; soundIter != state.mSoundIds.size(); soundIter++)
state.mSoundId.push_back(esm.mSound); {
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); mMagicBolts.push_back(state);
return true; return true;

@ -104,8 +104,8 @@ namespace MWWorld
bool mStack; bool mStack;
std::vector<MWBase::SoundPtr> mSound; std::vector<MWBase::SoundPtr> mSounds;
std::vector<std::string> mSoundId; std::vector<std::string> mSoundIds;
}; };
struct ProjectileState : public State struct ProjectileState : public State

Loading…
Cancel
Save