1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-13 01:20:34 +02:00

Fix target selection for teleport

This commit is contained in:
Ivan Savenko
2023-03-31 22:15:24 +03:00
parent 4c6dbb5037
commit e9aed2761c
4 changed files with 11 additions and 23 deletions

View File

@ -113,6 +113,7 @@ static std::string formatRangedAttack(const DamageEstimation & estimation, const
BattleActionsController::BattleActionsController(BattleInterface & owner):
owner(owner),
selectedStack(nullptr),
heroSpellToCast(nullptr)
{}
@ -177,7 +178,7 @@ void BattleActionsController::enterCreatureCastingMode()
if (isCastingPossible)
{
owner.giveCommand(EActionType::MONSTER_SPELL, BattleHex::INVALID, spell->getId());
owner.stacksController->setSelectedStack(nullptr);
selectedStack = nullptr;
CCS->curh->set(Cursor::Combat::POINTER);
}
@ -568,7 +569,7 @@ bool BattleActionsController::actionIsLegal(PossiblePlayerBattleAction action, B
return isCastingPossibleHere(action.spell().toSpell(), owner.stacksController->getActiveStack(), targetStack, targetHex);
case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
return targetStack && isCastingPossibleHere(action.spell().toSpell(), owner.stacksController->getActiveStack(), targetStack, targetHex);
return !selectedStack && targetStack && isCastingPossibleHere(action.spell().toSpell(), owner.stacksController->getActiveStack(), targetStack, targetHex);
case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
if(targetStack && targetStackOwned && targetStack != owner.stacksController->getActiveStack() && targetStack->alive()) //only positive spells for other allied creatures
@ -581,11 +582,11 @@ bool BattleActionsController::actionIsLegal(PossiblePlayerBattleAction action, B
case PossiblePlayerBattleAction::TELEPORT:
{
ui8 skill = getCurrentSpellcaster()->getEffectLevel(SpellID(SpellID::TELEPORT).toSpell());
return owner.curInt->cb->battleCanTeleportTo(owner.stacksController->getSelectedStack(), targetHex, skill);
return owner.curInt->cb->battleCanTeleportTo(selectedStack, targetHex, skill);
}
case PossiblePlayerBattleAction::SACRIFICE: //choose our living stack to sacrifice
return targetStack && targetStack != owner.stacksController->getSelectedStack() && targetStackOwned && targetStack->alive();
return targetStack && targetStack != selectedStack && targetStackOwned && targetStack->alive();
case PossiblePlayerBattleAction::OBSTACLE:
case PossiblePlayerBattleAction::FREE_LOCATION:
@ -697,14 +698,14 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
{
heroSpellToCast->aimToHex(targetHex);
possibleActions.push_back({PossiblePlayerBattleAction::SACRIFICE, action.spell()});
owner.stacksController->setSelectedStack(targetStack);
selectedStack = targetStack;
return;
}
if (action.spell() == SpellID::TELEPORT)
{
heroSpellToCast->aimToUnit(targetStack);
possibleActions.push_back({PossiblePlayerBattleAction::TELEPORT, action.spell()});
owner.stacksController->setSelectedStack(targetStack);
selectedStack = targetStack;
return;
}
}
@ -735,7 +736,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
owner.curInt->cb->battleMakeAction(heroSpellToCast.get());
endCastingSpell();
}
owner.stacksController->setSelectedStack(nullptr);
selectedStack = nullptr;
return;
}
}