BattleEvaluator.h 2.3 KB

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