From da76a2f227ee5b7925a3e34d4b3571cbf44ff9e7 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sun, 21 Dec 2014 14:50:26 +0100 Subject: [PATCH] Fixed AI trying to visit tile already occupied by different hero, including #1902. --- AI/VCAI/Goals.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AI/VCAI/Goals.cpp b/AI/VCAI/Goals.cpp index 3f042bdfc..fa190918c 100644 --- a/AI/VCAI/Goals.cpp +++ b/AI/VCAI/Goals.cpp @@ -715,7 +715,12 @@ TGoalVec VisitTile::getAllPossibleSubgoals() { auto obj = frontOrNull(cb->getVisitableObjs(tile)); if (obj && obj->ID == Obj::HERO && obj->tempOwner == ai->playerID) //our own hero stands on that tile - ret.push_back (sptr(Goals::VisitTile(tile).sethero(dynamic_cast(obj)).setisElementar(true))); + { + if (hero.get(true) && hero->id == obj->id) //if it's assigned hero, visit tile. If it's different hero, we can't visit tile now + ret.push_back(sptr(Goals::VisitTile(tile).sethero(dynamic_cast(obj)).setisElementar(true))); + else + throw cannotFulfillGoalException("Tile is already occupied by another hero "); //FIXME: we should give up this tile earlier + } else ret.push_back (sptr(Goals::ClearWayTo(tile))); }