瀏覽代碼

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

DjWarmonger 9 年之前
父節點
當前提交
76c4ef32c2
共有 2 個文件被更改,包括 9 次插入2 次删除
  1. 8 2
      AI/VCAI/VCAI.cpp
  2. 1 0
      AI/VCAI/VCAI.h

+ 8 - 2
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;

+ 1 - 0
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);