mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-11 13:06:56 +03:00
Simplify restore magicka priority
This commit is contained in:
parent
7c82405c9f
commit
ee92ae7e34
1 changed files with 7 additions and 16 deletions
|
@ -89,25 +89,19 @@ namespace
|
||||||
}) != active.end();
|
}) != active.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
float getRestoreMagickaPriority(const ESM::ENAMstruct& effect, const MWWorld::Ptr& actor, const MWWorld::Ptr& enemy)
|
float getRestoreMagickaPriority(const MWWorld::Ptr& actor)
|
||||||
{
|
{
|
||||||
const MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
const MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
||||||
const MWMechanics::DynamicStat<float>& current = stats.getMagicka();
|
const MWMechanics::DynamicStat<float>& current = stats.getMagicka();
|
||||||
const float magnitude = (effect.mMagnMin + effect.mMagnMax) / 2.f;
|
|
||||||
const float toHeal = magnitude * std::max(1, effect.mDuration);
|
|
||||||
float priority = 0.f;
|
|
||||||
for (const ESM::Spell* spell : stats.getSpells())
|
for (const ESM::Spell* spell : stats.getSpells())
|
||||||
{
|
{
|
||||||
auto found = std::find_if(spell->mEffects.mList.begin(), spell->mEffects.mList.end(),
|
if (spell->mData.mType != ESM::Spell::ST_Spell)
|
||||||
[&](const auto& e) { return &e == &effect; });
|
|
||||||
if (found != spell->mEffects.mList.end()) // Prevent recursion
|
|
||||||
continue;
|
continue;
|
||||||
int cost = MWMechanics::calcSpellCost(*spell);
|
int cost = MWMechanics::calcSpellCost(*spell);
|
||||||
if (cost < current.getCurrent() || cost > current.getCurrent() + toHeal)
|
if (cost > current.getCurrent() && cost < current.getModified())
|
||||||
continue;
|
return 2.f;
|
||||||
priority = std::max(priority, MWMechanics::rateSpell(spell, actor, enemy, false));
|
|
||||||
}
|
}
|
||||||
return priority;
|
return 0.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,10 +429,7 @@ namespace MWMechanics
|
||||||
if (!enemy.isEmpty() && enemy.getClass().getCreatureStats(enemy).getMagicka().getCurrent() <= 0.f)
|
if (!enemy.isEmpty() && enemy.getClass().getCreatureStats(enemy).getMagicka().getCurrent() <= 0.f)
|
||||||
{
|
{
|
||||||
rating = 0.5f;
|
rating = 0.5f;
|
||||||
float priority = getRestoreMagickaPriority(effect, actor, enemy);
|
rating *= getRestoreMagickaPriority(actor);
|
||||||
if (priority == 0.f)
|
|
||||||
priority = -1.f;
|
|
||||||
rating *= priority;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ESM::MagicEffect::RestoreHealth:
|
case ESM::MagicEffect::RestoreHealth:
|
||||||
|
@ -457,7 +448,7 @@ namespace MWMechanics
|
||||||
if (effect.mEffectID == ESM::MagicEffect::RestoreHealth)
|
if (effect.mEffectID == ESM::MagicEffect::RestoreHealth)
|
||||||
priority = 4.f;
|
priority = 4.f;
|
||||||
else if (effect.mEffectID == ESM::MagicEffect::RestoreMagicka)
|
else if (effect.mEffectID == ESM::MagicEffect::RestoreMagicka)
|
||||||
priority = std::max(0.1f, getRestoreMagickaPriority(effect, actor, enemy));
|
priority = std::max(0.1f, getRestoreMagickaPriority(actor));
|
||||||
else if (effect.mEffectID == ESM::MagicEffect::RestoreFatigue)
|
else if (effect.mEffectID == ESM::MagicEffect::RestoreFatigue)
|
||||||
priority = 2.f;
|
priority = 2.f;
|
||||||
float overheal = 0.f;
|
float overheal = 0.f;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue