mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-14 10:12:59 +02:00
Update BattleEvaluator.cpp
Restored spell-damage-calculations for units that would die from spells.
This commit is contained in:
parent
533806df6d
commit
c838f5d0c2
@ -731,7 +731,55 @@ bool BattleEvaluator::attemptCastingSpell(const CStack * activeStack)
|
||||
|
||||
ps.value = scoreEvaluator.evaluateExchange(updatedAttack, cachedAttack.turn, *targets, innerCache, state);
|
||||
}
|
||||
|
||||
//! Some units may be dead alltogether. So if they existed before but not now, we know they were killed by the spell
|
||||
for (const auto& unit : all)
|
||||
{
|
||||
if (!unit->isValidTarget())
|
||||
continue;
|
||||
bool isDead = true;
|
||||
for (const auto& remainingUnit : allUnits)
|
||||
{
|
||||
if (remainingUnit->unitId() == unit->unitId())
|
||||
isDead = false;
|
||||
}
|
||||
if (isDead)
|
||||
{
|
||||
auto newHealth = 0;
|
||||
auto oldHealth = vstd::find_or(healthOfStack, unit->unitId(), 0);
|
||||
if (oldHealth != newHealth)
|
||||
{
|
||||
auto damage = std::abs(oldHealth - newHealth);
|
||||
auto originalDefender = cb->getBattle(battleID)->battleGetUnitByID(unit->unitId());
|
||||
auto dpsReduce = AttackPossibility::calculateDamageReduce(
|
||||
nullptr,
|
||||
originalDefender && originalDefender->alive() ? originalDefender : unit,
|
||||
damage,
|
||||
innerCache,
|
||||
state);
|
||||
auto ourUnit = unit->unitSide() == side ? 1 : -1;
|
||||
auto goodEffect = newHealth > oldHealth ? 1 : -1;
|
||||
if (ourUnit * goodEffect == 1)
|
||||
{
|
||||
if (ourUnit && goodEffect && (unit->isClone() || unit->isGhost()))
|
||||
continue;
|
||||
ps.value += dpsReduce * scoreEvaluator.getPositiveEffectMultiplier();
|
||||
}
|
||||
else
|
||||
ps.value -= dpsReduce * scoreEvaluator.getNegativeEffectMultiplier();
|
||||
#if BATTLE_TRACE_LEVEL >= 1
|
||||
logAi->trace(
|
||||
"Spell %s to %d affects %s (%d), dps: %2f oldHealth: %d newHealth: %d",
|
||||
ps.spell->getNameTranslated(),
|
||||
ps.dest.at(0).hexValue.hex,
|
||||
unit->creatureId().toCreature()->getNameSingularTranslated(),
|
||||
unit->getCount(),
|
||||
dpsReduce,
|
||||
oldHealth,
|
||||
newHealth);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
for(const auto & unit : allUnits)
|
||||
{
|
||||
if(!unit->isValidTarget(true))
|
||||
|
Loading…
Reference in New Issue
Block a user