mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fix for wander - AI sitting at town will buy troops.
This commit is contained in:
parent
301565b315
commit
ea19716fb9
@ -1453,6 +1453,17 @@ bool VCAI::canRecruitAnyHero(const CGTownInstance * t) const
|
||||
|
||||
void VCAI::wander(HeroPtr h)
|
||||
{
|
||||
|
||||
auto visitTownIfAny = [this](HeroPtr h) -> bool
|
||||
{
|
||||
if (h->visitedTown)
|
||||
{
|
||||
townVisitsThisWeek[h].insert(h->visitedTown);
|
||||
buildArmyIn(h->visitedTown);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//unclaim objects that are now dangerous for us
|
||||
auto reservedObjsSetCopy = reservedHeroesMap[h];
|
||||
for(auto obj : reservedObjsSetCopy)
|
||||
@ -1585,26 +1596,23 @@ void VCAI::wander(HeroPtr h)
|
||||
|
||||
//wander should not cause heroes to be reserved - they are always considered free
|
||||
logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), dest.id.getNum());
|
||||
if(!goVisitObj(dest, h))
|
||||
if (!goVisitObj(dest, h))
|
||||
{
|
||||
if(!dest)
|
||||
if (!dest)
|
||||
{
|
||||
logAi->debug("Visit attempt made the object (id=%d) gone...", dest.id.getNum());
|
||||
}
|
||||
else
|
||||
{
|
||||
logAi->debug("Hero %s apparently used all MPs (%d left)", h->name, h->movement);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(h->visitedTown)
|
||||
{
|
||||
townVisitsThisWeek[h].insert(h->visitedTown);
|
||||
buildArmyIn(h->visitedTown);
|
||||
else //we reached our destination
|
||||
visitTownIfAny(h);
|
||||
}
|
||||
}
|
||||
visitTownIfAny(h); //in case hero is just sitting in town
|
||||
}
|
||||
|
||||
void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal)
|
||||
|
Loading…
Reference in New Issue
Block a user