From d5063e53a0e9c0799b3be1cb7a444af653403e73 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Wed, 7 Nov 2018 21:04:15 +0100 Subject: [PATCH] Do not evaluate goals related to removed hero --- AI/VCAI/VCAI.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 713df10a9..da1893d2f 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -2825,6 +2825,30 @@ void VCAI::lostHero(HeroPtr h) { vstd::erase_if_present(heroVec.second, h); } + + //remove goals with removed hero assigned from main loop + vstd::erase_if(ultimateGoalsFromBasic, [&](const std::pair & x) -> bool + { + if(x.first->hero == h) + return true; + else + return false; + }); + + auto removedHeroGoalPredicate = [&](const Goals::TSubgoal & x) ->bool + { + if(x->hero == h) + return true; + else + return false; + }; + + vstd::erase_if(basicGoals, removedHeroGoalPredicate); + vstd::erase_if(goalsToAdd, removedHeroGoalPredicate); + vstd::erase_if(goalsToRemove, removedHeroGoalPredicate); + + for(auto goal : ultimateGoalsFromBasic) + vstd::erase_if(goal.second, removedHeroGoalPredicate); } void VCAI::answerQuery(QueryID queryID, int selection)