1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

[2982] AI: unexpected error in AI logic when take resource on adjasent tile

This commit is contained in:
Andrii Danylchenko 2018-06-18 21:57:45 +03:00
parent ac293fb592
commit 4141e8e7b0

View File

@ -2041,6 +2041,11 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
if(teleportChannelProbingList.size()) if(teleportChannelProbingList.size())
doChannelProbing(); doChannelProbing();
} }
if(path.nodes[0].action == CGPathNode::BLOCKING_VISIT)
{
ret = h && i == 0; // when we take resource we do not reach its position. We even might not move
}
} }
if(h) if(h)
{ {
@ -2055,7 +2060,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
completeGoal(sptr(Goals::VisitTile(dst).sethero(h))); //we stepped on some tile, anyway completeGoal(sptr(Goals::VisitTile(dst).sethero(h))); //we stepped on some tile, anyway
completeGoal(sptr(Goals::ClearWayTo(dst).sethero(h))); completeGoal(sptr(Goals::ClearWayTo(dst).sethero(h)));
ret = (dst == h->visitablePos()); ret = ret || (dst == h->visitablePos());
if(!ret) //reserve object we are heading towards if(!ret) //reserve object we are heading towards
{ {
@ -2066,8 +2071,8 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
if(startHpos == h->visitablePos() && !ret) //we didn't move and didn't reach the target if(startHpos == h->visitablePos() && !ret) //we didn't move and didn't reach the target
{ {
vstd::erase_if_present(lockedHeroes, h); //hero seemingly is confused vstd::erase_if_present(lockedHeroes, h); //hero seemingly is confused or has only 95mp which is not enough to move
throw cannotFulfillGoalException("Invalid path found!"); //FIXME: should never happen throw cannotFulfillGoalException("Invalid path found!");
} }
evaluateGoal(h); //new hero position means new game situation evaluateGoal(h); //new hero position means new game situation
logAi->debug("Hero %s moved from %s to %s. Returning %d.", h->name, startHpos.toString(), h->visitablePos().toString(), ret); logAi->debug("Hero %s moved from %s to %s. Returning %d.", h->name, startHpos.toString(), h->visitablePos().toString(), ret);