2021-05-15 18:23:11 +02:00
|
|
|
/*
|
2021-05-15 21:04:26 +02:00
|
|
|
* RecruitHeroBehavior.cpp, part of VCMI engine
|
2021-05-15 18:23:11 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2021-05-15 18:23:11 +02:00
|
|
|
#include "../AIUtility.h"
|
|
|
|
#include "../Goals/RecruitHero.h"
|
2021-05-15 21:02:52 +02:00
|
|
|
#include "../Goals/ExecuteHeroChain.h"
|
2021-05-15 18:23:11 +02:00
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2021-05-15 18:23:11 +02:00
|
|
|
using namespace Goals;
|
|
|
|
|
|
|
|
std::string RecruitHeroBehavior::toString() const
|
|
|
|
{
|
|
|
|
return "Recruit hero";
|
|
|
|
}
|
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
Goals::TGoalVec RecruitHeroBehavior::decompose(const Nullkiller * ai) const
|
2021-05-15 18:23:11 +02:00
|
|
|
{
|
|
|
|
Goals::TGoalVec tasks;
|
2024-03-31 17:39:00 +02:00
|
|
|
auto towns = ai->cb->getTownsInfo();
|
2021-05-15 18:23:11 +02:00
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
auto ourHeroes = ai->heroManager->getHeroRoles();
|
2022-10-14 10:24:43 +02:00
|
|
|
auto minScoreToHireMain = std::numeric_limits<float>::max();
|
|
|
|
|
|
|
|
for(auto hero : ourHeroes)
|
|
|
|
{
|
|
|
|
if(hero.second != HeroRole::MAIN)
|
|
|
|
continue;
|
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
auto newScore = ai->heroManager->evaluateHero(hero.first.get());
|
2022-10-14 10:24:43 +02:00
|
|
|
|
|
|
|
if(minScoreToHireMain > newScore)
|
|
|
|
{
|
|
|
|
// weakest main hero score
|
|
|
|
minScoreToHireMain = newScore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:09:49 +02:00
|
|
|
for(auto town : towns)
|
2021-05-15 18:23:11 +02:00
|
|
|
{
|
2024-03-31 17:39:00 +02:00
|
|
|
if(ai->heroManager->canRecruitHero(town))
|
2021-05-15 18:23:11 +02:00
|
|
|
{
|
2024-03-31 17:39:00 +02:00
|
|
|
auto availableHeroes = ai->cb->getAvailableHeroes(town);
|
2022-10-14 10:24:43 +02:00
|
|
|
|
|
|
|
for(auto hero : availableHeroes)
|
|
|
|
{
|
2024-03-31 17:39:00 +02:00
|
|
|
auto score = ai->heroManager->evaluateHero(hero);
|
2022-10-14 10:24:43 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
for(auto obj : ai->objectClusterizer->getNearbyObjects())
|
2023-06-11 18:21:50 +02:00
|
|
|
{
|
2023-07-30 17:02:56 +02:00
|
|
|
if((obj->ID == Obj::RESOURCE)
|
2023-06-11 18:21:50 +02:00
|
|
|
|| obj->ID == Obj::TREASURE_CHEST
|
|
|
|
|| obj->ID == Obj::CAMPFIRE
|
2024-03-31 17:39:00 +02:00
|
|
|
|| isWeeklyRevisitable(ai, obj)
|
2023-06-11 18:21:50 +02:00
|
|
|
|| obj->ID ==Obj::ARTIFACT)
|
|
|
|
{
|
|
|
|
auto tile = obj->visitablePos();
|
2024-03-31 17:39:00 +02:00
|
|
|
auto closestTown = ai->dangerHitMap->getClosestTown(tile);
|
2023-06-11 18:21:50 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
if(ai->cb->getHeroesInfo().size() < ai->cb->getTownsInfo().size() + 1
|
|
|
|
|| (ai->getFreeResources()[EGameResID::GOLD] > 10000 && !ai->buildAnalyzer->isGoldPreasureHigh()))
|
2021-05-16 13:09:49 +02:00
|
|
|
{
|
2021-05-16 13:38:26 +02:00
|
|
|
tasks.push_back(Goals::sptr(Goals::RecruitHero(town).setpriority(3)));
|
2021-05-16 13:09:49 +02:00
|
|
|
}
|
2021-05-15 18:23:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 21:02:52 +02:00
|
|
|
return tasks;
|
|
|
|
}
|
2022-09-26 20:01:07 +02:00
|
|
|
|
|
|
|
}
|