소스 검색

Priorities

Swapped priority of attacking and defending.
Troop-delivery-missions will check safety of the delivering hero.
Xilmi 1 년 전
부모
커밋
05d948b582
3개의 변경된 파일18개의 추가작업 그리고 11개의 파일을 삭제
  1. 3 1
      AI/Nullkiller/Engine/Nullkiller.cpp
  2. 14 10
      AI/Nullkiller/Engine/PriorityEvaluator.cpp
  3. 1 0
      AI/Nullkiller/Engine/PriorityEvaluator.h

+ 3 - 1
AI/Nullkiller/Engine/Nullkiller.cpp

@@ -624,6 +624,8 @@ bool Nullkiller::handleTrading()
 				{
 					if (required[i] <= 0)
 						continue;
+					if (i != 6 && income[i] > 0)
+						continue;
 					float ratio = static_cast<float>(available[i]) / required[i];
 
 					if (ratio < minRatio) {
@@ -649,7 +651,7 @@ bool Nullkiller::handleTrading()
 					}
 					else
 					{
-						if (required[i] <= 0)
+						if (required[i] <= 0 && income[i] > 0)
 							okToSell = true;
 					}
 

+ 14 - 10
AI/Nullkiller/Engine/PriorityEvaluator.cpp

@@ -63,7 +63,8 @@ EvaluationContext::EvaluationContext(const Nullkiller* ai)
 	involvesSailing(false),
 	isTradeBuilding(false),
 	isChain(false),
-	isEnemy(false)
+	isEnemy(false),
+	isExchange(false)
 {
 }
 
@@ -899,6 +900,7 @@ public:
 		evaluationContext.addNonCriticalStrategicalValue(2.0f * armyStrength / (float)heroExchange.hero->getArmyStrength());
 		evaluationContext.conquestValue += 2.0f * armyStrength / (float)heroExchange.hero->getArmyStrength();
 		evaluationContext.heroRole = evaluationContext.evaluator.ai->heroManager->getHeroRole(heroExchange.hero);
+		evaluationContext.isExchange = true;
 	}
 };
 
@@ -1396,19 +1398,12 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
 
 		switch (priorityTier)
 		{
-			case 1: //Defend immediately threatened towns
-			{
-				if (evaluationContext.isDefend && evaluationContext.threatTurns == 0 && evaluationContext.turn == 0)
-					score = evaluationContext.armyInvolvement;
-				score *= evaluationContext.closestWayRatio;
-				break;
-			}
-			case 2: //Take towns
+			case 1: //Take towns
 			{
 				//score += evaluationContext.conquestValue * 1000;
 				if(evaluationContext.conquestValue > 0)
 					score = 1000;
-				if (score == 0 || (evaluationContext.enemyHeroDangerRatio > 1 && evaluationContext.turn > 0 && !ai->cb->getTownsInfo().empty()))
+				if (score == 0 || (evaluationContext.enemyHeroDangerRatio > 1 && (evaluationContext.turn > 0 || evaluationContext.isExchange) && !ai->cb->getTownsInfo().empty()))
 					return 0;
 				if (maxWillingToLose - evaluationContext.armyLossPersentage < 0)
 					return 0;
@@ -1417,6 +1412,13 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
 					score /= evaluationContext.movementCost;
 				break;
 			}
+			case 2: //Defend immediately threatened towns
+			{
+				if (evaluationContext.isDefend && evaluationContext.threatTurns == 0 && evaluationContext.turn == 0)
+					score = evaluationContext.armyInvolvement;
+				score *= evaluationContext.closestWayRatio;
+				break;
+			}
 			case 3: //Collect unguarded stuff
 			{
 				if (evaluationContext.enemyHeroDangerRatio > 1)
@@ -1475,6 +1477,8 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
 			}
 			case 5: //Defend whatever if nothing else is to do
 			{
+				if (evaluationContext.enemyHeroDangerRatio > 1 && evaluationContext.isExchange)
+					return 0;
 				if (evaluationContext.isDefend)
 					score = evaluationContext.armyInvolvement;
 				score *= evaluationContext.closestWayRatio;

+ 1 - 0
AI/Nullkiller/Engine/PriorityEvaluator.h

@@ -81,6 +81,7 @@ struct DLL_EXPORT EvaluationContext
 	bool isTradeBuilding;
 	bool isChain;
 	bool isEnemy;
+	bool isExchange;
 
 	EvaluationContext(const Nullkiller * ai);