Beispiel #1
0
        private void SetNextTarget()
        {
            Vector3D?prevTarget = TargetWorld;

            if (m_path == null || !m_path.IsValid)
            {
                UnsetTarget();
                return;
            }

            IMyDestinationShape dest         = m_path.Destination;
            Vector3D            closestPoint = dest.GetClosestPoint(CapsuleCenter());
            double distSq = TargetDistanceSq(ref closestPoint);

            // TODO: Get rid of the ad-hoc numbers and use goal shapes

            if (distSq > END_RADIUS * END_RADIUS)
            {
                float    radius;
                Vector3D targetWorld;
                MyEntity relativeEntity;

                Vector3D currentParentPosition = Parent.PositionAndOrientation.Translation;
                if (m_path.PathCompleted)
                {
                    if (distSq < DISTANCE_FOR_FINAL_APPROACH * DISTANCE_FOR_FINAL_APPROACH)
                    {
                        var endEntity = m_path.EndEntity;
                        UnsetPath();
                        SetTarget(closestPoint, END_RADIUS, endEntity, m_weight);
                        return;
                    }
                    else
                    {
                        if (prevTarget.HasValue)
                        {
                            m_path.Reinit(prevTarget.Value);
                        }
                        else
                        {
                            m_path.Reinit(currentParentPosition);
                        }
                    }
                }

                ProfilerShort.Begin("MySmartPath.GetNextTarget");
                MyPathfindingStopwatch.Start();
                bool result = m_path.GetNextTarget(Parent.PositionAndOrientation.Translation, out targetWorld, out radius, out relativeEntity);
                MyPathfindingStopwatch.Stop();
                ProfilerShort.End();

                if (result)
                {
                    SetTarget(targetWorld, radius, relativeEntity, m_weight);
                    return;
                }
            }

            UnsetPath();
        }
Beispiel #2
0
 public MyRDPath(MyRDPathfinding pathfinding, Vector3D begin, IMyDestinationShape destination)
 {
     this.m_pathfinding       = pathfinding;
     this.m_destination       = destination;
     this.m_isValid           = true;
     this.m_currentPointIndex = 0;
     this.m_planet            = this.GetClosestPlanet(begin);
 }
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity relativeEntity)
        {
            // TODO: relativeEntity NOT IMPLEMENTED

            // FOR DEBUG DRAW
            var path = new MyRDPath(this, begin, end);

            return(path);
        }
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity relativeEntity)
        {
            // TODO: relativeEntity NOT IMPLEMENTED

            // FOR DEBUG DRAW
            var path = new MyRDPath(this, begin, end);

            return path;
        }
Beispiel #5
0
        public MyRDPath(MyRDPathfinding pathfinding, Vector3D begin, IMyDestinationShape destination)
        {
            m_pathPoints = new List<Vector3D>();

            m_pathfinding = pathfinding;
            m_destination = destination;
            m_isValid = true;
            m_currentPointIndex = 0;

            m_planet = GetClosestPlanet(begin);
        }
Beispiel #6
0
        public MyRDPath(MyRDPathfinding pathfinding, Vector3D begin, IMyDestinationShape destination)
        {
            m_pathPoints = new List <Vector3D>();

            m_pathfinding       = pathfinding;
            m_destination       = destination;
            m_isValid           = true;
            m_currentPointIndex = 0;

            m_planet = GetClosestPlanet(begin);
        }
Beispiel #7
0
 public void Goto(IMyDestinationShape destination, MyEntity relativeEntity = null)
 {
     if (MyAIComponent.Static.Pathfinding != null)
     {
         IMyPath path = MyAIComponent.Static.Pathfinding.FindPathGlobal(this.PositionAndOrientation.Translation, destination, relativeEntity);
         if (path != null)
         {
             this.m_path.SetPath(path, 1f);
             this.m_stuckDetection.Reset(false);
         }
     }
 }
