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"
|
2021-05-16 14:39:38 +02:00
|
|
|
#include "../AIGateway.h"
|
2021-05-15 20:57:31 +02:00
|
|
|
#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
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2021-05-15 20:57:31 +02:00
|
|
|
extern boost::thread_specific_ptr<CCallback> cb;
|
2021-05-16 14:39:38 +02:00
|
|
|
extern boost::thread_specific_ptr<AIGateway> ai;
|
2021-05-15 20:57:31 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
auto heroes = cb->getHeroesInfo();
|
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
if(heroes.empty())
|
2021-05-15 20:57:31 +02:00
|
|
|
{
|
2021-05-16 14:39:38 +02:00
|
|
|
return tasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto town : cb->getTownsInfo())
|
|
|
|
{
|
|
|
|
auto townArmyAvailableToBuy = ai->nullkiller->armyManager->getArmyAvailableToBuyAsCCreatureSet(
|
|
|
|
town,
|
|
|
|
ai->nullkiller->getFreeResources());
|
2021-05-15 20:57:31 +02:00
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
for(const CGHeroInstance * targetHero : heroes)
|
2021-05-15 20:57:31 +02:00
|
|
|
{
|
2021-05-16 14:39:38 +02:00
|
|
|
if(ai->nullkiller->buildAnalyzer->getGoldPreasure() > MAX_GOLD_PEASURE
|
|
|
|
&& !town->hasBuilt(BuildingID::CITY_HALL))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-05-15 20:57:31 +02:00
|
|
|
|
2022-11-10 21:10:34 +02:00
|
|
|
if(ai->nullkiller->heroManager->getHeroRole(targetHero) == HeroRole::MAIN)
|
2021-05-15 20:57:31 +02:00
|
|
|
{
|
2021-05-16 14:39:38 +02:00
|
|
|
auto reinforcement = ai->nullkiller->armyManager->howManyReinforcementsCanGet(
|
|
|
|
targetHero,
|
|
|
|
targetHero,
|
|
|
|
&*townArmyAvailableToBuy);
|
2021-05-15 20:57:31 +02:00
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
if(reinforcement)
|
|
|
|
vstd::amin(reinforcement, ai->nullkiller->armyManager->howManyReinforcementsCanBuy(town->getUpperArmy(), town));
|
2021-05-15 20:57:31 +02:00
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
if(reinforcement)
|
|
|
|
{
|
|
|
|
tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(5)));
|
2021-05-15 20:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tasks;
|
2021-05-15 21:04:26 +02:00
|
|
|
}
|
2022-09-26 20:01:07 +02:00
|
|
|
|
|
|
|
}
|