瀏覽代碼

fix hang in AI's turn

kdmcser 6 月之前
父節點
當前提交
1210f0bf99
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      AI/Nullkiller/AIGateway.cpp

+ 7 - 1
AI/Nullkiller/AIGateway.cpp

@@ -1039,6 +1039,8 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
 	auto equipBest = [](const CGHeroInstance * h, const CGHeroInstance * otherh, bool giveStuffToFirstHero) -> void
 	{
 		bool changeMade = false;
+		int swapCount = 0;
+		const int maxSwapCount = 100;
 		do
 		{
 			changeMade = false;
@@ -1100,6 +1102,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
 						cb->swapArtifacts(location, destLocation); //just put into empty slot
 						emptySlotFound = true;
 						changeMade = true;
+						swapCount++;
 						break;
 					}
 				}
@@ -1138,6 +1141,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
 								}
 
 								changeMade = true;
+								swapCount++;
 								break;
 							}
 						}
@@ -1147,7 +1151,9 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
 					break; //start evaluating artifacts from scratch
 			}
 		}
-		while(changeMade);
+		while(changeMade && swapCount < maxSwapCount);
+		if (swapCount >= maxSwapCount)
+			logAi->warn("Maximum artifact swap count exceeded!");
 	};
 
 	equipBest(h, other, true);