mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-14 10:12:59 +02:00
Adaptive Build-order
When not threatened by nearby enemies the AI adds missing gold-income-buildings towards gold-pressure. This impacts the build-order in a way that they try to rush these more and get up a good economy more quickly.
This commit is contained in:
parent
6bd442e6f1
commit
c10c04779f
@ -149,9 +149,17 @@ void BuildAnalyzer::update()
|
||||
|
||||
auto towns = ai->cb->getTownsInfo();
|
||||
|
||||
float economyDevelopmentCost = 0;
|
||||
uint8_t closestThreat = UINT8_MAX;
|
||||
ai->dangerHitMap->updateHitMap();
|
||||
|
||||
for(const CGTownInstance* town : towns)
|
||||
{
|
||||
logAi->trace("Checking town %s", town->getNameTranslated());
|
||||
for (auto threat : ai->dangerHitMap->getTownThreats(town))
|
||||
{
|
||||
closestThreat = std::min(closestThreat, threat.turn);
|
||||
}
|
||||
logAi->trace("Checking town %s closest threat: %u", town->getNameTranslated(), (unsigned int)closestThreat);
|
||||
|
||||
developmentInfos.push_back(TownDevelopmentInfo(town));
|
||||
TownDevelopmentInfo & developmentInfo = developmentInfos.back();
|
||||
@ -161,6 +169,11 @@ void BuildAnalyzer::update()
|
||||
|
||||
requiredResources += developmentInfo.requiredResources;
|
||||
totalDevelopmentCost += developmentInfo.townDevelopmentCost;
|
||||
for(auto building : developmentInfo.toBuild)
|
||||
{
|
||||
if (building.dailyIncome[EGameResID::GOLD] > 0)
|
||||
economyDevelopmentCost += building.buildCostWithPrerequisites[EGameResID::GOLD];
|
||||
}
|
||||
armyCost += developmentInfo.armyCost;
|
||||
|
||||
for(auto bi : developmentInfo.toBuild)
|
||||
@ -169,6 +182,9 @@ void BuildAnalyzer::update()
|
||||
}
|
||||
}
|
||||
|
||||
if (closestThreat < 7)
|
||||
economyDevelopmentCost = 0;
|
||||
|
||||
std::sort(developmentInfos.begin(), developmentInfos.end(), [](const TownDevelopmentInfo & t1, const TownDevelopmentInfo & t2) -> bool
|
||||
{
|
||||
auto val1 = convertToGold(t1.armyCost) - convertToGold(t1.townDevelopmentCost);
|
||||
@ -180,7 +196,7 @@ void BuildAnalyzer::update()
|
||||
updateDailyIncome();
|
||||
|
||||
goldPressure = ai->getLockedResources()[EGameResID::GOLD] / 5000.0f
|
||||
+ (float)armyCost[EGameResID::GOLD] / (1 + 2 * ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f);
|
||||
+ ((float)armyCost[EGameResID::GOLD] + economyDevelopmentCost) / (1 + 2 * ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f);
|
||||
|
||||
logAi->trace("Gold pressure: %f", goldPressure);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user