1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +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:
Xilmi 2024-12-01 23:00:35 +01:00
parent d4b2ec5b0b
commit 1d79946825

View File

@ -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