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

NKAI: fix error message can not take away last stack

This commit is contained in:
Andrii Danylchenko 2023-07-30 12:21:47 +03:00
parent f1a9ae99ee
commit ec0596f3dd
3 changed files with 17 additions and 3 deletions

View File

@ -867,6 +867,19 @@ void AIGateway::pickBestCreatures(const CArmedInstance * destinationArmy, const
auto bestArmy = nullkiller->armyManager->getBestArmy(destinationArmy, destinationArmy, source);
for(auto army : armies)
{
// move first stack at first slot if empty to avoid can not take away last creature
if(!army->hasStackAtSlot(SlotID(0)) && army->stacksCount() > 0)
{
cb->mergeOrSwapStacks(
army,
army,
SlotID(0),
army->Slots().begin()->first);
}
}
//foreach best type -> iterate over slots in both armies and if it's the appropriate type, send it to the slot where it belongs
for(SlotID i = SlotID(0); i.validSlot(); i.advance(1)) //i-th strongest creature type will go to i-th slot
{

View File

@ -236,7 +236,7 @@ const CGHeroInstance * HeroManager::findWeakHeroToDismiss(uint64_t armyLimit) co
for(auto existingHero : myHeroes)
{
if(ai->isHeroLocked(existingHero) && ai->getHeroLockedReason(existingHero) == HeroLockedReason::DEFENCE
if(ai->getHeroLockedReason(existingHero) == HeroLockedReason::DEFENCE
|| existingHero->getArmyStrength() >armyLimit
|| getHeroRole(existingHero) == HeroRole::MAIN
|| existingHero->movementPointsRemaining()

View File

@ -119,10 +119,11 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her
HeroExchange heroExchange(hero, path);
float armyValue = (float)heroExchange.getReinforcementArmyStrength() / hero->getArmyStrength();
uint64_t armyValue = heroExchange.getReinforcementArmyStrength();
float armyRatio = (float)armyValue / hero->getArmyStrength();
// avoid transferring very small amount of army
if(armyValue < 0.1f && armyValue < 20000)
if((armyRatio < 0.1f && armyValue < 20000) || armyValue < 500)
{
#if NKAI_TRACE_LEVEL >= 2
logAi->trace("Army value is too small.");