1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-18 03:21:27 +02:00

Garrisoning behavior improvement

AI will now also garrison a hero as defender if the town to be defended has troops as long as the hero can merge their own troops with the town.

AI will no longer just dismiss existing troops in a town if a hero trying to garrison there can merge with it.
This commit is contained in:
Xilmi 2024-10-20 15:49:23 +02:00
parent f04e110e2c
commit 11980e0f97
2 changed files with 6 additions and 2 deletions

View File

@ -270,6 +270,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
// dismiss creatures we are not able to pick to be able to hide in garrison
if(town->garrisonHero
|| town->getUpperArmy()->stacksCount() == 0
|| path.targetHero->canBeMergedWith(*town)
|| (town->getUpperArmy()->getArmyStrength() < 500 && town->fortLevel() >= CGTownInstance::CITADEL))
{
tasks.push_back(

View File

@ -90,9 +90,12 @@ void ExchangeSwapTownHeroes::accept(AIGateway * ai)
if(!town->garrisonHero)
{
while(upperArmy->stacksCount() != 0)
if (!garrisonHero->canBeMergedWith(*town))
{
cb->dismissCreature(upperArmy, upperArmy->Slots().begin()->first);
while (upperArmy->stacksCount() != 0)
{
cb->dismissCreature(upperArmy, upperArmy->Slots().begin()->first);
}
}
}