1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/AI/Nullkiller/Behaviors/BuildingBehavior.cpp

80 lines
2.1 KiB
C++
Raw Normal View History

/*
* 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 "BuildingBehavior.h"
2021-05-16 14:39:38 +02:00
#include "../AIGateway.h"
#include "../AIUtility.h"
#include "../Goals/BuyArmy.h"
2021-05-16 14:39:38 +02:00
#include "../Goals/Composition.h"
#include "../Goals/BuildThis.h"
2021-05-16 14:39:38 +02:00
#include "../Goals/SaveResources.h"
#include "../Engine/Nullkiller.h"
2022-09-26 20:01:07 +02:00
namespace NKAI
{
using namespace Goals;
std::string BuildingBehavior::toString() const
{
return "Build";
}
2024-03-31 17:39:00 +02:00
Goals::TGoalVec BuildingBehavior::decompose(const Nullkiller * ai) const
{
Goals::TGoalVec tasks;
2024-03-31 17:39:00 +02:00
TResources resourcesRequired = ai->buildAnalyzer->getResourcesRequiredNow();
TResources totalDevelopmentCost = ai->buildAnalyzer->getTotalResourcesRequired();
TResources availableResources = ai->getFreeResources();
TResources dailyIncome = ai->buildAnalyzer->getDailyIncome();
2021-05-16 14:39:38 +02:00
logAi->trace("Free resources amount: %s", availableResources.toString());
resourcesRequired -= availableResources;
resourcesRequired.positive();
logAi->trace("daily income: %s", dailyIncome.toString());
logAi->trace("resources required to develop towns now: %s, total: %s",
resourcesRequired.toString(),
totalDevelopmentCost.toString());
2024-03-31 17:39:00 +02:00
auto & developmentInfos = ai->buildAnalyzer->getDevelopmentInfo();
2024-04-16 23:10:15 +02:00
auto isGoldPressureLow = !ai->buildAnalyzer->isGoldPressureHigh();
for(auto & developmentInfo : developmentInfos)
{
for(auto & buildingInfo : developmentInfo.toBuild)
{
2024-04-16 23:10:15 +02:00
if(isGoldPressureLow || buildingInfo.dailyIncome[EGameResID::GOLD] > 0)
2021-05-16 14:39:38 +02:00
{
if(buildingInfo.notEnoughRes)
{
2024-03-31 17:39:00 +02:00
if(ai->getLockedResources().canAfford(buildingInfo.buildCost))
2021-05-16 14:39:38 +02:00
continue;
Composition composition;
composition.addNext(BuildThis(buildingInfo, developmentInfo));
composition.addNext(SaveResources(buildingInfo.buildCost));
tasks.push_back(sptr(composition));
}
else
tasks.push_back(sptr(BuildThis(buildingInfo, developmentInfo)));
}
}
}
return tasks;
}
2022-09-26 20:01:07 +02:00
}