Dydzio 7 年之前
父節點
當前提交
5065f5a104
共有 2 個文件被更改,包括 20 次插入14 次删除
  1. 11 10
      AI/VCAI/Goals.cpp
  2. 9 4
      AI/VCAI/VCAI.cpp

+ 11 - 10
AI/VCAI/Goals.cpp

@@ -286,12 +286,6 @@ namespace Goals
 	{
 		return boost::format("Bought army of value %d in town of %s") % value, town->name;
 	}
-	GetObj::GetObj(int Objid): CGoal(Goals::GET_OBJ)
-	{	
-		objid = Objid;
-		tile = ai->myCb->getObjInstance(ObjectInstanceID(objid))->pos;
-		priority = 3;
-	}
 }
 
 TSubgoal Trade::whatToDoToAchieve()
@@ -521,7 +515,7 @@ std::string GetObj::completeMessage() const
 TGoalVec GetObj::getAllPossibleSubgoals()
 {
 	TGoalVec goalList;
-	const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid));
+	const CGObjectInstance * obj = cb->getObjInstance(ObjectInstanceID(objid));
 	if(!obj)
 	{
 		goalList.push_back(sptr(Goals::Explore()));
@@ -573,6 +567,13 @@ TSubgoal GetObj::whatToDoToAchieve()
 	return bestGoal;
 }
 
+Goals::GetObj::GetObj(int Objid) : CGoal(Goals::GET_OBJ)
+{
+	objid = Objid;
+	tile = ai->myCb->getObjInstance(ObjectInstanceID(objid))->visitablePos();
+	priority = 3;
+}
+
 bool Goals::GetObj::operator==(AbstractGoal & g)
 {
 	if (g.goalType != goalType)
@@ -582,11 +583,11 @@ bool Goals::GetObj::operator==(AbstractGoal & g)
 
 bool GetObj::fulfillsMe(TSubgoal goal)
 {
-	if(goal->goalType == Goals::VISIT_TILE) //visiting tile visits object at same time
+	if(goal->goalType == Goals::GET_OBJ)
 	{
 		if (!hero || hero == goal->hero)
 		{
-			auto obj = cb->getObj(ObjectInstanceID(objid));
+			auto obj = cb->getObjInstance(ObjectInstanceID(objid));
 			if (obj && obj->visitablePos() == goal->tile) //object could be removed
 				return true;
 		}
@@ -731,7 +732,7 @@ TGoalVec ClearWayTo::getAllPossibleSubgoals()
 				if(shouldVisit(h, topObj))
 				{
 					//do NOT use VISIT_TILE, as tile with quets guard can't be visited
-					ret.push_back(sptr(Goals::GetObj(topObj->id.getNum()).sethero(h)));
+					ret.push_back(sptr(Goals::GetObj(topObj->id.getNum()).sethero(h))); //TODO: Recheck this code - object visit became elementar goal
 					continue; //do not try to visit tile or gather army
 				}
 				else

+ 9 - 4
AI/VCAI/VCAI.cpp

@@ -1470,8 +1470,13 @@ void VCAI::wander(HeroPtr h)
 			decomposeGoal(bestObjectGoal)->accept(this);
 
 			//wander should not cause heroes to be reserved - they are always considered free
-			auto chosenObject = cb->getObjInstance(ObjectInstanceID(bestObjectGoal->objid));
-			logAi->debug("Of all %d destinations, object %s at pos=%s seems nice", dests.size(), chosenObject->getObjectName(), chosenObject->pos.toString());
+			if(bestObjectGoal->goalType == Goals::GET_OBJ)
+			{
+				auto chosenObject = cb->getObjInstance(ObjectInstanceID(bestObjectGoal->objid));
+				logAi->debug("Of all %d destinations, object %s at pos=%s seems nice", dests.size(), chosenObject->getObjectName(), chosenObject->pos.toString());
+			}
+			else
+				logAi->debug("Trying to realize goal of type %d as part of wandering.", bestObjectGoal->goalType);
 
 			visitTownIfAny(h);
 		}
@@ -1998,9 +2003,9 @@ void VCAI::tryRealize(Goals::VisitTile & g)
 
 void VCAI::tryRealize(Goals::GetObj & g)
 {
-	auto position = cb->getObjInstance((ObjectInstanceID)g.objid)->pos;
+	auto position = g.tile;
 	if(!g.hero->movement)
-		throw cannotFulfillGoalException("Cannot visit tile: hero is out of MPs!");
+		throw cannotFulfillGoalException("Cannot visit object: hero is out of MPs!");
 	if(position == g.hero->visitablePos() && cb->getVisitableObjs(g.hero->visitablePos()).size() < 2)
 	{
 		logAi->warn("Why do I want to move hero %s to tile %s? Already standing on that tile! ", g.hero->name, g.tile.toString());