1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-04 23:17:41 +02:00

BattleAI: fix dragon breath

This commit is contained in:
Andrii Danylchenko 2024-07-22 20:34:28 +03:00
parent 37cf788079
commit 33e0eeaa8a
3 changed files with 11 additions and 8 deletions

View File

@ -189,7 +189,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
else else
{ {
activeActionMade = true; activeActionMade = true;
return BattleAction::makeMeleeAttack(stack, bestAttack.attack.defender->getPosition(), bestAttack.from); return BattleAction::makeMeleeAttack(stack, bestAttack.attack.defenderPos, bestAttack.from);
} }
} }
} }

View File

@ -1247,7 +1247,7 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes(const battle:
if (!defender) if (!defender)
return at; // can't attack thin air return at; // can't attack thin air
bool reverse = isToReverse(attacker, defender); bool reverse = isToReverse(attacker, defender, attackOriginHex, destinationTile);
if(reverse && attacker->doubleWide()) if(reverse && attacker->doubleWide())
{ {
attackOriginHex = attacker->occupiedHex(attackOriginHex); //the other hex stack stands on attackOriginHex = attacker->occupiedHex(attackOriginHex); //the other hex stack stands on
@ -1303,8 +1303,8 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes(const battle:
// if targeted double-wide creature is attacked from above or below ( -> second hex is also adjacent to attack origin) // if targeted double-wide creature is attacked from above or below ( -> second hex is also adjacent to attack origin)
// then dragon breath should target tile on the opposite side of targeted creature // then dragon breath should target tile on the opposite side of targeted creature
if (BattleHex::mutualPosition(attackOriginHex, secondHex) != BattleHex::NONE) /*if(BattleHex::mutualPosition(attackOriginHex, secondHex) != BattleHex::NONE)
nextHex = secondHex.cloneInDirection(direction, false); nextHex = secondHex.cloneInDirection(direction, false);*/
} }
if (nextHex.isValid()) if (nextHex.isValid())
@ -1410,10 +1410,13 @@ static bool isHexInFront(BattleHex hex, BattleHex testHex, BattleSide::Type side
} }
//TODO: this should apply also to mechanics and cursor interface //TODO: this should apply also to mechanics and cursor interface
bool CBattleInfoCallback::isToReverse(const battle::Unit * attacker, const battle::Unit * defender) const bool CBattleInfoCallback::isToReverse(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerHex, BattleHex defenderHex) const
{ {
BattleHex attackerHex = attacker->getPosition(); if(!defenderHex.isValid())
BattleHex defenderHex = defender->getPosition(); defenderHex = defender->getPosition();
if(!attackerHex.isValid())
attackerHex = attacker->getPosition();
if (attackerHex < 0 ) //turret if (attackerHex < 0 ) //turret
return false; return false;

View File

@ -134,7 +134,7 @@ public:
AttackableTiles getPotentiallyShootableHexes(const battle::Unit* attacker, BattleHex destinationTile, BattleHex attackerPos) const; AttackableTiles getPotentiallyShootableHexes(const battle::Unit* attacker, BattleHex destinationTile, BattleHex attackerPos) const;
std::vector<const battle::Unit *> getAttackedBattleUnits(const battle::Unit* attacker, BattleHex destinationTile, bool rangedAttack, BattleHex attackerPos = BattleHex::INVALID) const; //calculates range of multi-hex attacks std::vector<const battle::Unit *> getAttackedBattleUnits(const battle::Unit* attacker, BattleHex destinationTile, bool rangedAttack, BattleHex attackerPos = BattleHex::INVALID) const; //calculates range of multi-hex attacks
std::set<const CStack*> getAttackedCreatures(const CStack* attacker, BattleHex destinationTile, bool rangedAttack, BattleHex attackerPos = BattleHex::INVALID) const; //calculates range of multi-hex attacks std::set<const CStack*> getAttackedCreatures(const CStack* attacker, BattleHex destinationTile, bool rangedAttack, BattleHex attackerPos = BattleHex::INVALID) const; //calculates range of multi-hex attacks
bool isToReverse(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, BattleHex attackerHex = BattleHex::INVALID, BattleHex defenderHex = BattleHex::INVALID) const; //determines if attacker standing at attackerHex should reverse in order to attack defender
ReachabilityInfo getReachability(const battle::Unit * unit) const; ReachabilityInfo getReachability(const battle::Unit * unit) const;
ReachabilityInfo getReachability(const ReachabilityInfo::Parameters & params) const; ReachabilityInfo getReachability(const ReachabilityInfo::Parameters & params) const;