BattleActionsController.h 4.0 KB

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