From b597171f91920f946dafe97617e0cd969c2093a7 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Wed, 9 May 2012 07:56:39 +0000 Subject: [PATCH] - EXPLORE goal can now be complete soAI won't get stuck - AI won't try to visit tiles occupied by allied heroes by default --- AI/StupidAI/StupidAI.cpp | 2 +- AI/VCAI/VCAI.cpp | 13 ++++++++++++- AI/VCAI/VCAI.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index 1f1025e48..ec93098d0 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -156,7 +156,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) else { const EnemyInfo &ei= *std::min_element(enemiesUnreachable.begin(), enemiesUnreachable.end(), boost::bind(isCloser, _1, _2, boost::ref(dists))); - if(distToNearestNeighbour(ei.s->position, dists) < GameConstants::BFIELD_SIZE) + if(distToNearestNeighbour(ei.s->position, dists) < GameConstants::BFIELD_SIZE) //FIXME: rare crash when AI attacks banks { return goTowards(stack, ei.s->position); } diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 8eac4f2aa..e89d1a68c 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -235,6 +235,7 @@ bool remove_if_present(Container &c, const Item &item) return false; } + template bool remove_if_present(std::map & c, const Item2 &item) { @@ -1443,9 +1444,17 @@ const CGObjectInstance * VCAI::getUnvisitedObj(const boost::functionsetSelection(h); + if (!includeAllies) + { //don't visit tile occupied by allied hero + BOOST_FOREACH (auto obj, cb->getVisitableObjs(pos)) + { + if (obj->ID == GameConstants::HEROI_TYPE && obj->tempOwner == h->tempOwner && obj != h) + return false; + } + } return cb->getPathInfo(pos)->reachable(); } @@ -2904,6 +2913,8 @@ int3 SectorMap::firstTileToGet(const CGHeroInstance *h, crint3 dst) if(!preds[dst]) { write("test.txt"); + ai->completeGoal (CGoal(EXPLORE).sethero(h)); //if we can't find the way, seemingly all tiles were explored + //TODO: more organized way? throw cannotFulfillGoalException(str(format("Cannot find connection between sectors %d and %d") % src->id % dst->id)); } diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index 4bd2a7f65..72dd2bb4f 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -305,7 +305,7 @@ public: const CGHeroInstance *getHeroWithGrail() const; const CGObjectInstance *getUnvisitedObj(const boost::function &predicate); - bool isAccessibleForHero(const int3 & pos, const CGHeroInstance * h) const; + bool isAccessibleForHero(const int3 & pos, const CGHeroInstance * h, bool includeAllies = false) const; const CGTownInstance *findTownWithTavern() const;