mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
Nullkiller AI will now prefer giving its scout heroes faster units to optimize their movement points on next turns. Unit selection logic: - AI prefers to give 'weak' units that won't affect army strength of main hero. Unit is considered 'weak' if its level below 4 or if its AI value is below 1% of total army strength. So AI can give high-tier unit to scout, but only if main hero already has massive army. - Within weak units, if hero is moving on terrain with penalty, AI will always prefer units that are native to this terrain. So on snow AI will always prefer unit from Tower even if its speed is lower than unit from another faction. - Within remaining candidates, AI will prefer unit that will give higher movement points limit. This also means that in case of H3 rules, all units with 11+ speed will be viewed as equally good - If there are multiple units with same speed, AI will prefer unit with lowest AI value
78 lines
1.7 KiB
C++
78 lines
1.7 KiB
C++
/*
|
|
* 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"
|
|
#include "../AIGateway.h"
|
|
#include "../AIUtility.h"
|
|
#include "../Goals/BuyArmy.h"
|
|
#include "../Engine/Nullkiller.h"
|
|
|
|
namespace NKAI
|
|
{
|
|
|
|
using namespace Goals;
|
|
|
|
std::string BuyArmyBehavior::toString() const
|
|
{
|
|
return "Buy army";
|
|
}
|
|
|
|
Goals::TGoalVec BuyArmyBehavior::decompose(const Nullkiller * ai) const
|
|
{
|
|
Goals::TGoalVec tasks;
|
|
|
|
auto heroes = cb->getHeroesInfo();
|
|
|
|
if(heroes.empty())
|
|
{
|
|
return tasks;
|
|
}
|
|
|
|
ai->dangerHitMap->updateHitMap();
|
|
|
|
for(auto town : cb->getTownsInfo())
|
|
{
|
|
uint8_t closestThreat = ai->dangerHitMap->getTileThreat(town->visitablePos()).fastestDanger.turn;
|
|
|
|
if (closestThreat >=2 && ai->buildAnalyzer->isGoldPressureHigh() && !town->hasBuilt(BuildingID::CITY_HALL) && cb->canBuildStructure(town, BuildingID::CITY_HALL) != EBuildingState::FORBIDDEN)
|
|
{
|
|
return tasks;
|
|
}
|
|
|
|
auto townArmyAvailableToBuy = ai->armyManager->getArmyAvailableToBuyAsCCreatureSet(
|
|
town,
|
|
ai->getFreeResources());
|
|
|
|
for(const CGHeroInstance * targetHero : heroes)
|
|
{
|
|
if(ai->heroManager->getHeroRole(targetHero) == HeroRole::MAIN)
|
|
{
|
|
auto reinforcement = ai->armyManager->howManyReinforcementsCanGet(
|
|
targetHero,
|
|
targetHero,
|
|
&*townArmyAvailableToBuy,
|
|
TerrainId::NONE);
|
|
|
|
if(reinforcement)
|
|
vstd::amin(reinforcement, ai->armyManager->howManyReinforcementsCanBuy(town->getUpperArmy(), town));
|
|
|
|
if(reinforcement)
|
|
{
|
|
tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(reinforcement)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return tasks;
|
|
}
|
|
|
|
}
|