Pārlūkot izejas kodu

- EXPLORE goal can now be complete soAI won't get stuck
- AI won't try to visit tiles occupied by allied heroes by default

DjWarmonger 13 gadi atpakaļ
vecāks
revīzija
b597171f91
3 mainītis faili ar 14 papildinājumiem un 3 dzēšanām
  1. 1 1
      AI/StupidAI/StupidAI.cpp
  2. 12 1
      AI/VCAI/VCAI.cpp
  3. 1 1
      AI/VCAI/VCAI.h

+ 1 - 1
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);
 		}

+ 12 - 1
AI/VCAI/VCAI.cpp

@@ -235,6 +235,7 @@ bool remove_if_present(Container &c, const Item &item)
 	return false;
 }
 
+
 template <typename V, typename Item, typename Item2>
 bool remove_if_present(std::map<Item,V> & c, const Item2 &item)
 {
@@ -1443,9 +1444,17 @@ const CGObjectInstance * VCAI::getUnvisitedObj(const boost::function<bool(const
 	return NULL;
 }
 
-bool VCAI::isAccessibleForHero(const int3 & pos, const CGHeroInstance * h) const
+bool VCAI::isAccessibleForHero(const int3 & pos, const CGHeroInstance * h, bool includeAllies) const
 {
 	cb->setSelection(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));
 		}
 

+ 1 - 1
AI/VCAI/VCAI.h

@@ -305,7 +305,7 @@ public:
 	const CGHeroInstance *getHeroWithGrail() const;
 
 	const CGObjectInstance *getUnvisitedObj(const boost::function<bool(const CGObjectInstance *)> &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;