2
0
Эх сурвалжийг харах

More fixes and tweaks for AI, including #1590.

DjWarmonger 12 жил өмнө
parent
commit
362a54b4df
2 өөрчлөгдсөн 9 нэмэгдсэн , 6 устгасан
  1. 2 2
      AI/VCAI/Goals.cpp
  2. 7 4
      AI/VCAI/VCAI.cpp

+ 2 - 2
AI/VCAI/Goals.cpp

@@ -242,7 +242,7 @@ TSubgoal GetObj::whatToDoToAchieve()
 	if(!obj)
 		return sptr (Goals::Explore());
 	int3 pos = obj->visitablePos();
-	return sptr (Goals::VisitTile(pos));
+	return sptr (Goals::VisitTile(pos).sethero(hero)); //we must visit object with same hero, if any
 }
 
 float GetObj::importanceWhenLocked() const
@@ -426,7 +426,7 @@ TGoalVec Explore::getAllPossibleSubgoals()
 		}
 
 		int3 t = whereToExplore(h);
-		if (t.z != -1) //no valid tile was found
+		if (cb->isInTheMap(t)) //valid tile was found - could be invalid (none)
 			ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
 	}
 	if (!hero && ai->canRecruitAnyHero())//if hero is assigned to that goal, no need to buy another one yet

+ 7 - 4
AI/VCAI/VCAI.cpp

@@ -796,6 +796,7 @@ void VCAI::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h)
 			}
 			break;
 	}
+	completeGoal (sptr(Goals::GetObj(obj->id.getNum()).sethero(h)));
 }
 
 void VCAI::moveCreaturesToHero(const CGTownInstance * t)
@@ -1823,7 +1824,7 @@ Goals::TSubgoal VCAI::striveToGoalInternal(Goals::TSubgoal ultimateGoal, bool on
 
 void VCAI::striveToQuest (const QuestInfo &q)
 {
-	if (q.quest->missionType && q.quest->progress != CQuest::COMPLETE) //FIXME: quests are never synchronized. Pointer handling needed
+	if (q.quest->missionType && q.quest->progress != CQuest::COMPLETE)
 	{
 		MetaString ms;
 		q.quest->getRolloverText(ms, false);
@@ -2494,8 +2495,7 @@ bool isWeeklyRevisitable (const CGObjectInstance * obj)
 bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
 {
 	switch (obj->ID)
-	{
-		case Obj::BORDERGUARD:
+	{	
 		case Obj::BORDER_GATE:
 		{
 			for (auto q : ai->myCb->getMyQuests())
@@ -2507,6 +2507,8 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
 			}
 			return true; //we don't have this quest yet
 		}
+			break;
+		case Obj::BORDERGUARD: //open borderguard if possible
 		case Obj::SEER_HUT:
 		case Obj::QUEST_GUARD:
 		{
@@ -2514,7 +2516,7 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
 			{
 				if (q.obj == obj)
 				{
-					if (q.quest->checkQuest(*h))
+					if (q.quest->checkQuest(h.h))
 						return true; //we completed the quest
 					else
 						return false; //we can't complete this quest
@@ -2522,6 +2524,7 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
 			}
 			return true; //we don't have this quest yet
 		}
+			break;
 		case Obj::CREATURE_GENERATOR1:
 		{
 			if (obj->tempOwner != h->tempOwner)