2021-05-15 20:57:31 +02:00
|
|
|
/*
|
2021-05-15 21:04:26 +02:00
|
|
|
* BuyArmyBehavior.cpp, part of VCMI engine
|
2021-05-15 20:57:31 +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 "BuyArmyBehavior.h"
|
|
|
|
#include "../VCAI.h"
|
|
|
|
#include "../AIhelper.h"
|
|
|
|
#include "../AIUtility.h"
|
|
|
|
#include "../Goals/BuyArmy.h"
|
2021-05-16 13:19:00 +02:00
|
|
|
#include "../Engine/Nullkiller.h"
|
2021-05-15 20:57:31 +02:00
|
|
|
#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;
|
|
|
|
extern FuzzyHelper * fh;
|
|
|
|
|
|
|
|
using namespace Goals;
|
|
|
|
|
|
|
|
std::string BuyArmyBehavior::toString() const
|
|
|
|
{
|
|
|
|
return "Buy army";
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:38:26 +02:00
|
|
|
Goals::TGoalVec BuyArmyBehavior::decompose() const
|
2021-05-15 20:57:31 +02:00
|
|
|
{
|
|
|
|
Goals::TGoalVec tasks;
|
|
|
|
|
|
|
|
if(cb->getDate(Date::DAY) == 1)
|
|
|
|
return tasks;
|
2021-05-16 13:19:00 +02:00
|
|
|
|
|
|
|
if(ai->nullkiller->buildAnalyzer->getGoldPreasure() > MAX_GOLD_PEASURE)
|
|
|
|
return tasks;
|
2021-05-15 20:57:31 +02:00
|
|
|
|
|
|
|
auto heroes = cb->getHeroesInfo();
|
|
|
|
|
|
|
|
if(heroes.size())
|
|
|
|
{
|
2021-05-15 21:02:57 +02:00
|
|
|
auto mainArmy = vstd::maxElementByFun(heroes, [](const CGHeroInstance * hero) -> uint64_t
|
2021-05-15 20:57:31 +02:00
|
|
|
{
|
2021-05-15 21:02:57 +02:00
|
|
|
return hero->getTotalStrength();
|
2021-05-15 20:57:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
for(auto town : cb->getTownsInfo())
|
|
|
|
{
|
2021-05-15 21:02:57 +02:00
|
|
|
const CGHeroInstance * targetHero = *mainArmy;
|
2021-05-15 20:57:31 +02:00
|
|
|
|
|
|
|
/*if(town->visitingHero)
|
|
|
|
{
|
|
|
|
targetHero = town->visitingHero.get();
|
|
|
|
|
|
|
|
if(ai->ah->howManyReinforcementsCanGet(targetHero, town->getUpperArmy()))
|
|
|
|
{
|
|
|
|
tasks.push_back(sptr(VisitTile(town->visitablePos()).sethero(targetHero).setpriority(5)));
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
auto reinforcement = ai->ah->howManyReinforcementsCanBuy(targetHero, town);
|
|
|
|
|
2021-05-15 21:02:57 +02:00
|
|
|
if(reinforcement)
|
|
|
|
reinforcement = ai->ah->howManyReinforcementsCanBuy(town->getUpperArmy(), town);
|
|
|
|
|
2021-05-15 20:57:31 +02:00
|
|
|
if(reinforcement)
|
|
|
|
{
|
|
|
|
tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(5)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tasks;
|
2021-05-15 21:04:26 +02:00
|
|
|
}
|