From 7ae7c139646c65fc5b315cccc0a3574b9344d309 Mon Sep 17 00:00:00 2001 From: MichalZr6 Date: Wed, 28 Aug 2024 15:12:33 +0200 Subject: [PATCH 1/2] drop setting reachability for turrets --- AI/BattleAI/BattleExchangeVariant.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/AI/BattleAI/BattleExchangeVariant.cpp b/AI/BattleAI/BattleExchangeVariant.cpp index 04ada089e..b1b7accdb 100644 --- a/AI/BattleAI/BattleExchangeVariant.cpp +++ b/AI/BattleAI/BattleExchangeVariant.cpp @@ -484,15 +484,18 @@ ReachabilityData BattleExchangeEvaluator::getExchangeUnits( vstd::concatenate(allReachableUnits, turn == 0 ? reachabilityMap.at(hex) : getOneTurnReachableUnits(turn, hex)); } - for(auto hex : ap.attack.attacker->getHexes()) + if(!ap.attack.attacker->isTurret()) { - auto unitsReachingAttacker = turn == 0 ? reachabilityMap.at(hex) : getOneTurnReachableUnits(turn, hex); - for(auto unit : unitsReachingAttacker) + for(auto hex : ap.attack.attacker->getHexes()) { - if(unit->unitSide() != ap.attack.attacker->unitSide()) + auto unitsReachingAttacker = turn == 0 ? reachabilityMap.at(hex) : getOneTurnReachableUnits(turn, hex); + for(auto unit : unitsReachingAttacker) { - allReachableUnits.push_back(unit); - result.enemyUnitsReachingAttacker.insert(unit->unitId()); + if(unit->unitSide() != ap.attack.attacker->unitSide()) + { + allReachableUnits.push_back(unit); + result.enemyUnitsReachingAttacker.insert(unit->unitId()); + } } } } From ca3d81f047962dcee38813d8d8b2e3c7381e3214 Mon Sep 17 00:00:00 2001 From: MichalZr6 Date: Wed, 28 Aug 2024 15:16:33 +0200 Subject: [PATCH 2/2] fix crash on heroRoles.clear() --- AI/Nullkiller/Analyzers/HeroManager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AI/Nullkiller/Analyzers/HeroManager.cpp b/AI/Nullkiller/Analyzers/HeroManager.cpp index 44b66b46b..a67fd8ebc 100644 --- a/AI/Nullkiller/Analyzers/HeroManager.cpp +++ b/AI/Nullkiller/Analyzers/HeroManager.cpp @@ -126,20 +126,23 @@ void HeroManager::update() } std::sort(myHeroes.begin(), myHeroes.end(), scoreSort); - heroRoles.clear(); + + std::map newHeroRoles; for(auto hero : myHeroes) { if(hero->patrol.patrolling) { - heroRoles[hero] = HeroRole::MAIN; + newHeroRoles[hero] = HeroRole::MAIN; } else { - heroRoles[hero] = (globalMainCount--) > 0 ? HeroRole::MAIN : HeroRole::SCOUT; + newHeroRoles[hero] = (globalMainCount--) > 0 ? HeroRole::MAIN : HeroRole::SCOUT; } } + heroRoles = std::move(newHeroRoles); + for(auto hero : myHeroes) { logAi->trace("Hero %s has role %s", hero->getNameTranslated(), heroRoles[hero] == HeroRole::MAIN ? "main" : "scout");