mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Fixed a freeze
It was happening when all slots were full but no unit even needed disbanding because the unit to be bought is part of the units that are inside of the existing slots. (This commit contains excessive debugging but I don't want to remove it just yet incase another issue pops up.)
This commit is contained in:
@@ -382,6 +382,7 @@ std::vector<creInfo> ArmyManager::getArmyAvailableToBuy(
|
||||
if (shouldDisband)
|
||||
{
|
||||
disbandMalus = leastValuableStackValue / ci.creID.toCreature()->getFullRecruitCost();
|
||||
logAi->info("Should disband %d %s at %s worth: %d", hero->getStack(leastValuableSlot).count, hero->getStack(leastValuableSlot).getCreatureID().toCreature()->getNamePluralTranslated(), town->getNameTranslated(), leastValuableStackValue.marketValue());
|
||||
alreadyDisbanded.insert(leastValuableSlot);
|
||||
}
|
||||
|
||||
|
@@ -58,7 +58,7 @@ void BuyArmy::accept(AIGateway * ai)
|
||||
|
||||
if(ci.count)
|
||||
{
|
||||
if (town->stacksCount() == GameConstants::ARMY_SIZE)
|
||||
if (town->getUpperArmy()->stacksCount() == GameConstants::ARMY_SIZE)
|
||||
{
|
||||
SlotID lowestValueSlot;
|
||||
int lowestValue = std::numeric_limits<int>::max();
|
||||
@@ -70,10 +70,14 @@ void BuyArmy::accept(AIGateway * ai)
|
||||
slot.second->getCreatureID().toCreature()->getFullRecruitCost().marketValue() * slot.second->getCount();
|
||||
|
||||
if (slot.second->getCreatureID().toCreature()->getFactionID() == town->getFactionID())
|
||||
{
|
||||
logAi->info("Skipped Dismissing %s due to same faction", slot.second->getCreatureID().toCreature()->getNamePluralTranslated());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentStackMarketValue < lowestValue)
|
||||
{
|
||||
logAi->info("Marked %s for dismissal.", slot.second->getCreatureID().toCreature()->getNamePluralTranslated());
|
||||
lowestValue = currentStackMarketValue;
|
||||
lowestValueSlot = slot.first;
|
||||
}
|
||||
@@ -81,10 +85,15 @@ void BuyArmy::accept(AIGateway * ai)
|
||||
}
|
||||
if (lowestValueSlot.validSlot())
|
||||
{
|
||||
logAi->info("Dismiss %d %s at %s slot: %d", town->getUpperArmy()->getStackCount(lowestValueSlot), town->getUpperArmy()->getStack(lowestValueSlot).getCreatureID().toCreature()->getNamePluralTranslated(), town->getNameTranslated(), lowestValueSlot.getNum());
|
||||
cb->dismissCreature(town->getUpperArmy(), lowestValueSlot);
|
||||
}
|
||||
}
|
||||
cb->recruitCreatures(town, town->getUpperArmy(), ci.creID, ci.count, ci.level);
|
||||
if (town->getUpperArmy()->stacksCount() < GameConstants::ARMY_SIZE || town->getUpperArmy()->getSlotFor(ci.creID).validSlot()) //It is possible we don't scrap despite we wanted to due to not scrapping stacks that fit our faction
|
||||
{
|
||||
logAi->info("Buy %d %s at %s", ci.count, ci.creID.toCreature()->getNamePluralTranslated(), town->getNameTranslated());
|
||||
cb->recruitCreatures(town, town->getUpperArmy(), ci.creID, ci.count, ci.level);
|
||||
}
|
||||
valueBought += ci.count * ci.creID.toCreature()->getAIValue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user