本文整理汇总了C++中Terrain::WhoIsOnTile方法的典型用法代码示例。如果您正苦于以下问题:C++ Terrain::WhoIsOnTile方法的具体用法?C++ Terrain::WhoIsOnTile怎么用?C++ Terrain::WhoIsOnTile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terrain
的用法示例。
在下文中一共展示了Terrain::WhoIsOnTile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConstructPath
void Pathfinder::ConstructPath(Tile* _goal, rVector<Node> &closedList, rVector<Goal> &pathList, bool _avoidEntities, unsigned char _allowedCost)
{
Terrain* terrain = Terrain::GetInstance();
Tile* lastTile = closedList[closedList.size() - 1].TilePointer;
pathList.push_back(lastTile);
for (int i = (int)(closedList.size() - 1); i > -1; i--)
{
if (closedList[i].Parent == nullptr)
continue;
int dx = abs(closedList[i].Parent->X - lastTile->X);
int dy = abs(closedList[i].Parent->Y - lastTile->Y);
if (dx > 1 || dy > 1)
continue;
lastTile = closedList[i].Parent;
pathList.push_back(lastTile);
}
#if AI_DEBUG == 1
for (int i = 0; i < pathList.size(); i++)
{
pathList[i].Tile->DebugInfo = 14;
}
#endif
//cut PATH
int costCutoff = 0;
for ( int i = (int)(pathList.size() - 1); i > 1; --i )
{
for ( int j = 0; j < i - 1; ++j )
{
costCutoff = glm::min( _allowedCost, glm::min( pathList[i].Tile->Cost, pathList[j].Tile->Cost ) );
if (terrain->FreePathBool(pathList[i].Tile, pathList[j].Tile, _avoidEntities, terrain->WhoIsOnTile(m_Start), costCutoff, m_StartFloat2))
{
// erase from (j+1) to (i-1))
pathList.erase( pathList.begin() + (j+1), pathList.begin() + (i) );
i = j;
break;
}
}
}
#if AI_DEBUG == 1
for (int i = 0; i < pathList.size(); i++)
{
pathList[i].Tile->DebugInfo = 15;
}
#endif
}
示例2: Estimate
rVector<Goal> Pathfinder::AStar(Tile* _agentTile,bool _avoidEntities, unsigned char _allowedCost, bool _squadPathFinding)
{
// uint64_t T0, T1; // ticks
//
// uint64_t calcTimeLimit = 0;
// float ms = 500;
// m_TimeLimit = (uint64_t)(m_ClockFreq*ms / (1000));
// T0 = SDL_GetPerformanceCounter();
int counter = 0;
Terrain* terrain = Terrain::GetInstance();
rVector<Goal> pathList;
Entity agent = terrain->WhoIsOnTile(_agentTile);
//if first run, set current = start
if (m_ClosedList.size() == 0)
{
m_Current = m_Start;
m_Nodes[m_Start->Y][m_Start->X].Fcost = 0;
m_Nodes[m_Start->Y][m_Start->X].TilePointer = m_Current;
m_Nodes[m_Start->Y][m_Start->X].Parent = m_Current;
DirtyTile dt;
dt.x = m_Start->Y;
dt.y = m_Start->X;
m_Dirty.push_back(dt);
m_OpenQ.push(m_Nodes[m_Start->Y][m_Start->X]);
// #if GENERATE_AI_MAP == 1
// if (terrain->IsUnpathableTerrain(m_Goal))
// {
// DirtyTile dt;
// dt.x = m_Goal->X;
// dt.y = m_Goal->Y;
// m_BadTiles.push_back(dt);
// return pathList;
// }
// #else
if (!UnblockGoal())
{
return pathList;
}
//#endif
}
m_Finished = false;
while (true)
{
counter++;
// #pragma omp parallel num_threads(8)
// {
// #pragma omp critical
// printf("ID: %d, threads: %d, cpus: %d\n", omp_get_thread_num(), omp_get_num_threads(),omp_get_num_procs());
//#pragma omp for
for (int i = -1; i < 2; i++)
{
for (int j = -1; j < 2; j++)
{
if (i == 0 && j == 0)
continue;
int x, y;
x = (*m_Current).X + j;
y = (*m_Current).Y + i;
if (x < 0 || y < 0 || x > m_GridWidth - 1 || y > m_GridHeight - 1)
{
continue;
}
if (m_Nodes[x][y].Closed)
continue;
Tile* t = Terrain::GetInstance()->GetTile(x, y);
//unwalkable
if (Terrain::GetInstance()->IsUnpathableTerrain(t))
continue;
if(_avoidEntities)
{
if(Terrain::GetInstance()->IsOccupiedByNonEvasiveUnitExclude(t, agent))
continue;
}
int diagonal = i*j;
int gCost = 0;
//use integers instead of float, multiply 100. 141 == approx sqrt(2)
diagonal == 0 ? gCost = COST_FACTOR_STRAIGHT : gCost = COST_FACTOR_DIAGONAL;
if (t->Cost < _allowedCost)
gCost += ((_allowedCost - t->Cost) * COST_FACTOR_STRAIGHT) * 4;
//.........这里部分代码省略.........