瀏覽代碼

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.
Xilmi 1 年之前
父節點
當前提交
11980e0f97
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 1 0
      AI/Nullkiller/Behaviors/DefenceBehavior.cpp
  2. 5 2
      AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp

+ 1 - 0
AI/Nullkiller/Behaviors/DefenceBehavior.cpp

@@ -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
 				// dismiss creatures we are not able to pick to be able to hide in garrison
 				if(town->garrisonHero
 				if(town->garrisonHero
 					|| town->getUpperArmy()->stacksCount() == 0
 					|| town->getUpperArmy()->stacksCount() == 0
+					|| path.targetHero->canBeMergedWith(*town)
 					|| (town->getUpperArmy()->getArmyStrength() < 500 && town->fortLevel() >= CGTownInstance::CITADEL))
 					|| (town->getUpperArmy()->getArmyStrength() < 500 && town->fortLevel() >= CGTownInstance::CITADEL))
 				{
 				{
 					tasks.push_back(
 					tasks.push_back(

+ 5 - 2
AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp

@@ -90,9 +90,12 @@ void ExchangeSwapTownHeroes::accept(AIGateway * ai)
 	
 	
 	if(!town->garrisonHero)
 	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);
+			}
 		}
 		}
 	}
 	}