CBattleInfoEssentials.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * CBattleInfoEssentials.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 "CCallbackBase.h"
  12. class CGTownInstance;
  13. class CGHeroInstance;
  14. class CStack;
  15. struct CObstacleInstance;
  16. class IBonusBearer;
  17. struct InfoAboutHero;
  18. class CArmedInstance;
  19. typedef std::vector<const CStack*> TStacks;
  20. typedef std::function<bool(const CStack *)> TStackFilter;
  21. namespace BattlePerspective
  22. {
  23. enum BattlePerspective
  24. {
  25. INVALID = -2,
  26. ALL_KNOWING = -1,
  27. LEFT_SIDE,
  28. RIGHT_SIDE
  29. };
  30. }
  31. namespace BattleSide
  32. {
  33. enum {ATTACKER = 0, DEFENDER = 1};
  34. }
  35. class DLL_LINKAGE CBattleInfoEssentials : public virtual CCallbackBase
  36. {
  37. protected:
  38. bool battleDoWeKnowAbout(ui8 side) const;
  39. const IBonusBearer * getBattleNode() const;
  40. public:
  41. enum EStackOwnership
  42. {
  43. ONLY_MINE, ONLY_ENEMY, MINE_AND_ENEMY
  44. };
  45. BattlePerspective::BattlePerspective battleGetMySide() const;
  46. ETerrainType battleTerrainType() const;
  47. BFieldType battleGetBattlefieldType() const;
  48. std::vector<std::shared_ptr<const CObstacleInstance> > battleGetAllObstacles(boost::optional<BattlePerspective::BattlePerspective> perspective = boost::none) const; //returns all obstacles on the battlefield
  49. /** @brief Main method for getting battle stacks
  50. *
  51. * @param predicate Functor that shall return true for desired stack
  52. * @return filtered stacks
  53. *
  54. */
  55. TStacks battleGetStacksIf(TStackFilter predicate) const;
  56. bool battleHasNativeStack(ui8 side) const;
  57. int battleGetMoatDmg() const; //what dmg unit will suffer if ending turn in the moat
  58. const CGTownInstance * battleGetDefendedTown() const; //returns defended town if current battle is a siege, nullptr instead
  59. const CStack *battleActiveStack() const;
  60. si8 battleTacticDist() const; //returns tactic distance in current tactics phase; 0 if not in tactics phase
  61. si8 battleGetTacticsSide() const; //returns which side is in tactics phase, undefined if none (?)
  62. bool battleCanFlee(PlayerColor player) const;
  63. bool battleCanSurrender(PlayerColor player) const;
  64. si8 playerToSide(PlayerColor player) const;
  65. bool playerHasAccessToHeroInfo(PlayerColor player, const CGHeroInstance * h) const;
  66. ui8 battleGetSiegeLevel() const; //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle
  67. bool battleHasHero(ui8 side) const;
  68. int battleCastSpells(ui8 side) const; //how many spells has given side cast
  69. const CGHeroInstance * battleGetFightingHero(ui8 side) const; //depracated for players callback, easy to get wrong
  70. const CArmedInstance * battleGetArmyObject(ui8 side) const;
  71. InfoAboutHero battleGetHeroInfo(ui8 side) const;
  72. // for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall,
  73. // [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle
  74. si8 battleGetWallState(int partOfWall) const;
  75. EGateState battleGetGateState() const;
  76. //helpers
  77. ///returns all stacks, alive or dead or undead or mechanical :)
  78. TStacks battleGetAllStacks(bool includeTurrets = false) const;
  79. ///returns all alive stacks excluding turrets
  80. TStacks battleAliveStacks() const;
  81. ///returns all alive stacks from particular side excluding turrets
  82. TStacks battleAliveStacks(ui8 side) const;
  83. const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID
  84. bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const;
  85. ///returns player that controls given stack; mind control included
  86. PlayerColor battleGetOwner(const CStack * stack) const;
  87. ///returns hero that controls given stack; nullptr if none; mind control included
  88. const CGHeroInstance * battleGetOwnerHero(const CStack * stack) const;
  89. ///check that stacks are controlled by same|other player(s) depending on positiveness
  90. ///mind control included
  91. bool battleMatchOwner(const CStack * attacker, const CStack * defender, const boost::logic::tribool positivness = false) const;
  92. };