BattleEvaluator.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * BattleEvaluator.h, 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. #pragma once
  11. #include "../../lib/AI_Base.h"
  12. #include "../../lib/battle/ReachabilityInfo.h"
  13. #include "PossibleSpellcast.h"
  14. #include "PotentialTargets.h"
  15. #include "BattleExchangeVariant.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class CSpell;
  18. VCMI_LIB_NAMESPACE_END
  19. class EnemyInfo;
  20. struct CachedAttack
  21. {
  22. std::optional<AttackPossibility> ap;
  23. float score = EvaluationResult::INEFFECTIVE_SCORE;
  24. uint8_t turn = 255;
  25. bool waited = false;
  26. };
  27. class BattleEvaluator
  28. {
  29. std::unique_ptr<PotentialTargets> targets;
  30. std::shared_ptr<HypotheticBattle> hb;
  31. BattleExchangeEvaluator scoreEvaluator;
  32. std::shared_ptr<CBattleCallback> cb;
  33. std::shared_ptr<Environment> env;
  34. bool activeActionMade = false;
  35. CachedAttack cachedAttack;
  36. PlayerColor playerID;
  37. BattleID battleID;
  38. BattleSide side;
  39. DamageCache damageCache;
  40. float strengthRatio;
  41. int simulationTurnsCount;
  42. public:
  43. BattleAction selectStackAction(const CStack * stack);
  44. bool attemptCastingSpell(const CStack * stack);
  45. bool canCastSpell();
  46. std::optional<PossibleSpellcast> findBestCreatureSpell(const CStack * stack);
  47. BattleAction goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes, const PotentialTargets & targets);
  48. std::vector<BattleHex> getBrokenWallMoatHexes() const;
  49. void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only
  50. void print(const std::string & text) const;
  51. BattleAction moveOrAttack(const CStack * stack, BattleHex hex, const PotentialTargets & targets);
  52. BattleEvaluator(
  53. std::shared_ptr<Environment> env,
  54. std::shared_ptr<CBattleCallback> cb,
  55. const battle::Unit * activeStack,
  56. PlayerColor playerID,
  57. BattleID battleID,
  58. BattleSide side,
  59. float strengthRatio,
  60. int simulationTurnsCount);
  61. BattleEvaluator(
  62. std::shared_ptr<Environment> env,
  63. std::shared_ptr<CBattleCallback> cb,
  64. std::shared_ptr<HypotheticBattle> hb,
  65. DamageCache & damageCache,
  66. const battle::Unit * activeStack,
  67. PlayerColor playerID,
  68. BattleID battleID,
  69. BattleSide side,
  70. float strengthRatio,
  71. int simulationTurnsCount);
  72. };