Beispiel #1
0
        public bool GetNextTarget(Vector3D position, out Vector3D target, out float targetRadius, out IMyEntity relativeEntity)
        {
            target         = Vector3D.Zero;
            relativeEntity = null;
            targetRadius   = 0.8f;

            if (!m_isValid)
            {
                return(false);
            }

            if (m_pathPoints.Count == 0 || m_pathCompleted || !m_isValid)
            {
                m_pathPoints = m_pathfinding.GetPath(m_planet, position, m_destination.GetDestination());
                if (m_pathPoints.Count < 2)
                {
                    return(false);
                }

                // m_pathPoints[0] is the begin position
                m_currentPointIndex = 1;
            }
            if (m_currentPointIndex == m_pathPoints.Count - 1)
            {
                //try to generate more points by RequestPath(position, destination)
            }
            target = m_pathPoints[m_currentPointIndex];

            // check distance
            if (Math.Abs(Vector3.Distance(target, position)) < targetRadius)
            {
                if (m_currentPointIndex == m_pathPoints.Count - 1)
                {
                    m_pathCompleted = true;
                    return(false);
                }
                else
                {
                    m_currentPointIndex++;
                }

                target = m_pathPoints[m_currentPointIndex];
            }

            return(true);
        }