Example #1
0
        private void AddToOpenList(NavigationNode _node, NavigationNode _parent, int _parentStartCost, NavigationNode _goalNode)
        {
            //first, calculate estimated distance from goal in 'steps'.
            float distance = Vector3.Distance(_node.WorldPosition, _goalNode.WorldPosition);

            //add the node plus it's accompanying info into the dictionary.
            OpenNodeInformation info = new OpenNodeInformation(_node, _parent, _parentStartCost);

            info.EstimatedDestinationCost = distance;
            m_openNodeList.Add(_node, info);
        }
Example #2
0
        /// <summary>
        /// Returns a path that excludes those on the exclusion list, if available.
        /// </summary>
        /// <param name="_startNode"></param>
        /// <param name="_endNode"></param>
        /// <param name="exclusionList"></param>
        /// <returns></returns>
        public List <NavigationNode> FindPathThatExcludesNodes(NavigationNode _startNode, NavigationNode _endNode, List <NavigationNode> exclusionList)
        {
            m_exclusionList = exclusionList;

            m_start = DateTime.Now;

            //clear everything.
            m_openNodeList.Clear();
            m_closedNodeList.Clear();
            m_pathNodeList = new List <NavigationNode>();

            //add the start node to the open list.
            AddToOpenList(_startNode, null, 0, _endNode);

            //start processing.
            bool pathFound = false;


            while (!pathFound)
            {
                bool failed;
                if (ProcessNodes(_endNode, out failed, true))
                {
                    pathFound = true;
                }

                if (failed)
                {
                    return(m_pathNodeList);
                }
            }

            RetracePath(_endNode, _startNode);

            m_timeTaken  = DateTime.Now - m_start;
            LastPathTime = m_timeTaken.Milliseconds.ToString();
            return(m_pathNodeList);
        }