mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Elementar GetObj - first attempt
This commit is contained in:
parent
e89c7eeba4
commit
2365946b62
@ -517,21 +517,35 @@ TSubgoal GetObj::whatToDoToAchieve()
|
|||||||
const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid));
|
const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid));
|
||||||
if(!obj)
|
if(!obj)
|
||||||
return sptr(Goals::Explore());
|
return sptr(Goals::Explore());
|
||||||
if(obj->tempOwner == ai->playerID) //we can't capture our own object -> move to Win codition
|
|
||||||
throw cannotFulfillGoalException("Cannot capture my own object " + obj->getObjectName());
|
|
||||||
|
|
||||||
int3 pos = obj->visitablePos();
|
int3 pos = obj->visitablePos();
|
||||||
if(hero)
|
if(hero)
|
||||||
{
|
{
|
||||||
if(ai->isAccessibleForHero(pos, hero))
|
if(ai->isAccessibleForHero(pos, hero))
|
||||||
return sptr(Goals::VisitTile(pos).sethero(hero));
|
{
|
||||||
|
if(isSafeToVisit(hero, pos))
|
||||||
|
return sptr(Goals::GetObj(obj->id.getNum()).sethero(hero).setisElementar(true));
|
||||||
|
else
|
||||||
|
return sptr(Goals::GatherArmy(evaluateDanger(pos, hero.h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
TGoalVec goalVersionsWithAllPossibleHeroes;
|
||||||
for(auto h : cb->getHeroesInfo())
|
for(auto h : cb->getHeroesInfo())
|
||||||
{
|
{
|
||||||
if(ai->isAccessibleForHero(pos, h))
|
if(ai->isAccessibleForHero(pos, h))
|
||||||
return sptr(Goals::VisitTile(pos).sethero(h)); //we must visit object with same hero, if any
|
{
|
||||||
|
if(isSafeToVisit(hero, pos))
|
||||||
|
goalVersionsWithAllPossibleHeroes.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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!goalVersionsWithAllPossibleHeroes.empty())
|
||||||
|
{
|
||||||
|
auto bestCandidate = fh->chooseSolution(goalVersionsWithAllPossibleHeroes);
|
||||||
|
return bestCandidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sptr(Goals::ClearWayTo(pos).sethero(hero));
|
return sptr(Goals::ClearWayTo(pos).sethero(hero));
|
||||||
@ -912,8 +926,6 @@ TSubgoal VisitTile::whatToDoToAchieve()
|
|||||||
{
|
{
|
||||||
if(isSafeToVisit(ret->hero, tile) && ai->isAccessibleForHero(tile, ret->hero))
|
if(isSafeToVisit(ret->hero, tile) && ai->isAccessibleForHero(tile, ret->hero))
|
||||||
{
|
{
|
||||||
if(cb->getTile(tile)->topVisitableId().num == Obj::TOWN) //if target is town, fuzzy system will use additional "estimatedReward" variable to increase priority a bit
|
|
||||||
ret->objid = Obj::TOWN; //TODO: move to getObj eventually and add appropiate logic there
|
|
||||||
ret->setisElementar(true);
|
ret->setisElementar(true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1386,13 +1398,9 @@ TGoalVec Conquer::getAllPossibleSubgoals()
|
|||||||
{
|
{
|
||||||
ret.push_back(sptr(Goals::VisitHero(obj->id.getNum()).sethero(h).setisAbstract(true)));
|
ret.push_back(sptr(Goals::VisitHero(obj->id.getNum()).sethero(h).setisAbstract(true)));
|
||||||
}
|
}
|
||||||
else //just visit that tile
|
else //just get that object
|
||||||
{
|
{
|
||||||
if(obj->ID.num == Obj::TOWN)
|
ret.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h).setisAbstract(true)));
|
||||||
//if target is town, fuzzy system will use additional "estimatedReward" variable to increase priority a bit
|
|
||||||
ret.push_back(sptr(Goals::VisitTile(dest).sethero(h).setobjid(obj->ID.num).setisAbstract(true))); //TODO: change to getObj eventually and and move appropiate logic there
|
|
||||||
else
|
|
||||||
ret.push_back(sptr(Goals::VisitTile(dest).sethero(h).setisAbstract(true)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2006,6 +2006,22 @@ void VCAI::tryRealize(Goals::VisitTile & g)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VCAI::tryRealize(Goals::GetObj & g)
|
||||||
|
{
|
||||||
|
auto position = cb->getObjInstance((ObjectInstanceID)g.objid)->pos;
|
||||||
|
if(!g.hero->movement)
|
||||||
|
throw cannotFulfillGoalException("Cannot visit tile: 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());
|
||||||
|
throw goalFulfilledException(sptr(g));
|
||||||
|
}
|
||||||
|
if(ai->moveHeroToTile(position, g.hero.get()))
|
||||||
|
{
|
||||||
|
throw goalFulfilledException(sptr(g));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VCAI::tryRealize(Goals::VisitHero & g)
|
void VCAI::tryRealize(Goals::VisitHero & g)
|
||||||
{
|
{
|
||||||
if(!g.hero->movement)
|
if(!g.hero->movement)
|
||||||
|
@ -121,6 +121,7 @@ public:
|
|||||||
void tryRealize(Goals::Explore & g);
|
void tryRealize(Goals::Explore & g);
|
||||||
void tryRealize(Goals::RecruitHero & g);
|
void tryRealize(Goals::RecruitHero & g);
|
||||||
void tryRealize(Goals::VisitTile & g);
|
void tryRealize(Goals::VisitTile & g);
|
||||||
|
void tryRealize(Goals::GetObj & g);
|
||||||
void tryRealize(Goals::VisitHero & g);
|
void tryRealize(Goals::VisitHero & g);
|
||||||
void tryRealize(Goals::BuildThis & g);
|
void tryRealize(Goals::BuildThis & g);
|
||||||
void tryRealize(Goals::DigAtTile & g);
|
void tryRealize(Goals::DigAtTile & g);
|
||||||
|
Loading…
Reference in New Issue
Block a user