ExploreNeighbourTile.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * ExploreNeighbourTile.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 "ExploreNeighbourTile.h"
  12. #include "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../Helpers/ExplorationHelper.h"
  15. namespace NK2AI
  16. {
  17. using namespace Goals;
  18. bool ExploreNeighbourTile::operator==(const ExploreNeighbourTile & other) const
  19. {
  20. return false;
  21. }
  22. void ExploreNeighbourTile::accept(AIGateway * aiGw)
  23. {
  24. ExplorationHelper h(hero, aiGw->nullkiller.get(), true);
  25. for(int i = 0; i < tilesToExplore && aiGw->cc->getObj(hero->id, false) && hero->movementPointsRemaining() > 0; i++)
  26. {
  27. int3 pos = hero->visitablePos();
  28. float value = 0;
  29. int3 target = int3(-1);
  30. foreach_neighbour(
  31. *aiGw->cc,
  32. pos,
  33. [&](int3 tile)
  34. {
  35. const auto pathInfo = aiGw->nullkiller->getPathsInfo(hero)->getPathInfo(tile);
  36. if(pathInfo->turns > 0)
  37. return;
  38. if(pathInfo->accessible == EPathAccessibility::ACCESSIBLE)
  39. {
  40. float newValue = h.howManyTilesWillBeDiscovered(tile);
  41. newValue /= std::min(0.1f, pathInfo->getCost());
  42. if(newValue > value)
  43. {
  44. value = newValue;
  45. target = tile;
  46. }
  47. }
  48. }
  49. );
  50. if(!target.isValid())
  51. {
  52. return;
  53. }
  54. auto danger = aiGw->nullkiller->dangerEvaluator->evaluateDanger(target, hero, true);
  55. if(danger > 0 || !aiGw->moveHeroToTile(target, HeroPtr(hero, aiGw->cc.get())))
  56. {
  57. return;
  58. }
  59. }
  60. }
  61. std::string ExploreNeighbourTile::toString() const
  62. {
  63. return "Explore neighbour tiles by " + hero->getNameTranslated();
  64. }
  65. }