CBattleInfoEssentials.h 4.5 KB

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