BattleAI.h 3.8 KB

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