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); } }
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 } }
void CMole::ProcessHunt(float _fTimeDelta, CTask& _rTask) { UpdateTaskTargetPath(_fTimeDelta, _rTask); // If have target if (_rTask.HasTargetNode()) { CFVec2 vSteerForce; ComputeSteerForce(_rTask.GetNodeIdsPath().back(), vSteerForce); UpdateRotation(_fTimeDelta, vSteerForce); UpdatePosition(_fTimeDelta); } else { // Reached disternace position m_Tasks.pop(); } }