From e1eb245565d6b6b8a7305d735cc4f9b2196514e2 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 27 Aug 2023 17:33:10 +0200 Subject: [PATCH 1/3] Better default stack action handling + "F shortcut" mode fixes --- client/battle/BattleActionsController.cpp | 36 +++++++++++++++++++---- client/battle/BattleActionsController.h | 2 +- client/battle/BattleWindow.cpp | 4 +++ client/gui/ShortcutHandler.cpp | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/client/battle/BattleActionsController.cpp b/client/battle/BattleActionsController.cpp index 1ccdbf10f..4920bb79b 100644 --- a/client/battle/BattleActionsController.cpp +++ b/client/battle/BattleActionsController.cpp @@ -215,7 +215,7 @@ std::vector BattleActionsController::getPossibleActi return std::vector(allActions); } -void BattleActionsController::reorderPossibleActionsPriority(const CStack * stack, MouseHoveredHexContext context) +void BattleActionsController::reorderPossibleActionsPriority(const CStack * stack, const CStack * targetStack) { if(owner.tacticsMode || possibleActions.empty()) return; //this function is not supposed to be called in tactics mode or before getPossibleActionsForStack @@ -229,8 +229,17 @@ void BattleActionsController::reorderPossibleActionsPriority(const CStack * stac case PossiblePlayerBattleAction::NO_LOCATION: case PossiblePlayerBattleAction::FREE_LOCATION: case PossiblePlayerBattleAction::OBSTACLE: - if(!stack->hasBonusOfType(BonusType::NO_SPELLCAST_BY_DEFAULT) && context == MouseHoveredHexContext::OCCUPIED_HEX) - return 1; + if(!stack->hasBonusOfType(BonusType::NO_SPELLCAST_BY_DEFAULT) && targetStack != nullptr) + { + PlayerColor stackOwner = owner.curInt->cb->battleGetOwner(targetStack); + bool enemyTargetingPositiveSpellcast = item.spell().toSpell()->isPositive() && stackOwner != LOCPLINT->playerID; + bool friendTargetingNegativeSpellcast = item.spell().toSpell()->isNegative() && stackOwner == LOCPLINT->playerID; + + if(enemyTargetingPositiveSpellcast || friendTargetingNegativeSpellcast) + return 100; + else + return 1; + } else return 100; //bottom priority break; @@ -788,7 +797,7 @@ PossiblePlayerBattleAction BattleActionsController::selectAction(BattleHex targe const CStack * targetStack = getStackForHex(targetHex); - reorderPossibleActionsPriority(owner.stacksController->getActiveStack(), targetStack ? MouseHoveredHexContext::OCCUPIED_HEX : MouseHoveredHexContext::UNOCCUPIED_HEX); + reorderPossibleActionsPriority(owner.stacksController->getActiveStack(), targetStack); for (PossiblePlayerBattleAction action : possibleActions) { @@ -972,6 +981,11 @@ void BattleActionsController::activateStack() case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE: actionsToSelect.push_back(possibleActions.front()); + actionsToSelect.push_back(PossiblePlayerBattleAction::ATTACK); + break; + case PossiblePlayerBattleAction::ANY_LOCATION: + actionsToSelect.push_back(possibleActions.front()); + actionsToSelect.push_back(PossiblePlayerBattleAction::ATTACK); break; } } @@ -981,8 +995,18 @@ void BattleActionsController::activateStack() void BattleActionsController::onHexRightClicked(BattleHex clickedHex) { - if (spellcastingModeActive()) + auto spellcastActionPredicate = [](PossiblePlayerBattleAction & action) + { + return action.spellcast(); + }; + + bool isCurrentStackInSpellcastMode = std::all_of(possibleActions.begin(), possibleActions.end(), spellcastActionPredicate); + + if (spellcastingModeActive() || isCurrentStackInSpellcastMode) + { endCastingSpell(); + return; + } auto selectedStack = owner.curInt->cb->battleGetStackByPos(clickedHex, true); @@ -998,7 +1022,7 @@ void BattleActionsController::onHexRightClicked(BattleHex clickedHex) bool BattleActionsController::spellcastingModeActive() const { - return heroSpellToCast != nullptr;; + return heroSpellToCast != nullptr; } bool BattleActionsController::currentActionSpellcasting(BattleHex hoveredHex) diff --git a/client/battle/BattleActionsController.h b/client/battle/BattleActionsController.h index 3010ac4e2..b686066bb 100644 --- a/client/battle/BattleActionsController.h +++ b/client/battle/BattleActionsController.h @@ -53,7 +53,7 @@ class BattleActionsController bool isCastingPossibleHere (const CSpell * spell, const CStack *shere, BattleHex myNumber); bool canStackMoveHere (const CStack *sactive, BattleHex MyNumber) const; //TODO: move to BattleState / callback std::vector getPossibleActionsForStack (const CStack *stack) const; //called when stack gets its turn - void reorderPossibleActionsPriority(const CStack * stack, MouseHoveredHexContext context); + void reorderPossibleActionsPriority(const CStack * stack, const CStack * targetStack); bool actionIsLegal(PossiblePlayerBattleAction action, BattleHex hoveredHex); diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index 36cf2441c..78a5f690c 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -450,6 +450,10 @@ void BattleWindow::showAlternativeActionIcon(PossiblePlayerBattleAction action) case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE: iconName = variables["actionIconSpell"].String(); break; + + case PossiblePlayerBattleAction::ANY_LOCATION: + iconName = variables["actionIconSpell"].String(); + break; //TODO: figure out purpose of this icon //case PossiblePlayerBattleAction::???: diff --git a/client/gui/ShortcutHandler.cpp b/client/gui/ShortcutHandler.cpp index 9014d1fcf..13f4f7307 100644 --- a/client/gui/ShortcutHandler.cpp +++ b/client/gui/ShortcutHandler.cpp @@ -120,7 +120,7 @@ std::vector ShortcutHandler::translateKeycode(SDL_Keycode key) const {SDLK_KP_MINUS, EShortcut::ADVENTURE_ZOOM_OUT }, {SDLK_BACKSPACE, EShortcut::ADVENTURE_ZOOM_RESET }, {SDLK_q, EShortcut::BATTLE_TOGGLE_QUEUE }, - {SDLK_c, EShortcut::BATTLE_USE_CREATURE_SPELL }, + {SDLK_f, EShortcut::BATTLE_USE_CREATURE_SPELL }, {SDLK_s, EShortcut::BATTLE_SURRENDER }, {SDLK_r, EShortcut::BATTLE_RETREAT }, {SDLK_a, EShortcut::BATTLE_AUTOCOMBAT }, From 321c9c2ca6eacd2db54a193550683547201d1a7f Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 27 Aug 2023 20:18:19 +0200 Subject: [PATCH 2/3] Remove now unused enum --- client/battle/BattleActionsController.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/client/battle/BattleActionsController.h b/client/battle/BattleActionsController.h index b686066bb..86acc8e44 100644 --- a/client/battle/BattleActionsController.h +++ b/client/battle/BattleActionsController.h @@ -23,12 +23,6 @@ VCMI_LIB_NAMESPACE_END class BattleInterface; -enum class MouseHoveredHexContext -{ - UNOCCUPIED_HEX, - OCCUPIED_HEX -}; - /// 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 class BattleActionsController From cba9ddd66af4a4d0767950b645b9660bdd686a1e Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 27 Aug 2023 23:01:04 +0200 Subject: [PATCH 3/3] Update client/battle/BattleActionsController.cpp Co-authored-by: Nordsoft91 --- client/battle/BattleActionsController.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/battle/BattleActionsController.cpp b/client/battle/BattleActionsController.cpp index 4920bb79b..3378140d0 100644 --- a/client/battle/BattleActionsController.cpp +++ b/client/battle/BattleActionsController.cpp @@ -235,13 +235,11 @@ void BattleActionsController::reorderPossibleActionsPriority(const CStack * stac bool enemyTargetingPositiveSpellcast = item.spell().toSpell()->isPositive() && stackOwner != LOCPLINT->playerID; bool friendTargetingNegativeSpellcast = item.spell().toSpell()->isNegative() && stackOwner == LOCPLINT->playerID; - if(enemyTargetingPositiveSpellcast || friendTargetingNegativeSpellcast) - return 100; - else + if(!enemyTargetingPositiveSpellcast && !friendTargetingNegativeSpellcast) return 1; } - else - return 100; //bottom priority + return 100; //bottom priority + break; case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL: return 2;