From 663ca23f6febd9fb39bc14b65fe24d7412152346 Mon Sep 17 00:00:00 2001 From: Xilmi Date: Fri, 12 Jul 2024 15:41:55 +0200 Subject: [PATCH] Army-hiring Supressing hiring army on turn one seems just bad. Starting the main-hero as strong as possible seems like a good idea to me and hiring the available troops outright will help achieve that goal. However, if there's a hero for hire, who has army with him that is a better deal, we hire that one first. --- AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp b/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp index d53adc023..e988c4519 100644 --- a/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp +++ b/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp @@ -28,9 +28,6 @@ Goals::TGoalVec BuyArmyBehavior::decompose(const Nullkiller * ai) const { Goals::TGoalVec tasks; - if(ai->cb->getDate(Date::DAY) == 1) - return tasks; - auto heroes = cb->getHeroesInfo(); if(heroes.empty()) @@ -40,17 +37,28 @@ Goals::TGoalVec BuyArmyBehavior::decompose(const Nullkiller * ai) const for(auto town : cb->getTownsInfo()) { + //If we can recruit a hero that comes with more army than he costs, we are better off spending our gold on them + if (ai->heroManager->canRecruitHero(town)) + { + auto availableHeroes = ai->cb->getAvailableHeroes(town); + for (auto hero : availableHeroes) + { + if (hero->getArmyCost() > GameConstants::HERO_GOLD_COST) + return tasks; + } + } + + if (ai->buildAnalyzer->isGoldPressureHigh() && !town->hasBuilt(BuildingID::CITY_HALL)) + { + return tasks; + } + auto townArmyAvailableToBuy = ai->armyManager->getArmyAvailableToBuyAsCCreatureSet( town, ai->getFreeResources()); for(const CGHeroInstance * targetHero : heroes) { - if(ai->buildAnalyzer->isGoldPressureHigh() && !town->hasBuilt(BuildingID::CITY_HALL)) - { - continue; - } - if(ai->heroManager->getHeroRole(targetHero) == HeroRole::MAIN) { auto reinforcement = ai->armyManager->howManyReinforcementsCanGet(