1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Re-evaluate goal after hero move to make AI more consistent.

This commit is contained in:
DjWarmonger
2016-11-27 18:10:20 +01:00
parent 7793a57b0a
commit 76c4ef32c2
2 changed files with 9 additions and 2 deletions

View File

@ -1618,15 +1618,20 @@ void VCAI::wander(HeroPtr h)
} }
void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal) void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal)
{ //TODO: check for presence? {
if(goal->invalid()) if(goal->invalid())
vstd::erase_if_present(lockedHeroes, h); vstd::erase_if_present(lockedHeroes, h);
else else
{ {
lockedHeroes[h] = goal; 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) 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 vstd::erase_if_present(lockedHeroes, h); //hero seemingly is confused
throw cannotFulfillGoalException("Invalid path found!"); //FIXME: should never happen 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); logAi->debug("Hero %s moved from %s to %s. Returning %d.", h->name, startHpos(), h->visitablePos()(), ret);
} }
return ret; return ret;

View File

@ -254,6 +254,7 @@ public:
void endTurn(); void endTurn();
void wander(HeroPtr h); void wander(HeroPtr h);
void setGoal(HeroPtr h, Goals::TSubgoal goal); 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 completeGoal (Goals::TSubgoal goal); //safely removes goal from reserved hero
void striveToQuest (const QuestInfo &q); void striveToQuest (const QuestInfo &q);