ExplorationBehavior.cpp 2.7 KB

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