mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Teach AI how to use massive timed effects.
This commit is contained in:
parent
82ac035340
commit
289cbbf2e7
@ -482,31 +482,43 @@ void CBattleAI::attemptCastingSpell()
|
|||||||
}
|
}
|
||||||
case TIMED_EFFECT:
|
case TIMED_EFFECT:
|
||||||
{
|
{
|
||||||
StackWithBonuses swb;
|
auto stacksAffected = ps.spell->getAffectedStacks(cb.get(), ECastingMode::HERO_CASTING, hero, skillLevel, ps.dest);
|
||||||
swb.stack = cb->battleGetStackByPos(ps.dest);
|
|
||||||
if(!swb.stack)
|
if(stacksAffected.empty())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
Bonus pseudoBonus;
|
int totalGain = 0;
|
||||||
pseudoBonus.sid = ps.spell->id;
|
|
||||||
pseudoBonus.val = skillLevel;
|
|
||||||
pseudoBonus.turnsRemain = 1; //TODO
|
|
||||||
CStack::stackEffectToFeature(swb.bonusesToAdd, pseudoBonus);
|
|
||||||
|
|
||||||
HypotheticChangesToBattleState state;
|
for(const CStack * sta : stacksAffected)
|
||||||
state.bonusesOfStacks[swb.stack] = &swb;
|
{
|
||||||
|
StackWithBonuses swb;
|
||||||
|
swb.stack = sta;
|
||||||
|
|
||||||
PotentialTargets pt(swb.stack, state);
|
Bonus pseudoBonus;
|
||||||
auto newValue = pt.bestActionValue();
|
pseudoBonus.sid = ps.spell->id;
|
||||||
auto oldValue = valueOfStack[swb.stack];
|
pseudoBonus.val = skillLevel;
|
||||||
auto gain = newValue - oldValue;
|
pseudoBonus.turnsRemain = 1; //TODO
|
||||||
if(swb.stack->owner != playerID) //enemy
|
CStack::stackEffectToFeature(swb.bonusesToAdd, pseudoBonus);
|
||||||
gain = -gain;
|
|
||||||
|
|
||||||
LOGFL("Casting %s on %s would improve the stack by %d points (from %d to %d)",
|
HypotheticChangesToBattleState state;
|
||||||
ps.spell->name % swb.stack->nodeName() % gain % (oldValue) % (newValue));
|
state.bonusesOfStacks[swb.stack] = &swb;
|
||||||
|
|
||||||
return gain;
|
PotentialTargets pt(swb.stack, state);
|
||||||
|
auto newValue = pt.bestActionValue();
|
||||||
|
auto oldValue = valueOfStack[swb.stack];
|
||||||
|
auto gain = newValue - oldValue;
|
||||||
|
if(swb.stack->owner != playerID) //enemy
|
||||||
|
gain = -gain;
|
||||||
|
|
||||||
|
LOGFL("Casting %s on %s would improve the stack by %d points (from %d to %d)",
|
||||||
|
ps.spell->name % sta->nodeName() % (gain) % (oldValue) % (newValue));
|
||||||
|
|
||||||
|
totalGain += gain;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGFL("Total gain of cast %s at hex %d is %d", ps.spell->name % (ps.dest.hex) % (totalGain));
|
||||||
|
|
||||||
|
return totalGain;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user