From 362a54b4dfac39916f156ee185cc33dc122b1850 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sat, 21 Dec 2013 21:31:28 +0000 Subject: [PATCH] More fixes and tweaks for AI, including #1590. --- AI/VCAI/Goals.cpp | 4 ++-- AI/VCAI/VCAI.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/AI/VCAI/Goals.cpp b/AI/VCAI/Goals.cpp index afdcdea3e..6e358a446 100644 --- a/AI/VCAI/Goals.cpp +++ b/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 diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index c6737912b..32f53dcdd 100644 --- a/AI/VCAI/VCAI.cpp +++ b/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)