From fbc9a32ad85d5999a0c4a9acfc3c2dc5ef367a5c Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sat, 22 Apr 2023 18:37:27 +0300 Subject: [PATCH] #2018 - fix shipyard usage for NKAI, allied shipyard should work now --- AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp | 2 +- AI/Nullkiller/Behaviors/DefenceBehavior.cpp | 14 +++++++------- AI/Nullkiller/Engine/Nullkiller.cpp | 2 +- AI/Nullkiller/Engine/Nullkiller.h | 1 + .../Pathfinding/Rules/AILayerTransitionRule.cpp | 6 ++---- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp b/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp index 8717900b6..e63e26c3a 100644 --- a/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp +++ b/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp @@ -209,7 +209,7 @@ Goals::TGoalVec CaptureObjectsBehavior::decompose() const { captureObjects(ai->nullkiller->objectClusterizer->getNearbyObjects()); - if(tasks.empty()) + if(tasks.empty() || ai->nullkiller->getScanDepth() == ScanDepth::FULL) captureObjects(ai->nullkiller->objectClusterizer->getFarObjects()); } diff --git a/AI/Nullkiller/Behaviors/DefenceBehavior.cpp b/AI/Nullkiller/Behaviors/DefenceBehavior.cpp index 3db20a1aa..da5e5f34e 100644 --- a/AI/Nullkiller/Behaviors/DefenceBehavior.cpp +++ b/AI/Nullkiller/Behaviors/DefenceBehavior.cpp @@ -58,13 +58,6 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta auto treatNode = ai->nullkiller->dangerHitMap->getObjectTreat(town); auto treats = { treatNode.maximumDanger, treatNode.fastestDanger }; - if(!treatNode.fastestDanger.hero) - { - logAi->trace("No treat found for town %s", town->getNameTranslated()); - - return; - } - int dayOfWeek = cb->getDate(Date::DAY_OF_WEEK); if(town->garrisonHero) @@ -91,6 +84,13 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta return; } + + if(!treatNode.fastestDanger.hero) + { + logAi->trace("No treat found for town %s", town->getNameTranslated()); + + return; + } uint64_t reinforcement = ai->nullkiller->armyManager->howManyReinforcementsCanBuy(town->getUpperArmy(), town); diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index b4e85fc97..c5aa3324f 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -117,7 +117,7 @@ Goals::TTask Nullkiller::choseBestTask(Goals::TSubgoal behavior, int decompositi void Nullkiller::resetAiState() { lockedResources = TResources(); - scanDepth = ScanDepth::SMALL; + scanDepth = ScanDepth::FULL; playerID = ai->playerID; lockedHeroes.clear(); dangerHitMap->reset(); diff --git a/AI/Nullkiller/Engine/Nullkiller.h b/AI/Nullkiller/Engine/Nullkiller.h index 3a5b7bdc1..1b5e513e6 100644 --- a/AI/Nullkiller/Engine/Nullkiller.h +++ b/AI/Nullkiller/Engine/Nullkiller.h @@ -88,6 +88,7 @@ public: int32_t getFreeGold() const { return getFreeResources()[EGameResID::GOLD]; } void lockResources(const TResources & res); const TResources & getLockedResources() const { return lockedResources; } + ScanDepth getScanDepth() const { return scanDepth; } private: void resetAiState(); diff --git a/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp b/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp index 4871501aa..596dda5de 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp +++ b/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp @@ -53,15 +53,13 @@ namespace AIPathfinding for(const CGTownInstance * t : cb->getTownsInfo()) { - // do not allow ally shipyards because of bug - if(t->hasBuilt(BuildingID::SHIPYARD) && t->getOwner() == ai->playerID) + if(t->hasBuilt(BuildingID::SHIPYARD)) shipyards.push_back(t); } for(const CGObjectInstance * obj : ai->memory->visitableObjs) { - // do not allow ally shipyards because of bug - if(obj->ID != Obj::TOWN && obj->getOwner() == ai->playerID) //towns were handled in the previous loop + if(obj->ID != Obj::TOWN) //towns were handled in the previous loop { if(const IShipyard * shipyard = IShipyard::castFrom(obj)) shipyards.push_back(shipyard);