BattleFieldController.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * BattleFieldController.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. class Rect;
  16. class Point;
  17. VCMI_LIB_NAMESPACE_END
  18. class BattleHero;
  19. class Canvas;
  20. class IImage;
  21. class BattleInterface;
  22. /// Handles battlefield grid as well as rendering of background layer of battle interface
  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> cellUnitMovementHighlight;
  29. std::shared_ptr<IImage> cellUnitMaxMovementHighlight;
  30. std::shared_ptr<IImage> cellShade;
  31. /// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
  32. std::unique_ptr<Canvas> backgroundWithHexes;
  33. /// hex from which the stack would perform attack with current cursor
  34. BattleHex attackingHex;
  35. /// hexes to which currently active stack can move
  36. std::vector<BattleHex> occupyableHexes;
  37. /// hexes that when in front of a unit cause it's amount box to move back
  38. std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;
  39. void showHighlightedHex(Canvas & to, std::shared_ptr<IImage> highlight, BattleHex hex, bool darkBorder);
  40. std::set<BattleHex> getHighlightedHexesForActiveStack();
  41. std::set<BattleHex> getMovementRangeForHoveredStack();
  42. std::set<BattleHex> STUB_getMaxMovementRangeForHoveredStack();
  43. std::set<BattleHex> getHighlightedHexesForSpellRange();
  44. std::set<BattleHex> getHighlightedHexesMovementTarget();
  45. void showBackground(Canvas & canvas);
  46. void showBackgroundImage(Canvas & canvas);
  47. void showBackgroundImageWithHexes(Canvas & canvas);
  48. void showHighlightedHexes(Canvas & canvas);
  49. void updateAccessibleHexes();
  50. BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
  51. void mouseMoved(const Point & cursorPosition) override;
  52. void clickLeft(tribool down, bool previousState) override;
  53. void clickRight(tribool down, bool previousState) override;
  54. void showAll(SDL_Surface * to) override;
  55. void show(SDL_Surface * to) override;
  56. public:
  57. BattleFieldController(BattleInterface & owner);
  58. void createHeroes();
  59. void redrawBackgroundWithHexes();
  60. void renderBattlefield(Canvas & canvas);
  61. /// Returns position of hex relative to owner (BattleInterface)
  62. Rect hexPositionLocal(BattleHex hex) const;
  63. /// Returns position of hex relative to game window
  64. Rect hexPositionAbsolute(BattleHex hex) const;
  65. /// Checks whether selected pixel is transparent, uses local coordinates of a hex
  66. bool isPixelInHex(Point const & position);
  67. /// Returns ID of currently hovered hex or BattleHex::INVALID if none
  68. BattleHex getHoveredHex();
  69. /// returns true if selected tile can be attacked in melee by current stack
  70. bool isTileAttackable(const BattleHex & number) const;
  71. /// returns true if stack should render its stack count image in default position - outside own hex
  72. bool stackCountOutsideHex(const BattleHex & number) const;
  73. void setBattleCursor(BattleHex myNumber);
  74. BattleHex fromWhichHexAttack(BattleHex myNumber);
  75. };