1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Move away subgoal collection logic for GetObj

This commit is contained in:
Dydzio
2018-08-07 14:33:45 +02:00
parent 2365946b62
commit 41df9d8283
2 changed files with 29 additions and 16 deletions

View File

@@ -512,11 +512,15 @@ std::string GetObj::completeMessage() const
return "hero " + hero.get()->name + " captured Object ID = " + boost::lexical_cast<std::string>(objid); return "hero " + hero.get()->name + " captured Object ID = " + boost::lexical_cast<std::string>(objid);
} }
TSubgoal GetObj::whatToDoToAchieve() TGoalVec GetObj::getAllPossibleSubgoals()
{ {
TGoalVec goalList;
const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid)); const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid));
if(!obj) if(!obj)
return sptr(Goals::Explore()); {
goalList.push_back(sptr(Goals::Explore()));
return goalList;
}
int3 pos = obj->visitablePos(); int3 pos = obj->visitablePos();
if(hero) if(hero)
@@ -524,31 +528,43 @@ TSubgoal GetObj::whatToDoToAchieve()
if(ai->isAccessibleForHero(pos, hero)) if(ai->isAccessibleForHero(pos, hero))
{ {
if(isSafeToVisit(hero, pos)) 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 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 else
{ {
TGoalVec goalVersionsWithAllPossibleHeroes;
for(auto h : cb->getHeroesInfo()) for(auto h : cb->getHeroesInfo())
{ {
if(ai->isAccessibleForHero(pos, h)) if(ai->isAccessibleForHero(pos, h))
{ {
if(isSafeToVisit(hero, pos)) 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 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 goalList;
return bestCandidate;
} }
} }
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) bool Goals::GetObj::operator==(AbstractGoal & g)

View File

@@ -472,10 +472,7 @@ public:
objid = Objid; objid = Objid;
priority = 3; priority = 3;
} }
TGoalVec getAllPossibleSubgoals() override TGoalVec getAllPossibleSubgoals() override;
{
return TGoalVec();
}
TSubgoal whatToDoToAchieve() override; TSubgoal whatToDoToAchieve() override;
bool operator==(AbstractGoal & g) override; bool operator==(AbstractGoal & g) override;
bool fulfillsMe(TSubgoal goal) override; bool fulfillsMe(TSubgoal goal) override;