mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
A common function is used for getting hexes in a certain range
getRangeHexes()
This commit is contained in:
parent
192f82152d
commit
e668ea3a03
@ -446,60 +446,22 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesForMovementTarget(
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BattleHex> BattleFieldController::getRangedFullDamageHexes()
|
std::vector<BattleHex> BattleFieldController::getRangeHexes(BattleHex sourceHex, uint8_t distance)
|
||||||
{
|
{
|
||||||
std::vector<BattleHex> rangedFullDamageHexes; // used for return
|
std::vector<BattleHex> rangeHexes; // 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())
|
if (!settings["battle"]["rangedFullDamageLimitHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown())
|
||||||
return rangedFullDamageHexes;
|
return rangeHexes;
|
||||||
|
|
||||||
if(!(hoveredStack && hoveredStack->isShooter()))
|
// get only battlefield hexes that are within the given distance
|
||||||
return rangedFullDamageHexes;
|
|
||||||
|
|
||||||
auto rangedFullDamageDistance = hoveredStack->getRangedFullDamageDistance();
|
|
||||||
|
|
||||||
// get only battlefield hexes that are in full range damage distance
|
|
||||||
std::set<BattleHex> fullRangeLimit;
|
|
||||||
for(auto i = 0; i < GameConstants::BFIELD_SIZE; i++)
|
for(auto i = 0; i < GameConstants::BFIELD_SIZE; i++)
|
||||||
{
|
{
|
||||||
BattleHex hex(i);
|
BattleHex hex(i);
|
||||||
if(hex.isAvailable() && BattleHex::getDistance(hoveredHex, hex) <= rangedFullDamageDistance)
|
if(hex.isAvailable() && BattleHex::getDistance(sourceHex, hex) <= distance)
|
||||||
rangedFullDamageHexes.push_back(hex);
|
rangeHexes.push_back(hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rangedFullDamageHexes;
|
return rangeHexes;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<BattleHex> BattleFieldController::getSootingRangeHexes()
|
|
||||||
{
|
|
||||||
std::vector<BattleHex> 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<BattleHex> 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BattleHex> BattleFieldController::getRangeLimitHexes(BattleHex hoveredHex, std::vector<BattleHex> rangeHexes, uint8_t distanceToLimit)
|
std::vector<BattleHex> BattleFieldController::getRangeLimitHexes(BattleHex hoveredHex, std::vector<BattleHex> rangeHexes, uint8_t distanceToLimit)
|
||||||
@ -613,15 +575,15 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas)
|
|||||||
if(hoveredStack && hoveredStack->isShooter())
|
if(hoveredStack && hoveredStack->isShooter())
|
||||||
{
|
{
|
||||||
// calculate array with highlight images for ranged full damage limit
|
// calculate array with highlight images for ranged full damage limit
|
||||||
std::vector<BattleHex> rangedFullDamageHexes = getRangedFullDamageHexes();
|
|
||||||
auto rangedFullDamageDistance = hoveredStack->getRangedFullDamageDistance();
|
auto rangedFullDamageDistance = hoveredStack->getRangedFullDamageDistance();
|
||||||
|
std::vector<BattleHex> rangedFullDamageHexes = getRangeHexes(hoveredHex, rangedFullDamageDistance);
|
||||||
rangedFullDamageLimitHexes = getRangeLimitHexes(hoveredHex, rangedFullDamageHexes, rangedFullDamageDistance);
|
rangedFullDamageLimitHexes = getRangeLimitHexes(hoveredHex, rangedFullDamageHexes, rangedFullDamageDistance);
|
||||||
std::vector<std::vector<BattleHex::EDir>> rangedFullDamageLimitHexesNeighbourDirections = getOutsideNeighbourDirectionsForLimitHexes(rangedFullDamageHexes, rangedFullDamageLimitHexes);
|
std::vector<std::vector<BattleHex::EDir>> rangedFullDamageLimitHexesNeighbourDirections = getOutsideNeighbourDirectionsForLimitHexes(rangedFullDamageHexes, rangedFullDamageLimitHexes);
|
||||||
rangedFullDamageLimitHexesHighligts = calculateRangeHighlightImages(rangedFullDamageLimitHexesNeighbourDirections, rangedFullDamageLimitImages);
|
rangedFullDamageLimitHexesHighligts = calculateRangeHighlightImages(rangedFullDamageLimitHexesNeighbourDirections, rangedFullDamageLimitImages);
|
||||||
|
|
||||||
// calculate array with highlight images for shooting range limit
|
// calculate array with highlight images for shooting range limit
|
||||||
std::vector<BattleHex> shootingRangeHexes = getSootingRangeHexes();
|
|
||||||
auto shootingRangeDistance = hoveredStack->getSootingRangeDistance();
|
auto shootingRangeDistance = hoveredStack->getSootingRangeDistance();
|
||||||
|
std::vector<BattleHex> shootingRangeHexes = getRangeHexes(hoveredHex, shootingRangeDistance);
|
||||||
shootingRangeLimitHexes = getRangeLimitHexes(hoveredHex, shootingRangeHexes, shootingRangeDistance);
|
shootingRangeLimitHexes = getRangeLimitHexes(hoveredHex, shootingRangeHexes, shootingRangeDistance);
|
||||||
std::vector<std::vector<BattleHex::EDir>> shootingRangeLimitHexesNeighbourDirections = getOutsideNeighbourDirectionsForLimitHexes(shootingRangeHexes, shootingRangeLimitHexes);
|
std::vector<std::vector<BattleHex::EDir>> shootingRangeLimitHexesNeighbourDirections = getOutsideNeighbourDirectionsForLimitHexes(shootingRangeHexes, shootingRangeLimitHexes);
|
||||||
shootingRangeLimitHexesHighligts = calculateRangeHighlightImages(shootingRangeLimitHexesNeighbourDirections, shootingRangeLimitImages);
|
shootingRangeLimitHexesHighligts = calculateRangeHighlightImages(shootingRangeLimitHexesNeighbourDirections, shootingRangeLimitImages);
|
||||||
|
@ -60,10 +60,8 @@ class BattleFieldController : public CIntObject
|
|||||||
std::set<BattleHex> getHighlightedHexesForSpellRange();
|
std::set<BattleHex> getHighlightedHexesForSpellRange();
|
||||||
std::set<BattleHex> getHighlightedHexesForMovementTarget();
|
std::set<BattleHex> getHighlightedHexesForMovementTarget();
|
||||||
|
|
||||||
/// get all hexes where a ranged unit can do full damage
|
/// get all hexes within a certain distance of given hex
|
||||||
std::vector<BattleHex> getRangedFullDamageHexes();
|
std::vector<BattleHex> getRangeHexes(BattleHex sourceHex, uint8_t distance);
|
||||||
|
|
||||||
std::vector<BattleHex> getSootingRangeHexes();
|
|
||||||
|
|
||||||
/// get only hexes at the limit of a range
|
/// get only hexes at the limit of a range
|
||||||
std::vector<BattleHex> getRangeLimitHexes(BattleHex hoveredHex, std::vector<BattleHex> hexRange, uint8_t distanceToLimit);
|
std::vector<BattleHex> getRangeLimitHexes(BattleHex hoveredHex, std::vector<BattleHex> hexRange, uint8_t distanceToLimit);
|
||||||
|
Loading…
Reference in New Issue
Block a user