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

48 lines
1.1 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"
#include "../VCAI.h"
#include "../AIUtility.h"
#include "../Goals/RecruitHero.h"
2021-05-15 21:02:52 +02:00
#include "../Goals/ExecuteHeroChain.h"
#include "lib/mapping/CMap.h" //for victory conditions
#include "lib/CPathfinder.h"
extern boost::thread_specific_ptr<CCallback> cb;
extern boost::thread_specific_ptr<VCAI> ai;
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();
2021-05-16 13:09:49 +02:00
for(auto town : towns)
{
if(!town->garrisonHero && !town->visitingHero && ai->canRecruitAnyHero(town))
{
2021-05-16 13:09:49 +02:00
if(cb->getHeroesInfo().size() < cb->getTownsInfo().size() + 1
|| cb->getResourceAmount(Res::GOLD) > 10000)
{
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;
}