diff --git a/client/battle/BattleFieldController.cpp b/client/battle/BattleFieldController.cpp index 3695ba411..507cfe11e 100644 --- a/client/battle/BattleFieldController.cpp +++ b/client/battle/BattleFieldController.cpp @@ -446,60 +446,22 @@ std::set BattleFieldController::getHighlightedHexesForMovementTarget( return {}; } -std::vector BattleFieldController::getRangedFullDamageHexes() +std::vector BattleFieldController::getRangeHexes(BattleHex sourceHex, uint8_t distance) { - std::vector rangedFullDamageHexes; // used for return - - // if not a hovered arcer unit -> return - auto hoveredHex = getHoveredHex(); - const CStack * hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true); + std::vector rangeHexes; // used for return if (!settings["battle"]["rangedFullDamageLimitHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown()) - return rangedFullDamageHexes; + return rangeHexes; - if(!(hoveredStack && hoveredStack->isShooter())) - return rangedFullDamageHexes; - - auto rangedFullDamageDistance = hoveredStack->getRangedFullDamageDistance(); - - // get only battlefield hexes that are in full range damage distance - std::set fullRangeLimit; + // get only battlefield hexes that are within the given distance for(auto i = 0; i < GameConstants::BFIELD_SIZE; i++) { BattleHex hex(i); - if(hex.isAvailable() && BattleHex::getDistance(hoveredHex, hex) <= rangedFullDamageDistance) - rangedFullDamageHexes.push_back(hex); + if(hex.isAvailable() && BattleHex::getDistance(sourceHex, hex) <= distance) + rangeHexes.push_back(hex); } - return rangedFullDamageHexes; -} - -std::vector BattleFieldController::getSootingRangeHexes() -{ - std::vector sootingRangeHexes; // used for return - - // if not a hovered arcer unit -> return - auto hoveredHex = getHoveredHex(); - const CStack * hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true); - - if (!settings["battle"]["rangedFullDamageLimitHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown()) - return sootingRangeHexes; - - if(!(hoveredStack && hoveredStack->isShooter())) - return sootingRangeHexes; - - auto shootingRangeDistance = hoveredStack->getSootingRangeDistance(); - - // get only battlefield hexes that are in full range damage distance - std::set shootingRangeLimit; - for(auto i = 0; i < GameConstants::BFIELD_SIZE; i++) - { - BattleHex hex(i); - if(hex.isAvailable() && BattleHex::getDistance(hoveredHex, hex) <= shootingRangeDistance) - sootingRangeHexes.push_back(hex); - } - - return sootingRangeHexes; + return rangeHexes; } std::vector BattleFieldController::getRangeLimitHexes(BattleHex hoveredHex, std::vector rangeHexes, uint8_t distanceToLimit) @@ -613,15 +575,15 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas) if(hoveredStack && hoveredStack->isShooter()) { // calculate array with highlight images for ranged full damage limit - std::vector rangedFullDamageHexes = getRangedFullDamageHexes(); auto rangedFullDamageDistance = hoveredStack->getRangedFullDamageDistance(); + std::vector rangedFullDamageHexes = getRangeHexes(hoveredHex, rangedFullDamageDistance); rangedFullDamageLimitHexes = getRangeLimitHexes(hoveredHex, rangedFullDamageHexes, rangedFullDamageDistance); std::vector> rangedFullDamageLimitHexesNeighbourDirections = getOutsideNeighbourDirectionsForLimitHexes(rangedFullDamageHexes, rangedFullDamageLimitHexes); rangedFullDamageLimitHexesHighligts = calculateRangeHighlightImages(rangedFullDamageLimitHexesNeighbourDirections, rangedFullDamageLimitImages); // calculate array with highlight images for shooting range limit - std::vector shootingRangeHexes = getSootingRangeHexes(); auto shootingRangeDistance = hoveredStack->getSootingRangeDistance(); + std::vector shootingRangeHexes = getRangeHexes(hoveredHex, shootingRangeDistance); shootingRangeLimitHexes = getRangeLimitHexes(hoveredHex, shootingRangeHexes, shootingRangeDistance); std::vector> shootingRangeLimitHexesNeighbourDirections = getOutsideNeighbourDirectionsForLimitHexes(shootingRangeHexes, shootingRangeLimitHexes); shootingRangeLimitHexesHighligts = calculateRangeHighlightImages(shootingRangeLimitHexesNeighbourDirections, shootingRangeLimitImages); diff --git a/client/battle/BattleFieldController.h b/client/battle/BattleFieldController.h index acbe324fc..1eac44473 100644 --- a/client/battle/BattleFieldController.h +++ b/client/battle/BattleFieldController.h @@ -60,10 +60,8 @@ class BattleFieldController : public CIntObject std::set getHighlightedHexesForSpellRange(); std::set getHighlightedHexesForMovementTarget(); - /// get all hexes where a ranged unit can do full damage - std::vector getRangedFullDamageHexes(); - - std::vector getSootingRangeHexes(); + /// get all hexes within a certain distance of given hex + std::vector getRangeHexes(BattleHex sourceHex, uint8_t distance); /// get only hexes at the limit of a range std::vector getRangeLimitHexes(BattleHex hoveredHex, std::vector hexRange, uint8_t distanceToLimit);