CBattleInfoEssentials.h 4.5 KB

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