BattleActionsController.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. VCMI_LIB_NAMESPACE_END
  15. class BattleInterface;
  16. enum class MouseHoveredHexContext
  17. {
  18. UNOCCUPIED_HEX,
  19. OCCUPIED_HEX
  20. };
  21. /// Class that controls actions that can be performed by player, e.g. moving stacks, attacking, etc
  22. /// As well as all relevant feedback for these actions in user interface
  23. class BattleActionsController
  24. {
  25. BattleInterface * owner;
  26. /// all actions possible to call at the moment by player
  27. std::vector<PossiblePlayerBattleAction> possibleActions;
  28. /// actions possible to take on hovered hex
  29. std::vector<PossiblePlayerBattleAction> localActions;
  30. /// these actions display message in case of illegal target
  31. std::vector<PossiblePlayerBattleAction> illegalActions;
  32. /// action that will be performed on l-click
  33. PossiblePlayerBattleAction currentAction;
  34. /// last action chosen (and saved) by player
  35. PossiblePlayerBattleAction selectedAction;
  36. /// if there are not possible actions to choose from, this action should be show as "illegal" in UI
  37. PossiblePlayerBattleAction illegalAction;
  38. /// if true, stack currently aims to cats a spell
  39. bool creatureCasting;
  40. /// if true, player is choosing destination for his spell - only for GUI / console
  41. bool spellDestSelectMode;
  42. /// spell for which player is choosing destination
  43. std::shared_ptr<BattleAction> spellToCast;
  44. /// spell for which player is choosing destination, pointer for convenience
  45. const CSpell *currentSpell;
  46. /// cached message that was set by this class in status bar
  47. std::string currentConsoleMsg;
  48. bool isCastingPossibleHere (const CStack *sactive, const CStack *shere, BattleHex myNumber);
  49. bool canStackMoveHere (const CStack *sactive, BattleHex MyNumber) const; //TODO: move to BattleState / callback
  50. std::vector<PossiblePlayerBattleAction> getPossibleActionsForStack (const CStack *stack) const; //called when stack gets its turn
  51. void reorderPossibleActionsPriority(const CStack * stack, MouseHoveredHexContext context);
  52. public:
  53. BattleActionsController(BattleInterface * owner);
  54. /// initialize list of potential actions for new active stack
  55. void activateStack();
  56. /// initialize potential actions for spells that can be cast by active stack
  57. void enterCreatureCastingMode();
  58. /// initialize potential actions for selected spell
  59. void castThisSpell(SpellID spellID);
  60. /// ends casting spell (eg. when spell has been cast or canceled)
  61. void endCastingSpell();
  62. /// update UI (e.g. status bar/cursor) according to new active hex
  63. void handleHex(BattleHex myNumber, int eventType);
  64. /// returns currently selected spell or SpellID::NONE on error
  65. SpellID selectedSpell() const;
  66. /// returns true if UI is currently in target selection mode
  67. bool spellcastingModeActive() const;
  68. };