فهرست منبع

AI should only defend with one hero, not several who won't fit into the city anyways

Xilmi 11 ماه پیش
والد
کامیت
d3987d8456
1فایلهای تغییر یافته به همراه12 افزوده شده و 1 حذف شده
  1. 12 1
      AI/Nullkiller/Behaviors/DefenceBehavior.cpp

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

@@ -214,11 +214,15 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
 
 		std::vector<int> pathsToDefend;
 		std::map<const CGHeroInstance *, std::vector<int>> defferedPaths;
+		AIPath* closestWay = nullptr;
 
 		for(int i = 0; i < paths.size(); i++)
 		{
 			auto & path = paths[i];
 
+			if (!closestWay || path.movementCost() < closestWay->movementCost())
+				closestWay = &path;
+
 #if NKAI_TRACE_LEVEL >= 1
 			logAi->trace(
 				"Hero %s can defend town with force %lld in %s turns, cost: %f, path: %s",
@@ -382,7 +386,14 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
 					town->getObjectName());
 #endif
 
-			sequence.push_back(sptr(ExecuteHeroChain(path, town)));
+			ExecuteHeroChain heroChain = ExecuteHeroChain(path, town);
+				
+			if (closestWay)
+			{
+				heroChain.closestWayRatio = closestWay->movementCost() / heroChain.getPath().movementCost();
+			}
+
+			sequence.push_back(sptr(heroChain));
 			composition.addNextSequence(sequence);
 
 			auto firstBlockedAction = path.getFirstBlockedAction();