2021-05-16 13:14:17 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2021-05-16 13:14:17 +02:00
|
|
|
#include "../AIUtility.h"
|
|
|
|
#include "../Goals/BuyArmy.h"
|
2021-05-16 14:39:38 +02:00
|
|
|
#include "../Goals/Composition.h"
|
2020-05-04 17:58:43 +02:00
|
|
|
#include "../Goals/BuildThis.h"
|
2021-05-16 14:39:38 +02:00
|
|
|
#include "../Goals/SaveResources.h"
|
2021-05-16 13:14:17 +02:00
|
|
|
#include "../Engine/Nullkiller.h"
|
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2021-05-16 13:14:17 +02:00
|
|
|
using namespace Goals;
|
|
|
|
|
|
|
|
std::string BuildingBehavior::toString() const
|
|
|
|
{
|
|
|
|
return "Build";
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:38:26 +02:00
|
|
|
Goals::TGoalVec BuildingBehavior::decompose() const
|
2021-05-16 13:14:17 +02:00
|
|
|
{
|
|
|
|
Goals::TGoalVec tasks;
|
|
|
|
|
2021-05-16 13:15:03 +02:00
|
|
|
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();
|
2021-05-16 13:15:03 +02:00
|
|
|
TResources dailyIncome = ai->nullkiller->buildAnalyzer->getDailyIncome();
|
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
logAi->trace("Free resources amount: %s", availableResources.toString());
|
2021-05-16 13:15:03 +02:00
|
|
|
|
|
|
|
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();
|
2021-05-16 13:19:00 +02:00
|
|
|
auto goldPreasure = ai->nullkiller->buildAnalyzer->getGoldPreasure();
|
2021-05-16 13:15:03 +02:00
|
|
|
|
|
|
|
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)));
|
|
|
|
}
|
2021-05-16 13:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-16 13:14:17 +02:00
|
|
|
|
|
|
|
return tasks;
|
|
|
|
}
|
2022-09-26 20:01:07 +02:00
|
|
|
|
|
|
|
}
|