BattleEvaluator.h 2.5 KB

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