mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
AI can finally clear Subterranean Gate with guard on the other side :)
This commit is contained in:
parent
b0b0249524
commit
1196eb5d81
@ -207,6 +207,19 @@ ui64 evaluateDanger(crint3 tile, const CGHeroInstance *visitor)
|
||||
if(armedObj)
|
||||
objectDanger *= fh->getTacticalAdvantage(visitor, armedObj); //this line tends to go infinite for allied towns (?)
|
||||
}
|
||||
if (dangerousObject->ID == Obj::SUBTERRANEAN_GATE)
|
||||
{ //check guard on the other side of the gate
|
||||
auto it = ai->knownSubterraneanGates.find(dangerousObject);
|
||||
if (it != ai->knownSubterraneanGates.end())
|
||||
{
|
||||
auto guards = cb->getGuardingCreatures(it->second->visitablePos());
|
||||
for (auto cre : guards)
|
||||
{
|
||||
vstd::amax (guardDanger, evaluateDanger(cre) *
|
||||
fh->getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance*>(cre)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto guards = cb->getGuardingCreatures(tile);
|
||||
@ -215,6 +228,7 @@ ui64 evaluateDanger(crint3 tile, const CGHeroInstance *visitor)
|
||||
vstd::amax (guardDanger, evaluateDanger(cre) * fh->getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance*>(cre))); //we are interested in strongest monster around
|
||||
}
|
||||
|
||||
|
||||
//TODO mozna odwiedzic blockvis nie ruszajac straznika
|
||||
return std::max(objectDanger, guardDanger);
|
||||
}
|
||||
|
@ -2713,7 +2713,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num)
|
||||
auto obj = t->visitableObjects.front();
|
||||
if (vstd::contains(ai->knownSubterraneanGates, obj))
|
||||
{ //not really sure what does it do, but subtrranean gates do not make one sector
|
||||
toVisit.push(ai->knownSubterraneanGates[obj]->visitablePos());
|
||||
//toVisit.push(ai->knownSubterraneanGates[obj]->visitablePos());
|
||||
s.subterraneanGates.push_back (obj);
|
||||
}
|
||||
}
|
||||
@ -2878,15 +2878,15 @@ For ship construction etc, another function (goal?) is needed
|
||||
if(sourceSector != destinationSector)
|
||||
{
|
||||
const Sector *src = &infoOnSectors[sourceSector],
|
||||
*dst = &infoOnSectors[destinationSector];
|
||||
*dest = &infoOnSectors[destinationSector];
|
||||
|
||||
std::map<const Sector*, const Sector*> preds;
|
||||
std::queue<const Sector *> sq;
|
||||
sq.push(src);
|
||||
while(!sq.empty())
|
||||
std::queue<const Sector *> sectorQueue;
|
||||
sectorQueue.push(src);
|
||||
while(!sectorQueue.empty())
|
||||
{
|
||||
const Sector *s = sq.front();
|
||||
sq.pop();
|
||||
const Sector *s = sectorQueue.front();
|
||||
sectorQueue.pop();
|
||||
|
||||
for(int3 ep : s->embarkmentPoints)
|
||||
{
|
||||
@ -2895,7 +2895,7 @@ For ship construction etc, another function (goal?) is needed
|
||||
if(!preds[neigh])
|
||||
{
|
||||
preds[neigh] = s;
|
||||
sq.push(neigh);
|
||||
sectorQueue.push(neigh);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2909,15 +2909,15 @@ For ship construction etc, another function (goal?) is needed
|
||||
if(!preds[neigh]) //if we didn't come into this sector yet
|
||||
{
|
||||
preds[neigh] = s; //it becomes our new target sector
|
||||
sq.push(neigh);
|
||||
sectorQueue.push(neigh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!preds[dst])
|
||||
if(!preds[dest])
|
||||
{
|
||||
write("test.txt");
|
||||
//write("test.txt");
|
||||
ai->completeGoal (sptr(Goals::Explore(h))); //if we can't find the way, seemingly all tiles were explored
|
||||
//TODO: more organized way?
|
||||
|
||||
@ -2926,13 +2926,13 @@ For ship construction etc, another function (goal?) is needed
|
||||
}
|
||||
|
||||
std::vector<const Sector*> toTraverse;
|
||||
toTraverse.push_back(dst);
|
||||
toTraverse.push_back(dest);
|
||||
while(toTraverse.back() != src)
|
||||
{
|
||||
toTraverse.push_back(preds[toTraverse.back()]);
|
||||
}
|
||||
|
||||
if(preds[dst])
|
||||
if(preds[dest])
|
||||
{
|
||||
const Sector *sectorToReach = toTraverse.at(toTraverse.size() - 2);
|
||||
if(!src->water && sectorToReach->water) //embark
|
||||
@ -3024,7 +3024,7 @@ For ship construction etc, another function (goal?) is needed
|
||||
{
|
||||
auto firstGate = boost::find_if(src->subterraneanGates, [=](const CGObjectInstance * gate) -> bool
|
||||
{
|
||||
return retreiveTile(gate->visitablePos()) == sectorToReach->id;
|
||||
return retreiveTile(ai->knownSubterraneanGates[gate]->visitablePos()) == sectorToReach->id;
|
||||
});
|
||||
|
||||
if(firstGate != src->subterraneanGates.end())
|
||||
|
Loading…
Reference in New Issue
Block a user