本文整理汇总了C++中CCircuitAI::UpdateFriendlyUnits方法的典型用法代码示例。如果您正苦于以下问题:C++ CCircuitAI::UpdateFriendlyUnits方法的具体用法?C++ CCircuitAI::UpdateFriendlyUnits怎么用?C++ CCircuitAI::UpdateFriendlyUnits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCircuitAI
的用法示例。
在下文中一共展示了CCircuitAI::UpdateFriendlyUnits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void CSReclaimTask::Update()
{
CCircuitAI* circuit = manager->GetCircuit();
if (circuit->GetEconomyManager()->IsMetalFull()) {
manager->AbortTask(this);
} else if ((++updCount % 4 == 0) && !units.empty()) {
// Check for damaged units
CBuilderManager* builderManager = circuit->GetBuilderManager();
CAllyUnit* repairTarget = nullptr;
circuit->UpdateFriendlyUnits();
auto us = std::move(circuit->GetCallback()->GetFriendlyUnitsIn(position, radius * 0.9f));
for (Unit* u : us) {
CAllyUnit* candUnit = circuit->GetFriendlyUnit(u);
if ((candUnit == nullptr) || builderManager->IsReclaimed(candUnit)) {
continue;
}
if (!u->IsBeingBuilt() && (u->GetHealth() < u->GetMaxHealth())) {
repairTarget = candUnit;
break;
}
}
utils::free_clear(us);
if (repairTarget != nullptr) {
// Repair task
IBuilderTask* task = circuit->GetFactoryManager()->EnqueueRepair(IBuilderTask::Priority::NORMAL, repairTarget);
decltype(units) tmpUnits = units;
for (CCircuitUnit* unit : tmpUnits) {
manager->AssignTask(unit, task);
}
manager->AbortTask(this);
}
}
}
示例2: FindUnitToAssist
CCircuitUnit* CBRepairTask::FindUnitToAssist(CCircuitUnit* unit)
{
CCircuitUnit* target = nullptr;
Unit* su = unit->GetUnit();
const AIFloat3& pos = su->GetPos();
float maxSpeed = su->GetMaxSpeed();
float radius = unit->GetCircuitDef()->GetBuildDistance() + maxSpeed * FRAMES_PER_SEC * 30;
CCircuitAI* circuit = manager->GetCircuit();
circuit->UpdateFriendlyUnits();
auto units = std::move(circuit->GetCallback()->GetFriendlyUnitsIn(pos, radius));
for (auto u : units) {
if ((u != nullptr) && u->GetHealth() < u->GetMaxHealth() && u->GetVel().Length() <= maxSpeed * 1.5f) {
target = circuit->GetFriendlyUnit(u);
if (target != nullptr) {
break;
}
}
}
utils::free_clear(units);
return target;
}