mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user