mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
Use BattleHex as const ref wherever possible
Minor Fixes Drop unused function from BattleHexArray
This commit is contained in:
@ -282,7 +282,7 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
||||
{
|
||||
BattleHexArray hexesToShade = occupiableHexes;
|
||||
hexesToShade.insert(attackableHexes);
|
||||
for(BattleHex hex : hexesToShade)
|
||||
for(const BattleHex & hex : hexesToShade)
|
||||
{
|
||||
showHighlightedHex(*backgroundWithHexes, cellShade, hex, false);
|
||||
}
|
||||
@ -303,7 +303,7 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
||||
}
|
||||
}
|
||||
|
||||
void BattleFieldController::showHighlightedHex(Canvas & canvas, std::shared_ptr<IImage> highlight, BattleHex hex, bool darkBorder)
|
||||
void BattleFieldController::showHighlightedHex(Canvas & canvas, std::shared_ptr<IImage> highlight, const BattleHex & hex, bool darkBorder)
|
||||
{
|
||||
Point hexPos = hexPositionLocal(hex).topLeft();
|
||||
|
||||
@ -314,41 +314,30 @@ void BattleFieldController::showHighlightedHex(Canvas & canvas, std::shared_ptr<
|
||||
|
||||
BattleHexArray BattleFieldController::getHighlightedHexesForActiveStack()
|
||||
{
|
||||
BattleHexArray result;
|
||||
|
||||
if(!owner.stacksController->getActiveStack())
|
||||
return result;
|
||||
return BattleHexArray();
|
||||
|
||||
if(!settings["battle"]["stackRange"].Bool())
|
||||
return result;
|
||||
return BattleHexArray();
|
||||
|
||||
auto hoveredHex = getHoveredHex();
|
||||
|
||||
BattleHexArray set = owner.getBattle()->battleGetAttackedHexes(owner.stacksController->getActiveStack(), hoveredHex);
|
||||
for(BattleHex hex : set)
|
||||
result.insert(hex);
|
||||
|
||||
return result;
|
||||
return owner.getBattle()->battleGetAttackedHexes(owner.stacksController->getActiveStack(), hoveredHex);
|
||||
}
|
||||
|
||||
BattleHexArray BattleFieldController::getMovementRangeForHoveredStack()
|
||||
{
|
||||
BattleHexArray result;
|
||||
|
||||
if (!owner.stacksController->getActiveStack())
|
||||
return result;
|
||||
return BattleHexArray();
|
||||
|
||||
if (!settings["battle"]["movementHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown())
|
||||
return result;
|
||||
return BattleHexArray();
|
||||
|
||||
auto hoveredStack = getHoveredStack();
|
||||
if(hoveredStack)
|
||||
{
|
||||
BattleHexArray v = owner.getBattle()->battleGetAvailableHexes(hoveredStack, true, true, nullptr);
|
||||
for(BattleHex hex : v)
|
||||
result.insert(hex);
|
||||
}
|
||||
return result;
|
||||
return owner.getBattle()->battleGetAvailableHexes(hoveredStack, true, true, nullptr);
|
||||
else
|
||||
return BattleHexArray();
|
||||
}
|
||||
|
||||
BattleHexArray BattleFieldController::getHighlightedHexesForSpellRange()
|
||||
@ -369,7 +358,7 @@ BattleHexArray BattleFieldController::getHighlightedHexesForSpellRange()
|
||||
spells::BattleCast event(owner.getBattle().get(), caster, mode, spell);
|
||||
auto shadedHexes = spell->battleMechanics(&event)->rangeInHexes(hoveredHex);
|
||||
|
||||
for(BattleHex shadedHex : shadedHexes)
|
||||
for(const BattleHex & shadedHex : shadedHexes)
|
||||
{
|
||||
if((shadedHex.getX() != 0) && (shadedHex.getX() != GameConstants::BFIELD_WIDTH - 1))
|
||||
result.insert(shadedHex);
|
||||
@ -412,7 +401,7 @@ BattleHexArray BattleFieldController::getHighlightedHexesForMovementTarget()
|
||||
|
||||
if(stack->doubleWide())
|
||||
{
|
||||
for(auto hex : availableHexes)
|
||||
for(const auto & hex : availableHexes)
|
||||
{
|
||||
if(stack->occupiedHex(hex) == hoveredHex)
|
||||
return {hoveredHex, hex};
|
||||
@ -424,7 +413,7 @@ BattleHexArray BattleFieldController::getHighlightedHexesForMovementTarget()
|
||||
|
||||
// Range limit highlight helpers
|
||||
|
||||
BattleHexArray BattleFieldController::getRangeHexes(BattleHex sourceHex, uint8_t distance)
|
||||
BattleHexArray BattleFieldController::getRangeHexes(const BattleHex & sourceHex, uint8_t distance)
|
||||
{
|
||||
BattleHexArray rangeHexes;
|
||||
|
||||
@ -442,7 +431,7 @@ BattleHexArray BattleFieldController::getRangeHexes(BattleHex sourceHex, uint8_t
|
||||
return rangeHexes;
|
||||
}
|
||||
|
||||
BattleHexArray BattleFieldController::getRangeLimitHexes(BattleHex hoveredHex, const BattleHexArray & rangeHexes, uint8_t distanceToLimit)
|
||||
BattleHexArray BattleFieldController::getRangeLimitHexes(const BattleHex & hoveredHex, const BattleHexArray & rangeHexes, uint8_t distanceToLimit)
|
||||
{
|
||||
BattleHexArray rangeLimitHexes;
|
||||
|
||||
@ -456,7 +445,7 @@ BattleHexArray BattleFieldController::getRangeLimitHexes(BattleHex hoveredHex, c
|
||||
return rangeLimitHexes;
|
||||
}
|
||||
|
||||
bool BattleFieldController::IsHexInRangeLimit(BattleHex hex, const BattleHexArray & rangeLimitHexes, int * hexIndexInRangeLimit)
|
||||
bool BattleFieldController::IsHexInRangeLimit(const BattleHex & hex, const BattleHexArray & rangeLimitHexes, int * hexIndexInRangeLimit)
|
||||
{
|
||||
bool hexInRangeLimit = false;
|
||||
|
||||
@ -478,7 +467,7 @@ std::vector<std::vector<BattleHex::EDir>> BattleFieldController::getOutsideNeigh
|
||||
if(wholeRangeHexes.empty())
|
||||
return output;
|
||||
|
||||
for(auto hex : rangeLimitHexes)
|
||||
for(const auto & hex : rangeLimitHexes)
|
||||
{
|
||||
// get all neighbours and their directions
|
||||
|
||||
@ -607,7 +596,7 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas)
|
||||
}
|
||||
}
|
||||
|
||||
Rect BattleFieldController::hexPositionLocal(BattleHex hex) const
|
||||
Rect BattleFieldController::hexPositionLocal(const BattleHex & hex) const
|
||||
{
|
||||
int x = 14 + ((hex.getY())%2==0 ? 22 : 0) + 44*hex.getX();
|
||||
int y = 86 + 42 *hex.getY();
|
||||
@ -616,7 +605,7 @@ Rect BattleFieldController::hexPositionLocal(BattleHex hex) const
|
||||
return Rect(x, y, w, h);
|
||||
}
|
||||
|
||||
Rect BattleFieldController::hexPositionAbsolute(BattleHex hex) const
|
||||
Rect BattleFieldController::hexPositionAbsolute(const BattleHex & hex) const
|
||||
{
|
||||
return hexPositionLocal(hex) + pos.topLeft();
|
||||
}
|
||||
@ -675,7 +664,7 @@ BattleHex BattleFieldController::getHexAtPosition(Point hoverPos)
|
||||
return BattleHex::INVALID;
|
||||
}
|
||||
|
||||
BattleHex::EDir BattleFieldController::selectAttackDirection(BattleHex myNumber)
|
||||
BattleHex::EDir BattleFieldController::selectAttackDirection(const BattleHex & myNumber)
|
||||
{
|
||||
const bool doubleWide = owner.stacksController->getActiveStack()->doubleWide();
|
||||
const BattleHexArray & neighbours = myNumber.getAllNeighbouringTiles();
|
||||
@ -749,7 +738,7 @@ BattleHex::EDir BattleFieldController::selectAttackDirection(BattleHex myNumber)
|
||||
return BattleHex::EDir(nearest);
|
||||
}
|
||||
|
||||
BattleHex BattleFieldController::fromWhichHexAttack(BattleHex attackTarget)
|
||||
BattleHex BattleFieldController::fromWhichHexAttack(const BattleHex & attackTarget)
|
||||
{
|
||||
BattleHex::EDir direction = selectAttackDirection(getHoveredHex());
|
||||
|
||||
|
Reference in New Issue
Block a user