本文整理汇总了C++中bwapi::Unitset类的典型用法代码示例。如果您正苦于以下问题:C++ Unitset类的具体用法?C++ Unitset怎么用?C++ Unitset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Unitset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: immediateThreat
bool ScoutManager::immediateThreat()
{
BWAPI::Unitset enemyAttackingWorkers;
for (auto & unit : BWAPI::Broodwar->enemy()->getUnits())
{
if (unit->getType().isWorker() && unit->isAttacking())
{
enemyAttackingWorkers.insert(unit);
}
}
if (_workerScout->isUnderAttack())
{
return true;
}
for (auto & unit : BWAPI::Broodwar->enemy()->getUnits())
{
double dist = unit->getDistance(_workerScout);
double range = unit->getType().groundWeapon().maxRange();
if (unit->getType().canAttack() && !unit->getType().isWorker() && (dist <= range + 32))
{
return true;
}
}
return false;
}
示例2: getClosestUnitToPosition
BWAPI::Unit ProductionManager::getClosestUnitToPosition(const BWAPI::Unitset & units, BWAPI::Position closestTo)
{
if (units.size() == 0)
{
return nullptr;
}
// if we don't care where the unit is return the first one we have
if (closestTo == BWAPI::Positions::None)
{
return *(units.begin());
}
BWAPI::Unit closestUnit = nullptr;
double minDist(1000000);
for (auto & unit : units)
{
UAB_ASSERT(unit != nullptr, "Unit was null");
double distance = unit->getDistance(closestTo);
if (!closestUnit || distance < minDist)
{
closestUnit = unit;
minDist = distance;
}
}
return closestUnit;
}
示例3: getMineralPatchesNearDepot
BWAPI::Unitset WorkerData::getMineralPatchesNearDepot(BWAPI::Unit depot)
{
// if there are minerals near the depot, add them to the set
BWAPI::Unitset mineralsNearDepot;
int radius = 300;
for (auto & unit : BWAPI::Broodwar->getAllUnits())
{
if ((unit->getType() == BWAPI::UnitTypes::Resource_Mineral_Field) && unit->getDistance(depot) < radius)
{
mineralsNearDepot.insert(unit);
}
}
// if we didn't find any, use the whole map
if (mineralsNearDepot.empty())
{
for (auto & unit : BWAPI::Broodwar->getAllUnits())
{
if ((unit->getType() == BWAPI::UnitTypes::Resource_Mineral_Field))
{
mineralsNearDepot.insert(unit);
}
}
}
return mineralsNearDepot;
}
示例4: StayPut
void CombatCommander::StayPut() {
Squad & stayPut = _squadData.getSquad("StayPut");
// defend untill we have a science vessel
if (_combatUnits.empty() || BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Terran_Science_Vessel) == 1)
{
return;
}
for (auto & unit : _combatUnits)
{
// get every unit of a lower priority and put it into the defense squad
if (!unit->getType().isWorker() && (unit->getType() != BWAPI::UnitTypes::Zerg_Overlord) && _squadData.canAssignUnitToSquad(unit, stayPut))
{
// if theres a bunker with room, go into it
for (auto unit2 : BWAPI::Broodwar->self()->getUnits()){
if ((*unit2).getType() == BWAPI::UnitTypes::Terran_Bunker){
BWAPI::Unit bunker = BWAPI::Broodwar->getUnit((*unit2).getID());
BWAPI::Unitset set = bunker->getLoadedUnits();
if (set.size() < 4) {
(*unit).rightClick(bunker);
}
}
}
// add units to squad
_squadData.assignUnitToSquad(unit, stayPut);
}
}
// fufill squad order
SquadOrder mainAttackOrder(SquadOrderTypes::Defend, defensePos, 300, "Attack Enemy Base");
stayPut.setSquadOrder(mainAttackOrder);
}
示例5: computeResourceBox
void BuildingPlacer::computeResourceBox()
{
BWAPI::Position start(BWAPI::Broodwar->self()->getStartLocation());
BWAPI::Unitset unitsAroundNexus;
for (auto & unit : BWAPI::Broodwar->getAllUnits())
{
// if the units are less than 400 away add them if they are resources
if (unit->getDistance(start) < 300 && unit->getType().isMineralField())
{
unitsAroundNexus.insert(unit);
}
}
for (auto & unit : unitsAroundNexus)
{
int x = unit->getPosition().x;
int y = unit->getPosition().y;
int left = x - unit->getType().dimensionLeft();
int right = x + unit->getType().dimensionRight() + 1;
int top = y - unit->getType().dimensionUp();
int bottom = y + unit->getType().dimensionDown() + 1;
_boxTop = top < _boxTop ? top : _boxTop;
_boxBottom = bottom > _boxBottom ? bottom : _boxBottom;
_boxLeft = left < _boxLeft ? left : _boxLeft;
_boxRight = right > _boxRight ? right : _boxRight;
}
//BWAPI::Broodwar->printf("%d %d %d %d", boxTop, boxBottom, boxLeft, boxRight);
}
示例6: getMainAttackLocation
BWAPI::Position CombatCommander::getMainAttackLocation()
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
// First choice: Attack an enemy region if we can see units inside it
if (enemyBaseLocation)
{
BWAPI::Position enemyBasePosition = enemyBaseLocation->getPosition();
// get all known enemy units in the area
BWAPI::Unitset enemyUnitsInArea;
MapGrid::Instance().GetUnits(enemyUnitsInArea, enemyBasePosition, 800, false, true);
bool onlyOverlords = true;
for (auto & unit : enemyUnitsInArea)
{
if (unit->getType() != BWAPI::UnitTypes::Zerg_Overlord)
{
onlyOverlords = false;
}
}
if (!BWAPI::Broodwar->isExplored(BWAPI::TilePosition(enemyBasePosition)) || !enemyUnitsInArea.empty())
{
if (!onlyOverlords)
{
return enemyBaseLocation->getPosition();
}
}
}
// Second choice: Attack known enemy buildings
for (const auto & kv : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
const UnitInfo & ui = kv.second;
if (ui.type.isBuilding() && ui.lastPosition != BWAPI::Positions::None)
{
return ui.lastPosition;
}
}
// Third choice: Attack visible enemy units that aren't overlords
for (auto & unit : BWAPI::Broodwar->enemy()->getUnits())
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
continue;
}
if (UnitUtil::IsValidUnit(unit) && unit->isVisible())
{
return unit->getPosition();
}
}
// Fourth choice: We can't see anything so explore the map attacking along the way
return MapGrid::Instance().getLeastExplored();
}
示例7: executeMicro
void MedicManager::executeMicro(const BWAPI::Unitset & targets)
{
const BWAPI::Unitset & medics = getUnits();
// create a set of all medic targets
BWAPI::Unitset medicTargets;
for (auto & unit : BWAPI::Broodwar->self()->getUnits())
{
if (unit->getHitPoints() < unit->getInitialHitPoints() && !unit->getType().isMechanical() && !unit->getType().isBuilding())
{
medicTargets.insert(unit);
}
}
BWAPI::Unitset availableMedics(medics);
// for each target, send the closest medic to heal it
for (auto & target : medicTargets)
{
// only one medic can heal a target at a time
if (target->isBeingHealed())
{
continue;
}
double closestMedicDist = std::numeric_limits<double>::infinity();
BWAPI::Unit closestMedic = nullptr;
for (auto & medic : availableMedics)
{
double dist = medic->getDistance(target);
if (!closestMedic || (dist < closestMedicDist))
{
closestMedic = medic;
closestMedicDist = dist;
}
}
// if we found a medic, send it to heal the target
if (closestMedic)
{
closestMedic->useTech(BWAPI::TechTypes::Healing, target);
availableMedics.erase(closestMedic);
}
// otherwise we didn't find a medic which means they're all in use so break
else
{
break;
}
}
// the remaining medics should head to the squad order position
for (auto & medic : availableMedics)
{
Micro::SmartAttackMove(medic, order.getPosition());
}
}
示例8: getTarget
// get a target for the zealot to attack
BWAPI::Unit TankManager::getTarget(BWAPI::Unit tank, const BWAPI::Unitset & targets)
{
int bestPriorityDistance = 1000000;
int bestPriority = 0;
double bestLTD = 0;
BWAPI::Unit bestTargetThreatInRange = nullptr;
double bestTargetThreatInRangeLTD = 0;
int highPriority = 0;
double closestDist = std::numeric_limits<double>::infinity();
BWAPI::Unit closestTarget = nullptr;
int siegeTankRange = BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode.groundWeapon().maxRange() - 32;
BWAPI::Unitset targetsInSiegeRange;
for (auto & target : targets)
{
if (target->getDistance(tank) < siegeTankRange && UnitUtil::CanAttack(tank, target))
{
targetsInSiegeRange.insert(target);
}
}
const BWAPI::Unitset & newTargets = targetsInSiegeRange.empty() ? targets : targetsInSiegeRange;
// check first for units that are in range of our attack that can cause damage
// choose the highest priority one from them at the lowest health
for (const auto & target : newTargets)
{
if (!UnitUtil::CanAttack(tank, target))
{
continue;
}
double distance = tank->getDistance(target);
double LTD = UnitUtil::CalculateLTD(target, tank);
int priority = getAttackPriority(tank, target);
bool targetIsThreat = LTD > 0;
BWAPI::Broodwar->drawTextMap(target->getPosition(), "%d", priority);
if (!closestTarget || (priority > highPriority) || (priority == highPriority && distance < closestDist))
{
closestDist = distance;
highPriority = priority;
closestTarget = target;
}
}
if (bestTargetThreatInRange)
{
return bestTargetThreatInRange;
}
return closestTarget;
}
示例9: unitNearEnemy
bool Squad::unitNearEnemy(BWAPI::Unit unit)
{
assert(unit);
BWAPI::Unitset enemyNear;
MapGrid::Instance().GetUnits(enemyNear, unit->getPosition(), 400, false, true);
return enemyNear.size() > 0;
}
示例10: assignTargetsOld
void InterceptorManager::assignTargetsOld(const BWAPI::Unitset & targets)
{
const BWAPI::Unitset & rangedUnits = getUnits();
// figure out targets
BWAPI::Unitset rangedUnitTargets;
for (auto & target : targets)
{
// conditions for targeting
if (!(target->getType() == BWAPI::UnitTypes::Zerg_Larva) &&
!(target->getType() == BWAPI::UnitTypes::Zerg_Egg) &&
!(target->getType() == BWAPI::UnitTypes::Buildings) &&
(target->isTargetable()) &&
target->isVisible() &&
target->getType() != BWAPI::UnitTypes::Resource_Vespene_Geyser)
{
rangedUnitTargets.insert(target);
}
}
auto attacker2target = assignEnemy(rangedUnits, rangedUnitTargets);
BWAPI::Position shome = BWAPI::Position(BWTA::getStartLocation(BWAPI::Broodwar->self())->getPosition());
for (auto & rangedUnit : rangedUnits)
{
// train sub units such as scarabs or interceptors
//trainSubUnits(rangedUnit);
// if the order is to attack or defend
if (order.getType() == SquadOrderTypes::Attack || order.getType() == SquadOrderTypes::Defend)
{
// if there are targets
if (!rangedUnitTargets.empty())
{
// find the best target for this zealot
auto targetIdx = attacker2target.find(rangedUnit);
BWAPI::Unit target = targetIdx == attacker2target.end() ? getTarget(rangedUnit, rangedUnitTargets) : targetIdx->first;
if (target && Config::Debug::DrawUnitTargetInfo)
{
BWAPI::Broodwar->drawLineMap(rangedUnit->getPosition(), rangedUnit->getTargetPosition(), BWAPI::Colors::Purple);
}
Micro::SmartAttackUnit(rangedUnit, target);
}
// if there are no targets
else
{
// if we're not near the order position
if (rangedUnit->getDistance(order.getPosition()) > 100)
{
// move to it
Micro::SmartAttackMove(rangedUnit, order.getPosition());
}
}
}
}
}
示例11: assignUnit
void GameCommander::assignUnit(BWAPI::Unit unit, BWAPI::Unitset & set)
{
if (_scoutUnits.contains(unit)) { _scoutUnits.erase(unit); }
else if (_combatUnits.contains(unit)) { _combatUnits.erase(unit); }
set.insert(unit);
}
示例12: move
void ECGStarcraftManager::move(Message* message, bool* blocking)
{
UnitDescriptor commandedUnits = message->readCommandedUnit();
BWAPI::Position landmark = message->readLandmark();
Region region = message->readRegion();
BWAPI::Unitset movers = ECGUtil::resolveUnitDescriptor(commandedUnits);
BWAPI::Position destination = ECGUtil::resolveLocation(region, landmark);
if (!movers.empty())
movers.move(destination);
// TODO: register boolean army event to make sure they moved
if (blocking != nullptr)
*blocking = false;
}
示例13: onSendText
void DevAIModule::onSendText(std::string text)
{
if (text == "/morph")
{
BWAPI::Unitset larvae = self->getUnits();
larvae.erase_if(Filter::GetType != UnitTypes::Zerg_Larva);
if (!larvae.empty())
{
if (!(*larvae.begin())->morph(UnitTypes::Zerg_Mutalisk))
{
Broodwar << bw->getLastError() << ":" << self->incompleteUnitCount(UnitTypes::Zerg_Greater_Spire) << ":" << self->incompleteUnitCount(UnitTypes::Zerg_Spire) << std::endl;
}
}
}
Broodwar->sendText("%s", text.c_str());
}
示例14: setAllUnits
void Squad::setAllUnits()
{
// clean up the _units vector just in case one of them died
BWAPI::Unitset goodUnits;
for (auto & unit : _units)
{
if( unit->isCompleted() &&
unit->getHitPoints() > 0 &&
unit->exists() &&
unit->getPosition().isValid() &&
unit->getType() != BWAPI::UnitTypes::Unknown)
{
goodUnits.insert(unit);
}
}
_units = goodUnits;
}
示例15: assignTargetsOld
void LurkerManager::assignTargetsOld(const BWAPI::Unitset & targets)
{
const BWAPI::Unitset & LurkerUnits = getUnits();
// figure out targets
BWAPI::Unitset LurkerUnitTargets;
std::copy_if(targets.begin(), targets.end(), std::inserter(LurkerUnitTargets, LurkerUnitTargets.end()), [](BWAPI::Unit u){ return u->isVisible() && !u->isFlying(); });
for (auto & LurkerUnit : LurkerUnits)
{
/* We don't care what the order is, we just want to attack */
// if the order is to attack or defend
//if (order.getType() == SquadOrderTypes::Attack || order.getType() == SquadOrderTypes::Defend)
//{
// if there are targets
//if (!LurkerUnitTargets.empty())
//{
// find the best target for this lurker
BWAPI::Unit target = getTarget(LurkerUnit, LurkerUnitTargets);
if (target && Config::Debug::DrawUnitTargetInfo)
{
BWAPI::Broodwar->drawLineMap(LurkerUnit->getPosition(), LurkerUnit->getTargetPosition(), BWAPI::Colors::Purple);
}
// burrow and attack it
if (targetsInRange(LurkerUnit, targets) > 0) {
LurkerUnit->burrow();
Micro::SmartAttackUnit(LurkerUnit, target);
}
else if (targetsInRange(LurkerUnit,targets) == 0){
LurkerUnit->unburrow();
Micro::SmartMove(LurkerUnit, order.getPosition());
}
}
// if there are no targets
//else
//{
// LurkerUnit->unburrow();
// if we're not near the order position
//Micro::SmartMove(LurkerUnit, order.getPosition());
//}
//}
//}
}