diff --git a/AI/VCAI/Goals.cpp b/AI/VCAI/Goals.cpp index 472734b1f..6bdca1c0f 100644 --- a/AI/VCAI/Goals.cpp +++ b/AI/VCAI/Goals.cpp @@ -512,11 +512,15 @@ std::string GetObj::completeMessage() const return "hero " + hero.get()->name + " captured Object ID = " + boost::lexical_cast(objid); } -TSubgoal GetObj::whatToDoToAchieve() +TGoalVec GetObj::getAllPossibleSubgoals() { + TGoalVec goalList; const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid)); if(!obj) - return sptr(Goals::Explore()); + { + goalList.push_back(sptr(Goals::Explore())); + return goalList; + } int3 pos = obj->visitablePos(); if(hero) @@ -524,31 +528,43 @@ TSubgoal GetObj::whatToDoToAchieve() if(ai->isAccessibleForHero(pos, hero)) { if(isSafeToVisit(hero, pos)) - return sptr(Goals::GetObj(obj->id.getNum()).sethero(hero).setisElementar(true)); + goalList.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(hero))); else - return sptr(Goals::GatherArmy(evaluateDanger(pos, hero.h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true)); + goalList.push_back(sptr(Goals::GatherArmy(evaluateDanger(pos, hero.h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true))); + + return goalList; } } else { - TGoalVec goalVersionsWithAllPossibleHeroes; for(auto h : cb->getHeroesInfo()) - { + { if(ai->isAccessibleForHero(pos, h)) { if(isSafeToVisit(hero, pos)) - goalVersionsWithAllPossibleHeroes.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h))); + goalList.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h))); else - return sptr(Goals::GatherArmy(evaluateDanger(pos, h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true)); + goalList.push_back(sptr(Goals::GatherArmy(evaluateDanger(pos, h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true))); } } - if(!goalVersionsWithAllPossibleHeroes.empty()) + if(!goalList.empty()) { - auto bestCandidate = fh->chooseSolution(goalVersionsWithAllPossibleHeroes); - return bestCandidate; + return goalList; } } - return sptr(Goals::ClearWayTo(pos).sethero(hero)); + + goalList.push_back(sptr(Goals::ClearWayTo(pos).sethero(hero))); + return goalList; +} + +TSubgoal GetObj::whatToDoToAchieve() +{ + auto bestGoal = fh->chooseSolution(getAllPossibleSubgoals()); + + if(bestGoal->goalType == Goals::GET_OBJ && bestGoal->hero) + bestGoal->setisElementar(true); + + return bestGoal; } bool Goals::GetObj::operator==(AbstractGoal & g) diff --git a/AI/VCAI/Goals.h b/AI/VCAI/Goals.h index 6adcea7b4..1cb8e2833 100644 --- a/AI/VCAI/Goals.h +++ b/AI/VCAI/Goals.h @@ -472,10 +472,7 @@ public: objid = Objid; priority = 3; } - TGoalVec getAllPossibleSubgoals() override - { - return TGoalVec(); - } + TGoalVec getAllPossibleSubgoals() override; TSubgoal whatToDoToAchieve() override; bool operator==(AbstractGoal & g) override; bool fulfillsMe(TSubgoal goal) override;