1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-18 03:21:27 +02:00

Update BuyArmyBehavior.cpp

Allow building army in threatened town even when it wants to save for a building.
This commit is contained in:
Xilmi 2024-08-18 09:49:02 +02:00
parent ea5ee039ca
commit 65b8576687

View File

@ -35,6 +35,8 @@ Goals::TGoalVec BuyArmyBehavior::decompose(const Nullkiller * ai) const
return tasks;
}
ai->dangerHitMap->updateHitMap();
for(auto town : cb->getTownsInfo())
{
//If we can recruit a hero that comes with more army than he costs, we are better off spending our gold on them
@ -48,7 +50,13 @@ Goals::TGoalVec BuyArmyBehavior::decompose(const Nullkiller * ai) const
}
}
if (ai->buildAnalyzer->isGoldPressureHigh() && !town->hasBuilt(BuildingID::CITY_HALL) && cb->canBuildStructure(town, BuildingID::CITY_HALL) != EBuildingState::FORBIDDEN)
uint8_t closestThreat = UINT8_MAX;
for (auto threat : ai->dangerHitMap->getTownThreats(town))
{
closestThreat = std::min(closestThreat, threat.turn);
}
if (closestThreat >=2 && ai->buildAnalyzer->isGoldPressureHigh() && !town->hasBuilt(BuildingID::CITY_HALL) && cb->canBuildStructure(town, BuildingID::CITY_HALL) != EBuildingState::FORBIDDEN)
{
return tasks;
}