CBattleInfoEssentials.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "IBattleInfoCallback.h"
  13. class CGTownInstance;
  14. class CGHeroInstance;
  15. class CStack;
  16. class IBonusBearer;
  17. struct InfoAboutHero;
  18. class CArmedInstance;
  19. typedef std::vector<const CStack *> TStacks;
  20. typedef std::function<bool(const CStack *)> TStackFilter;
  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 virtual CCallbackBase, 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. BattlePerspective::BattlePerspective battleGetMySide() const;
  41. const IBonusBearer * getBattleNode() const;
  42. ETerrainType battleTerrainType() const override;
  43. BFieldType battleGetBattlefieldType() const override;
  44. int32_t battleGetEnchanterCounter(ui8 side) 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. std::shared_ptr<const CObstacleInstance> battleGetObstacleByID(uint32_t ID) const;
  47. /** @brief Main method for getting battle stacks
  48. * returns also turrets and removed stacks
  49. * @param predicate Functor that shall return true for desired stack
  50. * @return filtered stacks
  51. *
  52. */
  53. TStacks battleGetStacksIf(TStackFilter predicate) const; //deprecated
  54. battle::Units battleGetUnitsIf(battle::UnitFilter predicate) const override;
  55. const battle::Unit * battleGetUnitByID(uint32_t ID) const override;
  56. const battle::Unit * battleActiveUnit() const override;
  57. uint32_t battleNextUnitId() const override;
  58. bool battleHasNativeStack(ui8 side) const;
  59. const CGTownInstance * battleGetDefendedTown() const; //returns defended town if current battle is a siege, nullptr instead
  60. si8 battleTacticDist() const override; //returns tactic distance in current tactics phase; 0 if not in tactics phase
  61. si8 battleGetTacticsSide() const override; //returns which side is in tactics phase, undefined if none (?)
  62. bool battleCanFlee(PlayerColor player) const;
  63. bool battleCanSurrender(PlayerColor player) const;
  64. ui8 otherSide(ui8 side) const;
  65. PlayerColor otherPlayer(PlayerColor player) const;
  66. BattleSideOpt playerToSide(PlayerColor player) const;
  67. PlayerColor sideToPlayer(ui8 side) const;
  68. bool playerHasAccessToHeroInfo(PlayerColor player, const CGHeroInstance * h) const;
  69. ui8 battleGetSiegeLevel() const; //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle
  70. bool battleHasHero(ui8 side) const;
  71. uint32_t battleCastSpells(ui8 side) const; //how many spells has given side cast
  72. const CGHeroInstance * battleGetFightingHero(ui8 side) const; //deprecated for players callback, easy to get wrong
  73. const CArmedInstance * battleGetArmyObject(ui8 side) const;
  74. InfoAboutHero battleGetHeroInfo(ui8 side) const;
  75. // for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall,
  76. // [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
  77. si8 battleGetWallState(int partOfWall) const;
  78. EGateState battleGetGateState() const;
  79. //helpers
  80. ///returns all stacks, alive or dead or undead or mechanical :)
  81. TStacks battleGetAllStacks(bool includeTurrets = false) const;
  82. const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID
  83. bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const;
  84. ///returns player that controls given stack; mind control included
  85. PlayerColor battleGetOwner(const battle::Unit * unit) const;
  86. ///returns hero that controls given stack; nullptr if none; mind control included
  87. const CGHeroInstance * battleGetOwnerHero(const battle::Unit * unit) const;
  88. ///check that stacks are controlled by same|other player(s) depending on positiveness
  89. ///mind control included
  90. bool battleMatchOwner(const battle::Unit * attacker, const battle::Unit * defender, const boost::logic::tribool positivness = false) const;
  91. bool battleMatchOwner(const PlayerColor & attacker, const battle::Unit * defender, const boost::logic::tribool positivness = false) const;
  92. };