BattleEvaluator.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. bool hasWorkingTowers() const;
  50. void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only
  51. void print(const std::string & text) const;
  52. BattleAction moveOrAttack(const CStack * stack, BattleHex hex, const PotentialTargets & targets);
  53. BattleEvaluator(
  54. std::shared_ptr<Environment> env,
  55. std::shared_ptr<CBattleCallback> cb,
  56. const battle::Unit * activeStack,
  57. PlayerColor playerID,
  58. BattleID battleID,
  59. BattleSide side,
  60. float strengthRatio,
  61. int simulationTurnsCount);
  62. BattleEvaluator(
  63. std::shared_ptr<Environment> env,
  64. std::shared_ptr<CBattleCallback> cb,
  65. std::shared_ptr<HypotheticBattle> hb,
  66. DamageCache & damageCache,
  67. const battle::Unit * activeStack,
  68. PlayerColor playerID,
  69. BattleID battleID,
  70. BattleSide side,
  71. float strengthRatio,
  72. int simulationTurnsCount);
  73. };