ExplorationBehavior.cpp 2.1 KB

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