当前位置: 首页>>代码示例>>C++>>正文


C++ Path::GetLength方法代码示例

本文整理汇总了C++中Path::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Path::GetLength方法的具体用法?C++ Path::GetLength怎么用?C++ Path::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Path的用法示例。


在下文中一共展示了Path::GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FindNearest

int NavDijkstra::FindNearest(const Vector2& start, int type, Path& aPath, int iTurn)
{
	Init(start, iTurn);

	// Browse
	for (m_iHead = 0 ; m_iHead < m_aStep.size() && m_iHead < m_iQueue ; ++m_iHead)
	{
		uint id = m_aStep[m_iHead];

		Case& oCase = m_oPathGrid.GetCase(id);

		ASSERT(oCase.iCount != BLOCK);
		Vector2 vCoord = m_oPathGrid.GetCoord(id);
		ASSERT(m_oPathGrid.GetIndex(vCoord) == id);

		int dir_offset = rand() % CardDirCount;
		for (int dir = 0 ; dir < CardDirCount ; ++dir)
		{
			Vector2 vSideCoord = m_oPathGrid.GetCoord(vCoord, (EDirection)((dir + dir_offset)%CardDirCount));
			Case& oSideCase = m_oPathGrid.GetCase(vSideCoord);
			if (oSideCase.iCount == BLANK)
			{
				oSideCase.iCount = oCase.iCount + 1;
				oSideCase.iPreviousCase = id;
				ASSERT(m_oPathGrid.DistanceSq(m_oPathGrid.GetCoord(id), vSideCoord) == 1);
				uint iSideId = m_oPathGrid.GetIndex(vSideCoord);
				m_aStep[m_iQueue++] = iSideId;
			}

			const Square& square = m_pModelGrid->GetCase(vSideCoord);
			if (!square.IsWater())
			{
				int sqtype = None;

				if (!square.IsDiscovered(iTurn))	sqtype |= Undiscovered;
				if (!square.IsVisible())			sqtype |= Unvisible;
				if (square.IsFood())				sqtype |= Food;
				if (square.IsEnemyHill())			sqtype |= EnemyHill;
				if (square.HasEnemyAnt())			sqtype |= EnemyAnt;
				if (square.IsFriendHill())			sqtype |= FriendHill;
				if (square.HasFriendAnt())			sqtype |= FriendAnt;
				if (square.GetAntInfluence() > 0)	sqtype |= Safe;

				if (type & sqtype)
				{
					GetPath((oSideCase.iCount == BLOCK ? vCoord : vSideCoord), aPath);
					ASSERT(aPath.GetLength() > 0);
					return sqtype;
				}
			}
		}
	}

	return None;
}
开发者ID:beanhome,项目名称:dev,代码行数:55,代码来源:NavDijkstra.cpp


注:本文中的Path::GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。