2022-11-20 22:56:42 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleActionsController.h, part of VCMI engine
|
2022-11-20 22:56:42 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/battle/CBattleInfoCallback.h"
|
|
|
|
|
2022-11-29 02:00:08 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-11-20 22:56:42 +02:00
|
|
|
class BattleAction;
|
2022-11-29 02:00:08 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleInterface;
|
2022-11-20 22:56:42 +02:00
|
|
|
|
|
|
|
enum class MouseHoveredHexContext
|
|
|
|
{
|
|
|
|
UNOCCUPIED_HEX,
|
|
|
|
OCCUPIED_HEX
|
|
|
|
};
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// Class that controls actions that can be performed by player, e.g. moving stacks, attacking, etc
|
|
|
|
/// As well as all relevant feedback for these actions in user interface
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleActionsController
|
2022-11-20 22:56:42 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleInterface & owner;
|
2022-11-20 22:56:42 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// all actions possible to call at the moment by player
|
|
|
|
std::vector<PossiblePlayerBattleAction> possibleActions;
|
2022-11-20 22:56:42 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// actions possible to take on hovered hex
|
|
|
|
std::vector<PossiblePlayerBattleAction> localActions;
|
2022-11-20 22:56:42 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// these actions display message in case of illegal target
|
|
|
|
std::vector<PossiblePlayerBattleAction> illegalActions;
|
2022-11-20 22:56:42 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// action that will be performed on l-click
|
|
|
|
PossiblePlayerBattleAction currentAction;
|
|
|
|
|
|
|
|
/// last action chosen (and saved) by player
|
|
|
|
PossiblePlayerBattleAction selectedAction;
|
|
|
|
|
|
|
|
/// if there are not possible actions to choose from, this action should be show as "illegal" in UI
|
|
|
|
PossiblePlayerBattleAction illegalAction;
|
|
|
|
|
|
|
|
/// if true, stack currently aims to cats a spell
|
|
|
|
bool creatureCasting;
|
2022-11-20 22:56:42 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// if true, player is choosing destination for his spell - only for GUI / console
|
|
|
|
bool spellDestSelectMode;
|
|
|
|
|
|
|
|
/// spell for which player is choosing destination
|
|
|
|
std::shared_ptr<BattleAction> spellToCast;
|
|
|
|
|
|
|
|
/// spell for which player is choosing destination, pointer for convenience
|
|
|
|
const CSpell *currentSpell;
|
|
|
|
|
|
|
|
/// cached message that was set by this class in status bar
|
2022-12-01 23:36:41 +02:00
|
|
|
std::string currentConsoleMsg;
|
2022-12-11 23:16:23 +02:00
|
|
|
|
|
|
|
bool isCastingPossibleHere (const CStack *sactive, const CStack *shere, BattleHex myNumber);
|
|
|
|
bool canStackMoveHere (const CStack *sactive, BattleHex MyNumber) const; //TODO: move to BattleState / callback
|
|
|
|
std::vector<PossiblePlayerBattleAction> getPossibleActionsForStack (const CStack *stack) const; //called when stack gets its turn
|
|
|
|
void reorderPossibleActionsPriority(const CStack * stack, MouseHoveredHexContext context);
|
|
|
|
|
2022-11-20 22:56:42 +02:00
|
|
|
public:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleActionsController(BattleInterface & owner);
|
2022-11-20 22:56:42 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// initialize list of potential actions for new active stack
|
2022-11-20 22:56:42 +02:00
|
|
|
void activateStack();
|
2022-12-11 23:16:23 +02:00
|
|
|
|
|
|
|
/// initialize potential actions for spells that can be cast by active stack
|
2022-11-20 22:56:42 +02:00
|
|
|
void enterCreatureCastingMode();
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// initialize potential actions for selected spell
|
|
|
|
void castThisSpell(SpellID spellID);
|
|
|
|
|
|
|
|
/// ends casting spell (eg. when spell has been cast or canceled)
|
|
|
|
void endCastingSpell();
|
|
|
|
|
|
|
|
/// update UI (e.g. status bar/cursor) according to new active hex
|
2022-11-20 22:56:42 +02:00
|
|
|
void handleHex(BattleHex myNumber, int eventType);
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// returns currently selected spell or SpellID::NONE on error
|
|
|
|
SpellID selectedSpell() const;
|
|
|
|
|
|
|
|
/// returns true if UI is currently in target selection mode
|
|
|
|
bool spellcastingModeActive() const;
|
2022-12-20 01:28:20 +02:00
|
|
|
|
|
|
|
/// methods to work with array of possible actions, needed to control special creatures abilities
|
|
|
|
const std::vector<PossiblePlayerBattleAction> & getPossibleActions() const;
|
|
|
|
void removePossibleAction(PossiblePlayerBattleAction);
|
|
|
|
|
|
|
|
/// inserts possible action in the beggining in order to prioritize it
|
|
|
|
void pushFrontPossibleAction(PossiblePlayerBattleAction);
|
2022-12-11 23:16:23 +02:00
|
|
|
|
2022-11-20 22:56:42 +02:00
|
|
|
};
|