CBattleInfoEssentials.h 4.7 KB

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