1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Let AI do not self-destruct with armageddon too often.

This commit is contained in:
AlexVinS 2016-09-22 22:29:48 +03:00
parent 62d272f3e5
commit bd79298ca6

View File

@ -352,6 +352,7 @@ struct PossibleSpellcast
{ {
const CSpell *spell; const CSpell *spell;
BattleHex dest; BattleHex dest;
si32 value;
}; };
struct CurrentOffensivePotential struct CurrentOffensivePotential
@ -426,7 +427,7 @@ void CBattleAI::attemptCastingSpell()
{ {
for(auto hex : getTargetsToConsider(spell, hero)) for(auto hex : getTargetsToConsider(spell, hero))
{ {
PossibleSpellcast ps = {spell, hex}; PossibleSpellcast ps = {spell, hex, 0};
possibleCasts.push_back(ps); possibleCasts.push_back(ps);
} }
} }
@ -466,11 +467,10 @@ void CBattleAI::attemptCastingSpell()
damageDealt += dmg; damageDealt += dmg;
} }
const int damageDiff = damageDealt - damageReceived; const int damageDiff = damageDealt - damageReceived * 10;
LOGFL("Casting %s on hex %d would deal { %d %d } damage points among %d stacks.",
LOGFL("Casting %s on hex %d would deal %d damage points among %d stacks.", ps.spell->name % ps.dest % damageDealt % damageReceived % stacksSuffering.size());
ps.spell->name % ps.dest % damageDiff % stacksSuffering.size());
//TODO tactic effect too //TODO tactic effect too
return damageDiff; return damageDiff;
} }
@ -520,7 +520,15 @@ void CBattleAI::attemptCastingSpell()
} }
}; };
auto castToPerform = *vstd::maxElementByFun(possibleCasts, evaluateSpellcast); for(PossibleSpellcast & psc : possibleCasts)
psc.value = evaluateSpellcast(psc);
auto pscValue = [] (const PossibleSpellcast &ps) -> int
{
return ps.value;
};
auto castToPerform = *vstd::maxElementByFun(possibleCasts, pscValue);
LOGFL("Best spell is %s. Will cast.", castToPerform.spell->name); LOGFL("Best spell is %s. Will cast.", castToPerform.spell->name);
BattleAction spellcast; BattleAction spellcast;