Przeglądaj źródła

- More fixes for wander targets
- SectorMap won't find paths through the rock

DjWarmonger 10 lat temu
rodzic
commit
3e8c395156
4 zmienionych plików z 11 dodań i 6 usunięć
  1. 2 2
      AI/VCAI/Goals.cpp
  2. 6 3
      AI/VCAI/VCAI.cpp
  3. 1 1
      AI/VCAI/VCAI.h
  4. 2 0
      lib/mapping/CMap.cpp

+ 2 - 2
AI/VCAI/Goals.cpp

@@ -632,7 +632,7 @@ TGoalVec Explore::getAllPossibleSubgoals()
 		for (auto obj : objs) //double loop, performance risk?
 		{
 			auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
-			if (ai->canReachTile(h, t))
+			if (ai->isTileNotReserved(h, t))
 				ret.push_back (sptr(Goals::ClearWayTo(obj->visitablePos(), h).setisAbstract(true)));
 		}
 
@@ -968,7 +968,7 @@ TGoalVec Conquer::getAllPossibleSubgoals()
 		for (auto obj : ourObjs) //double loop, performance risk?
 		{
 			auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
-			if (ai->canReachTile(h, t))
+			if (ai->isTileNotReserved(h, t))
 				ret.push_back (sptr(Goals::ClearWayTo(obj->visitablePos(), h).setisAbstract(true)));
 		}
 	}

+ 6 - 3
AI/VCAI/VCAI.cpp

@@ -1348,13 +1348,16 @@ bool VCAI::isGoodForVisit(const CGObjectInstance *obj, HeroPtr h, SectorMap &sm)
 {
 	const int3 pos = obj->visitablePos();
 	const int3 targetPos = sm.firstTileToGet(h, pos);
-	if (canReachTile(h.get(), targetPos) &&
+	if (!targetPos.valid())
+		return false;
+	if (isTileNotReserved(h.get(), targetPos) &&
 			!obj->wasVisited(playerID) &&
 			(cb->getPlayerRelations(ai->playerID, obj->tempOwner) == PlayerRelations::ENEMIES || isWeeklyRevisitable(obj)) && //flag or get weekly resources / creatures
 			isSafeToVisit(h, pos) &&
 			shouldVisit(h, obj) &&
 			!vstd::contains(alreadyVisited, obj) &&
-			!vstd::contains(reservedObjs, obj))
+			!vstd::contains(reservedObjs, obj) &&
+			isAccessibleForHero(targetPos, h))
 	{
 		const CGObjectInstance *topObj = cb->getVisitableObjs(obj->visitablePos()).back(); //it may be hero visiting this obj
 		//we don't try visiting object on which allied or owned hero stands
@@ -1386,7 +1389,7 @@ std::vector<const CGObjectInstance *> VCAI::getPossibleDestinations(HeroPtr h)
 	return possibleDestinations;
 }
 
-bool VCAI::canReachTile (const CGHeroInstance * h, int3 t)
+bool VCAI::isTileNotReserved(const CGHeroInstance * h, int3 t)
 {
 	if (t.valid())
 	{

+ 1 - 1
AI/VCAI/VCAI.h

@@ -184,7 +184,7 @@ public:
 	int3 explorationBestNeighbour(int3 hpos, int radius, HeroPtr h);
 	int3 explorationNewPoint(HeroPtr h);
 	int3 explorationDesperate(HeroPtr h);
-	bool canReachTile (const CGHeroInstance * h, int3 t);
+	bool isTileNotReserved(const CGHeroInstance * h, int3 t); //the tile is not occupied by allied hero and the object is not reserved
 	void recruitHero();
 
 	virtual std::string getBattleAIName() const override;

+ 2 - 0
lib/mapping/CMap.cpp

@@ -340,6 +340,8 @@ bool CMap::isWaterTile(const int3 &pos) const
 
 bool CMap::checkForVisitableDir(const int3 & src, const TerrainTile *pom, const int3 & dst ) const
 {
+	if (!pom->entrableTerrain()) //rock is never accessible
+		return false;
 	for(ui32 b=0; b<pom->visitableObjects.size(); ++b) //checking destination tile
 	{
 		if(!vstd::contains(pom->blockingObjects, pom->visitableObjects[b])) //this visitable object is not blocking, ignore