本文整理汇总了C++中CCircuitAI类的典型用法代码示例。如果您正苦于以下问题:C++ CCircuitAI类的具体用法?C++ CCircuitAI怎么用?C++ CCircuitAI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCircuitAI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
void CAttackTask::Execute(CCircuitUnit* unit, bool isUpdating)
{
Unit* u = unit->GetUnit();
CCircuitAI* circuit = manager->GetCircuit();
CTerrainManager* terrainManager = circuit->GetTerrainManager();
float minSqDist;
CEnemyUnit* bestTarget = FindBestTarget(unit, minSqDist);
if (bestTarget == nullptr) {
if (!isUpdating) {
float x = rand() % (terrainManager->GetTerrainWidth() + 1);
float z = rand() % (terrainManager->GetTerrainHeight() + 1);
position = AIFloat3(x, circuit->GetMap()->GetElevationAt(x, z), z);
}
} else {
position = bestTarget->GetPos();
float range = u->GetMaxRange();
if (minSqDist < range * range) {
u->Attack(bestTarget->GetUnit(), UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 300);
return;
}
}
u->Fight(position, UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 300);
}
示例2: Update
void CRetreatTask::Update()
{
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
bool isExecute = (++updCount % 4 == 0);
auto assignees = units;
for (CCircuitUnit* unit : assignees) {
Unit* u = unit->GetUnit();
const float healthPerc = u->GetHealth() / u->GetMaxHealth();
bool isRepaired;
// FIXME: Wait until 101.0 engine
// if (ass->GetShield() != nullptr) {
// isRepaired = (healthPerc > 0.98f) && unit->IsShieldCharged(0.9f));
// } else {
isRepaired = healthPerc > 0.98f;
// }
if (isRepaired && !unit->IsDisarmed(frame)) {
RemoveAssignee(unit);
} else if (unit->IsForceExecute() || isExecute) {
Execute(unit);
} else {
unit->Update(circuit);
}
}
}
示例3: FindTarget
void CDefendTask::FindTarget()
{
CCircuitAI* circuit = manager->GetCircuit();
auto enemies = std::move(circuit->GetCallback()->GetEnemyUnitsIn(GetPosition(), radius));
if (enemies.empty()) {
enemies = std::move(circuit->GetCallback()->GetEnemyUnitsIn(circuit->GetSetupManager()->GetBasePos(), radius));
if (enemies.empty()) {
SetTarget(nullptr);
return;
}
}
CEnemyUnit* bestTarget = nullptr;
float minSqDist = std::numeric_limits<float>::max();
for (Unit* e : enemies) {
if (e == nullptr) {
continue;
}
CEnemyUnit* enemy = circuit->GetEnemyUnit(e);
if (enemy != nullptr) {
float sqDist = GetPosition().SqDistance2D(enemy->GetPos());
if (minSqDist > sqDist) {
minSqDist = sqDist;
bestTarget = enemy;
}
}
delete e;
}
SetTarget(bestTarget);
}
示例4: OnUnitIdle
void CRetreatTask::OnUnitIdle(CCircuitUnit* unit)
{
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
CFactoryManager* factoryManager = circuit->GetFactoryManager();
AIFloat3 haven = (repairer != nullptr) ? repairer->GetPos(frame) : factoryManager->GetClosestHaven(unit);
if (haven == -RgtVector) {
haven = circuit->GetSetupManager()->GetBasePos();
}
if (unit->GetCircuitDef()->IsPlane()) {
// force rearm/repair | CMD_FIND_PAD
unit->GetUnit()->Fight(haven, UNIT_COMMAND_OPTION_RIGHT_MOUSE_KEY, frame + FRAMES_PER_SEC * 60);
return;
}
const float maxDist = factoryManager->GetAssistDef()->GetBuildDistance();
const AIFloat3& unitPos = unit->GetPos(frame);
if (unitPos.SqDistance2D(haven) > maxDist * maxDist) {
// TODO: push MoveAction into unit? to avoid enemy fire
unit->GetUnit()->MoveTo(haven, UNIT_COMMAND_OPTION_RIGHT_MOUSE_KEY, frame + FRAMES_PER_SEC * 1);
// TODO: Add fail counter?
} else {
// TODO: push WaitAction into unit
// unit->GetUnit()->ExecuteCustomCommand(CMD_PRIORITY, {0.0f});
AIFloat3 pos = unitPos;
const float size = SQUARE_SIZE * 16;
CTerrainManager* terrainManager = circuit->GetTerrainManager();
float centerX = terrainManager->GetTerrainWidth() / 2;
float centerZ = terrainManager->GetTerrainHeight() / 2;
pos.x += (pos.x > centerX) ? size : -size;
pos.z += (pos.z > centerZ) ? size : -size;
AIFloat3 oldPos = pos;
terrainManager->CorrectPosition(pos);
if (oldPos.SqDistance2D(pos) > SQUARE_SIZE * SQUARE_SIZE) {
pos = unitPos;
pos.x += (pos.x > centerX) ? -size : size;
pos.z += (pos.z > centerZ) ? -size : size;
}
CTerrainManager::TerrainPredicate predicate = [unitPos](const AIFloat3& p) {
return unitPos.SqDistance2D(p) > SQUARE(SQUARE_SIZE * 8);
};
pos = terrainManager->FindBuildSite(unit->GetCircuitDef(), pos, maxDist, UNIT_COMMAND_BUILD_NO_FACING, predicate);
unit->GetUnit()->PatrolTo(pos);
IUnitAction* act = static_cast<IUnitAction*>(unit->End());
if (act->IsAny(IUnitAction::Mask::MOVE | IUnitAction::Mask::FIGHT)) {
static_cast<ITravelAction*>(act)->SetFinished(true);
}
}
}
示例5: Execute
void CDefendTask::Execute(CCircuitUnit* unit)
{
CCircuitAI* circuit = manager->GetCircuit();
CTerrainManager* terrainManager = circuit->GetTerrainManager();
AIFloat3 pos = utils::get_radial_pos(position, SQUARE_SIZE * 32);
terrainManager->CorrectPosition(pos);
pos = terrainManager->FindBuildSite(unit->GetCircuitDef(), pos, 300.0f, UNIT_COMMAND_BUILD_NO_FACING);
TRY_UNIT(circuit, unit,
unit->GetUnit()->Fight(pos, UNIT_COMMAND_OPTION_RIGHT_MOUSE_KEY, circuit->GetLastFrame() + FRAMES_PER_SEC * 60);
unit->GetUnit()->SetWantedMaxSpeed(MAX_UNIT_SPEED);
)
}
示例6: Update
void IFighterTask::Update()
{
CCircuitAI* circuit = manager->GetCircuit();
CMilitaryManager* militaryManager = circuit->GetMilitaryManager();
const float minShield = circuit->GetSetupManager()->GetEmptyShield();
decltype(units) tmpUnits = shields;
for (CCircuitUnit* unit : tmpUnits) {
if (!unit->IsShieldCharged(minShield)) {
CRetreatTask* task = militaryManager->EnqueueRetreat();
manager->AssignTask(unit, task);
}
}
}
示例7: OnUnitDamaged
void CBWaitTask::OnUnitDamaged(CCircuitUnit* unit, CEnemyUnit* attacker)
{
CCircuitAI* circuit = manager->GetCircuit();
const int frame = circuit->GetLastFrame();
CCircuitDef* cdef = unit->GetCircuitDef();
const float healthPerc = unit->GetHealthPercent();
if ((healthPerc > cdef->GetRetreat()) && !unit->IsDisarmed(frame)) {
return;
}
CRetreatTask* task = manager->GetCircuit()->GetBuilderManager()->EnqueueRetreat();
manager->AssignTask(unit, task);
}
示例8: Execute
void CBPatrolTask::Execute(CCircuitUnit* unit)
{
CCircuitAI* circuit = manager->GetCircuit();
Unit* u = unit->GetUnit();
TRY_UNIT(circuit, unit,
u->ExecuteCustomCommand(CMD_PRIORITY, {0.0f});
const float size = SQUARE_SIZE * 100;
CTerrainManager* terrainManager = circuit->GetTerrainManager();
AIFloat3 pos = position;
pos.x += (pos.x > terrainManager->GetTerrainWidth() / 2) ? -size : size;
pos.z += (pos.z > terrainManager->GetTerrainHeight() / 2) ? -size : size;
u->PatrolTo(pos);
)
}
示例9: Update
void CSuperTask::Update()
{
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
CCircuitUnit* unit = *units.begin();
CCircuitDef* cdef = unit->GetCircuitDef();
if (cdef->IsHoldFire()) {
if (targetFrame + (cdef->GetReloadTime() + TARGET_DELAY) > frame) {
if ((State::ENGAGE == state) && (targetFrame + TARGET_DELAY <= frame)) {
TRY_UNIT(circuit, unit,
unit->GetUnit()->Stop();
)
state = State::ROAM;
}
return;
}
示例10: 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);
}
}
}
示例11: Execute
void CArtilleryTask::Execute(CCircuitUnit* unit, bool isUpdating)
{
IUnitAction* act = static_cast<IUnitAction*>(unit->End());
if (!act->IsAny(IUnitAction::Mask::MOVE | IUnitAction::Mask::FIGHT | IUnitAction::Mask::JUMP)) {
return;
}
ITravelAction* travelAction = static_cast<ITravelAction*>(act);
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
const AIFloat3& pos = unit->GetPos(frame);
std::shared_ptr<F3Vec> pPath = std::make_shared<F3Vec>();
CEnemyUnit* bestTarget = FindTarget(unit, pos, *pPath);
if (bestTarget != nullptr) {
TRY_UNIT(circuit, unit,
unit->GetUnit()->Attack(bestTarget->GetUnit(), UNIT_COMMAND_OPTION_RIGHT_MOUSE_KEY, frame + FRAMES_PER_SEC * 60);
unit->GetUnit()->ExecuteCustomCommand(CMD_UNIT_SET_TARGET, {(float)bestTarget->GetId()});
)
示例12: Update
void IBuilderTask::Update()
{
CCircuitAI* circuit = manager->GetCircuit();
// for (auto unit : units) {
// IUnitAction* action = static_cast<IUnitAction*>(unit->Begin());
// if (action->GetType() == IUnitAction::Type::PRE_BUILD) {
// Unit* u = unit->GetUnit();
// const AIFloat3& vel = u->GetVel();
// Resource* metal = circuit->GetEconomyManager()->GetMetalRes();
// if ((vel == ZeroVector) && (u->GetResourceUse(metal) <= 0)) {
// // TODO: Something is on build site, get standing units in radius and push them.
// }
// }
// }
// FIXME: Replace const 1000.0f with build time?
if ((cost > 1000.0f) && (circuit->GetEconomyManager()->GetAvgMetalIncome() < savedIncome * 0.6f)) {
manager->AbortTask(this);
}
}
示例13: IUnitTask
IBuilderTask::IBuilderTask(ITaskManager* mgr, Priority priority,
CCircuitDef* buildDef, const AIFloat3& position,
BuildType type, float cost, bool isShake, int timeout)
: IUnitTask(mgr, priority, Type::BUILDER)
, position(position)
, isShake(isShake)
, buildDef(buildDef)
, buildType(type)
, buildPower(.0f)
, cost(cost)
, target(nullptr)
, buildPos(-RgtVector)
, facing(UNIT_COMMAND_BUILD_NO_FACING)
, nextTask(nullptr)
, timeout(timeout)
, buildFails(0)
{
CCircuitAI* circuit = manager->GetCircuit();
lastTouched = circuit->GetLastFrame();
savedIncome = circuit->GetEconomyManager()->GetAvgMetalIncome();
}
示例14: 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;
}
示例15: FindBestTarget
CEnemyUnit* CAttackTask::FindBestTarget(CCircuitUnit* unit, float& minSqDist)
{
CCircuitAI* circuit = manager->GetCircuit();
CTerrainManager* terrainManager = circuit->GetTerrainManager();
CThreatMap* threatMap = circuit->GetThreatMap();
const AIFloat3& pos = unit->GetUnit()->GetPos();
STerrainMapArea* area = unit->GetArea();
float power = threatMap->GetUnitThreat(unit);
int canTargetCat = unit->GetCircuitDef()->GetTargetCategory();
CEnemyUnit* bestTarget = nullptr;
minSqDist = std::numeric_limits<float>::max();
threatMap->SetThreatType(unit);
const CCircuitAI::EnemyUnits& enemies = circuit->GetEnemyUnits();
for (auto& kv : enemies) {
CEnemyUnit* enemy = kv.second;
if (enemy->IsHidden() || (threatMap->GetThreatAt(enemy->GetPos()) >= power) ||
!terrainManager->CanMoveToPos(area, enemy->GetPos()))
{
continue;
}
if (((canTargetCat & circuit->GetWaterCategory()) == 0) && (enemy->GetPos().y < -SQUARE_SIZE * 4)) {
continue;
}
CCircuitDef* edef = enemy->GetCircuitDef();
if ((edef != nullptr) && ((edef->GetCategory() & canTargetCat) == 0)) {
continue;
}
float sqDist = pos.SqDistance2D(enemy->GetPos());
if (sqDist < minSqDist) {
bestTarget = enemy;
minSqDist = sqDist;
}
}
return bestTarget;
}