本文整理汇总了C++中Squad::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Squad::clear方法的具体用法?C++ Squad::clear怎么用?C++ Squad::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Squad
的用法示例。
在下文中一共展示了Squad::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateDefenseSquadUnits
void CombatCommander::updateDefenseSquadUnits(Squad & defenseSquad, const size_t & flyingDefendersNeeded, const size_t & groundDefendersNeeded)
{
auto & squadUnits = defenseSquad.getUnits();
// TODO: right now this will assign arbitrary defenders, change this so that we make sure they can attack air/ground
// if there's nothing left to defend, clear the squad
if (flyingDefendersNeeded == 0 && groundDefendersNeeded == 0)
{
defenseSquad.clear();
return;
}
size_t defendersNeeded = flyingDefendersNeeded + groundDefendersNeeded;
size_t defendersAdded = 0;
while (defendersNeeded > defendersAdded)
{
UnitTag defenderToAdd = findClosestDefender(defenseSquad, defenseSquad.getSquadOrder().getPosition());
if (defenderToAdd)
{
m_squadData.assignUnitToSquad(defenderToAdd, defenseSquad);
defendersAdded++;
}
else
{
break;
}
}
}
示例2: updateDefenseSquadUnits
void CombatCommander::updateDefenseSquadUnits(Squad & defenseSquad, const size_t & flyingDefendersNeeded, const size_t & groundDefendersNeeded)
{
int zerglingsInOurBase = numZerglingsInOurBase();
bool zerglingRush = zerglingsInOurBase > 0 && BWAPI::Broodwar->getFrameCount() < 5000;
const BWAPI::Unitset & squadUnits = defenseSquad.getUnits();
size_t flyingDefendersInSquad = std::count_if(squadUnits.begin(), squadUnits.end(), UnitUtil::CanAttackAir);
size_t groundDefendersInSquad = std::count_if(squadUnits.begin(), squadUnits.end(), UnitUtil::CanAttackGround);
// if there's nothing left to defend, clear the squad
if (flyingDefendersNeeded == 0 && groundDefendersNeeded == 0)
{
defenseSquad.clear();
return;
}
// add flying defenders if we still need them
size_t flyingDefendersAdded = 0;
while (flyingDefendersNeeded > flyingDefendersInSquad + flyingDefendersAdded)
{
BWAPI::Unit defenderToAdd = findClosestDefender(defenseSquad, defenseSquad.getSquadOrder().getPosition(), true);
// if we find a valid flying defender, add it to the squad
if (defenderToAdd)
{
_squadData.assignUnitToSquad(defenderToAdd, defenseSquad);
++flyingDefendersAdded;
}
// otherwise we'll never find another one so break out of this loop
else
{
break;
}
}
// add ground defenders if we still need them
size_t groundDefendersAdded = 0;
while (groundDefendersNeeded > groundDefendersInSquad + groundDefendersAdded)
{
BWAPI::Unit defenderToAdd = findClosestDefender(defenseSquad, defenseSquad.getSquadOrder().getPosition(), false);
// if we find a valid ground defender add it
if (defenderToAdd)
{
_squadData.assignUnitToSquad(defenderToAdd, defenseSquad);
++groundDefendersAdded;
}
// otherwise we'll never find another one so break out of this loop
else
{
break;
}
}
}