mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Merge pull request #2684 from dydzio0614/creature-spellcasting-fixes
Better default stack action handling + "F shortcut" mode fixes
This commit is contained in:
commit
eafa9cbae1
@ -215,7 +215,7 @@ std::vector<PossiblePlayerBattleAction> BattleActionsController::getPossibleActi
|
||||
return std::vector<PossiblePlayerBattleAction>(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,10 +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;
|
||||
else
|
||||
return 100; //bottom priority
|
||||
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 1;
|
||||
}
|
||||
return 100; //bottom priority
|
||||
|
||||
break;
|
||||
case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
|
||||
return 2;
|
||||
@ -788,7 +795,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 +979,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 +993,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 +1020,7 @@ void BattleActionsController::onHexRightClicked(BattleHex clickedHex)
|
||||
|
||||
bool BattleActionsController::spellcastingModeActive() const
|
||||
{
|
||||
return heroSpellToCast != nullptr;;
|
||||
return heroSpellToCast != nullptr;
|
||||
}
|
||||
|
||||
bool BattleActionsController::currentActionSpellcasting(BattleHex hoveredHex)
|
||||
|
@ -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
|
||||
@ -53,7 +47,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<PossiblePlayerBattleAction> 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);
|
||||
|
||||
|
@ -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::???:
|
||||
|
@ -120,7 +120,7 @@ std::vector<EShortcut> 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 },
|
||||
|
Loading…
Reference in New Issue
Block a user