1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Teach AI how to use massive timed effects.

This commit is contained in:
AlexVinS
2016-09-05 14:17:46 +03:00
parent 82ac035340
commit 289cbbf2e7

View File

@ -482,11 +482,18 @@ void CBattleAI::attemptCastingSpell()
}
case TIMED_EFFECT:
{
StackWithBonuses swb;
swb.stack = cb->battleGetStackByPos(ps.dest);
if(!swb.stack)
auto stacksAffected = ps.spell->getAffectedStacks(cb.get(), ECastingMode::HERO_CASTING, hero, skillLevel, ps.dest);
if(stacksAffected.empty())
return -1;
int totalGain = 0;
for(const CStack * sta : stacksAffected)
{
StackWithBonuses swb;
swb.stack = sta;
Bonus pseudoBonus;
pseudoBonus.sid = ps.spell->id;
pseudoBonus.val = skillLevel;
@ -504,9 +511,14 @@ void CBattleAI::attemptCastingSpell()
gain = -gain;
LOGFL("Casting %s on %s would improve the stack by %d points (from %d to %d)",
ps.spell->name % swb.stack->nodeName() % gain % (oldValue) % (newValue));
ps.spell->name % sta->nodeName() % (gain) % (oldValue) % (newValue));
return gain;
totalGain += gain;
}
LOGFL("Total gain of cast %s at hex %d is %d", ps.spell->name % (ps.dest.hex) % (totalGain));
return totalGain;
}
default:
assert(0);