فهرست منبع

Fix for AI not defending in some cases

Instead of skipping the defense of other towns entirely when hiring a hero was considered as a way of defending, now only hiring the same hero twice will be avoided.
Xilmi 10 ماه پیش
والد
کامیت
1d79946825
1فایلهای تغییر یافته به همراه12 افزوده شده و 3 حذف شده
  1. 12 3
      AI/Nullkiller/Behaviors/DefenceBehavior.cpp

+ 12 - 3
AI/Nullkiller/Behaviors/DefenceBehavior.cpp

@@ -41,9 +41,6 @@ Goals::TGoalVec DefenceBehavior::decompose(const Nullkiller * ai) const
 	for(auto town : ai->cb->getTownsInfo())
 	{
 		evaluateDefence(tasks, town, ai);
-		//Let's do only one defence-task per pass since otherwise it can try to hire the same hero twice
-		if (!tasks.empty())
-			break;
 	}
 
 	return tasks;
@@ -422,6 +419,18 @@ void DefenceBehavior::evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitM
 			if(hero->getTotalStrength() < threat.danger)
 				continue;
 
+			bool heroAlreadyHiredInOtherTown = false;
+			for (const auto& task : tasks) 
+			{
+				if (auto recruitGoal = dynamic_cast<Goals::RecruitHero*>(task.get())) 
+				{
+					if (recruitGoal->getHero() == hero)
+						heroAlreadyHiredInOtherTown = true;
+				}
+			}
+			if (heroAlreadyHiredInOtherTown)
+				continue;
+
 			auto myHeroes = ai->cb->getHeroesInfo();
 
 #if NKAI_TRACE_LEVEL >= 1