Пример #1
0
void CSkeletonGroup::BuildPath()
{
	// For offset spawning, will break with more then 4

	XMVECTOR vecOffsets[NUM_SKELETONS] = { { -SPAWN_OFFSET_VALUE, 0, SPAWN_OFFSET_VALUE }, { SPAWN_OFFSET_VALUE, 0, SPAWN_OFFSET_VALUE }/*
	{ -SPAWN_OFFSET_VALUE, 0, -SPAWN_OFFSET_VALUE }, { SPAWN_OFFSET_VALUE, 0, -SPAWN_OFFSET_VALUE }*/ };

	// The new Path
	vector<XMFLOAT3> newPath;

	// Find an active skeleton
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		CSkeleton* curSkeleton = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);
		if (curSkeleton->GetIsActive())
		{
			// Path to offset player position
			XMVECTOR mathOffsetPos = XMLoadFloat3(m_cpPlayer->GetPosition());
			mathOffsetPos += vecOffsets[i];
			XMFLOAT3 offsetPosition; XMStoreFloat3(&offsetPosition, mathOffsetPos);

			// Find the target node
			int nPlayerNodeIndex = curSkeleton->GetPathPlanner()->FindClosestNode(&offsetPosition);

			// Get the closest nodes
			int nSkeletonNodeIndex = curSkeleton->GetPathPlanner()->FindClosestNode(curSkeleton->GetPosition());

			// Build a path to the target
			newPath = curSkeleton->GetPathPlanner()->GeneratePath(nSkeletonNodeIndex, nPlayerNodeIndex, false);

			if (newPath.empty())
			{
				newPath.push_back(*curSkeleton->GetPlayer()->GetPosition());
				newPath.push_back(*curSkeleton->GetPosition());

			}
			else if (newPath.size() == 1)
			{
				newPath.push_back(*curSkeleton->GetPlayer()->GetPosition());

			}

			// Set the new path
			curSkeleton->SetPath(newPath);

			// Set the node on path
			curSkeleton->SetNodeOnPath(newPath.size() - 1);
		}
	}

	// Went back to path finding for each
	//// Set each skeleton's new path
	//for (size_t ske = 0; ske < m_vSkeletons.size(); ske++)
	//{
	//	reinterpret_cast<CSkeleton*>(m_vSkeletons[ske])->SetPath(newPath);
	//
	//	// Set the current node
	//	reinterpret_cast<CSkeleton*>(m_vSkeletons[ske])->SetNodeOnPath(newPath.size() - 1);
	//}
}