1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Merge pull request #5176 from IvanSavenko/ai_upgrades

Fix potentially infinite attempts to upgrade units by AI
This commit is contained in:
Ivan Savenko 2024-12-31 16:07:27 +02:00 committed by GitHub
commit dfa8a956cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -805,7 +805,11 @@ bool AIGateway::makePossibleUpgrades(const CArmedInstance * obj)
{
return id.toCreature()->getAIValue();
});
if(nullkiller->getFreeResources().canAfford(upgradeInfo.getUpgradeCostsFor(upgID) * s->count))
int oldValue = s->getCreature()->getAIValue();
int newValue = upgID.toCreature()->getAIValue();
if(newValue > oldValue && nullkiller->getFreeResources().canAfford(upgradeInfo.getUpgradeCostsFor(upgID) * s->count))
{
myCb->upgradeCreature(obj, SlotID(i), upgID);
upgraded = true;