CBattleFieldController.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * CBattleFieldController.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 "../../lib/battle/BattleHex.h"
  12. #include "../gui/CIntObject.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CStack;
  15. VCMI_LIB_NAMESPACE_END
  16. struct SDL_Surface;
  17. struct Rect;
  18. struct Point;
  19. class ClickableHex;
  20. class CCanvas;
  21. class IImage;
  22. class BattleInterface;
  23. class BattleFieldController : public CIntObject
  24. {
  25. BattleInterface * owner;
  26. std::shared_ptr<IImage> background;
  27. std::shared_ptr<IImage> cellBorder;
  28. std::shared_ptr<IImage> cellShade;
  29. std::shared_ptr<CCanvas> cellBorders;
  30. /// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
  31. std::shared_ptr<CCanvas> backgroundWithHexes;
  32. //BattleHex previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
  33. //BattleHex currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
  34. BattleHex attackingHex; //hex from which the stack would perform attack with current cursor
  35. std::vector<BattleHex> occupyableHexes; //hexes available for active stack
  36. std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes; // hexes that when in front of a unit cause it's amount box to move back
  37. std::vector<std::shared_ptr<ClickableHex>> bfield; //11 lines, 17 hexes on each
  38. void showHighlightedHex(std::shared_ptr<CCanvas> to, BattleHex hex, bool darkBorder);
  39. std::set<BattleHex> getHighlightedHexesStackRange();
  40. std::set<BattleHex> getHighlightedHexesSpellRange();
  41. void showBackground(std::shared_ptr<CCanvas> canvas);
  42. void showBackgroundImage(std::shared_ptr<CCanvas> canvas);
  43. void showBackgroundImageWithHexes(std::shared_ptr<CCanvas> canvas);
  44. void showHighlightedHexes(std::shared_ptr<CCanvas> canvas);
  45. public:
  46. BattleFieldController(BattleInterface * owner);
  47. void redrawBackgroundWithHexes();
  48. void renderBattlefield(std::shared_ptr<CCanvas> canvas);
  49. Rect hexPositionLocal(BattleHex hex) const;
  50. Rect hexPosition(BattleHex hex) const;
  51. bool isPixelInHex(Point const & position);
  52. BattleHex getHoveredHex();
  53. void setBattleCursor(BattleHex myNumber);
  54. BattleHex fromWhichHexAttack(BattleHex myNumber);
  55. bool isTileAttackable(const BattleHex & number) const;
  56. bool stackCountOutsideHex(const BattleHex & number) const;
  57. };