mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
fix hang in AI's turn
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user