Beispiel #8
0
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity entity = null)
        {
            if (!MyPerGameSettings.EnablePathfinding)
            {
                return(null);
            }
            MySmartGoal goal  = new MySmartGoal(end, entity);
            MySmartPath path1 = new MySmartPath(this);

            path1.Init(begin, goal);
            return(path1);
        }
        /// <summary>
        /// Tells the bot to go to the given world coordinate.
        /// If the relative entity is set, the coordinate is updated automatically as the entity moves
        /// </summary>
        public void Goto(IMyDestinationShape destination, MyEntity relativeEntity = null)
        {
            var path = MyAIComponent.Static.Pathfinding.FindPathGlobal(PositionAndOrientation.Translation, destination, relativeEntity);

            if (path == null)
            {
                return;
            }

            m_path.SetPath(path);
            m_stuckDetection.Reset();
        }
Beispiel #10
0
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, VRage.Game.Entity.MyEntity relativeEntity)
        {
            Vector3D  vectord;
            float     num;
            IMyEntity entity;
            MyRDPath  path = new MyRDPath(this, begin, end);

            if (!path.GetNextTarget(begin, out vectord, out num, out entity))
            {
                path = null;
            }
            return(path);
        }
Beispiel #11
0
 public MySmartGoal(IMyDestinationShape goal, MyEntity entity = null)
 {
     this.m_destination       = goal;
     this.m_destinationCenter = goal.GetDestination();
     this.m_endEntity         = entity;
     if (this.m_endEntity != null)
     {
         this.m_destination.SetRelativeTransform(this.m_endEntity.PositionComp.WorldMatrixNormalizedInv);
         this.m_endEntity.OnClosing += new Action <MyEntity>(this.m_endEntity_OnClosing);
     }
     this.m_pathfindingHeuristic = new Func <MyNavigationPrimitive, float>(this.Heuristic);
     this.m_terminationCriterion = new Func <MyNavigationPrimitive, float>(this.Criterion);
     this.m_ignoredPrimitives    = new HashSet <MyHighLevelPrimitive>();
     this.IsValid = true;
 }
Beispiel #12
0
        // MW:TODO optimize or change
        public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance)
        {
            m_reachPredicateDistance = thresholdDistance;
            var beginPrimitive = FindClosestPrimitive(begin, false);
            var endPrimitive   = FindClosestPrimitive(end.GetDestination(), false);

            if (beginPrimitive == null || endPrimitive == null)
            {
                return(false);
            }

            var beginHL = beginPrimitive.GetHighLevelPrimitive();
            var endHL   = endPrimitive.GetHighLevelPrimitive();

            ProfilerShort.Begin("HL");
            MySmartGoal goal = new MySmartGoal(end);
            var         path = goal.FindHighLevelPath(this, beginHL);

            ProfilerShort.End();
            if (path == null)
            {
                return(false);
            }

            m_reachEndPrimitive = endPrimitive;
            ProfilerShort.Begin("Prepare for travesal");
            PrepareTraversal(beginPrimitive, null, ReachablePredicate);
            ProfilerShort.End();
            ProfilerShort.Begin("checking for vertices");
            try
            {
                foreach (var vertex in this)
                {
                    if (vertex.Equals(m_reachEndPrimitive))
                    {
                        return(true);
                    }
                }
            }
            finally
            {
                ProfilerShort.End();
            }

            return(false);
        }
Beispiel #13
0
        public MySmartGoal(IMyDestinationShape goal, MyEntity entity = null)
        {
            m_destination = goal;
            m_destinationCenter = goal.GetCenter();
            m_endEntity = entity;
            if (m_endEntity != null)
            {
                m_destination.SetRelativeTransform(m_endEntity.PositionComp.WorldMatrixNormalizedInv);
                m_endEntity.OnClosing += m_endEntity_OnClosing;
            }

            m_pathfindingHeuristic = this.Heuristic;
            m_terminationCriterion = this.Criterion;

            m_ignoredPrimitives = new HashSet<MyHighLevelPrimitive>();
            IsValid = true;
        }
Beispiel #14
0
        public MySmartGoal(IMyDestinationShape goal, MyEntity entity = null)
        {
            m_destination       = goal;
            m_destinationCenter = goal.GetCenter();
            m_endEntity         = entity;
            if (m_endEntity != null)
            {
                m_destination.SetRelativeTransform(m_endEntity.PositionComp.WorldMatrixNormalizedInv);
                m_endEntity.OnClosing += m_endEntity_OnClosing;
            }

            m_pathfindingHeuristic = this.Heuristic;
            m_terminationCriterion = this.Criterion;

            m_ignoredPrimitives = new HashSet <MyHighLevelPrimitive>();
            IsValid             = true;
        }
