浏览代码

AI can finally clear Subterranean Gate with guard on the other side :)

DjWarmonger 11 年之前
父节点
当前提交
1196eb5d81
共有 2 个文件被更改,包括 28 次插入14 次删除
  1. 14 0
      AI/VCAI/AIUtility.cpp
  2. 14 14
      AI/VCAI/VCAI.cpp

+ 14 - 0
AI/VCAI/AIUtility.cpp

@@ -207,6 +207,19 @@ ui64 evaluateDanger(crint3 tile, const CGHeroInstance *visitor)
 			if(armedObj)
 				objectDanger *= fh->getTacticalAdvantage(visitor, armedObj); //this line tends to go infinite for allied towns (?)
 		}
+		if (dangerousObject->ID == Obj::SUBTERRANEAN_GATE)
+		{ //check guard on the other side of the gate
+			auto it = ai->knownSubterraneanGates.find(dangerousObject);
+			if (it != ai->knownSubterraneanGates.end())
+			{
+				auto guards = cb->getGuardingCreatures(it->second->visitablePos());
+				for (auto cre : guards)
+				{
+					vstd::amax (guardDanger, evaluateDanger(cre) *
+						fh->getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance*>(cre)));
+				}
+			}
+		}
 	}
 
 	auto guards = cb->getGuardingCreatures(tile);
@@ -215,6 +228,7 @@ ui64 evaluateDanger(crint3 tile, const CGHeroInstance *visitor)
 		vstd::amax (guardDanger, evaluateDanger(cre) * fh->getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance*>(cre))); //we are interested in strongest monster around
 	}
 
+
 	//TODO mozna odwiedzic blockvis nie ruszajac straznika
 	return std::max(objectDanger, guardDanger);
 }

+ 14 - 14
AI/VCAI/VCAI.cpp

@@ -2713,7 +2713,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num)
 						auto obj = t->visitableObjects.front();
 						if (vstd::contains(ai->knownSubterraneanGates, obj))
 						{ //not really sure what does it do, but subtrranean gates do not make one sector
-							toVisit.push(ai->knownSubterraneanGates[obj]->visitablePos());
+							//toVisit.push(ai->knownSubterraneanGates[obj]->visitablePos());
 							s.subterraneanGates.push_back (obj);
 						}
 					}
@@ -2878,15 +2878,15 @@ For ship construction etc, another function (goal?) is needed
 	if(sourceSector != destinationSector)
 	{
 		const Sector *src = &infoOnSectors[sourceSector],
-			*dst = &infoOnSectors[destinationSector];
+			*dest = &infoOnSectors[destinationSector];
 
 		std::map<const Sector*, const Sector*> preds;
-		std::queue<const Sector *> sq;
-		sq.push(src);
-		while(!sq.empty())
+		std::queue<const Sector *> sectorQueue;
+		sectorQueue.push(src);
+		while(!sectorQueue.empty())
 		{
-			const Sector *s = sq.front();
-			sq.pop();
+			const Sector *s = sectorQueue.front();
+			sectorQueue.pop();
 
 			for(int3 ep : s->embarkmentPoints)
 			{
@@ -2895,7 +2895,7 @@ For ship construction etc, another function (goal?) is needed
 				if(!preds[neigh])
 				{
 					preds[neigh] = s;
-					sq.push(neigh);
+					sectorQueue.push(neigh);
 				}
 			}
 
@@ -2909,15 +2909,15 @@ For ship construction etc, another function (goal?) is needed
 					if(!preds[neigh]) //if we didn't come into this sector yet
 					{
 						preds[neigh] = s; //it becomes our new target sector
-						sq.push(neigh);
+						sectorQueue.push(neigh);
 					}
 				}
 			}
 		}
 
-		if(!preds[dst])
+		if(!preds[dest])
 		{
-			write("test.txt");
+			//write("test.txt");
 			ai->completeGoal (sptr(Goals::Explore(h))); //if we can't find the way, seemingly all tiles were explored
 			//TODO: more organized way?
 
@@ -2926,13 +2926,13 @@ For ship construction etc, another function (goal?) is needed
 		}
 
 		std::vector<const Sector*> toTraverse;
-		toTraverse.push_back(dst);
+		toTraverse.push_back(dest);
 		while(toTraverse.back() != src)
 		{
 			toTraverse.push_back(preds[toTraverse.back()]);
 		}
 
-		if(preds[dst])
+		if(preds[dest])
 		{
 			const Sector *sectorToReach  = toTraverse.at(toTraverse.size() - 2);
 			if(!src->water && sectorToReach->water) //embark
@@ -3024,7 +3024,7 @@ For ship construction etc, another function (goal?) is needed
 			{
 				auto firstGate = boost::find_if(src->subterraneanGates, [=](const CGObjectInstance * gate) -> bool
 				{
-					return retreiveTile(gate->visitablePos()) == sectorToReach->id;
+					return retreiveTile(ai->knownSubterraneanGates[gate]->visitablePos()) == sectorToReach->id;
 				});
 
 				if(firstGate != src->subterraneanGates.end())