BattleAI.h 3.8 KB

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