|
|
@@ -95,6 +95,7 @@ VCAI::VCAI(void)
|
|
|
{
|
|
|
LOG_TRACE(logAi);
|
|
|
makingTurn = nullptr;
|
|
|
+ currentSelection = nullptr;
|
|
|
}
|
|
|
|
|
|
VCAI::~VCAI(void)
|
|
|
@@ -664,9 +665,6 @@ void VCAI::makeTurn()
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- //FIXME: necessary? How to re-enable?
|
|
|
- //cb->recalculatePaths(cb->getSelectedHero());
|
|
|
-
|
|
|
markHeroAbleToExplore (primaryHero());
|
|
|
|
|
|
makeTurnInternal();
|
|
|
@@ -697,9 +695,9 @@ void VCAI::makeTurnInternal()
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- cb->setSelection(hero.first.get());
|
|
|
+ setSelection(hero.first.get());
|
|
|
std::vector<const CGObjectInstance *> vec(hero.second.begin(), hero.second.end());
|
|
|
- boost::sort (vec, isCloser);
|
|
|
+ boost::sort (vec, CDistanceSorter(hero.first.get()));
|
|
|
for (auto obj : vec)
|
|
|
{
|
|
|
if(!obj || !cb->getObj(obj->id))
|
|
|
@@ -1222,7 +1220,7 @@ std::vector<const CGObjectInstance *> VCAI::getPossibleDestinations(HeroPtr h)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- boost::sort(possibleDestinations, isCloser);
|
|
|
+ boost::sort(possibleDestinations, CDistanceSorter(h.get()));
|
|
|
|
|
|
return possibleDestinations;
|
|
|
}
|
|
|
@@ -1256,7 +1254,7 @@ bool VCAI::canRecruitAnyHero (const CGTownInstance * t) const
|
|
|
|
|
|
void VCAI::wander(HeroPtr h)
|
|
|
{
|
|
|
- cb->setSelection(*h);
|
|
|
+ setSelection(*h);
|
|
|
//unclaim objects that are now dangerous for us
|
|
|
auto reservedObjsSetCopy = reservedHeroesMap[h];
|
|
|
for (auto obj : reservedObjsSetCopy)
|
|
|
@@ -1381,7 +1379,7 @@ void VCAI::wander(HeroPtr h)
|
|
|
erase_if(dests, shouldBeErased);
|
|
|
|
|
|
erase_if_present(dests, dest); //why that fails sometimes when removing monsters?
|
|
|
- boost::sort(dests, isCloser); //find next closest one
|
|
|
+ boost::sort(dests, CDistanceSorter(h.get())); //find next closest one
|
|
|
}
|
|
|
|
|
|
if (h->visitedTown)
|
|
|
@@ -1618,7 +1616,6 @@ const CGObjectInstance * VCAI::getUnvisitedObj(const std::function<bool(const CG
|
|
|
|
|
|
bool VCAI::isAccessibleForHero(const int3 & pos, HeroPtr h, bool includeAllies /*= false*/) const
|
|
|
{
|
|
|
- cb->setSelection(*h);
|
|
|
if (!includeAllies)
|
|
|
{ //don't visit tile occupied by allied hero
|
|
|
for (auto obj : cb->getVisitableObjs(pos))
|
|
|
@@ -1629,12 +1626,12 @@ bool VCAI::isAccessibleForHero(const int3 & pos, HeroPtr h, bool includeAllies /
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- return cb->getPathInfo(pos)->reachable();
|
|
|
+ return cb->getPathsInfo(h.get())->getPathInfo(pos)->reachable();
|
|
|
}
|
|
|
|
|
|
bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
|
|
|
{
|
|
|
- cb->setSelection(h.h); //make sure we are using the RIGHT pathfinder
|
|
|
+ setSelection(h.h); //make sure we are using the RIGHT pathfinder
|
|
|
logAi->debugStream() << boost::format("Moving hero %s to tile %s") % h->name % dst;
|
|
|
int3 startHpos = h->visitablePos();
|
|
|
bool ret = false;
|
|
|
@@ -1649,11 +1646,10 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
|
|
|
else
|
|
|
{
|
|
|
CGPath path;
|
|
|
- cb->getPath2(dst, path);
|
|
|
+ cb->getPathsInfo(h.get())->getPath(dst, path);
|
|
|
if(path.nodes.empty())
|
|
|
{
|
|
|
logAi->errorStream() << "Hero " << h->name << " cannot reach " << dst;
|
|
|
- cb->recalculatePaths(h.get());
|
|
|
throw goalFulfilledException (sptr(Goals::VisitTile(dst).sethero(h)));
|
|
|
}
|
|
|
|
|
|
@@ -1702,7 +1698,6 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
|
|
|
reserveObject(h, obj);
|
|
|
}
|
|
|
|
|
|
- cb->recalculatePaths(h.get());
|
|
|
if (startHpos == h->visitablePos() && !ret) //we didn't move and didn't reach the target
|
|
|
{
|
|
|
erase_if_present (lockedHeroes, h); //hero seemingly is confused
|
|
|
@@ -2190,6 +2185,16 @@ void VCAI::striveToQuest (const QuestInfo &q)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const CArmedInstance * VCAI::getSelection()
|
|
|
+{
|
|
|
+ return currentSelection;
|
|
|
+}
|
|
|
+
|
|
|
+void VCAI::setSelection(const CArmedInstance * obj)
|
|
|
+{
|
|
|
+ currentSelection = obj;
|
|
|
+}
|
|
|
+
|
|
|
void VCAI::performTypicalActions()
|
|
|
{
|
|
|
for(auto h : getUnblockedHeroes())
|
|
|
@@ -2230,7 +2235,7 @@ int3 VCAI::explorationBestNeighbour(int3 hpos, int radius, HeroPtr h)
|
|
|
auto best = dstToRevealedTiles.begin();
|
|
|
for (auto i = dstToRevealedTiles.begin(); i != dstToRevealedTiles.end(); i++)
|
|
|
{
|
|
|
- const CGPathNode *pn = cb->getPathInfo(i->first);
|
|
|
+ const CGPathNode *pn = cb->getPathsInfo(h.get())->getPathInfo(i->first);
|
|
|
//const TerrainTile *t = cb->getTile(i->first);
|
|
|
if(best->second < i->second && pn->reachable() && pn->accessible == CGPathNode::ACCESSIBLE)
|
|
|
best = i;
|
|
|
@@ -2245,7 +2250,7 @@ int3 VCAI::explorationBestNeighbour(int3 hpos, int radius, HeroPtr h)
|
|
|
int3 VCAI::explorationNewPoint(HeroPtr h)
|
|
|
{
|
|
|
//logAi->debugStream() << "Looking for an another place for exploration...";
|
|
|
- cb->setSelection(h.h);
|
|
|
+ setSelection(h.h);
|
|
|
int radius = h->getSightRadious();
|
|
|
|
|
|
std::vector<std::vector<int3> > tiles; //tiles[distance_to_fow]
|
|
|
@@ -2269,13 +2274,11 @@ int3 VCAI::explorationNewPoint(HeroPtr h)
|
|
|
|
|
|
for(const int3 &tile : tiles[i])
|
|
|
{
|
|
|
- if (cbp->getTile(tile)->blocked) //does it shorten the time?
|
|
|
- continue;
|
|
|
- if (!cbp->getPathInfo(tile)->reachable()) //this will remove tiles that are guarded by monsters (or removable objects)
|
|
|
+ if (!cb->getPathsInfo(h.get())->getPathInfo(tile)->reachable()) //this will remove tiles that are guarded by monsters (or removable objects)
|
|
|
continue;
|
|
|
|
|
|
CGPath path;
|
|
|
- cbp->getPath2(tile, path);
|
|
|
+ cb->getPathsInfo(h.get())->getPath(tile, path);
|
|
|
float ourValue = (float)howManyTilesWillBeDiscovered(tile, radius, cbp) / (path.nodes.size() + 1); //+1 prevents erratic jumps
|
|
|
|
|
|
if (ourValue > bestValue) //avoid costly checks of tiles that don't reveal much
|
|
|
@@ -2655,7 +2658,7 @@ SectorMap::SectorMap()
|
|
|
|
|
|
SectorMap::SectorMap(HeroPtr h)
|
|
|
{
|
|
|
- cb->setSelection(h.h);
|
|
|
+ ai->setSelection(h.h);
|
|
|
update();
|
|
|
makeParentBFS(h->visitablePos());
|
|
|
}
|
|
|
@@ -3104,7 +3107,7 @@ int3 SectorMap::findFirstVisitableTile (HeroPtr h, crint3 dst)
|
|
|
logAi->warnStream() << ("Another allied hero stands in our way");
|
|
|
return ret;
|
|
|
}
|
|
|
- if(cb->getPathInfo(curtile)->reachable())
|
|
|
+ if(ai->myCb->getPathsInfo(h.get())->getPathInfo(curtile)->reachable())
|
|
|
{
|
|
|
return curtile;
|
|
|
}
|