mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Probably fixed crash when AI finish battle with spell
This commit is contained in:
parent
21de5817e3
commit
fb384d83b8
@ -103,11 +103,6 @@ void CBattleAI::init(std::shared_ptr<CBattleCallback> CB)
|
||||
CB->unlockGsWhenWaiting = false;
|
||||
}
|
||||
|
||||
static bool thereRemainsEnemy()
|
||||
{
|
||||
return !cbc->battleIsFinished();
|
||||
}
|
||||
|
||||
BattleAction CBattleAI::activeStack( const CStack * stack )
|
||||
{
|
||||
LOG_TRACE_PARAMS(logAi, "stack: %s", stack->nodeName()) ;
|
||||
@ -136,21 +131,20 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
|
||||
if(cb->battleCanCastSpell())
|
||||
attemptCastingSpell();
|
||||
|
||||
if(!thereRemainsEnemy())
|
||||
return BattleAction();
|
||||
if(auto ret = cbc->battleIsFinished())
|
||||
{
|
||||
//spellcast may finish battle
|
||||
//send special preudo-action
|
||||
BattleAction cancel;
|
||||
cancel.actionType = Battle::CANCEL;
|
||||
return cancel;
|
||||
}
|
||||
|
||||
if(auto action = considerFleeingOrSurrendering())
|
||||
return *action;
|
||||
|
||||
if(cb->battleGetStacks(CBattleInfoEssentials::ONLY_ENEMY).empty())
|
||||
{
|
||||
//We apparently won battle by casting spell, return defend... (accessing cb may cause trouble)
|
||||
return BattleAction::makeDefend(stack);
|
||||
}
|
||||
|
||||
PotentialTargets targets(stack);
|
||||
|
||||
|
||||
if(targets.possibleAttacks.size())
|
||||
{
|
||||
auto hlp = targets.bestAction();
|
||||
|
Loading…
Reference in New Issue
Block a user