浏览代码

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.)
Xilmi 11 月之前
父节点
当前提交
79fb5faa2e
共有 2 个文件被更改,包括 12 次插入2 次删除
  1. 1 0
      AI/Nullkiller/Analyzers/ArmyManager.cpp
  2. 11 2
      AI/Nullkiller/Goals/BuyArmy.cpp

+ 1 - 0
AI/Nullkiller/Analyzers/ArmyManager.cpp

@@ -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);
 		}
 

+ 11 - 2
AI/Nullkiller/Goals/BuyArmy.cpp

@@ -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();
 		}
 	}