diff --git a/AI/BattleAI/AttackPossibility.cpp b/AI/BattleAI/AttackPossibility.cpp index 8af4680fd..d663a1bf4 100644 --- a/AI/BattleAI/AttackPossibility.cpp +++ b/AI/BattleAI/AttackPossibility.cpp @@ -383,6 +383,11 @@ AttackPossibility AttackPossibility::evaluate( } defenderState->damage(damageDealt); + + if(u->unitId() == defender->unitId()) + { + ap.defenderDead = !defenderState->alive(); + } } } diff --git a/AI/BattleAI/AttackPossibility.h b/AI/BattleAI/AttackPossibility.h index b8ff77218..014a4266a 100644 --- a/AI/BattleAI/AttackPossibility.h +++ b/AI/BattleAI/AttackPossibility.h @@ -49,6 +49,7 @@ public: float attackerDamageReduce = 0; //usually by counter-attack float collateralDamageReduce = 0; // friendly fire (usually by two-hex attacks) int64_t shootersBlockedDmg = 0; + bool defenderDead = false; AttackPossibility(BattleHex from, BattleHex dest, const BattleAttackInfo & attack_); diff --git a/AI/BattleAI/BattleExchangeVariant.cpp b/AI/BattleAI/BattleExchangeVariant.cpp index 9010c3543..0200915c9 100644 --- a/AI/BattleAI/BattleExchangeVariant.cpp +++ b/AI/BattleAI/BattleExchangeVariant.cpp @@ -249,6 +249,7 @@ EvaluationResult BattleExchangeEvaluator::findBestTarget( updateReachabilityMap(hb); if(result.bestAttack.attack.shooting + && !result.bestAttack.defenderDead && !activeStack->waited() && hb->battleHasShootingPenalty(activeStack, result.bestAttack.dest)) { @@ -259,8 +260,9 @@ EvaluationResult BattleExchangeEvaluator::findBestTarget( for(auto & ap : targets.possibleAttacks) { float score = evaluateExchange(ap, 0, targets, damageCache, hb); + bool sameScoreButWaited = vstd::isAlmostEqual(score, result.score) && result.wait; - if(score > result.score || (vstd::isAlmostEqual(score, result.score) && result.wait)) + if(score > result.score || sameScoreButWaited) { result.score = score; result.bestAttack = ap; @@ -729,7 +731,7 @@ std::vector BattleExchangeEvaluator::getOneTurnReachableUn { std::vector result; - for(int i = 0; i < turnOrder.size(); i++, turn++) + for(int i = 0; i < turnOrder.size(); i++) { auto & turnQueue = turnOrder[i]; HypotheticBattle turnBattle(env.get(), cb); diff --git a/AI/BattleAI/BattleExchangeVariant.h b/AI/BattleAI/BattleExchangeVariant.h index 00a0dd5ba..728d163bc 100644 --- a/AI/BattleAI/BattleExchangeVariant.h +++ b/AI/BattleAI/BattleExchangeVariant.h @@ -148,7 +148,7 @@ public: std::shared_ptr cb, std::shared_ptr env, float strengthRatio): cb(cb), env(env) { - negativeEffectMultiplier = strengthRatio >= 1 ? 1 : strengthRatio; + negativeEffectMultiplier = strengthRatio >= 1 ? 1 : strengthRatio * strengthRatio; } EvaluationResult findBestTarget(