ExplorationBehavior.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 NK2AI
  22. {
  23. using namespace Goals;
  24. std::string ExplorationBehavior::toString() const
  25. {
  26. return "Explore";
  27. }
  28. Goals::TGoalVec ExplorationBehavior::decompose(const Nullkiller * aiNk) const
  29. {
  30. Goals::TGoalVec tasks;
  31. for (const ObjectInstanceID objId : aiNk->memory->visitableObjs)
  32. {
  33. const CGObjectInstance * obj = aiNk->cc->getObjInstance(objId);
  34. if(!obj)
  35. continue;
  36. switch (obj->ID.num)
  37. {
  38. case Obj::REDWOOD_OBSERVATORY:
  39. case Obj::PILLAR_OF_FIRE:
  40. {
  41. auto rObj = dynamic_cast<const CRewardableObject*>(obj);
  42. if (!rObj->wasScouted(aiNk->playerID))
  43. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 200)).addNext(CaptureObject(obj))));
  44. break;
  45. }
  46. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  47. case Obj::MONOLITH_TWO_WAY:
  48. case Obj::SUBTERRANEAN_GATE:
  49. case Obj::WHIRLPOOL:
  50. {
  51. const auto tObj = dynamic_cast<const CGTeleport*>(obj);
  52. for (auto exit : aiNk->cc->getTeleportChannelExits(tObj->channel))
  53. {
  54. if (exit != tObj->id)
  55. {
  56. // TODO: Mircea: Looks like a bug. Should use isVisibleFor with aiNk->playerID
  57. if (!aiNk->cc->isVisible(aiNk->cc->getObjInstance(exit)))
  58. tasks.push_back(sptr(Composition().addNext(ExplorationPoint(obj->visitablePos(), 50)).addNext(CaptureObject(obj))));
  59. }
  60. }
  61. }
  62. }
  63. }
  64. auto heroes = aiNk->cc->getHeroesInfo();
  65. for(const CGHeroInstance * hero : heroes)
  66. {
  67. ExplorationHelper scanResult(hero, aiNk);
  68. if(scanResult.scanSector(1))
  69. {
  70. tasks.push_back(scanResult.makeComposition());
  71. continue;
  72. }
  73. if(scanResult.scanSector(15))
  74. {
  75. tasks.push_back(scanResult.makeComposition());
  76. continue;
  77. }
  78. if(aiNk->getScanDepth() == ScanDepth::ALL_FULL)
  79. {
  80. if(scanResult.scanMap())
  81. {
  82. tasks.push_back(scanResult.makeComposition());
  83. }
  84. }
  85. }
  86. return tasks;
  87. }
  88. }