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

Nullkiller: calibration and small behavior fixes

This commit is contained in:
Andrii Danylchenko 2021-05-16 14:45:48 +03:00 committed by Andrii Danylchenko
parent 37f49f2ac5
commit f832a8b3cd
6 changed files with 34 additions and 15 deletions

View File

@ -92,7 +92,9 @@ bool needToRecruitHero(const CGTownInstance * startupTown)
} }
auto basicCount = cb->getTownsInfo().size() + 2; 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; return cb->getHeroCount(ai->playerID, true) < basicCount + boost;
} }
@ -106,21 +108,24 @@ Goals::TGoalVec StartupBehavior::decompose() const
return tasks; return tasks;
const CGTownInstance * startupTown = towns.front(); const CGTownInstance * startupTown = towns.front();
bool canRecruitHero = needToRecruitHero(startupTown);
if(towns.size() > 1) if(towns.size() > 1)
{ {
startupTown = *vstd::maxElementByFun(towns, [](const CGTownInstance * town) -> float startupTown = *vstd::maxElementByFun(towns, [](const CGTownInstance * town) -> float
{ {
if(town->garrisonHero)
return ai->ah->evaluateHero(town->garrisonHero.get());
auto closestHero = getNearestHero(town); auto closestHero = getNearestHero(town);
if(!closestHero) if(closestHero)
return 0;
return ai->ah->evaluateHero(closestHero); return ai->ah->evaluateHero(closestHero);
return 0;
}); });
} }
bool canRecruitHero = needToRecruitHero(startupTown);
auto closestHero = getNearestHero(startupTown); auto closestHero = getNearestHero(startupTown);
if(closestHero) if(closestHero)
@ -174,6 +179,19 @@ Goals::TGoalVec StartupBehavior::decompose() const
tasks.push_back(Goals::sptr(Goals::RecruitHero(startupTown))); 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()) if(tasks.empty() && towns.size())
{ {
for(const CGTownInstance * town : towns) for(const CGTownInstance * town : towns)

View File

@ -310,10 +310,10 @@ float getStrategicalValue(const CGObjectInstance * target)
switch(target->ID) switch(target->ID)
{ {
case Obj::MINE: 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: 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: case Obj::TOWN:
return dynamic_cast<const CGTownInstance *>(target)->hasFort() return dynamic_cast<const CGTownInstance *>(target)->hasFort()

View File

@ -42,14 +42,15 @@ namespace AIPathfinding
} }
CPathfinderHelper * AIPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs) 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();
} }
} }

View File

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