1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00

hero spread

Prefer hiring heroes at towns that don't have heroes nearby.
This commit is contained in:
Xilmi 2024-08-31 23:00:27 +02:00
parent f4578c6d3a
commit 72597b549b
2 changed files with 20 additions and 3 deletions

View File

@ -148,6 +148,7 @@ void BuildAnalyzer::update()
auto towns = ai->cb->getTownsInfo();
float economyDevelopmentCost = 0;
TResources nonGoldEconomyResources;
for(const CGTownInstance* town : towns)
{
@ -164,7 +165,10 @@ void BuildAnalyzer::update()
for(auto building : developmentInfo.toBuild)
{
if (building.dailyIncome[EGameResID::GOLD] > 0)
{
economyDevelopmentCost += building.buildCostWithPrerequisites[EGameResID::GOLD];
nonGoldEconomyResources += building.buildCostWithPrerequisites;
}
}
armyCost += developmentInfo.armyCost;
@ -173,6 +177,10 @@ void BuildAnalyzer::update()
logAi->trace("Building preferences %s", bi.toString());
}
}
nonGoldEconomyResources[EGameResID::GOLD] = 0;
//If we don't have the non-gold-resources to build a structure, we also don't need to save gold for it and can consider building something else instead
if (!ai->getFreeResources().canAfford(nonGoldEconomyResources))
economyDevelopmentCost = 0;
std::sort(developmentInfos.begin(), developmentInfos.end(), [](const TownDevelopmentInfo & t1, const TownDevelopmentInfo & t2) -> bool
{

View File

@ -64,9 +64,15 @@ Goals::TGoalVec RecruitHeroBehavior::decompose(const Nullkiller * ai) const
{
closestThreat = std::min(closestThreat, threat.turn);
}
//Don' hire a hero in a threatened town as one would have to stay outside
if (closestThreat <= 1 && (town->visitingHero || town->garrisonHero))
//Don't hire a hero where there already is one present
if (town->visitingHero || town->garrisonHero)
continue;
float visitability = 0;
for (auto checkHero : ourHeroes)
{
if (ai->dangerHitMap->getClosestTown(checkHero.first.get()->pos) == town)
visitability++;
}
if(ai->heroManager->canRecruitHero(town))
{
auto availableHeroes = ai->cb->getAvailableHeroes(town);
@ -81,7 +87,10 @@ Goals::TGoalVec RecruitHeroBehavior::decompose(const Nullkiller * ai) const
score *= hero->getArmyCost();
if (hero->type->heroClass->faction == town->getFaction())
score *= 1.5;
score *= town->getTownLevel();
if (visitability == 0)
score *= 30 * town->getTownLevel();
else
score *= town->getTownLevel() / visitability;
if (score > bestScore)
{
bestScore = score;