BattleAI.h 4.6 KB

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