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

76 lines
1.5 KiB
C++
Raw Normal View History

/*
* BuyArmyBehavior.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 "BuyArmyBehavior.h"
2021-05-16 14:39:38 +02:00
#include "../AIGateway.h"
#include "../AIUtility.h"
#include "../Goals/BuyArmy.h"
#include "../Engine/Nullkiller.h"
2022-09-26 20:01:07 +02:00
namespace NKAI
{
using namespace Goals;
std::string BuyArmyBehavior::toString() const
{
return "Buy army";
}
2024-03-31 17:39:00 +02:00
Goals::TGoalVec BuyArmyBehavior::decompose(const Nullkiller * ai) const
{
Goals::TGoalVec tasks;
2024-03-31 17:39:00 +02:00
if(ai->cb->getDate(Date::DAY) == 1)
return tasks;
auto heroes = cb->getHeroesInfo();
2021-05-16 14:39:38 +02:00
if(heroes.empty())
{
2021-05-16 14:39:38 +02:00
return tasks;
}
for(auto town : cb->getTownsInfo())
{
2024-03-31 17:39:00 +02:00
auto townArmyAvailableToBuy = ai->armyManager->getArmyAvailableToBuyAsCCreatureSet(
2021-05-16 14:39:38 +02:00
town,
2024-03-31 17:39:00 +02:00
ai->getFreeResources());
2021-05-16 14:39:38 +02:00
for(const CGHeroInstance * targetHero : heroes)
{
2024-04-16 23:10:15 +02:00
if(ai->buildAnalyzer->isGoldPressureHigh() && !town->hasBuilt(BuildingID::CITY_HALL))
2021-05-16 14:39:38 +02:00
{
continue;
}
2024-03-31 17:39:00 +02:00
if(ai->heroManager->getHeroRole(targetHero) == HeroRole::MAIN)
{
2024-03-31 17:39:00 +02:00
auto reinforcement = ai->armyManager->howManyReinforcementsCanGet(
2021-05-16 14:39:38 +02:00
targetHero,
targetHero,
&*townArmyAvailableToBuy);
2021-05-16 14:39:38 +02:00
if(reinforcement)
2024-03-31 17:39:00 +02:00
vstd::amin(reinforcement, ai->armyManager->howManyReinforcementsCanBuy(town->getUpperArmy(), town));
2021-05-16 14:39:38 +02:00
if(reinforcement)
{
tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(5)));
}
}
}
}
return tasks;
}
2022-09-26 20:01:07 +02:00
}