Send lists of models and sounds to launchMagicBolt

pull/55/head
Allofich 8 years ago
parent 96e1726e4d
commit 10842462c7

@ -486,7 +486,7 @@ namespace MWBase
virtual void castSpell (const MWWorld::Ptr& actor) = 0; 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<std::string>& models, const std::vector<std::string>& sounds, const std::string& spellId,
float speed, bool stack, const ESM::EffectList& effects, float speed, bool stack, const ESM::EffectList& effects,
const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection) = 0; const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection) = 0;
virtual void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile, virtual void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,

@ -304,11 +304,12 @@ namespace MWMechanics
speed /= count; speed /= count;
std::string model; std::string model;
std::vector<std::string> models;
std::string sound; std::string sound;
std::vector<std::string> sounds;
ESM::EffectList projectileEffects;
osg::Vec3f fallbackDirection (0,1,0); osg::Vec3f fallbackDirection (0,1,0);
bool isFirstProjectile = true;
for (std::vector<ESM::ENAMstruct>::const_iterator iter (effects.mList.begin()); for (std::vector<ESM::ENAMstruct>::const_iterator iter (effects.mList.begin());
iter!=effects.mList.end(); ++iter) iter!=effects.mList.end(); ++iter)
@ -322,6 +323,7 @@ namespace MWMechanics
model = magicEffect->mBolt; model = magicEffect->mBolt;
if (model.empty()) if (model.empty())
model = "VFX_DefaultBolt"; model = "VFX_DefaultBolt";
models.push_back(model);
static const std::string schools[] = { static const std::string schools[] = {
"alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration"
@ -330,6 +332,9 @@ namespace MWMechanics
sound = magicEffect->mBoltSound; sound = magicEffect->mBoltSound;
else else
sound = schools[magicEffect->mData.mSchool] + " bolt"; 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 // 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) // (e.g. when cast by a non-actor)
@ -338,19 +343,8 @@ namespace MWMechanics
osg::Vec3f(mTarget.getRefData().getPosition().asVec3())- osg::Vec3f(mTarget.getRefData().getPosition().asVec3())-
osg::Vec3f(mCaster.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 MWBase::Environment::get().getWorld()->launchMagicBolt(models, sounds, mId, speed,
// playing multiple times. false, projectileEffects, mCaster, mSourceName, fallbackDirection);
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;
}
} }
void CastSpell::inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, void CastSpell::inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster,

@ -112,7 +112,7 @@ namespace MWWorld
state.mEffectAnimationTime->addTime(duration); state.mEffectAnimationTime->addTime(duration);
} }
void ProjectileManager::launchMagicBolt(const std::string &model, const std::string &sound, void ProjectileManager::launchMagicBolt(const std::vector<std::string> &models, const std::vector<std::string> &sounds,
const std::string &spellId, float speed, bool stack, const std::string &spellId, float speed, bool stack,
const ESM::EffectList &effects, const Ptr &caster, const std::string &sourceName, const ESM::EffectList &effects, const Ptr &caster, const std::string &sourceName,
const osg::Vec3f& fallbackDirection) const osg::Vec3f& fallbackDirection)
@ -137,7 +137,6 @@ namespace MWWorld
MagicBoltState state; MagicBoltState state;
state.mSourceName = sourceName; state.mSourceName = sourceName;
state.mId = model;
state.mSpellId = spellId; state.mSpellId = spellId;
state.mCasterHandle = caster; state.mCasterHandle = caster;
if (caster.getClass().isActor()) if (caster.getClass().isActor())
@ -146,23 +145,23 @@ namespace MWWorld
state.mActorId = -1; state.mActorId = -1;
state.mSpeed = speed; state.mSpeed = speed;
state.mStack = stack; state.mStack = stack;
state.mSoundId = sound; state.mIdMagic = models;
state.mSoundId = sounds;
// Only interested in "on target" effects // Should have already had non-projectile effects removed
for (std::vector<ESM::ENAMstruct>::const_iterator iter (effects.mList.begin()); state.mEffects = effects;
iter!=effects.mList.end(); ++iter)
{
if (iter->mRange == ESM::RT_Target)
state.mEffects.mList.push_back(*iter);
}
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), model); for (int iter = 0; iter != models.size(); ++iter)
MWWorld::Ptr ptr = ref.getPtr(); {
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); createModel(state, ptr.getClass().getModel(ptr), pos, orient, true);
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); 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); if (iter < sounds.size())
state.mSound = sndMgr->playSound3D(pos, sounds.at(iter), 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop);
}
mMagicBolts.push_back(state); mMagicBolts.push_back(state);
} }
@ -173,7 +172,7 @@ namespace MWWorld
state.mActorId = actor.getClass().getCreatureStats(actor).getActorId(); state.mActorId = actor.getClass().getCreatureStats(actor).getActorId();
state.mBowId = bow.getCellRef().getRefId(); state.mBowId = bow.getCellRef().getRefId();
state.mVelocity = orient * osg::Vec3f(0,1,0) * speed; state.mVelocity = orient * osg::Vec3f(0,1,0) * speed;
state.mId = projectile.getCellRef().getRefId(); state.mIdArrow = projectile.getCellRef().getRefId();
state.mCasterHandle = actor; state.mCasterHandle = actor;
state.mAttackStrength = attackStrength; state.mAttackStrength = attackStrength;
@ -286,7 +285,7 @@ namespace MWWorld
{ {
if (result.mHit) 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. // Try to get a Ptr to the bow that was used. It might no longer exist.
MWWorld::Ptr bow = projectileRef.getPtr(); MWWorld::Ptr bow = projectileRef.getPtr();
@ -338,7 +337,7 @@ namespace MWWorld
writer.startRecord(ESM::REC_PROJ); writer.startRecord(ESM::REC_PROJ);
ESM::ProjectileState state; ESM::ProjectileState state;
state.mId = it->mId; state.mId = it->mIdArrow;
state.mPosition = ESM::Vector3(osg::Vec3f(it->mNode->getPosition())); state.mPosition = ESM::Vector3(osg::Vec3f(it->mNode->getPosition()));
state.mOrientation = ESM::Quaternion(osg::Quat(it->mNode->getAttitude())); state.mOrientation = ESM::Quaternion(osg::Quat(it->mNode->getAttitude()));
state.mActorId = it->mActorId; state.mActorId = it->mActorId;
@ -357,14 +356,14 @@ namespace MWWorld
writer.startRecord(ESM::REC_MPRJ); writer.startRecord(ESM::REC_MPRJ);
ESM::MagicBoltState state; ESM::MagicBoltState state;
state.mId = it->mId; state.mId = it->mIdMagic.at(0);
state.mPosition = ESM::Vector3(osg::Vec3f(it->mNode->getPosition())); state.mPosition = ESM::Vector3(osg::Vec3f(it->mNode->getPosition()));
state.mOrientation = ESM::Quaternion(osg::Quat(it->mNode->getAttitude())); state.mOrientation = ESM::Quaternion(osg::Quat(it->mNode->getAttitude()));
state.mActorId = it->mActorId; state.mActorId = it->mActorId;
state.mSpellId = it->mSpellId; state.mSpellId = it->mSpellId;
state.mEffects = it->mEffects; state.mEffects = it->mEffects;
state.mSound = it->mSoundId; state.mSound = it->mSoundId.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;
@ -386,7 +385,7 @@ namespace MWWorld
state.mActorId = esm.mActorId; state.mActorId = esm.mActorId;
state.mBowId = esm.mBowId; state.mBowId = esm.mBowId;
state.mVelocity = esm.mVelocity; state.mVelocity = esm.mVelocity;
state.mId = esm.mId; state.mIdArrow = esm.mId;
state.mAttackStrength = esm.mAttackStrength; state.mAttackStrength = esm.mAttackStrength;
std::string model; std::string model;
@ -413,7 +412,7 @@ namespace MWWorld
MagicBoltState state; MagicBoltState state;
state.mSourceName = esm.mSourceName; state.mSourceName = esm.mSourceName;
state.mId = esm.mId; state.mIdMagic.push_back(esm.mId);
state.mSpellId = esm.mSpellId; state.mSpellId = esm.mSpellId;
state.mActorId = esm.mActorId; state.mActorId = esm.mActorId;
state.mSpeed = esm.mSpeed; state.mSpeed = esm.mSpeed;
@ -437,7 +436,7 @@ namespace MWWorld
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
state.mSound = sndMgr->playSound3D(esm.mPosition, esm.mSound, 1.0f, 1.0f, state.mSound = sndMgr->playSound3D(esm.mPosition, esm.mSound, 1.0f, 1.0f,
MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop); MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Loop);
state.mSoundId = esm.mSound; state.mSoundId.push_back(esm.mSound);
mMagicBolts.push_back(state); mMagicBolts.push_back(state);
return true; return true;

@ -49,7 +49,7 @@ namespace MWWorld
MWRender::RenderingManager* rendering, MWPhysics::PhysicsSystem* physics); MWRender::RenderingManager* rendering, MWPhysics::PhysicsSystem* physics);
/// If caster is an actor, the actor's facing orientation is used. Otherwise fallbackDirection is used. /// 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<std::string>& models, const std::vector<std::string> &sounds, const std::string &spellId,
float speed, bool stack, const ESM::EffectList& effects, float speed, bool stack, const ESM::EffectList& effects,
const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection); const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection);
@ -84,8 +84,11 @@ namespace MWWorld
MWWorld::Ptr getCaster(); MWWorld::Ptr getCaster();
// MW-id of this projectile // MW-ids of a magic projectile
std::string mId; std::vector<std::string> mIdMagic;
// MW-id of an arrow projectile
std::string mIdArrow;
}; };
struct MagicBoltState : public State struct MagicBoltState : public State
@ -102,7 +105,7 @@ namespace MWWorld
bool mStack; bool mStack;
MWBase::SoundPtr mSound; MWBase::SoundPtr mSound;
std::string mSoundId; std::vector<std::string> mSoundId;
}; };
struct ProjectileState : public State struct ProjectileState : public State

@ -2705,11 +2705,11 @@ namespace MWWorld
mProjectileManager->launchProjectile(actor, projectile, worldPos, orient, bow, speed, attackStrength); 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<std::string> &models, const std::vector<std::string> &sounds, const std::string &spellId,
float speed, bool stack, const ESM::EffectList& effects, float speed, bool stack, const ESM::EffectList& effects,
const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection) 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<std::string>& World::getContentFiles() const const std::vector<std::string>& World::getContentFiles() const

@ -594,7 +594,7 @@ namespace MWWorld
*/ */
virtual void castSpell (const MWWorld::Ptr& actor); 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<std::string>& models, const std::vector<std::string>& sounds, const std::string& spellId,
float speed, bool stack, const ESM::EffectList& effects, float speed, bool stack, const ESM::EffectList& effects,
const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection); const MWWorld::Ptr& caster, const std::string& sourceName, const osg::Vec3f& fallbackDirection);
virtual void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile, virtual void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,

Loading…
Cancel
Save