From 13bbb573bdfdb40cc6683e0a253984a744cfb5fe Mon Sep 17 00:00:00 2001 From: Xilmi Date: Tue, 9 Jul 2024 22:55:39 +0200 Subject: [PATCH] Spellcasting-bug-fix Fixed a bug that prevented the AI from using spells when attacking an enemy settlement that has towers. The bug was caused by noticing how greatly effective spells would be against towers but not being able to actually target them. By skipping invalid targets, this no longer is an issue. --- AI/BattleAI/BattleEvaluator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AI/BattleAI/BattleEvaluator.cpp b/AI/BattleAI/BattleEvaluator.cpp index 7ad134b7c..98d1bf3e6 100644 --- a/AI/BattleAI/BattleEvaluator.cpp +++ b/AI/BattleAI/BattleEvaluator.cpp @@ -623,6 +623,9 @@ bool BattleEvaluator::attemptCastingSpell(const CStack * activeStack) for(const auto & unit : allUnits) { + if (!unit->isValidTarget()) + continue; + auto newHealth = unit->getAvailableHealth(); auto oldHealth = vstd::find_or(healthOfStack, unit->unitId(), 0); // old health value may not exist for newly summoned units