1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- Fixed secondary heroes stalking main hero

- Fixed exotic crash when all nearby tiles are occupied
This commit is contained in:
DjWarmonger 2014-02-15 21:32:49 +00:00
parent b368e565ab
commit afacb40f5a
2 changed files with 12 additions and 10 deletions

View File

@ -514,10 +514,7 @@ TGoalVec Explore::getAllPossibleSubgoals()
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
if (t.valid())
{
//auto topObj = backOrNull(cb->getVisitableObjs(t));
//if (topObj && topObj->ID == Obj::HERO && topObj != h)
// continue; //if the tile is occupied by another hero, we are not interested in going there
assert(cb->isInTheMap(t));
if (isSafeToVisit(h, t))
{
ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
@ -532,7 +529,10 @@ TGoalVec Explore::getAllPossibleSubgoals()
int3 t = whereToExplore(h);
if (t.valid())
{
assert(cb->isInTheMap(t));
ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
}
}
//we either don't have hero yet or none of heroes can explore
if ((!hero || ret.empty()) && ai->canRecruitAnyHero())
@ -599,6 +599,8 @@ TSubgoal VisitTile::whatToDoToAchieve()
TGoalVec VisitTile::getAllPossibleSubgoals()
{
assert(cb->isInTheMap(tile));
TGoalVec ret;
if (!cb->isVisible(tile))
ret.push_back (sptr(Goals::Explore())); //what sense does it make?
@ -807,12 +809,6 @@ TGoalVec Conquer::getAllPossibleSubgoals()
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
if (t.valid())
{
//auto topObj = backOrNull(cb->getVisitableObjs(t));
//if (topObj && topObj->ID == Obj::HERO && topObj != h)
// continue; //if the tile is occupied by another hero, we are not interested in going there
//FIXME: should firstTileToGet return position of our other hero?
if (isSafeToVisit(h, t))
{
if (obj->ID == Obj::HERO)

View File

@ -823,6 +823,9 @@ void VCAI::moveCreaturesToHero(const CGTownInstance * t)
bool VCAI::canGetArmy (const CGHeroInstance * army, const CGHeroInstance * source)
{ //TODO: merge with pickBestCreatures
if (ai->primaryHero().h == source)
return false; //TODO: allow exchange back and forth
if(army->tempOwner != source->tempOwner)
{
logAi->errorStream() << "Why are we even considering exchange between heroes from different players?";
@ -2158,6 +2161,9 @@ int3 VCAI::explorationBestNeighbour(int3 hpos, int radius, HeroPtr h)
if (isSafeToVisit(h, hpos + dir) && isAccessibleForHero (hpos + dir, h))
dstToRevealedTiles[hpos + dir] = howManyTilesWillBeDiscovered(radius, hpos, dir);
if (dstToRevealedTiles.empty()) //yes, it DID happen!
throw cannotFulfillGoalException("No neighbour will bring new discoveries!");
auto best = dstToRevealedTiles.begin();
for (auto i = dstToRevealedTiles.begin(); i != dstToRevealedTiles.end(); i++)
{