1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 18:15:37 +00:00

Change ActiveSpells to use ActorId

This commit is contained in:
scrawl 2014-05-14 07:14:08 +02:00
parent 67e942e733
commit dfacf8c044
11 changed files with 30 additions and 30 deletions

View file

@ -21,7 +21,7 @@ namespace MWGui
{ {
void EffectSourceVisitor::visit (MWMechanics::EffectKey key, void EffectSourceVisitor::visit (MWMechanics::EffectKey key,
const std::string& sourceName, const std::string& casterHandle, const std::string& sourceName, int casterActorId,
float magnitude, float remainingTime) float magnitude, float remainingTime)
{ {
MagicEffectInfo newEffectSource; MagicEffectInfo newEffectSource;

View file

@ -43,7 +43,7 @@ namespace MWGui
std::map <int, std::vector<MagicEffectInfo> > mEffectSources; std::map <int, std::vector<MagicEffectInfo> > mEffectSources;
virtual void visit (MWMechanics::EffectKey key, virtual void visit (MWMechanics::EffectKey key,
const std::string& sourceName, const std::string& casterHandle, const std::string& sourceName, int casterActorId,
float magnitude, float remainingTime = -1); float magnitude, float remainingTime = -1);
}; };

View file

@ -133,7 +133,7 @@ namespace MWMechanics
} }
void ActiveSpells::addSpell(const std::string &id, bool stack, std::vector<Effect> effects, void ActiveSpells::addSpell(const std::string &id, bool stack, std::vector<Effect> effects,
const std::string &displayName, const std::string& casterHandle) const std::string &displayName, int casterActorId)
{ {
bool exists = false; bool exists = false;
for (TContainer::const_iterator it = begin(); it != end(); ++it) for (TContainer::const_iterator it = begin(); it != end(); ++it)
@ -146,7 +146,7 @@ namespace MWMechanics
params.mTimeStamp = MWBase::Environment::get().getWorld()->getTimeStamp(); params.mTimeStamp = MWBase::Environment::get().getWorld()->getTimeStamp();
params.mEffects = effects; params.mEffects = effects;
params.mDisplayName = displayName; params.mDisplayName = displayName;
params.mCasterHandle = casterHandle; params.mCasterActorId = casterActorId;
if (!exists || stack) if (!exists || stack)
mSpells.insert (std::make_pair(id, params)); mSpells.insert (std::make_pair(id, params));
@ -178,7 +178,7 @@ namespace MWMechanics
float magnitude = effectIt->mMagnitude; float magnitude = effectIt->mMagnitude;
if (magnitude) if (magnitude)
visitor.visit(effectIt->mKey, name, it->second.mCasterHandle, magnitude, remainingTime); visitor.visit(effectIt->mKey, name, it->second.mCasterActorId, magnitude, remainingTime);
} }
} }
} }
@ -212,7 +212,7 @@ namespace MWMechanics
mSpellsChanged = true; mSpellsChanged = true;
} }
void ActiveSpells::purge(const std::string &actorHandle) void ActiveSpells::purge(int casterActorId)
{ {
for (TContainer::iterator it = mSpells.begin(); it != mSpells.end(); ++it) for (TContainer::iterator it = mSpells.begin(); it != mSpells.end(); ++it)
{ {
@ -221,7 +221,7 @@ namespace MWMechanics
{ {
const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectIt->mKey.mId); const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectIt->mKey.mId);
if (effect->mData.mFlags & ESM::MagicEffect::CasterLinked if (effect->mData.mFlags & ESM::MagicEffect::CasterLinked
&& it->second.mCasterHandle == actorHandle) && it->second.mCasterActorId == casterActorId)
effectIt = it->second.mEffects.erase(effectIt); effectIt = it->second.mEffects.erase(effectIt);
else else
++effectIt; ++effectIt;

View file

@ -37,8 +37,8 @@ namespace MWMechanics
MWWorld::TimeStamp mTimeStamp; MWWorld::TimeStamp mTimeStamp;
std::string mDisplayName; std::string mDisplayName;
// Handle to the caster that that inflicted this spell on us // The caster that inflicted this spell on us
std::string mCasterHandle; int mCasterActorId;
}; };
typedef std::multimap<std::string, ActiveSpellParams > TContainer; typedef std::multimap<std::string, ActiveSpellParams > TContainer;
@ -76,10 +76,9 @@ namespace MWMechanics
/// \param stack If false, the spell is not added if one with the same ID exists already. /// \param stack If false, the spell is not added if one with the same ID exists already.
/// \param effects /// \param effects
/// \param displayName Name for display in magic menu. /// \param displayName Name for display in magic menu.
/// \param casterHandle
/// ///
void addSpell (const std::string& id, bool stack, std::vector<Effect> effects, void addSpell (const std::string& id, bool stack, std::vector<Effect> effects,
const std::string& displayName, const std::string& casterHandle); const std::string& displayName, int casterActorId);
/// Removes the active effects from this spell/potion/.. with \a id /// Removes the active effects from this spell/potion/.. with \a id
void removeEffects (const std::string& id); void removeEffects (const std::string& id);
@ -90,8 +89,8 @@ namespace MWMechanics
/// Remove all active effects, if roll succeeds (for each effect) /// Remove all active effects, if roll succeeds (for each effect)
void purgeAll (float chance); void purgeAll (float chance);
/// Remove all effects with CASTER_LINKED flag that were cast by \a actorHandle /// Remove all effects with CASTER_LINKED flag that were cast by \a casterActorId
void purge (const std::string& actorHandle); void purge (int casterActorId);
bool isSpellActive (std::string id) const; bool isSpellActive (std::string id) const;
///< case insensitive ///< case insensitive

View file

@ -119,7 +119,7 @@ namespace MWMechanics
: mCreature(trappedCreature) {} : mCreature(trappedCreature) {}
virtual void visit (MWMechanics::EffectKey key, virtual void visit (MWMechanics::EffectKey key,
const std::string& sourceName, const std::string& casterHandle, const std::string& sourceName, int casterActorId,
float magnitude, float remainingTime = -1) float magnitude, float remainingTime = -1)
{ {
if (key.mId != ESM::MagicEffect::Soultrap) if (key.mId != ESM::MagicEffect::Soultrap)
@ -129,7 +129,7 @@ namespace MWMechanics
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::Ptr caster = world->searchPtrViaHandle(casterHandle); MWWorld::Ptr caster = world->searchPtrViaActorId(casterActorId);
if (caster.isEmpty() || !caster.getClass().isActor()) if (caster.isEmpty() || !caster.getClass().isActor())
return; return;
@ -938,18 +938,17 @@ namespace MWMechanics
continue; continue;
} }
// Make sure spell effects with CasterLinked flag are removed
// TODO: would be nice not to do this all the time...
for (PtrControllerMap::iterator iter2(mActors.begin());iter2 != mActors.end();++iter2)
{
MWMechanics::ActiveSpells& spells = iter2->first.getClass().getCreatureStats(iter2->first).getActiveSpells();
spells.purge(iter->first.getRefData().getHandle());
}
if (iter->second->kill()) if (iter->second->kill())
{ {
++mDeathCount[cls.getId(iter->first)]; ++mDeathCount[cls.getId(iter->first)];
// Make sure spell effects with CasterLinked flag are removed
for (PtrControllerMap::iterator iter2(mActors.begin());iter2 != mActors.end();++iter2)
{
MWMechanics::ActiveSpells& spells = iter2->first.getClass().getCreatureStats(iter2->first).getActiveSpells();
spells.purge(stats.getActorId());
}
// Apply soultrap // Apply soultrap
if (iter->first.getTypeName() == typeid(ESM::Creature).name()) if (iter->first.getTypeName() == typeid(ESM::Creature).name())
{ {

View file

@ -1372,9 +1372,9 @@ bool CharacterController::kill()
{ {
if( isDead() ) if( isDead() )
{ {
//player's death animation is over
if( mPtr.getRefData().getHandle()=="player" && !isAnimPlaying(mCurrentDeath) ) if( mPtr.getRefData().getHandle()=="player" && !isAnimPlaying(mCurrentDeath) )
{ {
//player's death animation is over
MWBase::Environment::get().getStateManager()->askLoadRecent(); MWBase::Environment::get().getStateManager()->askLoadRecent();
} }
return false; return false;

View file

@ -202,7 +202,9 @@ public:
void skipAnim(); void skipAnim();
bool isAnimPlaying(const std::string &groupName); bool isAnimPlaying(const std::string &groupName);
/// @return false if the character has already been killed before
bool kill(); bool kill();
void resurrect(); void resurrect();
bool isDead() const bool isDead() const
{ return mDeathState != CharState_None; } { return mDeathState != CharState_None; }

View file

@ -56,7 +56,7 @@ namespace MWMechanics
struct EffectSourceVisitor struct EffectSourceVisitor
{ {
virtual void visit (MWMechanics::EffectKey key, virtual void visit (MWMechanics::EffectKey key,
const std::string& sourceName, const std::string& casterHandle, const std::string& sourceName, int casterActorId,
float magnitude, float remainingTime = -1) = 0; float magnitude, float remainingTime = -1) = 0;
}; };

View file

@ -349,9 +349,9 @@ namespace MWMechanics
ActiveSpells::Effect effect_ = effect; ActiveSpells::Effect effect_ = effect;
effect_.mMagnitude *= -1; effect_.mMagnitude *= -1;
effects.push_back(effect_); effects.push_back(effect_);
// Also make sure to set casterHandle = target, so that the effect on the caster gets purged when the target dies // Also make sure to set casterActorId = target, so that the effect on the caster gets purged when the target dies
caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true, caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true,
effects, mSourceName, target.getRefData().getHandle()); effects, mSourceName, target.getClass().getCreatureStats(target).getActorId());
} }
} }
} }
@ -409,7 +409,7 @@ namespace MWMechanics
if (!appliedLastingEffects.empty()) if (!appliedLastingEffects.empty())
target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects, target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects,
mSourceName, caster.getRefData().getHandle()); mSourceName, caster.getClass().getCreatureStats(caster).getActorId());
// Notify the target actor they've been hit // Notify the target actor they've been hit
if (anyHarmfulEffect && target.getClass().isActor() && target != caster) if (anyHarmfulEffect && target.getClass().isActor() && target != caster)

View file

@ -211,7 +211,7 @@ namespace MWMechanics
random = it->second.at(i); random = it->second.at(i);
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * random; float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * random;
visitor.visit(MWMechanics::EffectKey(*effectIt), spell->mName, "", magnitude); visitor.visit(MWMechanics::EffectKey(*effectIt), spell->mName, -1, magnitude);
} }
} }
} }

View file

@ -599,7 +599,7 @@ void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisito
const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().mRefID][i]; const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().mRefID][i];
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * params.mRandom; float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * params.mRandom;
magnitude *= params.mMultiplier; magnitude *= params.mMultiplier;
visitor.visit(MWMechanics::EffectKey(*effectIt), (**iter).getClass().getName(**iter), "", magnitude); visitor.visit(MWMechanics::EffectKey(*effectIt), (**iter).getClass().getName(**iter), -1, magnitude);
++i; ++i;
} }