本文整理汇总了C++中CCircuitAI::GetPathfinder方法的典型用法代码示例。如果您正苦于以下问题:C++ CCircuitAI::GetPathfinder方法的具体用法?C++ CCircuitAI::GetPathfinder怎么用?C++ CCircuitAI::GetPathfinder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCircuitAI
的用法示例。
在下文中一共展示了CCircuitAI::GetPathfinder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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);
}