From eeea01d77885d5186a82921fb85cb006b0a180b5 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Mon, 26 Sep 2022 21:01:07 +0300 Subject: [PATCH] NKAI: namespace --- AI/Nullkiller/AIGateway.cpp | 5 +- AI/Nullkiller/AIGateway.h | 9 +- AI/Nullkiller/AIUtility.cpp | 5 + AI/Nullkiller/AIUtility.h | 49 +---- AI/Nullkiller/Analyzers/ArmyManager.cpp | 4 + AI/Nullkiller/Analyzers/ArmyManager.h | 5 + AI/Nullkiller/Analyzers/BuildAnalyzer.cpp | 5 + AI/Nullkiller/Analyzers/BuildAnalyzer.h | 5 + .../Analyzers/DangerHitMapAnalyzer.cpp | 5 + .../Analyzers/DangerHitMapAnalyzer.h | 5 + AI/Nullkiller/Analyzers/HeroManager.cpp | 5 + AI/Nullkiller/Analyzers/HeroManager.h | 5 + AI/Nullkiller/Analyzers/ObjectClusterizer.cpp | 23 ++- AI/Nullkiller/Analyzers/ObjectClusterizer.h | 5 + AI/Nullkiller/Behaviors/Behavior.cpp | 0 AI/Nullkiller/Behaviors/Behavior.h | 19 -- AI/Nullkiller/Behaviors/BuildingBehavior.cpp | 5 + AI/Nullkiller/Behaviors/BuildingBehavior.h | 3 + AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp | 5 + AI/Nullkiller/Behaviors/BuyArmyBehavior.h | 4 + .../Behaviors/CaptureObjectsBehavior.cpp | 18 +- .../Behaviors/CaptureObjectsBehavior.h | 4 + AI/Nullkiller/Behaviors/ClusterBehavior.cpp | 13 +- AI/Nullkiller/Behaviors/ClusterBehavior.h | 7 +- AI/Nullkiller/Behaviors/DefenceBehavior.cpp | 23 ++- AI/Nullkiller/Behaviors/DefenceBehavior.h | 4 + .../Behaviors/GatherArmyBehavior.cpp | 41 ++-- AI/Nullkiller/Behaviors/GatherArmyBehavior.h | 4 + .../Behaviors/RecruitHeroBehavior.cpp | 5 + AI/Nullkiller/Behaviors/RecruitHeroBehavior.h | 6 +- AI/Nullkiller/Behaviors/StartupBehavior.cpp | 5 + AI/Nullkiller/Behaviors/StartupBehavior.h | 4 + AI/Nullkiller/Engine/AIMemory.cpp | 7 +- AI/Nullkiller/Engine/AIMemory.h | 5 + AI/Nullkiller/Engine/DeepDecomposer.cpp | 21 +- AI/Nullkiller/Engine/DeepDecomposer.h | 7 +- AI/Nullkiller/Engine/FuzzyEngines.cpp | 5 + AI/Nullkiller/Engine/FuzzyEngines.h | 5 + AI/Nullkiller/Engine/FuzzyHelper.cpp | 9 +- AI/Nullkiller/Engine/FuzzyHelper.h | 7 +- AI/Nullkiller/Engine/Nullkiller.cpp | 11 +- AI/Nullkiller/Engine/Nullkiller.h | 5 + AI/Nullkiller/Engine/PriorityEvaluator.cpp | 7 +- AI/Nullkiller/Engine/PriorityEvaluator.h | 5 + AI/Nullkiller/Goals/AbstractGoal.cpp | 7 +- AI/Nullkiller/Goals/AbstractGoal.h | 9 +- AI/Nullkiller/Goals/AdventureSpellCast.cpp | 5 + AI/Nullkiller/Goals/AdventureSpellCast.h | 5 + AI/Nullkiller/Goals/Build.cpp | 5 + AI/Nullkiller/Goals/Build.h | 5 + AI/Nullkiller/Goals/BuildBoat.cpp | 5 + AI/Nullkiller/Goals/BuildBoat.h | 5 + AI/Nullkiller/Goals/BuildThis.cpp | 7 +- AI/Nullkiller/Goals/BuildThis.h | 5 + AI/Nullkiller/Goals/BuyArmy.cpp | 7 +- AI/Nullkiller/Goals/BuyArmy.h | 5 + AI/Nullkiller/Goals/CGoal.h | 34 +--- AI/Nullkiller/Goals/CaptureObject.cpp | 7 +- AI/Nullkiller/Goals/CaptureObject.h | 5 + AI/Nullkiller/Goals/CompleteQuest.cpp | 7 +- AI/Nullkiller/Goals/CompleteQuest.h | 4 + AI/Nullkiller/Goals/Composition.cpp | 7 +- AI/Nullkiller/Goals/Composition.h | 4 + AI/Nullkiller/Goals/DigAtTile.cpp | 5 + AI/Nullkiller/Goals/DigAtTile.h | 5 + AI/Nullkiller/Goals/DismissHero.cpp | 5 + AI/Nullkiller/Goals/DismissHero.h | 4 + .../Goals/ExchangeSwapTownHeroes.cpp | 7 +- AI/Nullkiller/Goals/ExchangeSwapTownHeroes.h | 4 + AI/Nullkiller/Goals/ExecuteHeroChain.cpp | 7 +- AI/Nullkiller/Goals/ExecuteHeroChain.h | 4 + AI/Nullkiller/Goals/GatherArmy.cpp | 5 + AI/Nullkiller/Goals/GatherArmy.h | 5 + AI/Nullkiller/Goals/Goals.h | 2 +- AI/Nullkiller/Goals/Invalid.h | 33 +++ AI/Nullkiller/Goals/RecruitHero.cpp | 7 +- AI/Nullkiller/Goals/RecruitHero.h | 5 + AI/Nullkiller/Goals/SaveResources.cpp | 5 + AI/Nullkiller/Goals/SaveResources.h | 4 + AI/Nullkiller/Goals/Trade.cpp | 6 +- AI/Nullkiller/Goals/Trade.h | 5 + AI/Nullkiller/Goals/Win.cpp | 189 ------------------ AI/Nullkiller/Goals/Win.h | 39 ---- AI/Nullkiller/Markers/ArmyUpgrade.cpp | 7 +- AI/Nullkiller/Markers/ArmyUpgrade.h | 6 +- AI/Nullkiller/Markers/DefendTown.cpp | 7 +- AI/Nullkiller/Markers/DefendTown.h | 6 +- AI/Nullkiller/Markers/HeroExchange.cpp | 7 +- AI/Nullkiller/Markers/HeroExchange.h | 6 +- AI/Nullkiller/Markers/UnlockCluster.cpp | 7 +- AI/Nullkiller/Markers/UnlockCluster.h | 7 +- AI/Nullkiller/Pathfinding/AINodeStorage.cpp | 33 +-- AI/Nullkiller/Pathfinding/AINodeStorage.h | 13 +- AI/Nullkiller/Pathfinding/AIPathfinder.cpp | 5 + AI/Nullkiller/Pathfinding/AIPathfinder.h | 5 + .../Pathfinding/AIPathfinderConfig.cpp | 4 + .../Pathfinding/AIPathfinderConfig.h | 5 + .../Pathfinding/Actions/BattleAction.cpp | 7 +- .../Pathfinding/Actions/BattleAction.h | 7 +- .../Pathfinding/Actions/BoatActions.cpp | 14 +- .../Pathfinding/Actions/BoatActions.h | 5 + .../Pathfinding/Actions/BuyArmyAction.cpp | 7 +- .../Pathfinding/Actions/BuyArmyAction.h | 6 +- .../Pathfinding/Actions/QuestAction.cpp | 7 +- .../Pathfinding/Actions/QuestAction.h | 6 +- .../Pathfinding/Actions/SpecialAction.cpp | 8 +- .../Pathfinding/Actions/SpecialAction.h | 5 + .../Pathfinding/Actions/TownPortalAction.cpp | 7 +- .../Pathfinding/Actions/TownPortalAction.h | 6 +- AI/Nullkiller/Pathfinding/Actors.cpp | 27 +-- AI/Nullkiller/Pathfinding/Actors.h | 5 + .../Rules/AILayerTransitionRule.cpp | 8 +- .../Pathfinding/Rules/AILayerTransitionRule.h | 4 + .../Rules/AIMovementAfterDestinationRule.cpp | 14 +- .../Rules/AIMovementAfterDestinationRule.h | 4 + .../Rules/AIMovementToDestinationRule.cpp | 6 +- .../Rules/AIMovementToDestinationRule.h | 4 + .../Pathfinding/Rules/AIPreviousNodeRule.cpp | 6 +- .../Pathfinding/Rules/AIPreviousNodeRule.h | 4 + AI/Nullkiller/main.cpp | 2 +- Global.h | 14 ++ 121 files changed, 713 insertions(+), 471 deletions(-) delete mode 100644 AI/Nullkiller/Behaviors/Behavior.cpp delete mode 100644 AI/Nullkiller/Behaviors/Behavior.h delete mode 100644 AI/Nullkiller/Goals/Win.cpp delete mode 100644 AI/Nullkiller/Goals/Win.h diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index f657d3ecf..1b7313d4e 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -23,7 +23,8 @@ #include "AIGateway.h" #include "Goals/Goals.h" -class CGVisitableOPW; +namespace NKAI +{ const float SAFE_ATTACK_CONSTANT = 1.2; @@ -1668,3 +1669,5 @@ bool AIStatus::channelProbing() { return ongoingChannelProbing; } + +} diff --git a/AI/Nullkiller/AIGateway.h b/AI/Nullkiller/AIGateway.h index 29066be81..f3a4d8454 100644 --- a/AI/Nullkiller/AIGateway.h +++ b/AI/Nullkiller/AIGateway.h @@ -25,11 +25,8 @@ #include "Pathfinding/AIPathfinder.h" #include "Engine/Nullkiller.h" -VCMI_LIB_NAMESPACE_BEGIN - -struct QuestInfo; - -VCMI_LIB_NAMESPACE_END +namespace NKAI +{ class AIStatus { @@ -222,3 +219,5 @@ public: h & battlename; } }; + +} diff --git a/AI/Nullkiller/AIUtility.cpp b/AI/Nullkiller/AIUtility.cpp index 2f2a29fde..52c127c75 100644 --- a/AI/Nullkiller/AIUtility.cpp +++ b/AI/Nullkiller/AIUtility.cpp @@ -20,6 +20,9 @@ #include "../../lib/CModHandler.h" +namespace NKAI +{ + extern boost::thread_specific_ptr ai; //extern static const int3 dirs[8]; @@ -446,3 +449,5 @@ bool shouldVisit(const Nullkiller * ai, const CGHeroInstance * h, const CGObject return true; } + +} diff --git a/AI/Nullkiller/AIUtility.h b/AI/Nullkiller/AIUtility.h index cdc19c1b5..68fa115f6 100644 --- a/AI/Nullkiller/AIUtility.h +++ b/AI/Nullkiller/AIUtility.h @@ -48,19 +48,19 @@ #include "../../lib/mapObjects/CObjectHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/CPathfinder.h" +#include "../../CCallback.h" #include using namespace tbb; -class CCallback; -class Nullkiller; -struct creInfo; - -typedef const int3 & crint3; -typedef const std::string & crstring; typedef std::pair> dwellingContent; +namespace NKAI +{ +struct creInfo; +class Nullkiller; + const int GOLD_MINE_PRODUCTION = 1000, WOOD_ORE_MINE_PRODUCTION = 2, RESOURCE_MINE_PRODUCTION = 1; const int ACTUAL_RESOURCE_COUNT = 7; const int ALLOWED_ROAMING_HEROES = 8; @@ -151,39 +151,6 @@ struct ObjectIdRef } }; -struct TimeCheck -{ - CStopWatch time; - std::string txt; - TimeCheck(crstring TXT) - : txt(TXT) - { - } - - ~TimeCheck() - { - logAi->trace("Time of %s was %d ms.", txt, time.getDiff()); - } -}; - -//TODO: replace with vstd:: -struct AtScopeExit -{ - std::function foo; - AtScopeExit(const std::function & FOO) - : foo(FOO) - {} - ~AtScopeExit() - { - foo(); - } -}; - - -class ObjsVector : public std::vector -{ -}; - template bool objWithID(const CGObjectInstance * obj) { @@ -278,7 +245,7 @@ uint64_t timeElapsed(std::chrono::time_point bool shouldVisit(const Nullkiller * ai, const CGHeroInstance * h, const CGObjectInstance * obj); template -void pforeachTilePos(crint3 mapSize, TFunc fn) +void pforeachTilePos(const int3 & mapSize, TFunc fn) { for(int z = 0; z < mapSize.z; ++z) { @@ -380,3 +347,5 @@ private: std::shared_ptr *> instance_tracker; boost::mutex sync; }; + +} diff --git a/AI/Nullkiller/Analyzers/ArmyManager.cpp b/AI/Nullkiller/Analyzers/ArmyManager.cpp index 48e2f3169..e5356d368 100644 --- a/AI/Nullkiller/Analyzers/ArmyManager.cpp +++ b/AI/Nullkiller/Analyzers/ArmyManager.cpp @@ -14,6 +14,8 @@ #include "../../../CCallback.h" #include "../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ class StackUpgradeInfo { public: @@ -497,3 +499,5 @@ ArmyUpgradeInfo ArmyManager::calculateCreaturesUpgrade( return result; } + +} diff --git a/AI/Nullkiller/Analyzers/ArmyManager.h b/AI/Nullkiller/Analyzers/ArmyManager.h index fddad9fcb..5b71bda48 100644 --- a/AI/Nullkiller/Analyzers/ArmyManager.h +++ b/AI/Nullkiller/Analyzers/ArmyManager.h @@ -17,6 +17,9 @@ #include "../../../lib/CTownHandler.h" #include "../../../lib/CBuildingHandler.h" +namespace NKAI +{ + class Nullkiller; struct SlotInfo @@ -102,3 +105,5 @@ private: std::vector getHillFortUpgrades(const CCreatureSet * army) const; std::vector getDwellingUpgrades(const CCreatureSet * army, const CGDwelling * dwelling) const; }; + +} diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp index 378598d5e..314b4174f 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp @@ -12,6 +12,9 @@ #include "../../../lib/mapping/CMap.h" //for victory conditions #include "../Engine/Nullkiller.h" +namespace NKAI +{ + void BuildAnalyzer::updateTownDwellings(TownDevelopmentInfo & developmentInfo) { auto townInfo = developmentInfo.town->town; @@ -394,3 +397,5 @@ std::string BuildingInfo::toString() const + " x " + creatureCost.toString() + ", daily: " + dailyIncome.toString(); } + +} diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.h b/AI/Nullkiller/Analyzers/BuildAnalyzer.h index 9fa58f97c..820442a72 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.h +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.h @@ -12,6 +12,9 @@ #include "../AIUtility.h" #include "../../../lib/ResourceSet.h" +namespace NKAI +{ + class Nullkiller; class DLL_EXPORT BuildingInfo @@ -104,3 +107,5 @@ private: void updateDailyIncome(); void reset(); }; + +} diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index 8192fd1a4..c3cdcbb71 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp @@ -11,6 +11,9 @@ #include "lib/mapping/CMap.h" //for victory conditions #include "../Engine/Nullkiller.h" +namespace NKAI +{ + void DangerHitMapAnalyzer::updateHitMap() { if(upToDate) @@ -137,3 +140,5 @@ void DangerHitMapAnalyzer::reset() { upToDate = false; } + +} diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h index 7d2e70661..b74b52a4e 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h @@ -11,6 +11,9 @@ #include "../AIUtility.h" +namespace NKAI +{ + struct HitMapInfo { uint64_t danger; @@ -55,3 +58,5 @@ public: const std::set & getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const; void reset(); }; + +} diff --git a/AI/Nullkiller/Analyzers/HeroManager.cpp b/AI/Nullkiller/Analyzers/HeroManager.cpp index 7b546f70c..76abf65b9 100644 --- a/AI/Nullkiller/Analyzers/HeroManager.cpp +++ b/AI/Nullkiller/Analyzers/HeroManager.cpp @@ -13,6 +13,9 @@ #include "../../../lib/mapObjects/MapObjects.h" #include "../../../lib/CHeroHandler.h" +namespace NKAI +{ + SecondarySkillEvaluator HeroManager::wariorSkillsScores = SecondarySkillEvaluator( { std::make_shared( @@ -305,3 +308,5 @@ float SecondarySkillEvaluator::evaluateSecSkill(const CGHeroInstance * hero, Sec return score; } + +} diff --git a/AI/Nullkiller/Analyzers/HeroManager.h b/AI/Nullkiller/Analyzers/HeroManager.h index 8248a2b0b..459604bef 100644 --- a/AI/Nullkiller/Analyzers/HeroManager.h +++ b/AI/Nullkiller/Analyzers/HeroManager.h @@ -17,6 +17,9 @@ #include "../../../lib/CTownHandler.h" #include "../../../lib/CBuildingHandler.h" +namespace NKAI +{ + class DLL_EXPORT IHeroManager //: public: IAbstractManager { public: @@ -104,3 +107,5 @@ private: public: void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const override; }; + +} diff --git a/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp b/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp index 65301992b..2acdef5e9 100644 --- a/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp +++ b/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp @@ -14,6 +14,9 @@ #include "../Engine/Nullkiller.h" #include "lib/mapping/CMap.h" //for victory conditions +namespace NKAI +{ + void ObjectCluster::addObject(const CGObjectInstance * obj, const AIPath & path, float priority) { ClusterObjects::accessor info; @@ -228,7 +231,7 @@ void ObjectClusterizer::clusterize() if(!shouldVisitObject(obj)) return; -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Check object %s%s.", obj->getObjectName(), obj->visitablePos().toString()); #endif @@ -236,7 +239,7 @@ void ObjectClusterizer::clusterize() if(paths.empty()) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("No paths found."); #endif continue; @@ -251,7 +254,7 @@ void ObjectClusterizer::clusterize() { farObjects.addObject(obj, paths.front(), 0); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Object ignored. Moved to far objects with path %s", paths.front().toString()); #endif @@ -262,13 +265,13 @@ void ObjectClusterizer::clusterize() for(auto & path : paths) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Checking path %s", path.toString()); #endif if(!shouldVisit(ai, path.targetHero, obj)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Hero %s does not need to visit %s", path.targetHero->name, obj->getObjectName()); #endif continue; @@ -282,7 +285,7 @@ void ObjectClusterizer::clusterize() { if(vstd::contains(heroesProcessed, path.targetHero)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Hero %s is already processed.", path.targetHero->name); #endif continue; @@ -302,7 +305,7 @@ void ObjectClusterizer::clusterize() cluster->second->addObject(obj, path, priority); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Path added to cluster %s%s", blocker->getObjectName(), blocker->visitablePos().toString()); #endif continue; @@ -327,7 +330,7 @@ void ObjectClusterizer::clusterize() farObjects.addObject(obj, path, priority); } -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Path %s added to %s objects. Turn: %d, priority: %f", path.toString(), interestingObject ? "near" : "far", @@ -345,7 +348,7 @@ void ObjectClusterizer::clusterize() { logAi->trace("Cluster %s %s count: %i", pair.first->getObjectName(), pair.first->visitablePos().toString(), pair.second->objects.size()); -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 for(auto obj : pair.second->getObjects()) { logAi->trace("Object %s %s", obj->getObjectName(), obj->visitablePos().toString()); @@ -355,3 +358,5 @@ void ObjectClusterizer::clusterize() logAi->trace("Clusterization complete in %ld", timeElapsed(start)); } + +} diff --git a/AI/Nullkiller/Analyzers/ObjectClusterizer.h b/AI/Nullkiller/Analyzers/ObjectClusterizer.h index 3972e3084..c8137bba9 100644 --- a/AI/Nullkiller/Analyzers/ObjectClusterizer.h +++ b/AI/Nullkiller/Analyzers/ObjectClusterizer.h @@ -11,6 +11,9 @@ #include "../Pathfinding/AINodeStorage.h" +namespace NKAI +{ + struct ClusterObjectInfo { float priority; @@ -72,3 +75,5 @@ public: private: bool shouldVisitObject(const CGObjectInstance * obj) const; }; + +} diff --git a/AI/Nullkiller/Behaviors/Behavior.cpp b/AI/Nullkiller/Behaviors/Behavior.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/AI/Nullkiller/Behaviors/Behavior.h b/AI/Nullkiller/Behaviors/Behavior.h deleted file mode 100644 index e9e36197e..000000000 --- a/AI/Nullkiller/Behaviors/Behavior.h +++ /dev/null @@ -1,19 +0,0 @@ -/* -* Behavior.h, 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 -* -*/ -#pragma once - -#include "../AIGateway.h" -#error REMOVE THIS FILE - -class Behavior : public Goals::AbstractGoal -{ -public: - virtual std::string toString() const = 0; -}; diff --git a/AI/Nullkiller/Behaviors/BuildingBehavior.cpp b/AI/Nullkiller/Behaviors/BuildingBehavior.cpp index 5fc50c213..e41840662 100644 --- a/AI/Nullkiller/Behaviors/BuildingBehavior.cpp +++ b/AI/Nullkiller/Behaviors/BuildingBehavior.cpp @@ -19,6 +19,9 @@ #include "lib/CPathfinder.h" #include "../Engine/Nullkiller.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -77,3 +80,5 @@ Goals::TGoalVec BuildingBehavior::decompose() const return tasks; } + +} diff --git a/AI/Nullkiller/Behaviors/BuildingBehavior.h b/AI/Nullkiller/Behaviors/BuildingBehavior.h index 914b2d241..813a37619 100644 --- a/AI/Nullkiller/Behaviors/BuildingBehavior.h +++ b/AI/Nullkiller/Behaviors/BuildingBehavior.h @@ -13,6 +13,8 @@ #include "../AIUtility.h" #include "../Goals/CGoal.h" +namespace NKAI +{ namespace Goals { class BuildingBehavior : public CGoal @@ -32,3 +34,4 @@ namespace Goals }; } +} diff --git a/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp b/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp index d7fbea89b..c4e96bb54 100644 --- a/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp +++ b/AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp @@ -16,6 +16,9 @@ #include "lib/mapping/CMap.h" //for victory conditions #include "lib/CPathfinder.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -75,3 +78,5 @@ Goals::TGoalVec BuyArmyBehavior::decompose() const return tasks; } + +} diff --git a/AI/Nullkiller/Behaviors/BuyArmyBehavior.h b/AI/Nullkiller/Behaviors/BuyArmyBehavior.h index 4c0aa8f3d..a6bf681c7 100644 --- a/AI/Nullkiller/Behaviors/BuyArmyBehavior.h +++ b/AI/Nullkiller/Behaviors/BuyArmyBehavior.h @@ -13,6 +13,8 @@ #include "../AIUtility.h" #include "../Goals/CGoal.h" +namespace NKAI +{ namespace Goals { class BuyArmyBehavior : public CGoal @@ -30,3 +32,5 @@ namespace Goals } }; } + +} diff --git a/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp b/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp index 0b65c4eac..d6b7eee41 100644 --- a/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp +++ b/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp @@ -12,9 +12,13 @@ #include "../Engine/Nullkiller.h" #include "../Goals/Composition.h" #include "../Goals/ExecuteHeroChain.h" +#include "../Goals/Invalid.h" #include "CaptureObjectsBehavior.h" #include "../AIUtility.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -59,13 +63,13 @@ Goals::TGoalVec CaptureObjectsBehavior::getVisitGoals(const std::vector { tasks.push_back(sptr(Goals::Invalid())); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Path found %s", path.toString()); #endif if(ai->nullkiller->dangerHitMap->enemyCanKillOurHeroesAlongThePath(path)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Ignore path. Target hero can be killed by enemy. Our power %lld", path.heroArmy->getArmyStrength()); #endif continue; @@ -85,7 +89,7 @@ Goals::TGoalVec CaptureObjectsBehavior::getVisitGoals(const std::vector { auto subGoal = firstBlockedAction->decompose(path.targetHero); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Decomposing special action %s returns %s", firstBlockedAction->toString(), subGoal->toString()); #endif @@ -104,7 +108,7 @@ Goals::TGoalVec CaptureObjectsBehavior::getVisitGoals(const std::vector auto isSafe = isSafeToVisit(hero, path.heroArmy, danger); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace( "It is %s to visit %s by %s with army %lld, danger %lld and army loss %lld", isSafe ? "safe" : "not safe", @@ -161,7 +165,7 @@ Goals::TGoalVec CaptureObjectsBehavior::decompose() const if(!objectMatchesFilter(objToVisit)) continue; -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Checking object %s, %s", objToVisit->getObjectName(), objToVisit->visitablePos().toString()); #endif @@ -171,7 +175,7 @@ Goals::TGoalVec CaptureObjectsBehavior::decompose() const std::vector> waysToVisitObj; std::shared_ptr closestWay; -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Found %d paths", paths.size()); #endif vstd::concatenate(tasks, getVisitGoals(paths, objToVisit)); @@ -219,3 +223,5 @@ bool CaptureObjectsBehavior::objectMatchesFilter(const CGObjectInstance * obj) c return true; } + +} diff --git a/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.h b/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.h index 45a4a907c..ce075c858 100644 --- a/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.h +++ b/AI/Nullkiller/Behaviors/CaptureObjectsBehavior.h @@ -14,6 +14,8 @@ #include "../Goals/CGoal.h" #include "../Pathfinding/AINodeStorage.h" +namespace NKAI +{ namespace Goals { class CaptureObjectsBehavior : public CGoal @@ -72,3 +74,5 @@ namespace Goals }; } + +} diff --git a/AI/Nullkiller/Behaviors/ClusterBehavior.cpp b/AI/Nullkiller/Behaviors/ClusterBehavior.cpp index 79ed91def..ff0679564 100644 --- a/AI/Nullkiller/Behaviors/ClusterBehavior.cpp +++ b/AI/Nullkiller/Behaviors/ClusterBehavior.cpp @@ -16,6 +16,9 @@ #include "../Goals/Composition.h" #include "../Behaviors/CaptureObjectsBehavior.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -50,7 +53,7 @@ Goals::TGoalVec ClusterBehavior::decomposeCluster(std::shared_ptr TGoalVec goals; -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace( "Checking cluster %s %s, found %d paths", cluster->blocker->getObjectName(), @@ -60,7 +63,7 @@ Goals::TGoalVec ClusterBehavior::decomposeCluster(std::shared_ptr for(auto path = paths.begin(); path != paths.end();) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Checking path %s", path->toString()); #endif @@ -89,13 +92,13 @@ Goals::TGoalVec ClusterBehavior::decomposeCluster(std::shared_ptr for(auto & node : clonedPath.nodes) node.parentIndex -= path->nodes.size() - clonedPath.nodes.size(); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Unlock path found %s", blockerPaths.back().toString()); #endif path++; } -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Decompose unlock paths"); #endif @@ -114,3 +117,5 @@ Goals::TGoalVec ClusterBehavior::decomposeCluster(std::shared_ptr return goals; } + +} diff --git a/AI/Nullkiller/Behaviors/ClusterBehavior.h b/AI/Nullkiller/Behaviors/ClusterBehavior.h index a05a4d05e..e5a52f73c 100644 --- a/AI/Nullkiller/Behaviors/ClusterBehavior.h +++ b/AI/Nullkiller/Behaviors/ClusterBehavior.h @@ -13,6 +13,9 @@ #include "../Goals/CGoal.h" #include "../AIUtility.h" +namespace NKAI +{ + struct ObjectCluster; namespace Goals @@ -36,4 +39,6 @@ namespace Goals private: Goals::TGoalVec decomposeCluster(std::shared_ptr cluster) const; }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Behaviors/DefenceBehavior.cpp b/AI/Nullkiller/Behaviors/DefenceBehavior.cpp index 41422b0b9..5ca3f1f4e 100644 --- a/AI/Nullkiller/Behaviors/DefenceBehavior.cpp +++ b/AI/Nullkiller/Behaviors/DefenceBehavior.cpp @@ -23,6 +23,9 @@ #include "lib/mapping/CMap.h" //for victory conditions #include "lib/CPathfinder.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -117,7 +120,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta || path.turn() < treat.turn - 1 || (path.turn() < treat.turn && treat.turn >= 2)) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace( "Hero %s can eliminate danger for town %s using path %s.", path.targetHero->name, @@ -148,7 +151,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta if(cb->getHeroesInfo().size() < ALLOWED_ROAMING_HEROES) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Hero %s can be recruited to defend %s", hero->name, town->name); #endif tasks.push_back(Goals::sptr(Goals::RecruitHero(town, hero).setpriority(1))); @@ -196,7 +199,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta { auto & path = paths[i]; -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace( "Hero %s can defend town with force %lld in %s turns, cost: %f, path: %s", path.targetHero->name, @@ -207,7 +210,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta #endif if(path.turn() <= treat.turn - 2) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Deffer defence of %s by %s because he has enough time to rich the town next trun", town->name, path.targetHero->name); @@ -220,7 +223,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta if(path.targetHero == town->visitingHero && path.exchangeCount == 1) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Put %s to garrison of town %s", path.targetHero->name, town->name); @@ -244,7 +247,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta { if(ai->nullkiller->arePathHeroesLocked(path)) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Can not move %s to defend town %s. Path is locked.", path.targetHero->name, town->name); @@ -272,7 +275,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta } } -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Move %s to defend town %s", path.targetHero->name, town->name); @@ -286,13 +289,13 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta { auto subGoal = firstBlockedAction->decompose(path.targetHero); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Decomposing special action %s returns %s", firstBlockedAction->toString(), subGoal->toString()); #endif if(subGoal->invalid()) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Path is invalid. Skipping"); #endif continue; @@ -307,3 +310,5 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta logAi->debug("Found %d tasks", tasks.size()); } + +} diff --git a/AI/Nullkiller/Behaviors/DefenceBehavior.h b/AI/Nullkiller/Behaviors/DefenceBehavior.h index a0e182ab6..bd606cd36 100644 --- a/AI/Nullkiller/Behaviors/DefenceBehavior.h +++ b/AI/Nullkiller/Behaviors/DefenceBehavior.h @@ -13,6 +13,8 @@ #include "../Goals/CGoal.h" #include "../AIUtility.h" +namespace NKAI +{ namespace Goals { class DefenceBehavior : public CGoal @@ -36,3 +38,5 @@ namespace Goals }; } + +} diff --git a/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp b/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp index f16f93d8d..9673cfd82 100644 --- a/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp +++ b/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp @@ -19,6 +19,9 @@ #include "lib/mapping/CMap.h" //for victory conditions #include "lib/CPathfinder.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -64,12 +67,12 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her Goals::TGoalVec tasks; const int3 pos = hero->visitablePos(); -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Checking ways to gaher army for hero %s, %s", hero->getObjectName(), pos.toString()); #endif if(ai->nullkiller->isHeroLocked(hero)) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Skipping locked hero %s, %s", hero->getObjectName(), pos.toString()); #endif return tasks; @@ -77,13 +80,13 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her auto paths = ai->nullkiller->pathfinder->getPathInfo(pos); -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Gather army found %d paths", paths.size()); #endif for(const AIPath & path : paths) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Path found %s", path.toString()); #endif @@ -91,7 +94,7 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her if(ai->nullkiller->dangerHitMap->enemyCanKillOurHeroesAlongThePath(path)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Ignore path. Target hero can be killed by enemy. Our power %lld", path.heroArmy->getArmyStrength()); #endif continue; @@ -99,7 +102,7 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her if(ai->nullkiller->arePathHeroesLocked(path)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Ignore path because of locked hero"); #endif continue; @@ -112,7 +115,7 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her // avoid transferring very small amount of army if(armyValue < 0.1f) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Army value is too small."); #endif continue; @@ -121,7 +124,7 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her // avoid trying to move bigger army to the weaker one. if(armyValue > 1) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Army value is too large."); #endif continue; @@ -131,7 +134,7 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her auto isSafe = isSafeToVisit(hero, path.heroArmy, danger); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace( "It is %s to visit %s by %s with army %lld, danger %lld and army loss %lld", isSafe ? "safe" : "not safe", @@ -156,7 +159,7 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her if(blockedAction) { - #if AI_TRACE_LEVEL >= 2 + #if NKAI_TRACE_LEVEL >= 2 logAi->trace("Action is blocked. Considering decomposition."); #endif composition.addNext(blockedAction->decompose(path.targetHero)); @@ -175,25 +178,25 @@ Goals::TGoalVec GatherArmyBehavior::upgradeArmy(const CGTownInstance * upgrader) const int3 pos = upgrader->visitablePos(); TResources availableResources = ai->nullkiller->getFreeResources(); -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Checking ways to upgrade army in town %s, %s", upgrader->getObjectName(), pos.toString()); #endif auto paths = ai->nullkiller->pathfinder->getPathInfo(pos); std::vector> waysToVisitObj; -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Found %d paths", paths.size()); #endif for(const AIPath & path : paths) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Path found %s", path.toString()); #endif if(upgrader->visitingHero != path.targetHero) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Ignore path. Town has visiting hero."); #endif continue; @@ -201,7 +204,7 @@ Goals::TGoalVec GatherArmyBehavior::upgradeArmy(const CGTownInstance * upgrader) if(ai->nullkiller->arePathHeroesLocked(path)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Ignore path because of locked hero"); #endif continue; @@ -209,7 +212,7 @@ Goals::TGoalVec GatherArmyBehavior::upgradeArmy(const CGTownInstance * upgrader) if(path.getFirstBlockedAction()) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 // TODO: decomposition? logAi->trace("Ignore path. Action is blocked."); #endif @@ -218,7 +221,7 @@ Goals::TGoalVec GatherArmyBehavior::upgradeArmy(const CGTownInstance * upgrader) if(ai->nullkiller->dangerHitMap->enemyCanKillOurHeroesAlongThePath(path)) { -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Ignore path. Target hero can be killed by enemy. Our power %lld", path.heroArmy->getArmyStrength()); #endif continue; @@ -234,7 +237,7 @@ Goals::TGoalVec GatherArmyBehavior::upgradeArmy(const CGTownInstance * upgrader) auto isSafe = isSafeToVisit(path.targetHero, path.heroArmy, danger); -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace( "It is %s to visit %s by %s with army %lld, danger %lld and army loss %lld", isSafe ? "safe" : "not safe", @@ -257,3 +260,5 @@ Goals::TGoalVec GatherArmyBehavior::upgradeArmy(const CGTownInstance * upgrader) return tasks; } + +} diff --git a/AI/Nullkiller/Behaviors/GatherArmyBehavior.h b/AI/Nullkiller/Behaviors/GatherArmyBehavior.h index cf900bb7f..b933575ba 100644 --- a/AI/Nullkiller/Behaviors/GatherArmyBehavior.h +++ b/AI/Nullkiller/Behaviors/GatherArmyBehavior.h @@ -13,6 +13,8 @@ #include "../Goals/CGoal.h" #include "../AIUtility.h" +namespace NKAI +{ namespace Goals { class GatherArmyBehavior : public CGoal @@ -37,3 +39,5 @@ namespace Goals }; } + +} diff --git a/AI/Nullkiller/Behaviors/RecruitHeroBehavior.cpp b/AI/Nullkiller/Behaviors/RecruitHeroBehavior.cpp index f90323bfa..e6ddae756 100644 --- a/AI/Nullkiller/Behaviors/RecruitHeroBehavior.cpp +++ b/AI/Nullkiller/Behaviors/RecruitHeroBehavior.cpp @@ -16,6 +16,9 @@ #include "lib/mapping/CMap.h" //for victory conditions #include "lib/CPathfinder.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -46,3 +49,5 @@ Goals::TGoalVec RecruitHeroBehavior::decompose() const return tasks; } + +} diff --git a/AI/Nullkiller/Behaviors/RecruitHeroBehavior.h b/AI/Nullkiller/Behaviors/RecruitHeroBehavior.h index 018d62e63..4d1102b4d 100644 --- a/AI/Nullkiller/Behaviors/RecruitHeroBehavior.h +++ b/AI/Nullkiller/Behaviors/RecruitHeroBehavior.h @@ -13,6 +13,8 @@ #include "../Goals/CGoal.h" #include "../AIUtility.h" +namespace NKAI +{ namespace Goals { class RecruitHeroBehavior : public CGoal @@ -31,4 +33,6 @@ namespace Goals return true; } }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Behaviors/StartupBehavior.cpp b/AI/Nullkiller/Behaviors/StartupBehavior.cpp index f5f84187f..462529005 100644 --- a/AI/Nullkiller/Behaviors/StartupBehavior.cpp +++ b/AI/Nullkiller/Behaviors/StartupBehavior.cpp @@ -20,6 +20,9 @@ #include "lib/CPathfinder.h" #include "../Engine/Nullkiller.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -221,3 +224,5 @@ Goals::TGoalVec StartupBehavior::decompose() const return tasks; } + +} diff --git a/AI/Nullkiller/Behaviors/StartupBehavior.h b/AI/Nullkiller/Behaviors/StartupBehavior.h index 1022339b4..12cfb33c2 100644 --- a/AI/Nullkiller/Behaviors/StartupBehavior.h +++ b/AI/Nullkiller/Behaviors/StartupBehavior.h @@ -13,6 +13,8 @@ #include "../Goals/CGoal.h" #include "../AIUtility.h" +namespace NKAI +{ namespace Goals { class StartupBehavior : public CGoal @@ -33,3 +35,5 @@ namespace Goals }; } + +} diff --git a/AI/Nullkiller/Engine/AIMemory.cpp b/AI/Nullkiller/Engine/AIMemory.cpp index 9f67f9d37..09535893c 100644 --- a/AI/Nullkiller/Engine/AIMemory.cpp +++ b/AI/Nullkiller/Engine/AIMemory.cpp @@ -11,6 +11,9 @@ #include "AIMemory.h" #include "../../../CCallback.h" +namespace NKAI +{ + void AIMemory::removeFromMemory(const CGObjectInstance * obj) { vstd::erase_if_present(visitableObjs, obj); @@ -101,4 +104,6 @@ void AIMemory::removeInvisibleObjects(CCallback * cb) vstd::erase_if(visitableObjs, shouldBeErased); vstd::erase_if(alreadyVisited, shouldBeErased); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Engine/AIMemory.h b/AI/Nullkiller/Engine/AIMemory.h index 7c0bf60b2..c3596726c 100644 --- a/AI/Nullkiller/Engine/AIMemory.h +++ b/AI/Nullkiller/Engine/AIMemory.h @@ -12,6 +12,9 @@ #include "../AIUtility.h" #include "../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ + class AIMemory { public: @@ -29,3 +32,5 @@ public: bool wasVisited(const CGObjectInstance * obj) const; void removeInvisibleObjects(CCallback * cb); }; + +} diff --git a/AI/Nullkiller/Engine/DeepDecomposer.cpp b/AI/Nullkiller/Engine/DeepDecomposer.cpp index 565aa7dfc..8e649634f 100644 --- a/AI/Nullkiller/Engine/DeepDecomposer.cpp +++ b/AI/Nullkiller/Engine/DeepDecomposer.cpp @@ -21,6 +21,9 @@ #include "../Goals/Invalid.h" #include "../Goals/Composition.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -49,7 +52,7 @@ Goals::TGoalVec DeepDecomposer::decompose(TSubgoal behavior, int depthLimit) TSubgoal current = goals[depth].back(); TGoalVec subgoals = decomposeCached(unwrapComposition(current), fromCache); -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Decomposition level %d returned %d goals", depth, subgoals.size()); #endif @@ -69,7 +72,7 @@ Goals::TGoalVec DeepDecomposer::decompose(TSubgoal behavior, int depthLimit) // 0 - goals directly from behavior Goals::TSubgoal task = depth >= 1 ? aggregateGoals(0, subgoal) : subgoal; -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Found task %s", task->toString()); #endif if(!isCompositionLoop(subgoal)) @@ -84,7 +87,7 @@ Goals::TGoalVec DeepDecomposer::decompose(TSubgoal behavior, int depthLimit) } else if(depth < depthLimit - 1) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Found abstract goal %s", subgoal->toString()); #endif if(!isCompositionLoop(subgoal)) @@ -176,7 +179,7 @@ bool DeepDecomposer::isCompositionLoop(TSubgoal goal) TGoalVec DeepDecomposer::decomposeCached(TSubgoal goal, bool & fromCache) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Decomposing %s, level %s", goal->toString(), depth); #endif @@ -188,7 +191,7 @@ TGoalVec DeepDecomposer::decomposeCached(TSubgoal goal, bool & fromCache) if(cached != decompositionCache[i].end()) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Use decomposition cache for %s, level: %d", goal->toString(), depth); #endif fromCache = true; @@ -200,7 +203,7 @@ TGoalVec DeepDecomposer::decomposeCached(TSubgoal goal, bool & fromCache) decompositionCache[depth][goal] = {}; // if goal decomposition yields no goals we still need it in cache to not decompose again } -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Calling decompose on %s, level %s", goal->toString(), depth); #endif @@ -221,7 +224,7 @@ void DeepDecomposer::addToCache(TSubgoal goal) { auto solution = parentDepth < depth ? aggregateGoals(parentDepth + 1, goal) : goal; -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Adding %s to decomosition cache of %s at level %d", solution->toString(), parent->toString(), parentDepth); #endif @@ -234,4 +237,6 @@ void DeepDecomposer::addToCache(TSubgoal goal) } } } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Engine/DeepDecomposer.h b/AI/Nullkiller/Engine/DeepDecomposer.h index bf10dbe3e..7d11764e8 100644 --- a/AI/Nullkiller/Engine/DeepDecomposer.h +++ b/AI/Nullkiller/Engine/DeepDecomposer.h @@ -11,6 +11,9 @@ #include "../Goals/AbstractGoal.h" +namespace NKAI +{ + struct GoalHash { uint64_t operator()(const Goals::TSubgoal & goal) const @@ -38,4 +41,6 @@ private: bool isCompositionLoop(Goals::TSubgoal goal); Goals::TGoalVec decomposeCached(Goals::TSubgoal goal, bool & fromCache); void addToCache(Goals::TSubgoal goal); -}; \ No newline at end of file +}; + +} diff --git a/AI/Nullkiller/Engine/FuzzyEngines.cpp b/AI/Nullkiller/Engine/FuzzyEngines.cpp index ab449e666..04f1fe758 100644 --- a/AI/Nullkiller/Engine/FuzzyEngines.cpp +++ b/AI/Nullkiller/Engine/FuzzyEngines.cpp @@ -14,6 +14,9 @@ #include "../../../lib/mapObjects/MapObjects.h" #include "../AIGateway.h" +namespace NKAI +{ + #define MIN_AI_STRENGTH (0.5f) //lower when combat AI gets smarter #define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us @@ -239,3 +242,5 @@ float TacticalAdvantageEngine::getTacticalAdvantage(const CArmedInstance * we, c return output; } + +} diff --git a/AI/Nullkiller/Engine/FuzzyEngines.h b/AI/Nullkiller/Engine/FuzzyEngines.h index 0e0c533da..1694d175c 100644 --- a/AI/Nullkiller/Engine/FuzzyEngines.h +++ b/AI/Nullkiller/Engine/FuzzyEngines.h @@ -17,6 +17,9 @@ class CArmedInstance; VCMI_LIB_NAMESPACE_END +namespace NKAI +{ + class engineBase //subclasses create fuzzylite variables with "new" that are not freed - this is desired as fl::Engine wants to destroy these... { protected: @@ -40,3 +43,5 @@ private: fl::InputVariable * castleWalls; fl::OutputVariable * threat; }; + +} diff --git a/AI/Nullkiller/Engine/FuzzyHelper.cpp b/AI/Nullkiller/Engine/FuzzyHelper.cpp index 132b6ad15..95076b274 100644 --- a/AI/Nullkiller/Engine/FuzzyHelper.cpp +++ b/AI/Nullkiller/Engine/FuzzyHelper.cpp @@ -14,6 +14,9 @@ #include "../Goals/Goals.h" #include "Nullkiller.h" +namespace NKAI +{ + ui64 FuzzyHelper::estimateBankDanger(const CBank * bank) { //this one is not fuzzy anymore, just calculate weighted average @@ -33,7 +36,7 @@ ui64 FuzzyHelper::estimateBankDanger(const CBank * bank) } -ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, bool checkGuards) +ui64 FuzzyHelper::evaluateDanger(const int3 & tile, const CGHeroInstance * visitor, bool checkGuards) { auto cb = ai->cb.get(); const TerrainTile * t = cb->getTile(tile, false); @@ -153,4 +156,6 @@ ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj) default: return 0; } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Engine/FuzzyHelper.h b/AI/Nullkiller/Engine/FuzzyHelper.h index 760b34279..a3a2f2955 100644 --- a/AI/Nullkiller/Engine/FuzzyHelper.h +++ b/AI/Nullkiller/Engine/FuzzyHelper.h @@ -16,6 +16,9 @@ class CBank; VCMI_LIB_NAMESPACE_END +namespace NKAI +{ + class Nullkiller; class DLL_EXPORT FuzzyHelper @@ -30,5 +33,7 @@ public: ui64 estimateBankDanger(const CBank * bank); //TODO: move to another class? ui64 evaluateDanger(const CGObjectInstance * obj); - ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, bool checkGuards = true); + ui64 evaluateDanger(const int3 & tile, const CGHeroInstance * visitor, bool checkGuards = true); }; + +} diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index add63e4bd..8b3e56f21 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -21,12 +21,15 @@ #include "../Goals/Invalid.h" #include "../Goals/Composition.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; using namespace Goals; -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 #define MAXPASS 1000000 #else #define MAXPASS 30 @@ -178,7 +181,7 @@ bool Nullkiller::arePathHeroesLocked(const AIPath & path) const { if(getHeroLockedReason(path.targetHero) == HeroLockedReason::STARTUP) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Hero %s is locked by STARTUP. Discarding %s", path.targetHero->name, path.toString()); #endif return true; @@ -190,7 +193,7 @@ bool Nullkiller::arePathHeroesLocked(const AIPath & path) const if(lockReason != HeroLockedReason::NOT_LOCKED) { -#if AI_TRACE_LEVEL >= 1 +#if NKAI_TRACE_LEVEL >= 1 logAi->trace("Hero %s is locked by STARTUP. Discarding %s", path.targetHero->name, path.toString()); #endif return true; @@ -326,3 +329,5 @@ void Nullkiller::lockResources(const TResources & res) { lockedResources += res; } + +} diff --git a/AI/Nullkiller/Engine/Nullkiller.h b/AI/Nullkiller/Engine/Nullkiller.h index 9bb3304c0..e462040ff 100644 --- a/AI/Nullkiller/Engine/Nullkiller.h +++ b/AI/Nullkiller/Engine/Nullkiller.h @@ -19,6 +19,9 @@ #include "../Analyzers/HeroManager.h" #include "../Analyzers/ObjectClusterizer.h" +namespace NKAI +{ + const float MAX_GOLD_PEASURE = 0.3f; const float MIN_PRIORITY = 0.01f; const float NEXT_SCAN_MIN_PRIORITY = 0.4f; @@ -92,3 +95,5 @@ private: Goals::TTask choseBestTask(Goals::TTaskVec & tasks) const; void executeTask(Goals::TTask task); }; + +} diff --git a/AI/Nullkiller/Engine/PriorityEvaluator.cpp b/AI/Nullkiller/Engine/PriorityEvaluator.cpp index 58f97b837..b0abfffac 100644 --- a/AI/Nullkiller/Engine/PriorityEvaluator.cpp +++ b/AI/Nullkiller/Engine/PriorityEvaluator.cpp @@ -26,6 +26,9 @@ #include "../Markers/ArmyUpgrade.h" #include "../Markers/DefendTown.h" +namespace NKAI +{ + #define MIN_AI_STRENGHT (0.5f) //lower when combat AI gets smarter #define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us @@ -847,7 +850,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task) logAi->error("evaluate VisitTile: %s", fe.getWhat()); } -#if AI_TRACE_LEVEL >= 2 +#if NKAI_TRACE_LEVEL >= 2 logAi->trace("Evaluated %s, loss: %f, turn: %d, turns main: %f, scout: %f, gold: %d, cost: %d, army gain: %d, danger: %d, role: %s, strategical value: %f, cwr: %f, fear: %f, result %f", task->toString(), evaluationContext.armyLossPersentage, @@ -867,3 +870,5 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task) return result; } + +} diff --git a/AI/Nullkiller/Engine/PriorityEvaluator.h b/AI/Nullkiller/Engine/PriorityEvaluator.h index 6156c08c2..e026f2259 100644 --- a/AI/Nullkiller/Engine/PriorityEvaluator.h +++ b/AI/Nullkiller/Engine/PriorityEvaluator.h @@ -18,6 +18,9 @@ class CGWitchHut; VCMI_LIB_NAMESPACE_END +namespace NKAI +{ + class BuildingInfo; class Nullkiller; @@ -105,3 +108,5 @@ private: EvaluationContext buildEvaluationContext(Goals::TSubgoal goal) const; }; + +} diff --git a/AI/Nullkiller/Goals/AbstractGoal.cpp b/AI/Nullkiller/Goals/AbstractGoal.cpp index 52d6056fc..9433dfad2 100644 --- a/AI/Nullkiller/Goals/AbstractGoal.cpp +++ b/AI/Nullkiller/Goals/AbstractGoal.cpp @@ -14,6 +14,9 @@ #include "../../../lib/CPathfinder.h" #include "../../../lib/StringConstants.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -84,4 +87,6 @@ bool TSubgoal::operator==(const TSubgoal & rhs) const bool AbstractGoal::invalid() const { return goalType == EGoals::INVALID; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/AbstractGoal.h b/AI/Nullkiller/Goals/AbstractGoal.h index 7407a5fc4..7c4788e72 100644 --- a/AI/Nullkiller/Goals/AbstractGoal.h +++ b/AI/Nullkiller/Goals/AbstractGoal.h @@ -15,6 +15,9 @@ #include "../../../lib/CTownHandler.h" #include "../AIUtility.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -171,8 +174,8 @@ class cannotFulfillGoalException : public std::exception std::string msg; public: - explicit cannotFulfillGoalException(crstring _Message) - : msg(_Message) + explicit cannotFulfillGoalException(const std::string & message) + : msg(message) { } @@ -208,3 +211,5 @@ public: return msg.c_str(); } }; + +} diff --git a/AI/Nullkiller/Goals/AdventureSpellCast.cpp b/AI/Nullkiller/Goals/AdventureSpellCast.cpp index ea8afd5b8..bffab6a13 100644 --- a/AI/Nullkiller/Goals/AdventureSpellCast.cpp +++ b/AI/Nullkiller/Goals/AdventureSpellCast.cpp @@ -13,6 +13,9 @@ #include "../../../lib/mapping/CMap.h" //for victory conditions #include "../../../lib/CPathfinder.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -69,3 +72,5 @@ std::string AdventureSpellCast::toString() const { return "AdventureSpellCast " + spellID.toSpell()->name; } + +} diff --git a/AI/Nullkiller/Goals/AdventureSpellCast.h b/AI/Nullkiller/Goals/AdventureSpellCast.h index 063848521..23cfc4a97 100644 --- a/AI/Nullkiller/Goals/AdventureSpellCast.h +++ b/AI/Nullkiller/Goals/AdventureSpellCast.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + namespace Goals { class DLL_EXPORT AdventureSpellCast : public ElementarGoal @@ -35,3 +38,5 @@ namespace Goals virtual bool operator==(const AdventureSpellCast & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/Build.cpp b/AI/Nullkiller/Goals/Build.cpp index 3497706ba..e59c877eb 100644 --- a/AI/Nullkiller/Goals/Build.cpp +++ b/AI/Nullkiller/Goals/Build.cpp @@ -1,3 +1,6 @@ +namespace Nullkiller +{ + /* * Build.cpp, part of VCMI engine * @@ -91,3 +94,5 @@ bool Build::fulfillsMe(TSubgoal goal) else return false; } + +} diff --git a/AI/Nullkiller/Goals/Build.h b/AI/Nullkiller/Goals/Build.h index df2311e2e..8ff8d3228 100644 --- a/AI/Nullkiller/Goals/Build.h +++ b/AI/Nullkiller/Goals/Build.h @@ -1,3 +1,6 @@ +namespace Nullkiller +{ + /* * Build.h, part of VCMI engine * @@ -35,3 +38,5 @@ namespace Goals } }; } + +} diff --git a/AI/Nullkiller/Goals/BuildBoat.cpp b/AI/Nullkiller/Goals/BuildBoat.cpp index 0b934ffbf..8c28b43f9 100644 --- a/AI/Nullkiller/Goals/BuildBoat.cpp +++ b/AI/Nullkiller/Goals/BuildBoat.cpp @@ -14,6 +14,9 @@ #include "../../../lib/CPathfinder.h" #include "../Behaviors/CaptureObjectsBehavior.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -77,3 +80,5 @@ std::string BuildBoat::toString() const { return "BuildBoat"; } + +} diff --git a/AI/Nullkiller/Goals/BuildBoat.h b/AI/Nullkiller/Goals/BuildBoat.h index 858e6810f..31383d256 100644 --- a/AI/Nullkiller/Goals/BuildBoat.h +++ b/AI/Nullkiller/Goals/BuildBoat.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + namespace Goals { class DLL_EXPORT BuildBoat : public ElementarGoal @@ -29,3 +32,5 @@ namespace Goals virtual bool operator==(const BuildBoat & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/BuildThis.cpp b/AI/Nullkiller/Goals/BuildThis.cpp index c43a26796..06a06b25b 100644 --- a/AI/Nullkiller/Goals/BuildThis.cpp +++ b/AI/Nullkiller/Goals/BuildThis.cpp @@ -16,6 +16,9 @@ #include "../../../lib/StringConstants.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -63,4 +66,6 @@ void BuildThis::accept(AIGateway * ai) } throw cannotFulfillGoalException("Cannot build a given structure!"); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/BuildThis.h b/AI/Nullkiller/Goals/BuildThis.h index a8a273ac9..f4bacbc5e 100644 --- a/AI/Nullkiller/Goals/BuildThis.h +++ b/AI/Nullkiller/Goals/BuildThis.h @@ -12,6 +12,9 @@ #include "CGoal.h" #include "../Analyzers/BuildAnalyzer.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -41,3 +44,5 @@ namespace Goals void accept(AIGateway * ai) override; }; } + +} diff --git a/AI/Nullkiller/Goals/BuyArmy.cpp b/AI/Nullkiller/Goals/BuyArmy.cpp index c4d6f7151..dc35c16ba 100644 --- a/AI/Nullkiller/Goals/BuyArmy.cpp +++ b/AI/Nullkiller/Goals/BuyArmy.cpp @@ -14,6 +14,9 @@ #include "../Engine/Nullkiller.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -72,4 +75,6 @@ void BuyArmy::accept(AIGateway * ai) { ai->moveHeroToTile(town->visitablePos(), town->visitingHero.get()); } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/BuyArmy.h b/AI/Nullkiller/Goals/BuyArmy.h index 79b6ef99d..d4fdc6166 100644 --- a/AI/Nullkiller/Goals/BuyArmy.h +++ b/AI/Nullkiller/Goals/BuyArmy.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -40,3 +43,5 @@ namespace Goals virtual void accept(AIGateway * ai) override; }; } + +} diff --git a/AI/Nullkiller/Goals/CGoal.h b/AI/Nullkiller/Goals/CGoal.h index e5f9679c8..722c7ebd2 100644 --- a/AI/Nullkiller/Goals/CGoal.h +++ b/AI/Nullkiller/Goals/CGoal.h @@ -11,6 +11,9 @@ #include "AbstractGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; @@ -93,33 +96,6 @@ namespace Goals virtual int getHeroExchangeCount() const override { return 0; } }; - - class DLL_EXPORT Invalid : public ElementarGoal - { - public: - Invalid() - : ElementarGoal(Goals::INVALID) - { - priority = -1; - } - TGoalVec decompose() const override - { - return TGoalVec(); - } - - virtual bool operator==(const Invalid & other) const override - { - return true; - } - - virtual std::string toString() const override - { - return "Invalid"; - } - - virtual void accept(AIGateway * ai) override - { - throw cannotFulfillGoalException("Can not fulfill Invalid goal!"); - } - }; +} + } diff --git a/AI/Nullkiller/Goals/CaptureObject.cpp b/AI/Nullkiller/Goals/CaptureObject.cpp index 1950e249f..0dd71dc93 100644 --- a/AI/Nullkiller/Goals/CaptureObject.cpp +++ b/AI/Nullkiller/Goals/CaptureObject.cpp @@ -15,6 +15,9 @@ #include "../Behaviors/CaptureObjectsBehavior.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; using namespace Goals; @@ -37,4 +40,6 @@ std::string CaptureObject::toString() const TGoalVec CaptureObject::decompose() const { return CaptureObjectsBehavior(cb->getObj(ObjectInstanceID(objid))).decompose(); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/CaptureObject.h b/AI/Nullkiller/Goals/CaptureObject.h index a53a78ff0..e78993638 100644 --- a/AI/Nullkiller/Goals/CaptureObject.h +++ b/AI/Nullkiller/Goals/CaptureObject.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -38,3 +41,5 @@ namespace Goals virtual uint64_t getHash() const override; }; } + +} diff --git a/AI/Nullkiller/Goals/CompleteQuest.cpp b/AI/Nullkiller/Goals/CompleteQuest.cpp index 65d08f8b0..25dd9eb7f 100644 --- a/AI/Nullkiller/Goals/CompleteQuest.cpp +++ b/AI/Nullkiller/Goals/CompleteQuest.cpp @@ -16,6 +16,9 @@ #include "../../../lib/VCMI_Lib.h" #include "../../../lib/CGeneralTextHandler.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -245,4 +248,6 @@ TGoalVec CompleteQuest::missionDestroyObj() const } return TGoalVec(); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/CompleteQuest.h b/AI/Nullkiller/Goals/CompleteQuest.h index b2895917c..007b8d212 100644 --- a/AI/Nullkiller/Goals/CompleteQuest.h +++ b/AI/Nullkiller/Goals/CompleteQuest.h @@ -14,6 +14,8 @@ #include "../Goals/CGoal.h" #include "../../../lib/CGameState.h" +namespace NKAI +{ namespace Goals { class CompleteQuest : public CGoal @@ -47,3 +49,5 @@ namespace Goals std::string questToString() const; }; } + +} diff --git a/AI/Nullkiller/Goals/Composition.cpp b/AI/Nullkiller/Goals/Composition.cpp index 4adafdfe0..caaef64b7 100644 --- a/AI/Nullkiller/Goals/Composition.cpp +++ b/AI/Nullkiller/Goals/Composition.cpp @@ -16,6 +16,9 @@ #include "../../../lib/StringConstants.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -77,4 +80,6 @@ bool Composition::isElementar() const int Composition::getHeroExchangeCount() const { return isElementar() ? taskptr(*subtasks.back())->getHeroExchangeCount() : 0; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/Composition.h b/AI/Nullkiller/Goals/Composition.h index ce8b66313..f7de02bb0 100644 --- a/AI/Nullkiller/Goals/Composition.h +++ b/AI/Nullkiller/Goals/Composition.h @@ -11,6 +11,8 @@ #include "CGoal.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT Composition : public ElementarGoal @@ -39,3 +41,5 @@ namespace Goals virtual int getHeroExchangeCount() const override; }; } + +} diff --git a/AI/Nullkiller/Goals/DigAtTile.cpp b/AI/Nullkiller/Goals/DigAtTile.cpp index 9236a3788..a573bfbd0 100644 --- a/AI/Nullkiller/Goals/DigAtTile.cpp +++ b/AI/Nullkiller/Goals/DigAtTile.cpp @@ -13,6 +13,9 @@ #include "../AIUtility.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -35,3 +38,5 @@ bool DigAtTile::operator==(const DigAtTile & other) const // // return sptr(VisitTile(tile)); //} + +} diff --git a/AI/Nullkiller/Goals/DigAtTile.h b/AI/Nullkiller/Goals/DigAtTile.h index 21af09404..b50708c9b 100644 --- a/AI/Nullkiller/Goals/DigAtTile.h +++ b/AI/Nullkiller/Goals/DigAtTile.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -36,3 +39,5 @@ namespace Goals //TSubgoal decomposeSingle() const override; }; } + +} diff --git a/AI/Nullkiller/Goals/DismissHero.cpp b/AI/Nullkiller/Goals/DismissHero.cpp index d84e79ca5..09d5ceab5 100644 --- a/AI/Nullkiller/Goals/DismissHero.cpp +++ b/AI/Nullkiller/Goals/DismissHero.cpp @@ -13,6 +13,9 @@ #include "../../../lib/mapping/CMap.h" //for victory conditions #include "../../../lib/CPathfinder.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -37,3 +40,5 @@ std::string DismissHero::toString() const { return "DismissHero " + hero.name; } + +} diff --git a/AI/Nullkiller/Goals/DismissHero.h b/AI/Nullkiller/Goals/DismissHero.h index 7437875e8..a6d180300 100644 --- a/AI/Nullkiller/Goals/DismissHero.h +++ b/AI/Nullkiller/Goals/DismissHero.h @@ -11,6 +11,8 @@ #include "CGoal.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT DismissHero : public ElementarGoal @@ -27,3 +29,5 @@ namespace Goals virtual bool operator==(const DismissHero & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp b/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp index 0b570d975..ff7ac5245 100644 --- a/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp +++ b/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp @@ -15,6 +15,9 @@ #include "../../../lib/CPathfinder.h" #include "../Engine/Nullkiller.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -89,4 +92,6 @@ void ExchangeSwapTownHeroes::accept(AIGateway * ai) } logAi->debug("Put hero %s to garrison of %s", garrisonHero->name, town->name); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.h b/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.h index 00e4e1f83..aad61d77e 100644 --- a/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.h +++ b/AI/Nullkiller/Goals/ExchangeSwapTownHeroes.h @@ -12,6 +12,8 @@ #include "CGoal.h" #include "../Engine/Nullkiller.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT ExchangeSwapTownHeroes : public ElementarGoal @@ -32,3 +34,5 @@ namespace Goals virtual bool operator==(const ExchangeSwapTownHeroes & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/ExecuteHeroChain.cpp b/AI/Nullkiller/Goals/ExecuteHeroChain.cpp index 3d19bdc49..18fc224ee 100644 --- a/AI/Nullkiller/Goals/ExecuteHeroChain.cpp +++ b/AI/Nullkiller/Goals/ExecuteHeroChain.cpp @@ -14,6 +14,9 @@ #include "../../../lib/CPathfinder.h" #include "../Engine/Nullkiller.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -197,4 +200,6 @@ bool ExecuteHeroChain::moveHeroToTile(const CGHeroInstance * hero, const int3 & } return ai->moveHeroToTile(tile, hero); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/ExecuteHeroChain.h b/AI/Nullkiller/Goals/ExecuteHeroChain.h index 7aaf20ad3..b22e18499 100644 --- a/AI/Nullkiller/Goals/ExecuteHeroChain.h +++ b/AI/Nullkiller/Goals/ExecuteHeroChain.h @@ -12,6 +12,8 @@ #include "CGoal.h" #include "../Pathfinding/AIPathfinder.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT ExecuteHeroChain : public ElementarGoal @@ -37,3 +39,5 @@ namespace Goals bool moveHeroToTile(const CGHeroInstance * hero, const int3 & tile); }; } + +} diff --git a/AI/Nullkiller/Goals/GatherArmy.cpp b/AI/Nullkiller/Goals/GatherArmy.cpp index 82e9f361a..ce4d146ca 100644 --- a/AI/Nullkiller/Goals/GatherArmy.cpp +++ b/AI/Nullkiller/Goals/GatherArmy.cpp @@ -1,3 +1,6 @@ +namespace Nullkiller +{ + /* * GatherArmy.cpp, part of VCMI engine * @@ -208,3 +211,5 @@ TGoalVec GatherArmy::getAllPossibleSubgoals() return ret; } + +} diff --git a/AI/Nullkiller/Goals/GatherArmy.h b/AI/Nullkiller/Goals/GatherArmy.h index d48e03e87..9dbb81ec3 100644 --- a/AI/Nullkiller/Goals/GatherArmy.h +++ b/AI/Nullkiller/Goals/GatherArmy.h @@ -1,3 +1,6 @@ +namespace Nullkiller +{ + /* * GatherArmy.h, part of VCMI engine * @@ -36,3 +39,5 @@ namespace Goals virtual bool operator==(const GatherArmy & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/Goals.h b/AI/Nullkiller/Goals/Goals.h index 02e4b733b..e7b857ccf 100644 --- a/AI/Nullkiller/Goals/Goals.h +++ b/AI/Nullkiller/Goals/Goals.h @@ -17,4 +17,4 @@ #include "Trade.h" #include "RecruitHero.h" #include "DigAtTile.h" -#include "AdventureSpellCast.h" \ No newline at end of file +#include "AdventureSpellCast.h" diff --git a/AI/Nullkiller/Goals/Invalid.h b/AI/Nullkiller/Goals/Invalid.h index 62326d387..6c2d7afa4 100644 --- a/AI/Nullkiller/Goals/Invalid.h +++ b/AI/Nullkiller/Goals/Invalid.h @@ -11,9 +11,42 @@ #include "CGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; namespace Goals { + class DLL_EXPORT Invalid : public ElementarGoal + { + public: + Invalid() + : ElementarGoal(Goals::INVALID) + { + priority = -1; + } + TGoalVec decompose() const override + { + return TGoalVec(); + } + + virtual bool operator==(const Invalid & other) const override + { + return true; + } + + virtual std::string toString() const override + { + return "Invalid"; + } + + virtual void accept(AIGateway * ai) override + { + throw cannotFulfillGoalException("Can not fulfill Invalid goal!"); + } + }; +} + } diff --git a/AI/Nullkiller/Goals/RecruitHero.cpp b/AI/Nullkiller/Goals/RecruitHero.cpp index d6b2450aa..361daedc4 100644 --- a/AI/Nullkiller/Goals/RecruitHero.cpp +++ b/AI/Nullkiller/Goals/RecruitHero.cpp @@ -16,6 +16,9 @@ #include "../../../lib/StringConstants.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -42,4 +45,6 @@ void RecruitHero::accept(AIGateway * ai) { throw cannotFulfillGoalException("No town to recruit hero!"); } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/RecruitHero.h b/AI/Nullkiller/Goals/RecruitHero.h index 5f8b98fd7..34a968f33 100644 --- a/AI/Nullkiller/Goals/RecruitHero.h +++ b/AI/Nullkiller/Goals/RecruitHero.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -42,3 +45,5 @@ namespace Goals void accept(AIGateway * ai) override; }; } + +} diff --git a/AI/Nullkiller/Goals/SaveResources.cpp b/AI/Nullkiller/Goals/SaveResources.cpp index d3f216898..42ed04c52 100644 --- a/AI/Nullkiller/Goals/SaveResources.cpp +++ b/AI/Nullkiller/Goals/SaveResources.cpp @@ -14,6 +14,9 @@ #include "../../../lib/CPathfinder.h" #include "../Behaviors/CaptureObjectsBehavior.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -37,3 +40,5 @@ std::string SaveResources::toString() const { return "SaveResources " + resources.toString(); } + +} diff --git a/AI/Nullkiller/Goals/SaveResources.h b/AI/Nullkiller/Goals/SaveResources.h index 26bb9a005..eb0fe3b5b 100644 --- a/AI/Nullkiller/Goals/SaveResources.h +++ b/AI/Nullkiller/Goals/SaveResources.h @@ -11,6 +11,8 @@ #include "CGoal.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT SaveResources : public ElementarGoal @@ -29,3 +31,5 @@ namespace Goals virtual bool operator==(const SaveResources & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/Trade.cpp b/AI/Nullkiller/Goals/Trade.cpp index e97e7c363..cc7175efa 100644 --- a/AI/Nullkiller/Goals/Trade.cpp +++ b/AI/Nullkiller/Goals/Trade.cpp @@ -10,9 +10,13 @@ #include "StdInc.h" #include "Trade.h" +namespace NKAI +{ using namespace Goals; bool Trade::operator==(const Trade & other) const { return resID == other.resID; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Goals/Trade.h b/AI/Nullkiller/Goals/Trade.h index 6109e517f..30c459be3 100644 --- a/AI/Nullkiller/Goals/Trade.h +++ b/AI/Nullkiller/Goals/Trade.h @@ -11,6 +11,9 @@ #include "CGoal.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -34,3 +37,5 @@ namespace Goals virtual bool operator==(const Trade & other) const override; }; } + +} diff --git a/AI/Nullkiller/Goals/Win.cpp b/AI/Nullkiller/Goals/Win.cpp deleted file mode 100644 index 82fc11776..000000000 --- a/AI/Nullkiller/Goals/Win.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* -* Win.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 "Goals.h" -#include "../AIGateway.h" -#include "../AIUtility.h" -#include "../AIhelper.h" -#include "../FuzzyHelper.h" -#include "../../../lib/mapping/CMap.h" //for victory conditions -#include "../../../lib/CPathfinder.h" -#include "../../../lib/StringConstants.h" - - -extern boost::thread_specific_ptr cb; -extern boost::thread_specific_ptr ai; -extern FuzzyHelper * fh; - -using namespace Goals; - -TSubgoal Win::whatToDoToAchieve() -{ - auto toBool = [=](const EventCondition &) - { - // TODO: proper implementation - // Right now even already fulfilled goals will be included into generated list - // Proper check should test if event condition is already fulfilled - // Easiest way to do this is to call CGameState::checkForVictory but this function should not be - // used on client side or in AI code - return false; - }; - - std::vector goals; - - for(const TriggeredEvent & event : cb->getMapHeader()->triggeredEvents) - { - //TODO: try to eliminate human player(s) using loss conditions that have isHuman element - - if(event.effect.type == EventEffect::VICTORY) - { - boost::range::copy(event.trigger.getFulfillmentCandidates(toBool), std::back_inserter(goals)); - } - } - - //TODO: instead of returning first encountered goal AI should generate list of possible subgoals - for(const EventCondition & goal : goals) - { - switch(goal.condition) - { - case EventCondition::HAVE_ARTIFACT: - return sptr(GetArtOfType(goal.objectType)); - case EventCondition::DESTROY: - { - if(goal.object) - { - auto obj = cb->getObj(goal.object->id); - /*if(obj) - if(obj->getOwner() == ai->playerID) //we can't capture our own object - return sptr(Conquer());*/ - - - return sptr(VisitObj(goal.object->id.getNum())); - } - else - { - // TODO: destroy all objects of type goal.objectType - // This situation represents "kill all creatures" condition from H3 - break; - } - } - case EventCondition::HAVE_BUILDING: - { - // TODO build other buildings apart from Grail - // goal.objectType = buidingID to build - // goal.object = optional, town in which building should be built - // Represents "Improve town" condition from H3 (but unlike H3 it consists from 2 separate conditions) - - if(goal.objectType == BuildingID::GRAIL) - { - if(auto h = ai->getHeroWithGrail()) - { - //hero is in a town that can host Grail - if(h->visitedTown && !vstd::contains(h->visitedTown->forbiddenBuildings, BuildingID::GRAIL)) - { - const CGTownInstance * t = h->visitedTown; - return sptr(BuildThis(BuildingID::GRAIL, t).setpriority(10)); - } - else - { - auto towns = cb->getTownsInfo(); - towns.erase(boost::remove_if(towns, - [](const CGTownInstance * t) -> bool - { - return vstd::contains(t->forbiddenBuildings, BuildingID::GRAIL); - }), - towns.end()); - boost::sort(towns, CDistanceSorter(h.get())); - if(towns.size()) - { - return sptr(VisitTile(towns.front()->visitablePos()).sethero(h)); - } - } - } - double ratio = 0; - // maybe make this check a bit more complex? For example: - // 0.75 -> dig randomly within 3 tiles radius - // 0.85 -> radius now 2 tiles - // 0.95 -> 1 tile radius, position is fully known - // AFAIK H3 AI does something like this - int3 grailPos = cb->getGrailPos(&ratio); - if(ratio > 0.99) - { - return sptr(DigAtTile(grailPos)); - } //TODO: use FIND_OBJ - else if(const CGObjectInstance * obj = ai->getUnvisitedObj(objWithID)) //there are unvisited Obelisks - return sptr(VisitObj(obj->id.getNum())); - /*else - return sptr(Explore());*/ - } - break; - } - case EventCondition::CONTROL: - { - if(goal.object) - { - auto objRelations = cb->getPlayerRelations(ai->playerID, goal.object->tempOwner); - - if(objRelations == PlayerRelations::ENEMIES) - { - return sptr(VisitObj(goal.object->id.getNum())); - } - else - { - // TODO: Defance - break; - } - } - else - { - //TODO: control all objects of type "goal.objectType" - // Represents H3 condition "Flag all mines" - break; - } - } - - case EventCondition::HAVE_RESOURCES: - //TODO mines? piles? marketplace? - //save? - return sptr(CollectRes(static_cast(goal.objectType), goal.value)); - case EventCondition::HAVE_CREATURES: - return sptr(GatherTroops(goal.objectType, goal.value)); - case EventCondition::TRANSPORT: - { - //TODO. merge with bring Grail to town? So AI will first dig grail, then transport it using this goal and builds it - // Represents "transport artifact" condition: - // goal.objectType = type of artifact - // goal.object = destination-town where artifact should be transported - break; - } - case EventCondition::STANDARD_WIN: - return sptr(Invalid()); - - // Conditions that likely don't need any implementation - case EventCondition::DAYS_PASSED: - break; // goal.value = number of days for condition to trigger - case EventCondition::DAYS_WITHOUT_TOWN: - break; // goal.value = number of days to trigger this - case EventCondition::IS_HUMAN: - break; // Should be only used in calculation of candidates (see toBool lambda) - case EventCondition::CONST_VALUE: - break; - - case EventCondition::HAVE_0: - case EventCondition::HAVE_BUILDING_0: - case EventCondition::DESTROY_0: - //TODO: support new condition format - return sptr(Invalid()); - default: - assert(0); - } - } - return sptr(Invalid()); -} diff --git a/AI/Nullkiller/Goals/Win.h b/AI/Nullkiller/Goals/Win.h deleted file mode 100644 index df24b7fd4..000000000 --- a/AI/Nullkiller/Goals/Win.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Win.h, 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 -* -*/ -#pragma once - -#include "CGoal.h" - -struct HeroPtr; -class AIGateway; -class FuzzyHelper; - -namespace Goals -{ - class DLL_EXPORT Win : public CGoal - { - public: - Win() - : CGoal(Goals::WIN) - { - priority = 100; - } - TGoalVec getAllPossibleSubgoals() override - { - return TGoalVec(); - } - TSubgoal whatToDoToAchieve() override; - - virtual bool operator==(const Win & other) const override - { - return true; - } - }; -} diff --git a/AI/Nullkiller/Markers/ArmyUpgrade.cpp b/AI/Nullkiller/Markers/ArmyUpgrade.cpp index 8720139e9..7b8165544 100644 --- a/AI/Nullkiller/Markers/ArmyUpgrade.cpp +++ b/AI/Nullkiller/Markers/ArmyUpgrade.cpp @@ -13,6 +13,9 @@ #include "../Engine/Nullkiller.h" #include "../AIUtility.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -33,4 +36,6 @@ bool ArmyUpgrade::operator==(const ArmyUpgrade & other) const std::string ArmyUpgrade::toString() const { return "Army upgrade at " + upgrader->getObjectName() + upgrader->visitablePos().toString(); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/ArmyUpgrade.h b/AI/Nullkiller/Markers/ArmyUpgrade.h index 475abf519..df30c3588 100644 --- a/AI/Nullkiller/Markers/ArmyUpgrade.h +++ b/AI/Nullkiller/Markers/ArmyUpgrade.h @@ -13,6 +13,8 @@ #include "../Pathfinding/AINodeStorage.h" #include "../Analyzers/ArmyManager.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT ArmyUpgrade : public CGoal @@ -32,4 +34,6 @@ namespace Goals uint64_t getUpgradeValue() const { return upgradeValue; } uint64_t getInitialArmyValue() const { return initialValue; } }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/DefendTown.cpp b/AI/Nullkiller/Markers/DefendTown.cpp index 62e50585e..b09952f22 100644 --- a/AI/Nullkiller/Markers/DefendTown.cpp +++ b/AI/Nullkiller/Markers/DefendTown.cpp @@ -13,6 +13,9 @@ #include "../Engine/Nullkiller.h" #include "../AIUtility.h" +namespace NKAI +{ + using namespace Goals; DefendTown::DefendTown(const CGTownInstance * town, const HitMapInfo & treat, const AIPath & defencePath) @@ -37,4 +40,6 @@ bool DefendTown::operator==(const DefendTown & other) const std::string DefendTown::toString() const { return "Defend town " + town->getObjectName(); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/DefendTown.h b/AI/Nullkiller/Markers/DefendTown.h index dac1c9cf2..083f9b07f 100644 --- a/AI/Nullkiller/Markers/DefendTown.h +++ b/AI/Nullkiller/Markers/DefendTown.h @@ -14,6 +14,8 @@ #include "../Analyzers/ArmyManager.h" #include "../Analyzers/DangerHitMapAnalyzer.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT DefendTown : public CGoal @@ -36,4 +38,6 @@ namespace Goals uint8_t getTurn() const { return turn; } }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/HeroExchange.cpp b/AI/Nullkiller/Markers/HeroExchange.cpp index e673ce0b4..562215bb3 100644 --- a/AI/Nullkiller/Markers/HeroExchange.cpp +++ b/AI/Nullkiller/Markers/HeroExchange.cpp @@ -14,6 +14,9 @@ #include "../AIUtility.h" #include "../Analyzers/ArmyManager.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -34,4 +37,6 @@ uint64_t HeroExchange::getReinforcementArmyStrength() const uint64_t armyValue = ai->nullkiller->armyManager->howManyReinforcementsCanGet(hero.get(), exchangePath.heroArmy); return armyValue; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/HeroExchange.h b/AI/Nullkiller/Markers/HeroExchange.h index 20942d6a0..532d62666 100644 --- a/AI/Nullkiller/Markers/HeroExchange.h +++ b/AI/Nullkiller/Markers/HeroExchange.h @@ -12,6 +12,8 @@ #include "../Goals/CGoal.h" #include "../Pathfinding/AINodeStorage.h" +namespace NKAI +{ namespace Goals { class DLL_EXPORT HeroExchange : public CGoal @@ -31,4 +33,6 @@ namespace Goals uint64_t getReinforcementArmyStrength() const; }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/UnlockCluster.cpp b/AI/Nullkiller/Markers/UnlockCluster.cpp index ef24095f3..bbf7c99c7 100644 --- a/AI/Nullkiller/Markers/UnlockCluster.cpp +++ b/AI/Nullkiller/Markers/UnlockCluster.cpp @@ -13,6 +13,9 @@ #include "../Engine/Nullkiller.h" #include "../AIUtility.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -26,4 +29,6 @@ bool UnlockCluster::operator==(const UnlockCluster & other) const std::string UnlockCluster::toString() const { return "Unlock Cluster " + cluster->blocker->getObjectName() + tile.toString(); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Markers/UnlockCluster.h b/AI/Nullkiller/Markers/UnlockCluster.h index 3e40ab850..3318fc7bc 100644 --- a/AI/Nullkiller/Markers/UnlockCluster.h +++ b/AI/Nullkiller/Markers/UnlockCluster.h @@ -13,6 +13,9 @@ #include "../Analyzers/ObjectClusterizer.h" +namespace NKAI +{ + struct HeroPtr; class AIGateway; class FuzzyHelper; @@ -38,4 +41,6 @@ namespace Goals std::shared_ptr getCluster() const { return cluster; } const AIPath & getPathToCenter() { return pathToCenter; } }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp index b62e047cb..763ec2894 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp @@ -19,6 +19,9 @@ #include "../../../lib/PathfinderUtil.h" #include "../../../lib/CPlayerState.h" +namespace NKAI +{ + std::shared_ptr> AISharedStorage::shared; std::set commitedTiles; std::set commitedTilesInitial; @@ -261,7 +264,7 @@ void AINodeStorage::commit( destination->theNodeBefore = source->theNodeBefore; destination->chainOther = nullptr; -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Commited %s -> %s, cost: %f, turn: %s, mp: %d, hero: %s, mask: %x, army: %lld", source->coord.toString(), @@ -589,7 +592,7 @@ void HeroChainCalculationTask::cleanupInefectiveChains(std::vector= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 if(isNotEffective) { logAi->trace( @@ -634,7 +637,7 @@ void HeroChainCalculationTask::calculateHeroChain( || (node->action == CGPathNode::ENodeAction::UNKNOWN && node->actor->hero) || (node->actor->chainMask & srcNode->actor->chainMask) != 0) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Skip exchange %s[%x] -> %s[%x] at %s because of %s", node->actor->toString(), @@ -651,7 +654,7 @@ void HeroChainCalculationTask::calculateHeroChain( continue; } -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Thy exchange %s[%x] -> %s[%x] at %s", node->actor->toString(), @@ -675,7 +678,7 @@ void HeroChainCalculationTask::calculateHeroChain( && carrier->action != CGPathNode::BLOCKING_VISIT && (other->armyLoss == 0 || other->armyLoss < other->actor->armyValue)) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Exchange allowed %s[%x] -> %s[%x] at %s", other->actor->toString(), @@ -692,7 +695,7 @@ void HeroChainCalculationTask::calculateHeroChain( if(hasLessMp && hasLessExperience) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace("Exchange at %s is ineficient. Blocked.", carrier->coord.toString()); #endif return; @@ -717,7 +720,7 @@ void HeroChainCalculationTask::addHeroChain(const std::vector if(!chainNodeOptional) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace("Exchange at %s can not allocate node. Blocked.", carrier->coord.toString()); #endif continue; @@ -727,7 +730,7 @@ void HeroChainCalculationTask::addHeroChain(const std::vector if(exchangeNode->action != CGPathNode::ENodeAction::UNKNOWN) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Skip exchange %s[%x] -> %s[%x] at %s because node is in use", other->actor->toString(), @@ -741,7 +744,7 @@ void HeroChainCalculationTask::addHeroChain(const std::vector if(exchangeNode->turns != 0xFF && exchangeNode->getCost() < chainInfo.getCost()) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Skip exchange %s[%x] -> %s[%x] at %s because not effective enough. %f < %f", other->actor->toString(), @@ -772,7 +775,7 @@ void HeroChainCalculationTask::addHeroChain(const std::vector exchangeNode->chainOther = other; exchangeNode->armyLoss = chainInfo.armyLoss; -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Chain accepted at %s %s -> %s, mask %x, cost %f, turn: %s, mp: %d, army %i", exchangeNode->coord.toString(), @@ -1096,7 +1099,7 @@ void AINodeStorage::calculateTownPortal( if(nodeOptional) { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace("Adding town portal node at %s", targetTown->name); #endif output.push_back(nodeOptional.get()); @@ -1180,7 +1183,7 @@ bool AINodeStorage::hasBetterChain( { if(node.getCost() < candidateNode->getCost()) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Block ineficient battle move %s->%s, hero: %s[%X], army %lld, mp diff: %i", source->coord.toString(), @@ -1204,7 +1207,7 @@ bool AINodeStorage::hasBetterChain( if(nodeArmyValue > candidateArmyValue && node.getCost() <= candidateNode->getCost()) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Block ineficient move because of stronger army %s->%s, hero: %s[%X], army %lld, mp diff: %i", source->coord.toString(), @@ -1230,7 +1233,7 @@ bool AINodeStorage::hasBetterChain( continue; } -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Block ineficient move because of stronger hero %s->%s, hero: %s[%X], army %lld, mp diff: %i", source->coord.toString(), @@ -1452,3 +1455,5 @@ std::string AIPath::toString() const return str.str(); } + +} diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.h b/AI/Nullkiller/Pathfinding/AINodeStorage.h index 075a90d32..008bff677 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.h +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.h @@ -10,10 +10,8 @@ #pragma once -#define PATHFINDER_TRACE_LEVEL 0 -#define AI_TRACE_LEVEL 0 -#define SCOUT_TURN_DISTANCE_LIMIT 3 -#define MAIN_TURN_DISTANCE_LIMIT 5 +#define NKAI_PATHFINDER_TRACE_LEVEL 0 +#define NKAI_TRACE_LEVEL 0 #include "../../../lib/CPathfinder.h" #include "../../../lib/mapObjects/CGHeroInstance.h" @@ -23,6 +21,11 @@ #include "Actions/SpecialAction.h" #include "Actors.h" +namespace NKAI +{ + const int SCOUT_TURN_DISTANCE_LIMIT = 3; + const int MAIN_TURN_DISTANCE_LIMIT = 5; + namespace AIPathfinding { #ifdef ENVIRONMENT64 @@ -256,3 +259,5 @@ private: const std::vector & initialNodes, TVector & output); }; + +} diff --git a/AI/Nullkiller/Pathfinding/AIPathfinder.cpp b/AI/Nullkiller/Pathfinding/AIPathfinder.cpp index 4b51369e1..87eb5fb79 100644 --- a/AI/Nullkiller/Pathfinding/AIPathfinder.cpp +++ b/AI/Nullkiller/Pathfinding/AIPathfinder.cpp @@ -14,6 +14,9 @@ #include "../../../lib/mapping/CMap.h" #include "../Engine/Nullkiller.h" +namespace NKAI +{ + AIPathfinder::AIPathfinder(CPlayerSpecificInfoCallback * cb, Nullkiller * ai) :cb(cb), ai(ai) { @@ -99,3 +102,5 @@ void AIPathfinder::updatePaths(std::map heroes logAi->trace("Recalculated paths in %ld", timeElapsed(start)); } + +} diff --git a/AI/Nullkiller/Pathfinding/AIPathfinder.h b/AI/Nullkiller/Pathfinding/AIPathfinder.h index 8f9389403..eb7b92f44 100644 --- a/AI/Nullkiller/Pathfinding/AIPathfinder.h +++ b/AI/Nullkiller/Pathfinding/AIPathfinder.h @@ -13,6 +13,9 @@ #include "AINodeStorage.h" #include "../AIUtility.h" +namespace NKAI +{ + class Nullkiller; struct PathfinderSettings @@ -42,3 +45,5 @@ public: void updatePaths(std::map heroes, PathfinderSettings pathfinderSettings); void init(); }; + +} diff --git a/AI/Nullkiller/Pathfinding/AIPathfinderConfig.cpp b/AI/Nullkiller/Pathfinding/AIPathfinderConfig.cpp index c34a05d05..0f1be5087 100644 --- a/AI/Nullkiller/Pathfinding/AIPathfinderConfig.cpp +++ b/AI/Nullkiller/Pathfinding/AIPathfinderConfig.cpp @@ -15,6 +15,8 @@ #include "Rules/AIPreviousNodeRule.h" #include "../Engine//Nullkiller.h" +namespace NKAI +{ namespace AIPathfinding { std::vector> makeRuleset( @@ -55,3 +57,5 @@ namespace AIPathfinding return helper.get(); } } + +} diff --git a/AI/Nullkiller/Pathfinding/AIPathfinderConfig.h b/AI/Nullkiller/Pathfinding/AIPathfinderConfig.h index 0b196e7a2..05e6f5558 100644 --- a/AI/Nullkiller/Pathfinding/AIPathfinderConfig.h +++ b/AI/Nullkiller/Pathfinding/AIPathfinderConfig.h @@ -12,6 +12,9 @@ #include "AINodeStorage.h" +namespace NKAI +{ + class Nullkiller; namespace AIPathfinding @@ -31,3 +34,5 @@ namespace AIPathfinding virtual CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs) override; }; } + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/BattleAction.cpp b/AI/Nullkiller/Pathfinding/Actions/BattleAction.cpp index fcfc0fac2..70a4b1063 100644 --- a/AI/Nullkiller/Pathfinding/Actions/BattleAction.cpp +++ b/AI/Nullkiller/Pathfinding/Actions/BattleAction.cpp @@ -14,6 +14,9 @@ #include "../../Goals/CompleteQuest.h" #include "../../../../lib/mapping/CMap.h" //for victory conditions +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -28,4 +31,6 @@ namespace AIPathfinding { return "Battle at " + targetTile.toString(); } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/BattleAction.h b/AI/Nullkiller/Pathfinding/Actions/BattleAction.h index 0a6b608b2..918b5974e 100644 --- a/AI/Nullkiller/Pathfinding/Actions/BattleAction.h +++ b/AI/Nullkiller/Pathfinding/Actions/BattleAction.h @@ -13,6 +13,9 @@ #include "SpecialAction.h" #include "../../../../lib/CGameState.h" +namespace NKAI +{ + namespace AIPathfinding { class BattleAction : public SpecialAction @@ -30,4 +33,6 @@ namespace AIPathfinding virtual std::string toString() const override; }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/BoatActions.cpp b/AI/Nullkiller/Pathfinding/Actions/BoatActions.cpp index 39aec27a2..214c0d366 100644 --- a/AI/Nullkiller/Pathfinding/Actions/BoatActions.cpp +++ b/AI/Nullkiller/Pathfinding/Actions/BoatActions.cpp @@ -12,11 +12,15 @@ #include "../../AIGateway.h" #include "../../Goals/AdventureSpellCast.h" #include "../../Goals/CaptureObject.h" +#include "../../Goals/Invalid.h" #include "../../Goals/BuildBoat.h" #include "../../../../lib/mapping/CMap.h" #include "../../../../lib/mapObjects/MapObjects.h" #include "BoatActions.h" +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -34,7 +38,7 @@ namespace AIPathfinding return Goals::sptr(Goals::CaptureObject(shipyard->o)); } - return sptr(Goals::Invalid()); + return Goals::sptr(Goals::Invalid()); } bool BuildBoatAction::canAct(const AIPathNode * source) const @@ -43,7 +47,7 @@ namespace AIPathfinding if(cb->getPlayerRelations(hero->tempOwner, shipyard->o->tempOwner) == PlayerRelations::ENEMIES) { -#if AI_TRACE_LEVEL > 1 +#if NKAI_TRACE_LEVEL > 1 logAi->trace("Can not build a boat. Shipyard is enemy."); #endif return false; @@ -55,7 +59,7 @@ namespace AIPathfinding if(!cb->getResourceAmount().canAfford(source->actor->armyCost + boatCost)) { -#if AI_TRACE_LEVEL > 1 +#if NKAI_TRACE_LEVEL > 1 logAi->trace("Can not build a boat. Not enough resources."); #endif @@ -128,4 +132,6 @@ namespace AIPathfinding return hero->getSpellCost(summonBoat.toSpell()); } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/BoatActions.h b/AI/Nullkiller/Pathfinding/Actions/BoatActions.h index 4b2812b21..a1634b09b 100644 --- a/AI/Nullkiller/Pathfinding/Actions/BoatActions.h +++ b/AI/Nullkiller/Pathfinding/Actions/BoatActions.h @@ -14,6 +14,9 @@ #include "../../../../lib/mapping/CMap.h" #include "../../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ + namespace AIPathfinding { class VirtualBoatAction : public SpecialAction @@ -69,3 +72,5 @@ namespace AIPathfinding virtual const CGObjectInstance * targetObject() const override; }; } + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.cpp b/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.cpp index 338a8b918..3a15f7e4c 100644 --- a/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.cpp +++ b/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.cpp @@ -14,6 +14,9 @@ #include "../../Goals/CompleteQuest.h" #include "../../../../lib/mapping/CMap.h" //for victory conditions +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -34,4 +37,6 @@ namespace AIPathfinding { return "Buy Army"; } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.h b/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.h index d609b9db2..89294aecf 100644 --- a/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.h +++ b/AI/Nullkiller/Pathfinding/Actions/BuyArmyAction.h @@ -13,6 +13,8 @@ #include "SpecialAction.h" #include "../../../../lib/CGameState.h" +namespace NKAI +{ namespace AIPathfinding { class BuyArmyAction : public SpecialAction @@ -28,4 +30,6 @@ namespace AIPathfinding void execute(const CGHeroInstance * hero) const override; std::string toString() const override; }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/QuestAction.cpp b/AI/Nullkiller/Pathfinding/Actions/QuestAction.cpp index 5249d6396..5deb87e7b 100644 --- a/AI/Nullkiller/Pathfinding/Actions/QuestAction.cpp +++ b/AI/Nullkiller/Pathfinding/Actions/QuestAction.cpp @@ -14,6 +14,9 @@ #include "../../Goals/CompleteQuest.h" #include "../../../../lib/mapping/CMap.h" //for victory conditions +namespace NKAI +{ + extern boost::thread_specific_ptr cb; extern boost::thread_specific_ptr ai; @@ -44,4 +47,6 @@ namespace AIPathfinding { return "Complete Quest"; } -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/QuestAction.h b/AI/Nullkiller/Pathfinding/Actions/QuestAction.h index d0c13ee05..ae5ae0490 100644 --- a/AI/Nullkiller/Pathfinding/Actions/QuestAction.h +++ b/AI/Nullkiller/Pathfinding/Actions/QuestAction.h @@ -13,6 +13,8 @@ #include "SpecialAction.h" #include "../../../../lib/CGameState.h" +namespace NKAI +{ namespace AIPathfinding { class QuestAction : public SpecialAction @@ -34,4 +36,6 @@ namespace AIPathfinding virtual std::string toString() const override; }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/SpecialAction.cpp b/AI/Nullkiller/Pathfinding/Actions/SpecialAction.cpp index 75222ac9e..d85395a8b 100644 --- a/AI/Nullkiller/Pathfinding/Actions/SpecialAction.cpp +++ b/AI/Nullkiller/Pathfinding/Actions/SpecialAction.cpp @@ -12,6 +12,10 @@ #include "SpecialAction.h" #include "../../AIGateway.h" #include "../../Goals/CGoal.h" +#include "../../Goals/Invalid.h" + +namespace NKAI +{ Goals::TSubgoal SpecialAction::decompose(const CGHeroInstance * hero) const { @@ -21,4 +25,6 @@ Goals::TSubgoal SpecialAction::decompose(const CGHeroInstance * hero) const void SpecialAction::execute(const CGHeroInstance * hero) const { throw cannotFulfillGoalException("Can not execute " + toString()); -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/SpecialAction.h b/AI/Nullkiller/Pathfinding/Actions/SpecialAction.h index 51977963b..b0d8799ad 100644 --- a/AI/Nullkiller/Pathfinding/Actions/SpecialAction.h +++ b/AI/Nullkiller/Pathfinding/Actions/SpecialAction.h @@ -13,6 +13,9 @@ #include "../../AIUtility.h" #include "../../Goals/AbstractGoal.h" +namespace NKAI +{ + struct AIPathNode; class SpecialAction @@ -42,3 +45,5 @@ public: virtual const CGObjectInstance * targetObject() const { return nullptr; } }; + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.cpp b/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.cpp index 889ec1245..30f1ffc6d 100644 --- a/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.cpp +++ b/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.cpp @@ -14,6 +14,9 @@ #include "../../../../lib/mapObjects/MapObjects.h" #include "TownPortalAction.h" +namespace NKAI +{ + using namespace AIPathfinding; extern boost::thread_specific_ptr cb; @@ -53,4 +56,6 @@ uint32_t TownPortalAction::getManaCost(const CGHeroInstance * hero) const SpellID summonBoat = SpellID::TOWN_PORTAL; return hero->getSpellCost(summonBoat.toSpell()); -}*/ \ No newline at end of file +}*/ + +} diff --git a/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.h b/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.h index d9dbd3efb..1afc58cb6 100644 --- a/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.h +++ b/AI/Nullkiller/Pathfinding/Actions/TownPortalAction.h @@ -15,6 +15,8 @@ #include "../../../../lib/mapObjects/MapObjects.h" #include "../../Goals/AdventureSpellCast.h" +namespace NKAI +{ namespace AIPathfinding { class TownPortalAction : public SpecialAction @@ -32,4 +34,6 @@ namespace AIPathfinding virtual std::string toString() const override; }; -} \ No newline at end of file +} + +} diff --git a/AI/Nullkiller/Pathfinding/Actors.cpp b/AI/Nullkiller/Pathfinding/Actors.cpp index b5f730a12..dcea063e1 100644 --- a/AI/Nullkiller/Pathfinding/Actors.cpp +++ b/AI/Nullkiller/Pathfinding/Actors.cpp @@ -16,6 +16,8 @@ #include "../../../lib/mapObjects/MapObjects.h" #include "Actions/BuyArmyAction.h" +using namespace NKAI; + CCreatureSet emptyArmy; bool HeroExchangeArmy::needsLastStack() const @@ -68,7 +70,7 @@ ChainActor::ChainActor(const CGObjectInstance * obj, const CCreatureSet * creatu int ChainActor::maxMovePoints(CGPathNode::ELayer layer) { -#if AI_TRACE_LEVEL > 0 +#if NKAI_TRACE_LEVEL > 0 if(!hero) throw std::logic_error("Asking movement points for static actor"); #endif @@ -164,25 +166,6 @@ ExchangeResult ChainActor::tryExchangeNoLock(const ChainActor * specialActor, co return baseActor->tryExchangeNoLock(specialActor, other); } -VCMI_LIB_NAMESPACE_BEGIN -namespace vstd -{ - template - typename M::mapped_type & getOrCompute(M &m, Key const& k, F f) - { - typedef typename M::mapped_type V; - - std::pair r = m.insert(typename M::value_type(k, V())); - V &v = r.first->second; - - if(r.second) - f(v); - - return v; - } -} -VCMI_LIB_NAMESPACE_END - ExchangeResult HeroActor::tryExchangeNoLock(const ChainActor * specialActor, const ChainActor * other) const { const ChainActor * otherBase = other->baseActor; @@ -282,7 +265,7 @@ ExchangeResult HeroExchangeMap::tryExchangeNoLock(const ChainActor * other) if(!resources.canAfford(actor->armyCost + other->armyCost)) { -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Can not afford exchange because of total cost %s but we have %s", (actor->armyCost + other->armyCost).toString(), @@ -322,7 +305,7 @@ ExchangeResult HeroExchangeMap::tryExchangeNoLock(const ChainActor * other) auto reinforcement = newArmy->getArmyStrength() - actor->creatureSet->getArmyStrength(); -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Exchange %s->%s reinforcement: %d, %f%%", actor->toString(), diff --git a/AI/Nullkiller/Pathfinding/Actors.h b/AI/Nullkiller/Pathfinding/Actors.h index 2f18df369..cf450dfbc 100644 --- a/AI/Nullkiller/Pathfinding/Actors.h +++ b/AI/Nullkiller/Pathfinding/Actors.h @@ -15,6 +15,9 @@ #include "../AIUtility.h" #include "Actions/SpecialAction.h" +namespace NKAI +{ + extern const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN; class ChainActor; @@ -170,3 +173,5 @@ public: TownGarrisonActor(const CGTownInstance * town, uint64_t chainMask); virtual std::string toString() const override; }; + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp b/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp index 7ce26bee3..f3143a239 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp +++ b/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.cpp @@ -11,6 +11,8 @@ #include "AILayerTransitionRule.h" #include "../../Engine/Nullkiller.h" +namespace NKAI +{ namespace AIPathfinding { AILayerTransitionRule::AILayerTransitionRule(CPlayerSpecificInfoCallback * cb, Nullkiller * ai, std::shared_ptr nodeStorage) @@ -38,7 +40,7 @@ namespace AIPathfinding if(virtualBoat && tryEmbarkVirtualBoat(destination, source, virtualBoat)) { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace("Embarking to virtual boat while moving %s -> %s!", source.coord.toString(), destination.coord.toString()); #endif } @@ -139,7 +141,7 @@ namespace AIPathfinding } else { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Special transition node already allocated. Blocked moving %s -> %s", source.coord.toString(), @@ -159,3 +161,5 @@ namespace AIPathfinding return result; } } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.h b/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.h index b18da7f7b..dd79f1b53 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.h +++ b/AI/Nullkiller/Pathfinding/Rules/AILayerTransitionRule.h @@ -17,6 +17,8 @@ #include "../../../../lib/mapping/CMap.h" #include "../../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ namespace AIPathfinding { class AILayerTransitionRule : public LayerTransitionRule @@ -50,3 +52,5 @@ namespace AIPathfinding std::shared_ptr virtualBoat) const; }; } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.cpp b/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.cpp index 225f139ca..45fd896bd 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.cpp +++ b/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.cpp @@ -14,6 +14,8 @@ #include "../../Goals/Invalid.h" #include "AIPreviousNodeRule.h" +namespace NKAI +{ namespace AIPathfinding { AIMovementAfterDestinationRule::AIMovementAfterDestinationRule( @@ -45,7 +47,7 @@ namespace AIPathfinding return; } -#if PATHFINDER_TRACE_LEVEL >= 2 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 2 logAi->trace( "Movement from tile %s is blocked. Try to bypass. Action: %d, blocker: %d", destination.coord.toString(), @@ -220,7 +222,7 @@ namespace AIPathfinding if(guardsAlreadyBypassed && srcNode->actor->allowBattle) { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Bypass guard at destination while moving %s -> %s", source.coord.toString(), @@ -248,7 +250,7 @@ namespace AIPathfinding if(!battleNodeOptional) { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Can not allocate battle node while moving %s -> %s", source.coord.toString(), @@ -261,7 +263,7 @@ namespace AIPathfinding if(battleNode->locked) { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Block bypass guard at destination while moving %s -> %s", source.coord.toString(), @@ -288,7 +290,7 @@ namespace AIPathfinding battleNode->specialAction = std::make_shared(destination.coord); -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Begin bypass guard at destination with danger %s while moving %s -> %s", std::to_string(danger), @@ -301,3 +303,5 @@ namespace AIPathfinding return false; } } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.h b/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.h index c118bdc40..31c0b1449 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.h +++ b/AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.h @@ -16,6 +16,8 @@ #include "../../../../lib/mapping/CMap.h" #include "../../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ namespace AIPathfinding { class AIMovementAfterDestinationRule : public MovementAfterDestinationRule @@ -66,3 +68,5 @@ namespace AIPathfinding CPathfinderHelper * pathfinderHelper) const; }; } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.cpp b/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.cpp index 4e1d10681..5cd4f9376 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.cpp +++ b/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.cpp @@ -10,6 +10,8 @@ #include "StdInc.h" #include "AIMovementToDestinationRule.h" +namespace NKAI +{ namespace AIPathfinding { AIMovementToDestinationRule::AIMovementToDestinationRule(std::shared_ptr nodeStorage) @@ -37,7 +39,7 @@ namespace AIPathfinding if(blocker == BlockingReason::SOURCE_GUARDED && nodeStorage->getAINode(source.node)->actor->allowBattle) { -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Bypass src guard while moving from %s to %s", source.coord.toString(), @@ -49,3 +51,5 @@ namespace AIPathfinding destination.blocked = true; } } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.h b/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.h index 4d0da1b49..1ae5ff862 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.h +++ b/AI/Nullkiller/Pathfinding/Rules/AIMovementToDestinationRule.h @@ -16,6 +16,8 @@ #include "../../../../lib/mapping/CMap.h" #include "../../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ namespace AIPathfinding { class AIMovementToDestinationRule : public MovementToDestinationRule @@ -33,3 +35,5 @@ namespace AIPathfinding CPathfinderHelper * pathfinderHelper) const override; }; } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.cpp b/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.cpp index a46b6558e..975f37c2d 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.cpp +++ b/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.cpp @@ -10,6 +10,8 @@ #include "StdInc.h" #include "AIPreviousNodeRule.h" +namespace NKAI +{ namespace AIPathfinding { AIPreviousNodeRule::AIPreviousNodeRule(std::shared_ptr nodeStorage) @@ -35,7 +37,7 @@ namespace AIPathfinding // we can not directly bypass objects, we need to interact with them first destination.node->theNodeBefore = source.node; -#if PATHFINDER_TRACE_LEVEL >= 1 +#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 logAi->trace( "Link src node %s to destination node %s while bypassing visitable obj", source.coord.toString(), @@ -45,3 +47,5 @@ namespace AIPathfinding } } } + +} diff --git a/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.h b/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.h index d3847c862..c337827e7 100644 --- a/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.h +++ b/AI/Nullkiller/Pathfinding/Rules/AIPreviousNodeRule.h @@ -16,6 +16,8 @@ #include "../../../../lib/mapping/CMap.h" #include "../../../../lib/mapObjects/MapObjects.h" +namespace NKAI +{ namespace AIPathfinding { class AIPreviousNodeRule : public MovementToDestinationRule @@ -33,3 +35,5 @@ namespace AIPathfinding CPathfinderHelper * pathfinderHelper) const override; }; } + +} diff --git a/AI/Nullkiller/main.cpp b/AI/Nullkiller/main.cpp index a6a95ef24..fff944c8d 100644 --- a/AI/Nullkiller/main.cpp +++ b/AI/Nullkiller/main.cpp @@ -28,5 +28,5 @@ extern "C" DLL_EXPORT void GetAiName(char * name) extern "C" DLL_EXPORT void GetNewAI(std::shared_ptr & out) { - out = std::make_shared(); + out = std::make_shared(); } diff --git a/Global.h b/Global.h index 80776b24f..0270d6942 100644 --- a/Global.h +++ b/Global.h @@ -746,6 +746,20 @@ namespace vstd return false; } + template + typename M::mapped_type & getOrCompute(M & m, Key const & k, F f) + { + typedef typename M::mapped_type V; + + std::pair r = m.insert(typename M::value_type(k, V())); + V & v = r.first->second; + + if(r.second) + f(v); + + return v; + } + using boost::math::round; } using vstd::operator-=;