mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-27 21:49:10 +02:00
Optimize battleAdjacentUnits method
This commit is contained in:
parent
a44bbf4527
commit
5375d61d1b
@ -1716,18 +1716,22 @@ bool CBattleInfoCallback::battleIsUnitBlocked(const battle::Unit * unit) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::set<const battle::Unit *> CBattleInfoCallback::battleAdjacentUnits(const battle::Unit * unit) const
|
||||
battle::Units CBattleInfoCallback::battleAdjacentUnits(const battle::Unit * unit) const
|
||||
{
|
||||
std::set<const battle::Unit *> ret;
|
||||
RETURN_IF_NOT_BATTLE(ret);
|
||||
RETURN_IF_NOT_BATTLE({});
|
||||
|
||||
for(auto hex : unit->getSurroundingHexes())
|
||||
const auto & hexes = unit->getSurroundingHexes();
|
||||
|
||||
const auto & units = battleGetUnitsIf([=](const battle::Unit * unit)
|
||||
{
|
||||
if(const auto * neighbour = battleGetUnitByPos(hex, true))
|
||||
ret.insert(neighbour);
|
||||
}
|
||||
const auto & unitHexes = unit->getHexes();
|
||||
for (const auto & hex : unitHexes)
|
||||
if (hexes.contains(hex))
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
return units;
|
||||
}
|
||||
|
||||
SpellID CBattleInfoCallback::getRandomBeneficialSpell(vstd::RNG & rand, const battle::Unit * caster, const battle::Unit * subject) const
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
bool battleCanShoot(const battle::Unit * attacker, BattleHex dest) const; //determines if stack with given ID shoot at the selected destination
|
||||
bool battleCanShoot(const battle::Unit * attacker) const; //determines if stack with given ID shoot in principle
|
||||
bool battleIsUnitBlocked(const battle::Unit * unit) const; //returns true if there is neighboring enemy stack
|
||||
std::set<const battle::Unit *> battleAdjacentUnits(const battle::Unit * unit) const;
|
||||
battle::Units battleAdjacentUnits(const battle::Unit * unit) const;
|
||||
|
||||
DamageEstimation calculateDmgRange(const BattleAttackInfo & info) const;
|
||||
|
||||
@ -173,4 +173,4 @@ protected:
|
||||
BattleHexArray getStoppers(BattleSide whichSidePerspective) const; //get hexes with stopping obstacles (quicksands)
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user