CBattleInfoEssentials.h 4.3 KB

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