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

85 lines
2.3 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 "lib/mapping/CMap.h" //for victory conditions
#include "lib/CPathfinder.h"
#include "../Engine/Nullkiller.h"
2022-09-26 20:01:07 +02:00
namespace NKAI
{
extern boost::thread_specific_ptr<CCallback> cb;
2021-05-16 14:39:38 +02:00
extern boost::thread_specific_ptr<AIGateway> ai;
using namespace Goals;
std::string BuildingBehavior::toString() const
{
return "Build";
}
Goals::TGoalVec BuildingBehavior::decompose() const
{
Goals::TGoalVec tasks;
TResources resourcesRequired = ai->nullkiller->buildAnalyzer->getResourcesRequiredNow();
TResources totalDevelopmentCost = ai->nullkiller->buildAnalyzer->getTotalResourcesRequired();
2021-05-16 14:39:38 +02:00
TResources availableResources = ai->nullkiller->getFreeResources();
TResources dailyIncome = ai->nullkiller->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());
auto & developmentInfos = ai->nullkiller->buildAnalyzer->getDevelopmentInfo();
auto goldPreasure = ai->nullkiller->buildAnalyzer->getGoldPreasure();
for(auto & developmentInfo : developmentInfos)
{
for(auto & buildingInfo : developmentInfo.toBuild)
{
2023-04-05 02:26:29 +02:00
if(goldPreasure < MAX_GOLD_PEASURE || buildingInfo.dailyIncome[EGameResID::GOLD] > 0)
2021-05-16 14:39:38 +02:00
{
if(buildingInfo.notEnoughRes)
{
if(ai->nullkiller->getLockedResources().canAfford(buildingInfo.buildCost))
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
}