BattleAI.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * BattleAI.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. class CSpell;
  16. class EnemyInfo;
  17. /*
  18. struct CurrentOffensivePotential
  19. {
  20. std::map<const CStack *, PotentialTargets> ourAttacks;
  21. std::map<const CStack *, PotentialTargets> enemyAttacks;
  22. CurrentOffensivePotential(ui8 side)
  23. {
  24. for(auto stack : cbc->battleGetStacks())
  25. {
  26. if(stack->side == side)
  27. ourAttacks[stack] = PotentialTargets(stack);
  28. else
  29. enemyAttacks[stack] = PotentialTargets(stack);
  30. }
  31. }
  32. int potentialValue()
  33. {
  34. int ourPotential = 0, enemyPotential = 0;
  35. for(auto &p : ourAttacks)
  36. ourPotential += p.second.bestAction().attackValue();
  37. for(auto &p : enemyAttacks)
  38. enemyPotential += p.second.bestAction().attackValue();
  39. return ourPotential - enemyPotential;
  40. }
  41. };
  42. */ // These lines may be usefull but they are't used in the code.
  43. class CBattleAI : public CBattleGameInterface
  44. {
  45. int side;
  46. std::shared_ptr<CBattleCallback> cb;
  47. std::shared_ptr<Environment> env;
  48. //Previous setting of cb
  49. bool wasWaitingForRealize, wasUnlockingGs;
  50. public:
  51. CBattleAI();
  52. ~CBattleAI();
  53. void init(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB) override;
  54. void attemptCastingSpell();
  55. void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only
  56. BattleAction activeStack(const CStack * stack) override; //called when it's turn of that stack
  57. boost::optional<BattleAction> considerFleeingOrSurrendering();
  58. void print(const std::string &text) const;
  59. BattleAction useCatapult(const CStack *stack);
  60. void battleStart(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance * hero1, const CGHeroInstance * hero2, bool Side) override;
  61. //void actionFinished(const BattleAction &action) override;//occurs AFTER every action taken by any stack or by the hero
  62. //void actionStarted(const BattleAction &action) override;//occurs BEFORE every action taken by any stack or by the hero
  63. //void battleAttack(const BattleAttack *ba) override; //called when stack is performing attack
  64. //void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa) override; //called when stack receives damage (after battleAttack())
  65. //void battleEnd(const BattleResult *br) override;
  66. //void battleResultsApplied() override; //called when all effects of last battle are applied
  67. //void battleNewRoundFirst(int round) override; //called at the beginning of each turn before changes are applied;
  68. //void battleNewRound(int round) override; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  69. //void battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance) override;
  70. //void battleSpellCast(const BattleSpellCast *sc) override;
  71. //void battleStacksEffectsSet(const SetStackEffect & sse) override;//called when a specific effect is set to stacks
  72. //void battleTriggerEffect(const BattleTriggerEffect & bte) override;
  73. //void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) override; //called by engine when battle starts; side=0 - left, side=1 - right
  74. //void battleCatapultAttacked(const CatapultAttack & ca) override; //called when catapult makes an attack
  75. private:
  76. BattleAction goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes) const;
  77. std::vector<BattleHex> getBrokenWallMoatHexes() const;
  78. };