1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/AI/Nullkiller/Behaviors/RecruitHeroBehavior.cpp

99 lines
2.3 KiB
C++
Raw Normal View History

/*
* RecruitHeroBehavior.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "RecruitHeroBehavior.h"
2021-05-16 14:39:38 +02:00
#include "../AIGateway.h"
#include "../AIUtility.h"
#include "../Goals/RecruitHero.h"
2021-05-15 21:02:52 +02:00
#include "../Goals/ExecuteHeroChain.h"
2022-09-26 20:01:07 +02:00
namespace NKAI
{
using namespace Goals;
std::string RecruitHeroBehavior::toString() const
{
return "Recruit hero";
}
Goals::TGoalVec RecruitHeroBehavior::decompose() const
{
Goals::TGoalVec tasks;
2021-05-16 13:09:49 +02:00
auto towns = cb->getTownsInfo();
2022-10-14 10:24:43 +02:00
auto ourHeroes = ai->nullkiller->heroManager->getHeroRoles();
auto minScoreToHireMain = std::numeric_limits<float>::max();
for(auto hero : ourHeroes)
{
if(hero.second != HeroRole::MAIN)
continue;
auto newScore = ai->nullkiller->heroManager->evaluateHero(hero.first.get());
if(minScoreToHireMain > newScore)
{
// weakest main hero score
minScoreToHireMain = newScore;
}
}
2021-05-16 13:09:49 +02:00
for(auto town : towns)
{
if(ai->nullkiller->heroManager->canRecruitHero(town))
{
2022-10-14 10:24:43 +02:00
auto availableHeroes = cb->getAvailableHeroes(town);
for(auto hero : availableHeroes)
{
auto score = ai->nullkiller->heroManager->evaluateHero(hero);
if(score > minScoreToHireMain)
{
tasks.push_back(Goals::sptr(Goals::RecruitHero(town, hero).setpriority(200)));
break;
}
}
2023-06-11 18:21:50 +02:00
int treasureSourcesCount = 0;
for(auto obj : ai->nullkiller->objectClusterizer->getNearbyObjects())
{
if((obj->ID == Obj::RESOURCE)
2023-06-11 18:21:50 +02:00
|| obj->ID == Obj::TREASURE_CHEST
|| obj->ID == Obj::CAMPFIRE
|| isWeeklyRevisitable(obj)
2023-06-11 18:21:50 +02:00
|| obj->ID ==Obj::ARTIFACT)
{
auto tile = obj->visitablePos();
auto closestTown = ai->nullkiller->dangerHitMap->getClosestTown(tile);
if(town == closestTown)
treasureSourcesCount++;
}
}
2023-08-12 21:02:37 +02:00
if(treasureSourcesCount < 5 && (town->garrisonHero || town->getUpperArmy()->getArmyStrength() < 10000))
2023-06-11 18:21:50 +02:00
continue;
2021-05-16 13:09:49 +02:00
if(cb->getHeroesInfo().size() < cb->getTownsInfo().size() + 1
2024-02-25 12:39:19 +02:00
|| (ai->nullkiller->getFreeResources()[EGameResID::GOLD] > 10000 && !ai->nullkiller->buildAnalyzer->isGoldPreasureHigh()))
2021-05-16 13:09:49 +02:00
{
tasks.push_back(Goals::sptr(Goals::RecruitHero(town).setpriority(3)));
2021-05-16 13:09:49 +02:00
}
}
}
2021-05-15 21:02:52 +02:00
return tasks;
}
2022-09-26 20:01:07 +02:00
}