ExplorationBehavior.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * ExplorationBehavior.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "ExplorationBehavior.h"
  12. #include "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../Goals/Invalid.h"
  15. #include "../Goals/Composition.h"
  16. #include "../Goals/ExecuteHeroChain.h"
  17. #include "../Markers/ExplorationPoint.h"
  18. #include "../Goals/CaptureObject.h"
  19. #include "../Goals/ExploreNeighbourTile.h"
  20. #include "../Helpers/ExplorationHelper.h"
  21. namespace NKAI
  22. {
  23. using namespace Goals;
  24. std::string ExplorationBehavior::toString() const
  25. {
  26. return "Explore";
  27. }
  28. Goals::TGoalVec ExplorationBehavior::decompose(const Nullkiller * ai) const
  29. {
  30. Goals::TGoalVec tasks;
  31. for (auto obj : ai->memory->visitableObjs)
  32. {
  33. switch (obj->ID.num)
  34. {
  35. case Obj::REDWOOD_OBSERVATORY:
  36. case Obj::PILLAR_OF_FIRE:
  37. {
  38. auto rObj = dynamic_cast<const CRewardableObject*>(obj);
  39. if (!rObj->wasScouted(ai->playerID))
  40. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 200)).addNext(CaptureObject(obj))));
  41. break;
  42. }
  43. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  44. case Obj::MONOLITH_TWO_WAY:
  45. case Obj::SUBTERRANEAN_GATE:
  46. case Obj::WHIRLPOOL:
  47. {
  48. auto tObj = dynamic_cast<const CGTeleport*>(obj);
  49. for (auto exit : cb->getTeleportChannelExits(tObj->channel))
  50. {
  51. if (exit != tObj->id)
  52. {
  53. if (!cb->isVisible(cb->getObjInstance(exit)))
  54. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 50)).addNext(CaptureObject(obj))));
  55. }
  56. }
  57. }
  58. }
  59. }
  60. auto heroes = ai->cb->getHeroesInfo();
  61. for(const CGHeroInstance * hero : heroes)
  62. {
  63. ExplorationHelper scanResult(hero, ai);
  64. if(scanResult.scanSector(1))
  65. {
  66. tasks.push_back(scanResult.makeComposition());
  67. continue;
  68. }
  69. if(scanResult.scanSector(15))
  70. {
  71. tasks.push_back(scanResult.makeComposition());
  72. continue;
  73. }
  74. if(ai->getScanDepth() == ScanDepth::ALL_FULL)
  75. {
  76. if(scanResult.scanMap())
  77. {
  78. tasks.push_back(scanResult.makeComposition());
  79. }
  80. }
  81. }
  82. return tasks;
  83. }
  84. }