瀏覽代碼

Better default stack action handling + "F shortcut" mode fixes

Dydzio 2 年之前
父節點
當前提交
e1eb245565

+ 30 - 6
client/battle/BattleActionsController.cpp

@@ -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,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)

+ 1 - 1
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<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);
 

+ 4 - 0
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::???:

+ 1 - 1
client/gui/ShortcutHandler.cpp

@@ -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         },