diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 8e907e338..301b5b8d9 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -785,15 +785,15 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, THex std::vector hexes; if (attacker->attackerOwned) { - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); //upper THex::checkAndPush(hex + 1, hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + THex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); //lower } else { - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); THex::checkAndPush(hex - 1, hexes); - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN ), hexes); + THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); } BOOST_FOREACH (THex tile, hexes) { diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index ec89e6349..e029a1d8c 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -504,7 +504,7 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer delete battleResult.data; } -void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CStack *def, int distance) +void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CStack *def, int distance, int targetHex) { bat.bsa.clear(); bat.stackAttacking = att->ID; @@ -538,7 +538,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CSt if (!bat.shot()) //multiple-hex attack - only in meele { - std::set attackedCreatures = gs->curB->getAttackedCreatures(att, def->position); + std::set attackedCreatures = gs->curB->getAttackedCreatures(att, targetHex); //TODO: get exact attacked hex for defender BOOST_FOREACH(CStack * stack, attackedCreatures) @@ -556,7 +556,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CSt bat.bsa.front().flags |= BattleStackAttacked::EFFECT; bat.bsa.front().effect = VLC->spellh->spells[bonus->subtype]->mainEffectAnim; //hopefully it does not interfere with any other effect? - std::set attackedCreatures = gs->curB->getAttackedCreatures(VLC->spellh->spells[bonus->subtype], bonus->val, att->owner, def->position); + std::set attackedCreatures = gs->curB->getAttackedCreatures(VLC->spellh->spells[bonus->subtype], bonus->val, att->owner, targetHex); //TODO: get exact attacked hex for defender BOOST_FOREACH(CStack * stack, attackedCreatures) @@ -3053,7 +3053,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) //attack BattleAttack bat; - prepareAttack(bat, curStack, stackAtEnd, distance); + prepareAttack(bat, curStack, stackAtEnd, distance, ba.additionalInfo); sendAndApply(&bat); handleAfterAttackCasting(bat); @@ -3064,7 +3064,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) && !stackAtEnd->hasBonusOfType(Bonus::SIEGE_WEAPON) && !stackAtEnd->hasBonusOfType(Bonus::HYPNOTIZED)) { - prepareAttack(bat, stackAtEnd, curStack, 0); + prepareAttack(bat, stackAtEnd, curStack, 0, curStack->position); bat.flags |= BattleAttack::COUNTER; sendAndApply(&bat); handleAfterAttackCasting(bat); @@ -3077,7 +3077,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) && stackAtEnd->alive() ) { bat.flags = 0; - prepareAttack(bat, curStack, stackAtEnd, 0); + prepareAttack(bat, curStack, stackAtEnd, 0, ba.additionalInfo); sendAndApply(&bat); handleAfterAttackCasting(bat); } @@ -3103,7 +3103,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) BattleAttack bat; bat.flags |= BattleAttack::SHOT; - prepareAttack(bat, curStack, destStack, 0); + prepareAttack(bat, curStack, destStack, 0, ba.destinationTile); sendAndApply(&bat); handleAfterAttackCasting(bat); @@ -3112,7 +3112,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) { BattleAttack bat2; bat2.flags |= BattleAttack::SHOT; - prepareAttack(bat2, curStack, destStack, 0); + prepareAttack(bat2, curStack, destStack, 0, ba.destinationTile); sendAndApply(&bat2); } @@ -3122,7 +3122,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) && curStack->shots ) { - prepareAttack(bat, curStack, destStack, 0); + prepareAttack(bat, curStack, destStack, 0, ba.destinationTile); sendAndApply(&bat); handleAfterAttackCasting(bat); } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 24e2731fd..c9d70b91e 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -117,7 +117,7 @@ public: bool visitObjectAfterVictory; // void endBattle(int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2); //ends battle - void prepareAttack(BattleAttack &bat, const CStack *att, const CStack *def, int distance); //distance - number of hexes travelled before attacking + void prepareAttack(BattleAttack &bat, const CStack *att, const CStack *def, int distance, int targetHex); //distance - number of hexes travelled before attacking void applyBattleEffects(BattleAttack &bat, const CStack *att, const CStack *def, int distance, bool secondary); //damage, drain life & fire shield void checkForBattleEnd( std::vector &stacks ); void setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance *heroes[2], bool creatureBank, const CGTownInstance *town);