1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Merge pull request #3814 from vcmi/fixes

NKAI: fix patrolling heroes never retreat and town danger evaluation
This commit is contained in:
Andrii Danylchenko
2024-04-23 18:52:47 +03:00
committed by GitHub
3 changed files with 26 additions and 3 deletions

View File

@ -545,6 +545,11 @@ std::optional<BattleAction> AIGateway::makeSurrenderRetreatDecision(const Battle
LOG_TRACE(logAi); LOG_TRACE(logAi);
NET_EVENT_HANDLER; NET_EVENT_HANDLER;
if(battleState.ourHero && battleState.ourHero->patrol.patrolling)
{
return std::nullopt;
}
double ourStrength = battleState.getOurStrength(); double ourStrength = battleState.getOurStrength();
double fightRatio = ourStrength / (double)battleState.getEnemyStrength(); double fightRatio = ourStrength / (double)battleState.getEnemyStrength();

View File

@ -129,9 +129,16 @@ void HeroManager::update()
heroRoles.clear(); heroRoles.clear();
for(auto hero : myHeroes) for(auto hero : myHeroes)
{
if(hero->patrol.patrolling)
{
heroRoles[hero] = HeroRole::MAIN;
}
else
{ {
heroRoles[hero] = (globalMainCount--) > 0 ? HeroRole::MAIN : HeroRole::SCOUT; heroRoles[hero] = (globalMainCount--) > 0 ? HeroRole::MAIN : HeroRole::SCOUT;
} }
}
for(auto hero : myHeroes) for(auto hero : myHeroes)
{ {

View File

@ -53,7 +53,7 @@ ui64 FuzzyHelper::evaluateDanger(const int3 & tile, const CGHeroInstance * visit
// in some scenarios hero happens to be "under" the object (eg town). Then we consider ONLY the hero. // in some scenarios hero happens to be "under" the object (eg town). Then we consider ONLY the hero.
if(vstd::contains_if(visitableObjects, objWithID<Obj::HERO>)) if(vstd::contains_if(visitableObjects, objWithID<Obj::HERO>))
{ {
vstd::erase_if(visitableObjects, [](const CGObjectInstance * obj) vstd::erase_if(visitableObjects, [](const CGObjectInstance * obj) -> bool
{ {
return !objWithID<Obj::HERO>(obj); return !objWithID<Obj::HERO>(obj);
}); });
@ -62,6 +62,17 @@ ui64 FuzzyHelper::evaluateDanger(const int3 & tile, const CGHeroInstance * visit
if(const CGObjectInstance * dangerousObject = vstd::backOrNull(visitableObjects)) if(const CGObjectInstance * dangerousObject = vstd::backOrNull(visitableObjects))
{ {
objectDanger = evaluateDanger(dangerousObject); //unguarded objects can also be dangerous or unhandled objectDanger = evaluateDanger(dangerousObject); //unguarded objects can also be dangerous or unhandled
if(objWithID<Obj::HERO>(dangerousObject))
{
auto hero = dynamic_cast<const CGHeroInstance *>(dangerousObject);
if(hero->visitedTown && !hero->visitedTown->garrisonHero)
{
objectDanger += evaluateDanger(hero->visitedTown.get());
}
}
if(objectDanger) if(objectDanger)
{ {
//TODO: don't downcast objects AI shouldn't know about! //TODO: don't downcast objects AI shouldn't know about!