本文整理汇总了C++中CNavArea::GetParent方法的典型用法代码示例。如果您正苦于以下问题:C++ CNavArea::GetParent方法的具体用法?C++ CNavArea::GetParent怎么用?C++ CNavArea::GetParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNavArea
的用法示例。
在下文中一共展示了CNavArea::GetParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ComputePath
// Compute shortest path to goal position via A* algorithm
// If 'goalArea' is NULL, path will get as close as it can.
bool CCSBot::ComputePath(CNavArea *goalArea, const Vector *goal, RouteType route)
{
// Throttle re-pathing
if (!m_repathTimer.IsElapsed())
return false;
// randomize to distribute CPU load
m_repathTimer.Start(RANDOM_FLOAT(0.4f, 0.6f));
DestroyPath();
CNavArea *startArea = m_lastKnownArea;
if (!startArea)
return false;
// note final specific position
Vector pathEndPosition;
if (!goal && !goalArea)
return false;
if (!goal)
pathEndPosition = *goalArea->GetCenter();
else
pathEndPosition = *goal;
// make sure path end position is on the ground
if (goalArea)
pathEndPosition.z = goalArea->GetZ(&pathEndPosition);
else
GetGroundHeight(&pathEndPosition, &pathEndPosition.z);
// if we are already in the goal area, build trivial path
if (startArea == goalArea)
{
BuildTrivialPath(&pathEndPosition);
return true;
}
// Compute shortest path to goal
CNavArea *closestArea = nullptr;
PathCost pathCost(this, route);
bool pathToGoalExists = NavAreaBuildPath(startArea, goalArea, goal, pathCost, &closestArea);
CNavArea *effectiveGoalArea = (pathToGoalExists) ? goalArea : closestArea;
// Build path by following parent links
// get count
int count = 0;
CNavArea *area;
for (area = effectiveGoalArea; area; area = area->GetParent())
{
count++;
}
// save room for endpoint
if (count > MAX_PATH_LENGTH - 1)
count = MAX_PATH_LENGTH - 1;
if (count == 0)
return false;
if (count == 1)
{
BuildTrivialPath(&pathEndPosition);
return true;
}
// build path
m_pathLength = count;
for (area = effectiveGoalArea; count && area; area = area->GetParent())
{
count--;
m_path[count].area = area;
m_path[count].how = area->GetParentHow();
}
// compute path positions
if (ComputePathPositions() == false)
{
PrintIfWatched("Error building path\n");
DestroyPath();
return false;
}
if (!goal)
{
switch (m_path[m_pathLength - 1].how)
{
case GO_NORTH:
case GO_SOUTH:
pathEndPosition.x = m_path[m_pathLength - 1].pos.x;
pathEndPosition.y = effectiveGoalArea->GetCenter()->y;
break;
case GO_EAST:
case GO_WEST:
pathEndPosition.x = effectiveGoalArea->GetCenter()->x;
//.........这里部分代码省略.........