mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
- Fixed secondary heroes stalking main hero
- Fixed exotic crash when all nearby tiles are occupied
This commit is contained in:
parent
b368e565ab
commit
afacb40f5a
@ -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
|
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
|
||||||
if (t.valid())
|
if (t.valid())
|
||||||
{
|
{
|
||||||
//auto topObj = backOrNull(cb->getVisitableObjs(t));
|
assert(cb->isInTheMap(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
|
|
||||||
|
|
||||||
if (isSafeToVisit(h, t))
|
if (isSafeToVisit(h, t))
|
||||||
{
|
{
|
||||||
ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
|
ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
|
||||||
@ -532,8 +529,11 @@ TGoalVec Explore::getAllPossibleSubgoals()
|
|||||||
|
|
||||||
int3 t = whereToExplore(h);
|
int3 t = whereToExplore(h);
|
||||||
if (t.valid())
|
if (t.valid())
|
||||||
|
{
|
||||||
|
assert(cb->isInTheMap(t));
|
||||||
ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
|
ret.push_back (sptr (Goals::VisitTile(t).sethero(h)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//we either don't have hero yet or none of heroes can explore
|
//we either don't have hero yet or none of heroes can explore
|
||||||
if ((!hero || ret.empty()) && ai->canRecruitAnyHero())
|
if ((!hero || ret.empty()) && ai->canRecruitAnyHero())
|
||||||
ret.push_back (sptr(Goals::RecruitHero()));
|
ret.push_back (sptr(Goals::RecruitHero()));
|
||||||
@ -599,6 +599,8 @@ TSubgoal VisitTile::whatToDoToAchieve()
|
|||||||
|
|
||||||
TGoalVec VisitTile::getAllPossibleSubgoals()
|
TGoalVec VisitTile::getAllPossibleSubgoals()
|
||||||
{
|
{
|
||||||
|
assert(cb->isInTheMap(tile));
|
||||||
|
|
||||||
TGoalVec ret;
|
TGoalVec ret;
|
||||||
if (!cb->isVisible(tile))
|
if (!cb->isVisible(tile))
|
||||||
ret.push_back (sptr(Goals::Explore())); //what sense does it make?
|
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
|
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
|
||||||
if (t.valid())
|
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 (isSafeToVisit(h, t))
|
||||||
{
|
{
|
||||||
if (obj->ID == Obj::HERO)
|
if (obj->ID == Obj::HERO)
|
||||||
|
@ -823,6 +823,9 @@ void VCAI::moveCreaturesToHero(const CGTownInstance * t)
|
|||||||
|
|
||||||
bool VCAI::canGetArmy (const CGHeroInstance * army, const CGHeroInstance * source)
|
bool VCAI::canGetArmy (const CGHeroInstance * army, const CGHeroInstance * source)
|
||||||
{ //TODO: merge with pickBestCreatures
|
{ //TODO: merge with pickBestCreatures
|
||||||
|
if (ai->primaryHero().h == source)
|
||||||
|
return false; //TODO: allow exchange back and forth
|
||||||
|
|
||||||
if(army->tempOwner != source->tempOwner)
|
if(army->tempOwner != source->tempOwner)
|
||||||
{
|
{
|
||||||
logAi->errorStream() << "Why are we even considering exchange between heroes from different players?";
|
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))
|
if (isSafeToVisit(h, hpos + dir) && isAccessibleForHero (hpos + dir, h))
|
||||||
dstToRevealedTiles[hpos + dir] = howManyTilesWillBeDiscovered(radius, hpos, dir);
|
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();
|
auto best = dstToRevealedTiles.begin();
|
||||||
for (auto i = dstToRevealedTiles.begin(); i != dstToRevealedTiles.end(); i++)
|
for (auto i = dstToRevealedTiles.begin(); i != dstToRevealedTiles.end(); i++)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user