ExplorationBehavior.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if(TeleportChannel::IMPASSABLE == ai->memory->knownTeleportChannels[tObj->channel]->passability)
  50. break;
  51. for(auto exit : ai->memory->knownTeleportChannels[tObj->channel]->exits)
  52. {
  53. if (exit != tObj->id)
  54. {
  55. if (!cb->isVisible(cb->getObjInstance(exit)))
  56. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 50)).addNext(CaptureObject(obj))));
  57. }
  58. }
  59. }
  60. }
  61. }
  62. auto heroes = ai->cb->getHeroesInfo();
  63. for(const CGHeroInstance * hero : heroes)
  64. {
  65. ExplorationHelper scanResult(hero, ai);
  66. if(scanResult.scanSector(1))
  67. {
  68. tasks.push_back(scanResult.makeComposition());
  69. continue;
  70. }
  71. if(scanResult.scanSector(15))
  72. {
  73. tasks.push_back(scanResult.makeComposition());
  74. continue;
  75. }
  76. if(ai->getScanDepth() == ScanDepth::ALL_FULL)
  77. {
  78. if(scanResult.scanMap())
  79. {
  80. tasks.push_back(scanResult.makeComposition());
  81. }
  82. }
  83. }
  84. return tasks;
  85. }
  86. }