Browse Source

Probably fixed crash when AI finish battle with spell

AlexVinS 9 years ago
parent
commit
fb384d83b8
1 changed files with 8 additions and 14 deletions
  1. 8 14
      AI/BattleAI/BattleAI.cpp

+ 8 - 14
AI/BattleAI/BattleAI.cpp

@@ -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();