BattleActionsController.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * BattleActionsController.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/CBattleInfoCallback.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class BattleAction;
  14. namespace spells {
  15. class Caster;
  16. enum class Mode;
  17. }
  18. VCMI_LIB_NAMESPACE_END
  19. class BattleInterface;
  20. enum class MouseHoveredHexContext
  21. {
  22. UNOCCUPIED_HEX,
  23. OCCUPIED_HEX
  24. };
  25. /// Class that controls actions that can be performed by player, e.g. moving stacks, attacking, etc
  26. /// As well as all relevant feedback for these actions in user interface
  27. class BattleActionsController
  28. {
  29. BattleInterface & owner;
  30. /// mouse or touchscreen click mode
  31. bool touchscreenMode = false;
  32. /// all actions possible to call at the moment by player
  33. std::vector<PossiblePlayerBattleAction> possibleActions;
  34. /// spell for which player's hero is choosing destination
  35. std::shared_ptr<BattleAction> heroSpellToCast;
  36. /// cached message that was set by this class in status bar
  37. std::string currentConsoleMsg;
  38. /// if true, active stack could possibly cast some target spell
  39. std::vector<const CSpell *> creatureSpells;
  40. /// stack that has been selected as first target for multi-target spells (Teleport & Sacrifice)
  41. const CStack * selectedStack;
  42. bool isCastingPossibleHere (const CSpell * spell, const CStack *shere, BattleHex myNumber);
  43. bool canStackMoveHere (const CStack *sactive, BattleHex MyNumber) const; //TODO: move to BattleState / callback
  44. std::vector<PossiblePlayerBattleAction> getPossibleActionsForStack (const CStack *stack) const; //called when stack gets its turn
  45. void reorderPossibleActionsPriority(const CStack * stack, MouseHoveredHexContext context);
  46. bool actionIsLegal(PossiblePlayerBattleAction action, BattleHex hoveredHex);
  47. void actionSetCursor(PossiblePlayerBattleAction action, BattleHex hoveredHex);
  48. void actionSetCursorBlocked(PossiblePlayerBattleAction action, BattleHex hoveredHex);
  49. std::string actionGetStatusMessage(PossiblePlayerBattleAction action, BattleHex hoveredHex);
  50. std::string actionGetStatusMessageBlocked(PossiblePlayerBattleAction action, BattleHex hoveredHex);
  51. void actionRealize(PossiblePlayerBattleAction action, BattleHex hoveredHex);
  52. PossiblePlayerBattleAction selectAction(BattleHex myNumber);
  53. const CStack * getStackForHex(BattleHex myNumber) ;
  54. /// attempts to initialize spellcasting action for stack
  55. /// will silently return if stack is not a spellcaster
  56. void tryActivateStackSpellcasting(const CStack *casterStack);
  57. /// returns spell that is currently being cast by hero or nullptr if none
  58. const CSpell * getHeroSpellToCast() const;
  59. /// if current stack is spellcaster, returns spell being cast, or null othervice
  60. const CSpell * getStackSpellToCast(BattleHex hoveredHex);
  61. /// returns true if current stack is a spellcaster
  62. bool isActiveStackSpellcaster() const;
  63. public:
  64. BattleActionsController(BattleInterface & owner);
  65. /// initialize list of potential actions for new active stack
  66. void activateStack();
  67. /// returns true if UI is currently in target selection mode
  68. bool spellcastingModeActive() const;
  69. /// returns true if one of the following is true:
  70. /// - we are casting spell by hero
  71. /// - we are casting spell by creature in targeted mode (F hotkey)
  72. /// - current creature is spellcaster and preferred action for current hex is spellcast
  73. bool currentActionSpellcasting(BattleHex hoveredHex);
  74. /// enter targeted spellcasting mode for creature, e.g. via "F" hotkey
  75. void enterCreatureCastingMode();
  76. /// initialize hero spellcasting mode, e.g. on selecting spell in spellbook
  77. void castThisSpell(SpellID spellID);
  78. /// ends casting spell (eg. when spell has been cast or canceled)
  79. void endCastingSpell();
  80. /// update cursor and status bar according to new active hex
  81. void onHexHovered(BattleHex hoveredHex);
  82. /// called when cursor is no longer over battlefield and cursor/battle log should be reset
  83. void onHoverEnded();
  84. /// performs action according to selected hex
  85. void onHexLeftClicked(BattleHex clickedHex);
  86. /// performs action according to selected hex
  87. void onHexRightClicked(BattleHex clickedHex);
  88. const spells::Caster * getCurrentSpellcaster() const;
  89. const CSpell * getCurrentSpell(BattleHex hoveredHex);
  90. spells::Mode getCurrentCastMode() const;
  91. /// methods to work with array of possible actions, needed to control special creatures abilities
  92. const std::vector<PossiblePlayerBattleAction> & getPossibleActions() const;
  93. void removePossibleAction(PossiblePlayerBattleAction);
  94. /// inserts possible action in the beggining in order to prioritize it
  95. void pushFrontPossibleAction(PossiblePlayerBattleAction);
  96. void setTouchScreenMode(bool enabled);
  97. };