예제 #1
0
void
CMole::UpdateTaskTargetPath(float _fTimeDelta, CTask& _rTask)
{
	// Has target
	if (_rTask.HasTargetNode())
	{
		const int kiTargetNodeId = _rTask.GetTargetNodeId();


		// Reached target
		if (s_pSharedPath->IsIntersectingNode(m_vPosition, m_fRadius, kiTargetNodeId))
		{
			_rTask.ClearTarget();
		}
		else
		{
			// Check path update needed
			if (_rTask.GetPathUpdateTimer() <= 0.0f)
			{
				// Refresh path
				std::vector<int> aNewPath;
				bool bPathFound = s_pSharedPath->FindPath(m_vPosition, kiTargetNodeId, aNewPath);


				if (bPathFound)
				{
					_rTask.SetNodeIdsPath(aNewPath);
				}


				_rTask.SetPathUpdateTimer(0.1f);
			}
			else
			{
				// Update timer
				_rTask.SetPathUpdateTimer(_rTask.GetPathUpdateTimer() - _fTimeDelta);
			}
		}
	}
	else
	{
		// Do nothing
	}
}
예제 #2
0
void
CMole::ProcessExplore(float _fTimeDelta, CTask& _rTask)
{
	UpdateTaskTargetPath(_fTimeDelta, _rTask);


	if (!_rTask.HasTargetNode() ||
		(s_pSharedPath->GetNode(_rTask.GetTargetNodeId()).bDiscovered && s_pSharedPath->HasUndiscoveredNodesLeft()))
	{
		int iTargetNodeId = 0;
		
		
		bool bFoundNode = s_pSharedPath->FindUndiscoveredNode(m_vPosition, m_fRadius, m_fHeading, iTargetNodeId);


		if (!bFoundNode)
		{
			s_pSharedPath->FindRandomAccesableNode(iTargetNodeId);
			bFoundNode = true;
		}


		if (bFoundNode)
		{
			_rTask.SetTargetNodeId(iTargetNodeId);
			UpdateTaskTargetPath(_fTimeDelta, _rTask);
		}
	}


	// If have target
	if (_rTask.HasTargetNode())
	{
		CFVec2 vSteerForce;
		ComputeSteerForce(_rTask.GetNodeIdsPath().back(), vSteerForce);


		UpdateRotation(_fTimeDelta, vSteerForce);
		UpdatePosition(_fTimeDelta);
	}
}
예제 #3
0
void
CMole::DrawTaskPathTarget(CTask& _rTask) const
{
	int iTargetNodeId = _rTask.GetTargetNodeId();
	const std::vector<int>& karNodeIdsPath = _rTask.GetNodeIdsPath();
	GDE::CRenderer* pRenderer = CMMMContext::GetInstance().GetRenderer();


	if (karNodeIdsPath.size() > 0)
	{
		// Draw line to first target
		const CFVec2& kvrNextPosition = s_pSharedPath->GetNode(karNodeIdsPath.back()).vPosition;


		GDE::SVertex FirstLine[2];
		FirstLine[0].m_uColour = 0xFF509999;
		FirstLine[1].m_uColour = 0xFF509999;


		FirstLine[0].m_fX = m_vPosition.X();
		FirstLine[0].m_fY = m_vPosition.Y();
		FirstLine[0].m_fZ = 0.0f;

		FirstLine[1].m_fX = kvrNextPosition.X();
		FirstLine[1].m_fY = kvrNextPosition.Y();
		FirstLine[1].m_fZ = 0.0f;


		pRenderer->DrawPrimitives(GDE::PT_LineList, 1, FirstLine);


		// Draw path lines
		for (int i = karNodeIdsPath.size() - 1; i > 0; -- i)
		{
			const CFVec2& kvrCurrentPosition = s_pSharedPath->GetNode(karNodeIdsPath[i]).vPosition;
			const CFVec2& kvrNextPosition = s_pSharedPath->GetNode(karNodeIdsPath[i - 1]).vPosition;


			GDE::SVertex Vertex[2];
			Vertex[0].m_uColour = 0xFF509999;
			Vertex[1].m_uColour = 0xFF509999;


			Vertex[0].m_fX = kvrCurrentPosition.X();
			Vertex[0].m_fY = kvrCurrentPosition.Y();
			Vertex[0].m_fZ = 0.0f;

			Vertex[1].m_fX = kvrNextPosition.X();
			Vertex[1].m_fY = kvrNextPosition.Y();
			Vertex[1].m_fZ = 0.0f;


			pRenderer->DrawPrimitives(GDE::PT_LineList, 1, Vertex);
		}
	}


	if (iTargetNodeId != -1)
	{
		// Draw cross on target
		const Path::TNode& ktrTargetNode = s_pSharedPath->GetNode(iTargetNodeId);


		GDE::SVertex Cross[4];
		Cross[0].m_uColour = 0xFF509999;
		Cross[1].m_uColour = 0xFF509999;
		Cross[2].m_uColour = 0xFF509999;
		Cross[3].m_uColour = 0xFF509999;


		// One
		Cross[0].m_fX = ktrTargetNode.vPosition.X() - 10;
		Cross[0].m_fY = ktrTargetNode.vPosition.Y() - 10;
		Cross[0].m_fZ = 0.0f;

		Cross[1].m_fX = ktrTargetNode.vPosition.X() + 10;
		Cross[1].m_fY = ktrTargetNode.vPosition.Y() + 10;
		Cross[1].m_fZ = 0.0f;


		// Two
		Cross[2].m_fX = ktrTargetNode.vPosition.X() - 10;
		Cross[2].m_fY = ktrTargetNode.vPosition.Y() + 10;
		Cross[2].m_fZ = 0.0f;

		Cross[3].m_fX = ktrTargetNode.vPosition.X() + 10;
		Cross[3].m_fY = ktrTargetNode.vPosition.Y() - 10;
		Cross[3].m_fZ = 0.0f;


		pRenderer->DrawPrimitives(GDE::PT_LineList, 2, Cross);
	}
}
예제 #4
0
void
CMole::ProcessPatrol(float _fTimeDelta, CTask& _rTask)
{
	// Check acorn is no longer avaiable
	if (_rTask.GetAcorn()->GetState() != CAcorn::ES_Available || 
		s_mKnownAcorns[_rTask.GetAcorn()] == false ||
		_rTask.GetAcorn()->GetMole() != this)
	{
		m_Tasks.pop();
		m_bHasPatrolTask = false;
	}
	else
	{
		UpdateTaskTargetPath(_fTimeDelta, _rTask);
		

		// Check have no target
		if (_rTask.GetTargetNodeId() == -1)
		{
			int iRandomTargetId = 0;


			// Find new target
			bool bRandomNodeFound = s_pSharedPath->FindRandomAccesableNode(_rTask.GetAcorn()->GetPosition(), PARTROL_RADIUS, iRandomTargetId);


			if (bRandomNodeFound)
			{
				std::vector<int> aNodeIdsPath;
				bool bPathFound = s_pSharedPath->FindPath(m_vPosition, iRandomTargetId, aNodeIdsPath);

			
				if (bPathFound)
				{
					_rTask.SetTargetNodeId(iRandomTargetId);
					_rTask.SetNodeIdsPath(aNodeIdsPath);
				}
				else
				{
					// Do nothing
				}
			}
			else
			{
				// Do nothing
			}
		}


		// Check has target
		if (_rTask.GetTargetNodeId() != -1)
		{
			
			CFVec2 vSteerForce;
			ComputeSteerForce(_rTask.GetNodeIdsPath().back(), vSteerForce);


			UpdateRotation(_fTimeDelta, vSteerForce);
			UpdatePosition(_fTimeDelta);


			// Check within in range of target to be able to add onto sleep timer
			if (sqrt(_rTask.GetAcorn()->GetPosition().SquareDistance(m_vPosition)) - PARTROL_RADIUS - (PARTROL_RADIUS / 4) <= 0.0f)
			{
				_rTask.Update(_fTimeDelta);


				// Check if have been patroling for 4 seconds
				if (_rTask.GetTimeElapsed() > 4.0f)
				{
					float fSleepTime = static_cast<float>(SLEEP_TIME) - (DIFFICULTY_SLEEP_TIME_DESC * m_iDifficultyLevel);


					// Sleep for 5 seconds
					AppendSnoozeTask(fSleepTime);
					_rTask.ResetTimeElapsed();
				}
				else
				{
					// Do nothing
				}
			}
		}
		else
		{
			// Do nothing
		}
	}
}