diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 453dc4118..4b7ffd12a 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1618,15 +1618,20 @@ void VCAI::wander(HeroPtr h) } void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal) -{ //TODO: check for presence? +{ if(goal->invalid()) vstd::erase_if_present(lockedHeroes, h); else { lockedHeroes[h] = goal; - goal->setisElementar(false); //always evaluate goals before realizing + goal->setisElementar(false); //Force always evaluate goals before realizing } } +void VCAI::evaluateGoal(HeroPtr h) +{ + if (vstd::contains(lockedHeroes, h)) + fh->setPriority(lockedHeroes[h]); +} void VCAI::completeGoal (Goals::TSubgoal goal) { @@ -2037,6 +2042,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h) vstd::erase_if_present(lockedHeroes, h); //hero seemingly is confused throw cannotFulfillGoalException("Invalid path found!"); //FIXME: should never happen } + evaluateGoal(h); //new hero position means new game situation logAi->debug("Hero %s moved from %s to %s. Returning %d.", h->name, startHpos(), h->visitablePos()(), ret); } return ret; diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index bd83a9863..e12d4e50d 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -254,6 +254,7 @@ public: void endTurn(); void wander(HeroPtr h); void setGoal(HeroPtr h, Goals::TSubgoal goal); + void evaluateGoal(HeroPtr h); //evaluates goal assigned to hero, if any void completeGoal (Goals::TSubgoal goal); //safely removes goal from reserved hero void striveToQuest (const QuestInfo &q);