BattleEvaluator.h 2.7 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/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. class BattleEvaluator
  21. {
  22. std::unique_ptr<PotentialTargets> targets;
  23. std::shared_ptr<HypotheticBattle> hb;
  24. BattleExchangeEvaluator scoreEvaluator;
  25. std::shared_ptr<CBattleCallback> cb;
  26. std::shared_ptr<Environment> env;
  27. bool activeActionMade = false;
  28. std::optional<AttackPossibility> cachedAttack;
  29. PlayerColor playerID;
  30. BattleID battleID;
  31. int side;
  32. float cachedScore;
  33. DamageCache damageCache;
  34. float strengthRatio;
  35. public:
  36. BattleAction selectStackAction(const CStack * stack);
  37. bool attemptCastingSpell(const CStack * stack);
  38. bool canCastSpell();
  39. std::optional<PossibleSpellcast> findBestCreatureSpell(const CStack * stack);
  40. BattleAction goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes);
  41. std::vector<BattleHex> getBrokenWallMoatHexes() const;
  42. void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only
  43. void print(const std::string & text) const;
  44. BattleEvaluator(
  45. std::shared_ptr<Environment> env,
  46. std::shared_ptr<CBattleCallback> cb,
  47. const battle::Unit * activeStack,
  48. PlayerColor playerID,
  49. BattleID battleID,
  50. int side,
  51. float strengthRatio)
  52. :scoreEvaluator(cb->getBattle(battleID), env, strengthRatio), cachedAttack(), playerID(playerID), side(side), env(env), cb(cb), strengthRatio(strengthRatio), battleID(battleID)
  53. {
  54. hb = std::make_shared<HypotheticBattle>(env.get(), cb->getBattle(battleID));
  55. damageCache.buildDamageCache(hb, side);
  56. targets = std::make_unique<PotentialTargets>(activeStack, damageCache, hb);
  57. cachedScore = EvaluationResult::INEFFECTIVE_SCORE;
  58. }
  59. BattleEvaluator(
  60. std::shared_ptr<Environment> env,
  61. std::shared_ptr<CBattleCallback> cb,
  62. std::shared_ptr<HypotheticBattle> hb,
  63. DamageCache & damageCache,
  64. const battle::Unit * activeStack,
  65. PlayerColor playerID,
  66. BattleID battleID,
  67. int side,
  68. float strengthRatio)
  69. :scoreEvaluator(cb->getBattle(battleID), env, strengthRatio), cachedAttack(), playerID(playerID), side(side), env(env), cb(cb), hb(hb), damageCache(damageCache), strengthRatio(strengthRatio), battleID(battleID)
  70. {
  71. targets = std::make_unique<PotentialTargets>(activeStack, damageCache, hb);
  72. cachedScore = EvaluationResult::INEFFECTIVE_SCORE;
  73. }
  74. };