CBattleInfoEssentials.h 4.6 KB

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