1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Fixes following review

This commit is contained in:
MichalZr6
2024-12-16 16:05:46 +01:00
parent bbc41fc1b9
commit af9445c16f
11 changed files with 39 additions and 38 deletions

View File

@@ -788,29 +788,30 @@ bool AIGateway::makePossibleUpgrades(const CArmedInstance * obj)
{
if(const CStackInstance * s = obj->getStackPtr(SlotID(i)))
{
UpgradeInfo ui(s->getId());
UpgradeInfo upgradeInfo(s->getId());
do
{
myCb->fillUpgradeInfo(obj, SlotID(i), ui);
myCb->fillUpgradeInfo(obj, SlotID(i), upgradeInfo);
if(ui.hasUpgrades())
if(upgradeInfo.hasUpgrades())
{
// creature at given slot might have alternative upgrades, pick best one
CreatureID upgID = *vstd::maxElementByFun(ui.getAvailableUpgrades(), [](const CreatureID & id)
CreatureID upgID = *vstd::maxElementByFun(upgradeInfo.getAvailableUpgrades(), [](const CreatureID & id)
{
return id.toCreature()->getAIValue();
});
if(nullkiller->getFreeResources().canAfford(ui.getUpgradeCostsFor(upgID) * s->count))
if(nullkiller->getFreeResources().canAfford(upgradeInfo.getUpgradeCostsFor(upgID) * s->count))
{
myCb->upgradeCreature(obj, SlotID(i), upgID);
upgraded = true;
logAi->debug("Upgraded %d %s to %s", s->count, ui.oldID.toCreature()->getNamePluralTranslated(), ui.getNextUpgrade().toCreature()->getNamePluralTranslated());
logAi->debug("Upgraded %d %s to %s", s->count, upgradeInfo.oldID.toCreature()->getNamePluralTranslated(),
upgradeInfo.getNextUpgrade().toCreature()->getNamePluralTranslated());
}
else
break;
}
}
while(ui.hasUpgrades());
while(upgradeInfo.hasUpgrades());
}
}