BattleActionsController.h 4.7 KB

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