ExplorationBehavior.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if(!vstd::contains(ai->memory->alreadyVisited, obj))
  34. {
  35. switch(obj->ID.num)
  36. {
  37. case Obj::REDWOOD_OBSERVATORY:
  38. case Obj::PILLAR_OF_FIRE:
  39. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 200)).addNext(CaptureObject(obj))));
  40. break;
  41. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  42. case Obj::MONOLITH_TWO_WAY:
  43. case Obj::SUBTERRANEAN_GATE:
  44. case Obj::WHIRLPOOL:
  45. auto tObj = dynamic_cast<const CGTeleport *>(obj);
  46. if(TeleportChannel::IMPASSABLE != ai->memory->knownTeleportChannels[tObj->channel]->passability)
  47. {
  48. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 50)).addNext(CaptureObject(obj))));
  49. }
  50. break;
  51. }
  52. }
  53. else
  54. {
  55. switch(obj->ID.num)
  56. {
  57. case Obj::MONOLITH_TWO_WAY:
  58. case Obj::SUBTERRANEAN_GATE:
  59. case Obj::WHIRLPOOL:
  60. auto tObj = dynamic_cast<const CGTeleport *>(obj);
  61. if(TeleportChannel::IMPASSABLE == ai->memory->knownTeleportChannels[tObj->channel]->passability)
  62. break;
  63. for(auto exit : ai->memory->knownTeleportChannels[tObj->channel]->exits)
  64. {
  65. if(!cb->getObj(exit))
  66. {
  67. // Always attempt to visit two-way teleports if one of channel exits is not visible
  68. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 50)).addNext(CaptureObject(obj))));
  69. break;
  70. }
  71. }
  72. break;
  73. }
  74. }
  75. }
  76. auto heroes = ai->cb->getHeroesInfo();
  77. for(const CGHeroInstance * hero : heroes)
  78. {
  79. ExplorationHelper scanResult(hero, ai);
  80. if(scanResult.scanSector(1))
  81. {
  82. tasks.push_back(scanResult.makeComposition());
  83. continue;
  84. }
  85. if(scanResult.scanSector(15))
  86. {
  87. tasks.push_back(scanResult.makeComposition());
  88. continue;
  89. }
  90. if(ai->getScanDepth() == ScanDepth::ALL_FULL)
  91. {
  92. if(scanResult.scanMap())
  93. {
  94. tasks.push_back(scanResult.makeComposition());
  95. }
  96. }
  97. }
  98. return tasks;
  99. }
  100. }