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

97 lines
2.1 KiB
C++
Raw Normal View History

2024-05-19 09:04:45 +02:00
/*
* ExplorationBehavior.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "ExplorationBehavior.h"
#include "../AIGateway.h"
#include "../AIUtility.h"
#include "../Goals/Invalid.h"
#include "../Goals/Composition.h"
#include "../Goals/ExecuteHeroChain.h"
#include "../Markers/ExplorationPoint.h"
#include "../Goals/CaptureObject.h"
2024-05-22 21:49:11 +02:00
#include "../Goals/ExploreNeighbourTile.h"
#include "../Helpers/ExplorationHelper.h"
2024-05-19 09:04:45 +02:00
namespace NKAI
{
using namespace Goals;
std::string ExplorationBehavior::toString() const
{
return "Explore";
}
Goals::TGoalVec ExplorationBehavior::decompose(const Nullkiller * ai) const
{
Goals::TGoalVec tasks;
for (auto obj : ai->memory->visitableObjs)
2024-05-19 09:04:45 +02:00
{
switch (obj->ID.num)
2024-05-19 09:04:45 +02:00
{
case Obj::REDWOOD_OBSERVATORY:
case Obj::PILLAR_OF_FIRE:
{
auto rObj = dynamic_cast<const CRewardableObject*>(obj);
if (!rObj->wasScouted(ai->playerID))
tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 200)).addNext(CaptureObject(obj))));
break;
}
case Obj::MONOLITH_ONE_WAY_ENTRANCE:
case Obj::MONOLITH_TWO_WAY:
case Obj::SUBTERRANEAN_GATE:
case Obj::WHIRLPOOL:
2024-05-19 09:04:45 +02:00
{
auto tObj = dynamic_cast<const CGTeleport*>(obj);
for (auto exit : cb->getTeleportChannelExits(tObj->channel))
2024-05-19 09:04:45 +02:00
{
if (exit != tObj->id)
{
if (!cb->isVisible(cb->getObjInstance(exit)))
tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 50)).addNext(CaptureObject(obj))));
}
2024-05-19 09:04:45 +02:00
}
}
}
}
auto heroes = ai->cb->getHeroesInfo();
for(const CGHeroInstance * hero : heroes)
{
ExplorationHelper scanResult(hero, ai);
2024-05-22 21:49:11 +02:00
if(scanResult.scanSector(1))
2024-05-19 09:04:45 +02:00
{
tasks.push_back(scanResult.makeComposition());
continue;
}
2024-05-22 21:49:11 +02:00
if(scanResult.scanSector(15))
2024-05-19 09:04:45 +02:00
{
tasks.push_back(scanResult.makeComposition());
continue;
}
if(ai->getScanDepth() == ScanDepth::ALL_FULL)
{
2024-05-22 21:49:11 +02:00
if(scanResult.scanMap())
2024-05-19 09:04:45 +02:00
{
tasks.push_back(scanResult.makeComposition());
}
}
}
return tasks;
}
}