浏览代码

New object target handling in wander

Dydzio 7 年之前
父节点
当前提交
616a6bbdf7
共有 2 个文件被更改,包括 11 次插入10 次删除
  1. 1 1
      AI/VCAI/Goals.cpp
  2. 10 9
      AI/VCAI/VCAI.cpp

+ 1 - 1
AI/VCAI/Goals.cpp

@@ -1142,7 +1142,7 @@ TGoalVec Goals::CollectRes::getAllPossibleSubgoals()
 						if (dest != t) //there is something blocking our way
 							ret.push_back(sptr(Goals::ClearWayTo(dest, h).setisAbstract(true)));
 						else
-							ret.push_back(sptr(Goals::VisitTile(dest).sethero(h).setisAbstract(true)));
+							ret.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h).setisAbstract(true)));
 					}
 					else //we need to get army in order to pick that object
 						ret.push_back(sptr(Goals::GatherArmy(evaluateDanger(dest, h) * SAFE_ATTACK_CONSTANT).sethero(h).setisAbstract(true)));

+ 10 - 9
AI/VCAI/VCAI.cpp

@@ -1460,17 +1460,18 @@ void VCAI::wander(HeroPtr h)
 		//end of objs empty
 
 		if(dests.size()) //performance improvement
-		{
-			auto fuzzyLogicSorter = [h](const ObjectIdRef & l, const ObjectIdRef & r) -> bool //TODO: create elementar GetObj goal usable for goal decomposition and Wander based on VisitTile logic and object value on top of it
+		{			
+			Goals::TGoalVec targetObjectGoals;
+			for(auto destination : dests)
 			{
-				return fh->getWanderTargetObjectValue( *h.get(), l) < fh->getWanderTargetObjectValue(*h.get(), r);
-			};
-
-			const ObjectIdRef & dest = *boost::max_element(dests, fuzzyLogicSorter); //find best object to visit based on fuzzy logic evaluation, TODO: use elementar version of GetObj here in future
+				targetObjectGoals.push_back(sptr(Goals::GetObj(destination.id.getNum()).sethero(h).setisAbstract(true)));
+			}
+			auto bestObjectGoal = fh->chooseSolution(targetObjectGoals);
+			decomposeGoal(bestObjectGoal)->accept(this);
 
 			//wander should not cause heroes to be reserved - they are always considered free
-			logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), dest.id.getNum());
-			if (!goVisitObj(dest, h))
+			logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), bestObjectGoal->objid);
+			/*if (!goVisitObj(dest, h))
 			{
 				if (!dest)
 				{
@@ -1483,7 +1484,7 @@ void VCAI::wander(HeroPtr h)
 				}
 			}
 			else //we reached our destination
-				visitTownIfAny(h);
+				visitTownIfAny(h);*/
 		}
 	}
 	visitTownIfAny(h); //in case hero is just sitting in town