1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-05 15:05:40 +02:00

Update BuildingBehavior.cpp

Fixed an issue that prevented generating more building-tasks when there already were tasks.
This commit is contained in:
Xilmi 2024-09-01 13:46:44 +02:00
parent be43c4d5f0
commit 751f3b0e7d

View File

@ -53,6 +53,7 @@ Goals::TGoalVec BuildingBehavior::decompose(const Nullkiller * ai) const
for(auto & developmentInfo : developmentInfos)
{
bool emergencyDefense = false;
uint8_t closestThreat = UINT8_MAX;
for (auto threat : ai->dangerHitMap->getTownThreats(developmentInfo.town))
{
@ -63,13 +64,17 @@ Goals::TGoalVec BuildingBehavior::decompose(const Nullkiller * ai) const
if (closestThreat <= 1 && developmentInfo.town->fortLevel() < CGTownInstance::EFortLevel::CASTLE && !buildingInfo.notEnoughRes)
{
if (buildingInfo.id == BuildingID::FORT || buildingInfo.id == BuildingID::CITADEL || buildingInfo.id == BuildingID::CASTLE)
{
tasks.push_back(sptr(BuildThis(buildingInfo, developmentInfo)));
emergencyDefense = true;
}
}
}
if (tasks.empty())
if (!emergencyDefense)
{
for (auto& buildingInfo : developmentInfo.toBuild)
{
logAi->trace("Looking at %s", buildingInfo.toString());
if (isGoldPressureLow || buildingInfo.dailyIncome[EGameResID::GOLD] > 0)
{
if (buildingInfo.notEnoughRes)
@ -81,11 +86,14 @@ Goals::TGoalVec BuildingBehavior::decompose(const Nullkiller * ai) const
composition.addNext(BuildThis(buildingInfo, developmentInfo));
composition.addNext(SaveResources(buildingInfo.buildCost));
logAi->trace("Generate task to build: %s", buildingInfo.toString());
tasks.push_back(sptr(composition));
}
else
{
tasks.push_back(sptr(BuildThis(buildingInfo, developmentInfo)));
logAi->trace("Generate task to build: %s", buildingInfo.toString());
}
}
}
}