Beispiel #15
0
        public MySmartPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity entity = null)
        {
            Debug.Assert(MyPerGameSettings.EnablePathfinding, "Pathfinding is not enabled!");
            if (!MyPerGameSettings.EnablePathfinding)
            {
                return(null);
            }

            ProfilerShort.Begin("MyPathfinding.FindPathGlobal");

            // CH: TODO: Use pooling
            MySmartPath newPath = new MySmartPath(this);
            MySmartGoal newGoal = new MySmartGoal(end, entity);

            newPath.Init(begin, newGoal);

            ProfilerShort.End();
            return(newPath);
        }
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity relativeEntity)
        {
            // TODO: relativeEntity NOT IMPLEMENTED

            // FOR DEBUG DRAW
            var path = new MyRDPath(this, begin, end);

            Vector3D targetPos;
            float    targetRadius;

            VRage.ModAPI.IMyEntity relEnt;
            // If no next target, path is not found
            if (!path.GetNextTarget(begin, out targetPos, out targetRadius, out relEnt))
            {
                path = null;
            }

            return(path);
        }
Beispiel #17
0
        public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance)
        {
            this.m_reachPredicateDistance = thresholdDistance;
            MyNavigationPrimitive startingVertex = this.FindClosestPrimitive(begin, false, null);
            MyNavigationPrimitive primitive2     = this.FindClosestPrimitive(end.GetDestination(), false, null);

            if ((startingVertex != null) && (primitive2 != null))
            {
                MyHighLevelPrimitive highLevelPrimitive = startingVertex.GetHighLevelPrimitive();
                primitive2.GetHighLevelPrimitive();
                if (new MySmartGoal(end, null).FindHighLevelPath(this, highLevelPrimitive) == null)
                {
                    return(false);
                }
                this.m_reachEndPrimitive = primitive2;
                base.PrepareTraversal(startingVertex, null, new Predicate <MyNavigationPrimitive>(this.ReachablePredicate), null);
                try
                {
                    using (MyPathFindingSystem <MyNavigationPrimitive> .Enumerator enumerator = base.GetEnumerator())
                    {
                        while (true)
                        {
                            if (!enumerator.MoveNext())
                            {
                                break;
                            }
                            if (enumerator.Current.Equals(this.m_reachEndPrimitive))
                            {
                                return(true);
                            }
                        }
                    }
                }
                finally
                {
                }
            }
            return(false);
        }
 public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance)
 {
     // TODO: IMPLEMENT THIS!!! Eventually...
     return true;
 }
Beispiel #19
0
 public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance) =>
 true;
Beispiel #20
0
 public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, VRage.Game.Entity.MyEntity relativeEntity) =>
 null;
        public IMyPath FindPathGlobal(Vector3D begin, IMyDestinationShape end, MyEntity relativeEntity)
        {
            // TODO: relativeEntity NOT IMPLEMENTED
            //if (m_visualNavmesh == null || m_navmeshOBBs.GetOBB(begin) == null)
            //    CreateNavmesh(begin);

            // FOR DEBUG DRAW
            /*var path = new MyRDPath(this, end);
            m_debugDrawPaths.Add(path);

            return path;  */
            return null;
        }
        /// <summary>
        /// Tells the bot to go to the given world coordinate.
        /// If the relative entity is set, the coordinate is updated automatically as the entity moves
        /// </summary>
        public void Goto(IMyDestinationShape destination, MyEntity relativeEntity = null)
        {
            if (MyAIComponent.Static.Pathfinding == null) return;

            var path = MyAIComponent.Static.Pathfinding.FindPathGlobal(PositionAndOrientation.Translation, destination, relativeEntity);
            if (path == null)
            {
                return;
            }

            m_path.SetPath(path);
            m_stuckDetection.Reset();
        }
 public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance)
 {
     // TODO: IMPLEMENT THIS!!! Eventually...
     return(true);
 }