1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

avoid assertions in stack position checks

This commit is contained in:
AlexVinS 2017-07-03 12:59:33 +03:00
parent 4f8c7bd4bb
commit e4c14c4cc2
2 changed files with 4 additions and 4 deletions

View File

@ -2036,7 +2036,7 @@ std::string formatDmgRange(std::pair<ui32, ui32> dmgRange)
bool CBattleInterface::canStackMoveHere(const CStack * activeStack, BattleHex myNumber) bool CBattleInterface::canStackMoveHere(const CStack * activeStack, BattleHex myNumber)
{ {
std::vector<BattleHex> acc = curInt->cb->battleGetAvailableHexes (activeStack, false); std::vector<BattleHex> acc = curInt->cb->battleGetAvailableHexes (activeStack, false);
BattleHex shiftedDest = myNumber + activeStack->destShiftDir(); BattleHex shiftedDest = myNumber.cloneInDirection(activeStack->destShiftDir(), false);
if (vstd::contains(acc, myNumber)) if (vstd::contains(acc, myNumber))
return true; return true;
@ -2265,7 +2265,7 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
if(activeStack->doubleWide()) if(activeStack->doubleWide())
{ {
std::vector<BattleHex> acc = curInt->cb->battleGetAvailableHexes(activeStack, false); std::vector<BattleHex> acc = curInt->cb->battleGetAvailableHexes(activeStack, false);
BattleHex shiftedDest = myNumber + activeStack->destShiftDir(); BattleHex shiftedDest = myNumber.cloneInDirection(activeStack->destShiftDir(), false);
if(vstd::contains(acc, myNumber)) if(vstd::contains(acc, myNumber))
giveCommand(Battle::WALK, myNumber, activeStack->ID); giveCommand(Battle::WALK, myNumber, activeStack->ID);
else if(vstd::contains(acc, shiftedDest)) else if(vstd::contains(acc, shiftedDest))

View File

@ -1164,7 +1164,7 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
//shifting destination (if we have double wide stack and we can occupy dest but not be exactly there) //shifting destination (if we have double wide stack and we can occupy dest but not be exactly there)
if(!stackAtEnd && curStack->doubleWide() && !accessibility.accessible(dest, curStack)) if(!stackAtEnd && curStack->doubleWide() && !accessibility.accessible(dest, curStack))
{ {
BattleHex shifted = dest.cloneInDirection(curStack->destShiftDir()); BattleHex shifted = dest.cloneInDirection(curStack->destShiftDir(), false);
if(accessibility.accessible(shifted, curStack)) if(accessibility.accessible(shifted, curStack))
dest = shifted; dest = shifted;
@ -3948,7 +3948,7 @@ bool CGameHandler::makeBattleAction(BattleAction &ba)
logGlobal->trace("%s will attack %s", stack->nodeName(), destinationStack->nodeName()); logGlobal->trace("%s will attack %s", stack->nodeName(), destinationStack->nodeName());
if(stack->position != ba.destinationTile //we wasn't able to reach destination tile if(stack->position != ba.destinationTile //we wasn't able to reach destination tile
&& !(stack->doubleWide() && (stack->position == ba.destinationTile.cloneInDirection(stack->destShiftDir()))) //nor occupy specified hex && !(stack->doubleWide() && (stack->position == ba.destinationTile.cloneInDirection(stack->destShiftDir(), false))) //nor occupy specified hex
) )
{ {
complain("We cannot move this stack to its destination " + stack->getCreature()->namePl); complain("We cannot move this stack to its destination " + stack->getCreature()->namePl);