本文整理汇总了C++中CCircuitAI::GetThreatMap方法的典型用法代码示例。如果您正苦于以下问题:C++ CCircuitAI::GetThreatMap方法的具体用法?C++ CCircuitAI::GetThreatMap怎么用?C++ CCircuitAI::GetThreatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCircuitAI
的用法示例。
在下文中一共展示了CCircuitAI::GetThreatMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnUnitDamaged
void IFighterTask::OnUnitDamaged(CCircuitUnit* unit, CEnemyUnit* attacker)
{
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
CCircuitDef* cdef = unit->GetCircuitDef();
Unit* u = unit->GetUnit();
const float healthPerc = u->GetHealth() / u->GetMaxHealth();
if (unit->GetShield() != nullptr) {
const float minShield = circuit->GetSetupManager()->GetEmptyShield();
if ((healthPerc > cdef->GetRetreat()) && unit->IsShieldCharged(minShield)) {
if (cdef->IsRoleHeavy() && (healthPerc < 0.9f)) {
circuit->GetBuilderManager()->EnqueueRepair(IBuilderTask::Priority::NOW, unit);
}
return;
}
} else if ((healthPerc > cdef->GetRetreat()) && !unit->IsDisarmed(frame)) {
if (cdef->IsRoleHeavy() && (healthPerc < 0.9f)) {
circuit->GetBuilderManager()->EnqueueRepair(IBuilderTask::Priority::NOW, unit);
}
return;
} else if (healthPerc < 0.2f) { // stuck units workaround: they don't shoot and don't see distant threat
CRetreatTask* task = manager->GetCircuit()->GetMilitaryManager()->EnqueueRetreat();
manager->AssignTask(unit, task);
return;
}
CThreatMap* threatMap = circuit->GetThreatMap();
const float range = cdef->GetMaxRange();
if ((target == nullptr) || !target->IsInLOS()) {
CRetreatTask* task = circuit->GetMilitaryManager()->EnqueueRetreat();
manager->AssignTask(unit, task);
return;
}
const AIFloat3& pos = unit->GetPos(frame);
if ((target->GetPos().SqDistance2D(pos) > SQUARE(range)) ||
(threatMap->GetThreatAt(unit, pos) * 2 > threatMap->GetUnitThreat(unit)))
{
CRetreatTask* task = circuit->GetMilitaryManager()->EnqueueRetreat();
manager->AssignTask(unit, task);
return;
}
cowards.insert(unit);
}
示例2: 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;
}
示例3: CheckRepairer
void CRetreatTask::CheckRepairer(CCircuitUnit* unit)
{
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
CPathFinder* pathfinder = circuit->GetPathfinder();
AIFloat3 startPos = (*units.begin())->GetPos(frame);
AIFloat3 endPos;
float range;
bool isRepairer = (repairer != nullptr);
if (isRepairer) {
endPos = repairer->GetPos(frame);
range = pathfinder->GetSquareSize();
} else {
CFactoryManager* factoryManager = circuit->GetFactoryManager();
endPos = factoryManager->GetClosestHaven(unit);
if (endPos == -RgtVector) {
endPos = circuit->GetSetupManager()->GetBasePos();
}
range = factoryManager->GetAssistDef()->GetBuildDistance() * 0.6f + pathfinder->GetSquareSize();
}
circuit->GetTerrainManager()->CorrectPosition(startPos);
pathfinder->SetMapData(unit, circuit->GetThreatMap(), frame);
float prevCost = pathfinder->PathCost(startPos, endPos, range);
if (isRepairer && repairer->GetCircuitDef()->IsMobile()) {
prevCost /= 4;
}
endPos = unit->GetPos(frame);
float nextCost = pathfinder->PathCost(startPos, endPos, range);
if (unit->GetCircuitDef()->IsMobile()) {
nextCost /= 4;
}
if (prevCost > nextCost) {
SetRepairer(unit);
}
}
示例4: Execute
void CRetreatTask::Execute(CCircuitUnit* unit)
{
IUnitAction* act = static_cast<IUnitAction*>(unit->End());
if (!act->IsAny(IUnitAction::Mask::MOVE | IUnitAction::Mask::FIGHT)) {
return;
}
ITravelAction* travelAction = static_cast<ITravelAction*>(act);
CCircuitAI* circuit = manager->GetCircuit();
int frame = circuit->GetLastFrame();
CPathFinder* pathfinder = circuit->GetPathfinder();
AIFloat3 startPos = unit->GetPos(frame);
AIFloat3 endPos;
float range;
if (repairer != nullptr) {
endPos = repairer->GetPos(frame);
range = pathfinder->GetSquareSize();
} else {
CFactoryManager* factoryManager = circuit->GetFactoryManager();
endPos = factoryManager->GetClosestHaven(unit);
if (endPos == -RgtVector) {
endPos = circuit->GetSetupManager()->GetBasePos();
}
range = factoryManager->GetAssistDef()->GetBuildDistance() * 0.6f + pathfinder->GetSquareSize();
}
std::shared_ptr<F3Vec> pPath = std::make_shared<F3Vec>();
pathfinder->SetMapData(unit, circuit->GetThreatMap(), frame);
pathfinder->MakePath(*pPath, startPos, endPos, range);
if (pPath->empty()) {
pPath->push_back(endPos);
}
travelAction->SetPath(pPath);
unit->Update(circuit);
}
示例5: Execute
void IBuilderTask::Execute(CCircuitUnit* unit)
{
Unit* u = unit->GetUnit();
u->ExecuteCustomCommand(CMD_PRIORITY, {static_cast<float>(priority)});
CCircuitAI* circuit = manager->GetCircuit();
if (target != nullptr) {
Unit* tu = target->GetUnit();
u->Build(target->GetCircuitDef()->GetUnitDef(), tu->GetPos(), tu->GetBuildingFacing(), UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 60);
return;
}
CTerrainManager* terrainManager = circuit->GetTerrainManager();
UnitDef* buildUDef = buildDef->GetUnitDef();
if (buildPos != -RgtVector) {
if (circuit->GetMap()->IsPossibleToBuildAt(buildUDef, buildPos, facing)) {
u->Build(buildUDef, buildPos, facing, UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 60);
return;
} else {
terrainManager->RemoveBlocker(buildDef, buildPos, facing);
// FIXME: If enemy blocked position then reset will have no effect
// terrain->ResetBuildFrame();
}
}
circuit->GetThreatMap()->SetThreatType(unit);
// FIXME: Replace const 999.0f with build time?
if (circuit->IsAllyAware() && (cost > 999.0f)) {
// circuit->UpdateFriendlyUnits();
auto friendlies = std::move(circuit->GetCallback()->GetFriendlyUnitsIn(position, cost));
for (Unit* au : friendlies) {
CCircuitUnit* alu = circuit->GetFriendlyUnit(au);
if (alu == nullptr) {
continue;
}
if ((*alu->GetCircuitDef() == *buildDef) && au->IsBeingBuilt()) {
const AIFloat3& pos = au->GetPos();
if (terrainManager->CanBuildAt(unit, pos)) {
u->Build(buildUDef, pos, au->GetBuildingFacing(), UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 60);
utils::free_clear(friendlies);
return;
}
}
}
utils::free_clear(friendlies);
}
// Alter/randomize position
AIFloat3 pos;
if (isShake) {
AIFloat3 offset((float)rand() / RAND_MAX - 0.5f, 0.0f, (float)rand() / RAND_MAX - 0.5f);
pos = position + offset * SQUARE_SIZE * 16;
} else {
pos = position;
}
const float searchRadius = 200.0f * SQUARE_SIZE;
FindBuildSite(unit, pos, searchRadius);
if (buildPos != -RgtVector) {
terrainManager->AddBlocker(buildDef, buildPos, facing);
u->Build(buildUDef, buildPos, facing, UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 60);
} else {
// TODO: Select new proper BasePos, like near metal cluster.
int terWidth = terrainManager->GetTerrainWidth();
int terHeight = terrainManager->GetTerrainHeight();
float x = terWidth / 4 + rand() % (int)(terWidth / 2 + 1);
float z = terHeight / 4 + rand() % (int)(terHeight / 2 + 1);
AIFloat3 pos(x, circuit->GetMap()->GetElevationAt(x, z), z);
circuit->GetSetupManager()->SetBasePos(pos);
// Fallback to Guard/Assist/Patrol
manager->FallbackTask(unit);
}
}
示例6: Update
void CBReclaimTask::Update()
{
if (!isMetal) {
return;
}
CCircuitAI* circuit = manager->GetCircuit();
if (circuit->GetEconomyManager()->IsMetalFull()) {
manager->AbortTask(this);
} else if (!units.empty()) {
/*
* Update reclaim position
*/
// FIXME: Works only with 1 task per worker
CCircuitUnit* unit = *units.begin();
int frame = circuit->GetLastFrame();
const AIFloat3& pos = unit->GetPos(frame);
auto enemies = std::move(circuit->GetCallback()->GetEnemyUnitsIn(pos, 300.0f));
if (!enemies.empty()) {
for (Unit* enemy : enemies) {
if ((enemy != nullptr) && enemy->IsBeingBuilt()) {
unit->GetUnit()->ReclaimUnit(enemy, UNIT_COMMAND_OPTION_INTERNAL_ORDER, frame + FRAMES_PER_SEC * 60);
utils::free_clear(enemies);
return;
}
}
utils::free_clear(enemies);
}
auto features = std::move(circuit->GetCallback()->GetFeaturesIn(pos, 500.0f));
if (!features.empty()) {
CTerrainManager* terrainManager = circuit->GetTerrainManager();
circuit->GetThreatMap()->SetThreatType(unit);
AIFloat3 reclPos;
float minSqDist = std::numeric_limits<float>::max();
Resource* metalRes = circuit->GetEconomyManager()->GetMetalRes();
for (Feature* feature : features) {
AIFloat3 featPos = feature->GetPosition();
terrainManager->CorrectPosition(featPos); // Impulsed flying feature
if (!terrainManager->CanBuildAt(unit, featPos)) {
continue;
}
FeatureDef* featDef = feature->GetDef();
float reclaimValue = featDef->GetContainedResource(metalRes)/* * feature->GetReclaimLeft()*/;
delete featDef;
if (reclaimValue < 1.0f) {
continue;
}
float sqDist = pos.SqDistance2D(featPos);
if (sqDist < minSqDist) {
reclPos = featPos;
minSqDist = sqDist;
}
}
if (minSqDist < std::numeric_limits<float>::max()) {
const float radius = 8.0f; // unit->GetCircuitDef()->GetBuildDistance();
unit->GetUnit()->ReclaimInArea(reclPos, radius, UNIT_COMMAND_OPTION_INTERNAL_ORDER, frame + FRAMES_PER_SEC * 60);
}
utils::free_clear(features);
}
}
}