From b8c5a32b9b2b568049c53d86f43e48680e5205c5 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 19 Jan 2023 19:43:16 +0200 Subject: [PATCH] Fix attack targeting selection for double-wide units --- client/battle/BattleStacksController.cpp | 1 - lib/battle/CBattleInfoCallback.cpp | 10 +++++----- lib/battle/CBattleInfoCallback.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/battle/BattleStacksController.cpp b/client/battle/BattleStacksController.cpp index 37c73e7a6..afd0a69a5 100644 --- a/client/battle/BattleStacksController.cpp +++ b/client/battle/BattleStacksController.cpp @@ -543,7 +543,6 @@ void BattleStacksController::stackMoved(const CStack *stack, std::vectorcb->isToReverse( - attacker->getPosition(), attacker, defender); diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index dc9daae4d..03c1e2ba5 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -1470,8 +1470,7 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes (const battl if (!defender) return at; // can't attack thin air - //FIXME: dragons or cerbers can rotate before attack, making their base hex different (#1124) - bool reverse = isToReverse(destinationTile, attacker, defender); + bool reverse = isToReverse(attacker, defender); if(reverse && attacker->doubleWide()) { hex = attacker->occupiedHex(hex); //the other hex stack stands on @@ -1622,13 +1621,14 @@ static bool isHexInFront(BattleHex hex, BattleHex testHex, BattleSide::Type side } //TODO: this should apply also to mechanics and cursor interface -bool CBattleInfoCallback::isToReverse (BattleHex attackerHex, const battle::Unit * attacker, const battle::Unit * defender) const +bool CBattleInfoCallback::isToReverse (const battle::Unit * attacker, const battle::Unit * defender) const { + BattleHex attackerHex = attacker->getPosition(); + BattleHex defenderHex = defender->getPosition(); + if (attackerHex < 0 ) //turret return false; - BattleHex defenderHex = defender->getPosition(); - if (isHexInFront(attackerHex, defenderHex, BattleSide::Type(attacker->unitSide()))) return false; diff --git a/lib/battle/CBattleInfoCallback.h b/lib/battle/CBattleInfoCallback.h index 378ecdecd..9dccfcc5c 100644 --- a/lib/battle/CBattleInfoCallback.h +++ b/lib/battle/CBattleInfoCallback.h @@ -137,7 +137,7 @@ public: AttackableTiles getPotentiallyShootableHexes(const battle::Unit* attacker, BattleHex destinationTile, BattleHex attackerPos) const; std::vector getAttackedBattleUnits(const battle::Unit* attacker, BattleHex destinationTile, bool rangedAttack, BattleHex attackerPos = BattleHex::INVALID) const; //calculates range of multi-hex attacks std::set getAttackedCreatures(const CStack* attacker, BattleHex destinationTile, bool rangedAttack, BattleHex attackerPos = BattleHex::INVALID) const; //calculates range of multi-hex attacks - bool isToReverse(BattleHex attackerHex, const battle::Unit *attacker, const battle::Unit *defender) const; //determines if attacker standing at attackerHex should reverse in order to attack defender + bool isToReverse(const battle::Unit *attacker, const battle::Unit *defender) const; //determines if attacker standing at attackerHex should reverse in order to attack defender ReachabilityInfo getReachability(const battle::Unit * unit) const; ReachabilityInfo getReachability(const ReachabilityInfo::Parameters & params) const;