Browse Source

Nullkiller: calibration and small behavior fixes

Andrii Danylchenko 4 years ago
parent
commit
f832a8b3cd

+ 23 - 5
AI/Nullkiller/Behaviors/StartupBehavior.cpp

@@ -92,7 +92,9 @@ bool needToRecruitHero(const CGTownInstance * startupTown)
 	}
 
 	auto basicCount = cb->getTownsInfo().size() + 2;
-	auto boost = (int)std::floor(std::pow(treasureSourcesCount / 3.0, 2));
+	auto boost = (int)std::floor(std::pow(treasureSourcesCount / 2.0, 2));
+
+	logAi->trace("Startup allows %d+%d heroes", basicCount, boost);
 
 	return cb->getHeroCount(ai->playerID, true) < basicCount + boost;
 }
@@ -106,21 +108,24 @@ Goals::TGoalVec StartupBehavior::decompose() const
 		return tasks;
 
 	const CGTownInstance * startupTown = towns.front();
-	bool canRecruitHero = needToRecruitHero(startupTown);
 
 	if(towns.size() > 1)
 	{
 		startupTown = *vstd::maxElementByFun(towns, [](const CGTownInstance * town) -> float
 		{
+			if(town->garrisonHero)
+				return ai->ah->evaluateHero(town->garrisonHero.get());
+
 			auto closestHero = getNearestHero(town);
 
-			if(!closestHero)
-				return 0;
+			if(closestHero)
+				return ai->ah->evaluateHero(closestHero);
 
-			return ai->ah->evaluateHero(closestHero);
+			return 0;
 		});
 	}
 
+	bool canRecruitHero = needToRecruitHero(startupTown);
 	auto closestHero = getNearestHero(startupTown);
 
 	if(closestHero)
@@ -174,6 +179,19 @@ Goals::TGoalVec StartupBehavior::decompose() const
 		tasks.push_back(Goals::sptr(Goals::RecruitHero(startupTown)));
 	}
 
+	if(tasks.empty() && !startupTown->visitingHero)
+	{
+		for(auto town : towns)
+		{
+			if(!town->visitingHero && needToRecruitHero(town))
+			{
+				tasks.push_back(Goals::sptr(Goals::RecruitHero(town)));
+
+				break;
+			}
+		}
+	}
+
 	if(tasks.empty() && towns.size())
 	{
 		for(const CGTownInstance * town : towns)

+ 2 - 2
AI/Nullkiller/Engine/PriorityEvaluator.cpp

@@ -310,10 +310,10 @@ float getStrategicalValue(const CGObjectInstance * target)
 	switch(target->ID)
 	{
 	case Obj::MINE:
-		return target->subID == Res::GOLD ? 0.5f : 0.05f * getTotalResourceRequirementStrength(target->subID) + 0.05f * getResourceRequirementStrength(target->subID);
+		return target->subID == Res::GOLD ? 0.5f : 0.02f * getTotalResourceRequirementStrength(target->subID) + 0.02f * getResourceRequirementStrength(target->subID);
 
 	case Obj::RESOURCE:
-		return target->subID == Res::GOLD ? 0 : 0.3f * getResourceRequirementStrength(target->subID);
+		return target->subID == Res::GOLD ? 0 : 0.1f * getResourceRequirementStrength(target->subID);
 
 	case Obj::TOWN:
 		return dynamic_cast<const CGTownInstance *>(target)->hasFort()

+ 1 - 1
AI/Nullkiller/Goals/ExecuteHeroChain.cpp

@@ -95,7 +95,7 @@ void ExecuteHeroChain::accept(VCAI * ai)
 					}
 				}
 
-				if(node.turns == 0 && node.coord != hero->visitablePos())
+					if(node.turns == 0 && node.coord != hero->visitablePos())
 				{
 					auto targetNode = cb->getPathsInfo(hero)->getPathInfo(node.coord);
 

+ 1 - 1
AI/Nullkiller/Pathfinding/AINodeStorage.h

@@ -11,7 +11,7 @@
 #pragma once
 
 #define PATHFINDER_TRACE_LEVEL 0
-#define AI_TRACE_LEVEL 1	
+#define AI_TRACE_LEVEL 1
 
 #include "../../../lib/CPathfinder.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"

+ 6 - 5
AI/Nullkiller/Pathfinding/AIPathfinderConfig.cpp

@@ -43,13 +43,14 @@ namespace AIPathfinding
 
 	CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
 	{
-		if(!pathfindingHelper)
-		{
-			auto hero = aiNodeStorage->getHero(source.node);
+		auto hero = aiNodeStorage->getHero(source.node);
+		auto & helper = pathfindingHelpers[hero];
 
-			pathfindingHelper.reset(new CPathfinderHelper(gs, hero, options));
+		if(!helper)
+		{
+			helper.reset(new CPathfinderHelper(gs, hero, options));
 		}
 
-		return pathfindingHelper.get();
+		return helper.get();
 	}
 }

+ 1 - 1
AI/Nullkiller/Pathfinding/AIPathfinderConfig.h

@@ -18,7 +18,7 @@ namespace AIPathfinding
 	class AIPathfinderConfig : public PathfinderConfig
 	{
 	private:
-		std::unique_ptr<CPathfinderHelper> pathfindingHelper;
+		std::map<const CGHeroInstance *, std::unique_ptr<CPathfinderHelper>> pathfindingHelpers;
 		std::shared_ptr<AINodeStorage> aiNodeStorage;
 
 	public: