示例#1
0
        private bool MoveAndRotate()
        {
            INavigatorMover navM = m_navSet.Settings_Current.NavigatorMover;

            if (navM != null)
            {
                Profiler.Profile(navM.Move);

                INavigatorRotator navR = m_navSet.Settings_Current.NavigatorRotator;                 // fetched here because mover might remove it
                if (navR != null)
                {
                    Profiler.Profile(navR.Rotate);
                }
                else
                {
                    navR = m_navSet.Settings_Current.NavigatorMover as INavigatorRotator;                     // fetch again in case it was removed
                    if (navR != null)
                    {
                        Profiler.Profile(navR.Rotate);
                    }
                }

                Profiler.Profile(m_mover.MoveAndRotate);
                return(true);
            }
            return(false);
        }
示例#2
0
        public void TestPath(Vector3D destination, bool landing)
        {
            if (m_navSet.Settings_Current.DestinationChanged || m_prevMover != m_navSet.Settings_Current.NavigatorMover)
            {
                m_logger.debugLog("new destination: " + destination, Logger.severity.INFO);
                m_navSet.Settings_Task_NavWay.DestinationChanged = false;
                m_prevMover = m_navSet.Settings_Current.NavigatorMover;
                m_runId++;
                m_pathLow.Clear();
                ClearAltPath();
                m_pathState = PathState.Not_Running;
                m_planetCheckDest.Stop();
                m_planetCheckSpeed.Stop();
            }
            //else
            //	m_logger.debugLog("destination unchanged", "TestPath()");

            if (Globals.UpdateCount < m_nextRunPath)
                return;
            m_nextRunPath = Globals.UpdateCount + 10ul;

            if (m_pathLow.Count != 0)
            {
                m_logger.debugLog("path low is running");
                return;
            }

            m_navBlock = m_navSet.Settings_Current.NavigationBlock;
            m_destination = destination;
            m_ignoreAsteroid = m_navSet.Settings_Current.IgnoreAsteroid;
            m_landing = landing;
            m_canChangeCourse = m_navSet.Settings_Current.PathfinderCanChangeCourse;
            MyEntity destEntity = m_navSet.Settings_Current.DestinationEntity as MyEntity;
            m_logger.debugLog("DestinationEntity: " + m_navSet.Settings_Current.DestinationEntity.getBestName());
            byte runId = m_runId;

            const float minimumDistance = 100f;
            const float minDistSquared = minimumDistance * minimumDistance;
            const float seconds = 10f;
            const float distOverSeconds = minimumDistance / seconds;

            Vector3 displacement = destination - m_navBlock.WorldPosition;
            float distanceSquared = displacement.LengthSquared();
            float testDistance;
            Vector3 move_direction = m_grid.Physics.LinearVelocity;
            float speedSquared = move_direction.LengthSquared();
            if (distanceSquared > minDistSquared)
            {
                // only look ahead 10 s / 100 m
                testDistance = speedSquared < distOverSeconds ? minimumDistance : (float)Math.Sqrt(speedSquared) * seconds;
                if (testDistance * testDistance < distanceSquared)
                {
                    Vector3 direction = displacement / (float)Math.Sqrt(distanceSquared);
                    destination = m_navBlock.WorldPosition + testDistance * direction;
                    m_logger.debugLog("moved destination: " + destination + ", distance: " + testDistance + ", direction: " + direction);
                }
            }
            else
                m_logger.debugLog("using actual destination: " + destination);

            m_pathHigh.Enqueue(() => TestPath(destination, destEntity, runId, isAlternate: false, tryAlternates: true));
            if (m_ignoreAsteroid)
                m_planetCheckDest.Stop();
            else
                m_planetCheckDest.Start(destination - m_navBlock.WorldPosition);

            // given velocity and distance, calculate destination
            if (speedSquared > 1f)
            {
                Vector3D moveDest = m_navBlock.WorldPosition + move_direction * LookAheadSpeed_Seconds;
                m_pathHigh.Enqueue(() => TestPath(moveDest, null, runId, isAlternate: false, tryAlternates: false, slowDown: true));
                if (m_ignoreAsteroid)
                    m_planetCheckSpeed.Stop();
                else
                    m_planetCheckSpeed.Start(moveDest - m_navBlock.WorldPosition);
            }
            else
            {
                m_navSet.Settings_Task_NavWay.SpeedMaxRelative = float.MaxValue;
                m_navSet.Settings_Task_NavWay.SpeedTarget = float.MaxValue;
            }

            RunItem();
        }
示例#3
0
        public void TestPath(Vector3D destination, bool landing)
        {
            if (m_navSet.Settings_Current.DestinationChanged || m_prevMover != m_navSet.Settings_Current.NavigatorMover)
            {
                m_logger.debugLog("new destination: " + destination, Logger.severity.INFO);
                m_navSet.Settings_Task_NavWay.DestinationChanged = false;
                m_prevMover = m_navSet.Settings_Current.NavigatorMover;
                m_runId++;
                m_pathLow.Clear();
                ClearAltPath();
                m_pathState = PathState.Not_Running;
                m_planetCheckDest.Stop();
                m_planetCheckSpeed.Stop();
            }
            //else
            //	m_logger.debugLog("destination unchanged", "TestPath()");

            if (Globals.UpdateCount < m_nextRunPath)
            {
                return;
            }
            m_nextRunPath = Globals.UpdateCount + 10ul;

            if (m_pathLow.Count != 0)
            {
                m_logger.debugLog("path low is running");
                return;
            }

            m_navBlock        = m_navSet.Settings_Current.NavigationBlock;
            m_destination     = destination;
            m_ignoreAsteroid  = m_navSet.Settings_Current.IgnoreAsteroid;
            m_landing         = landing;
            m_canChangeCourse = m_navSet.Settings_Current.PathfinderCanChangeCourse;
            MyEntity destEntity = m_navSet.Settings_Current.DestinationEntity as MyEntity;

            m_logger.debugLog("DestinationEntity: " + m_navSet.Settings_Current.DestinationEntity.getBestName());
            byte runId = m_runId;

            const float minimumDistance = 100f;
            const float minDistSquared  = minimumDistance * minimumDistance;
            const float seconds         = 10f;
            const float distOverSeconds = minimumDistance / seconds;

            Vector3 displacement    = destination - m_navBlock.WorldPosition;
            float   distanceSquared = displacement.LengthSquared();
            float   testDistance;
            Vector3 move_direction = m_grid.Physics.LinearVelocity;
            float   speedSquared   = move_direction.LengthSquared();

            if (distanceSquared > minDistSquared)
            {
                // only look ahead 10 s / 100 m
                testDistance = speedSquared < distOverSeconds ? minimumDistance : (float)Math.Sqrt(speedSquared) * seconds;
                if (testDistance * testDistance < distanceSquared)
                {
                    Vector3 direction = displacement / (float)Math.Sqrt(distanceSquared);
                    destination = m_navBlock.WorldPosition + testDistance * direction;
                    m_logger.debugLog("moved destination: " + destination + ", distance: " + testDistance + ", direction: " + direction);
                }
            }
            else
            {
                m_logger.debugLog("using actual destination: " + destination);
            }

            m_pathHigh.Enqueue(() => TestPath(destination, destEntity, runId, isAlternate: false, tryAlternates: true));
            if (m_ignoreAsteroid)
            {
                m_planetCheckDest.Stop();
            }
            else
            {
                m_planetCheckDest.Start(destination - m_navBlock.WorldPosition);
            }

            // given velocity and distance, calculate destination
            if (speedSquared > 1f)
            {
                Vector3D moveDest = m_navBlock.WorldPosition + move_direction * LookAheadSpeed_Seconds;
                m_pathHigh.Enqueue(() => TestPath(moveDest, null, runId, isAlternate: false, tryAlternates: false, slowDown: true));
                if (m_ignoreAsteroid)
                {
                    m_planetCheckSpeed.Stop();
                }
                else
                {
                    m_planetCheckSpeed.Start(moveDest - m_navBlock.WorldPosition);
                }
            }
            else
            {
                m_navSet.Settings_Task_NavWay.SpeedMaxRelative = float.MaxValue;
                m_navSet.Settings_Task_NavWay.SpeedTarget      = float.MaxValue;
            }

            RunItem();
        }
示例#4
0
        private void UpdateCustomInfo()
        {
            AutopilotTerminal ApTerm = m_block.AutopilotTerminal;

            AllNavigationSettings.SettingsLevel Settings_Current = m_navSet.Settings_Current;

            ApTerm.m_autopilotStatus = m_state;
            if (m_state == State.Halted)
            {
                return;
            }

            AutopilotTerminal.AutopilotFlags flags = AutopilotTerminal.AutopilotFlags.None;
            if (m_controlledGrid != null)
            {
                flags |= AutopilotTerminal.AutopilotFlags.HasControl;
            }

            if (m_pathfinder.ReportedObstruction != null)
            {
                ApTerm.m_blockedBy = m_pathfinder.ReportedObstruction.EntityId;
                if (m_pathfinder.RotateCheck.ObstructingEntity != null)
                {
                    flags |= AutopilotTerminal.AutopilotFlags.RotationBlocked;
                }
            }
            else if (m_pathfinder.RotateCheck.ObstructingEntity != null)
            {
                flags |= AutopilotTerminal.AutopilotFlags.RotationBlocked;
                ApTerm.m_blockedBy = m_pathfinder.RotateCheck.ObstructingEntity.EntityId;
            }

            EnemyFinder ef = Settings_Current.EnemyFinder;

            if (ef != null && ef.Grid == null)
            {
                flags |= AutopilotTerminal.AutopilotFlags.EnemyFinderIssue;
                ApTerm.m_reasonCannotTarget = ef.m_reason;
                if (ef.m_bestGrid != null)
                {
                    ApTerm.m_enemyFinderBestTarget = ef.m_bestGrid.Entity.EntityId;
                }
            }
            INavigatorMover navM = Settings_Current.NavigatorMover;

            if (navM != null)
            {
                flags |= AutopilotTerminal.AutopilotFlags.HasNavigatorMover;
                ApTerm.m_prevNavMover = navM.GetType().Name;
                AutopilotTerminal.Static.prevNavMoverInfo.Update((IMyTerminalBlock)m_block.CubeBlock, navM.AppendCustomInfo);
            }
            INavigatorRotator navR = Settings_Current.NavigatorRotator;

            if (navR != null && navR != navM)
            {
                flags |= AutopilotTerminal.AutopilotFlags.HasNavigatorRotator;
                ApTerm.m_prevNavRotator = navR.GetType().Name;
                AutopilotTerminal.Static.prevNavRotatorInfo.Update((IMyTerminalBlock)m_block.CubeBlock, navR.AppendCustomInfo);
            }
            ApTerm.m_autopilotFlags  = flags;
            ApTerm.m_pathfinderState = m_pathfinder.CurrentState;
            ApTerm.SetWaitUntil(Settings_Current.WaitUntil);
            ApTerm.SetDistance(Settings_Current.Distance, Settings_Current.DistanceAngle);
            ApTerm.m_welderUnfinishedBlocks = m_navSet.WelderUnfinishedBlocks;
            ApTerm.m_complaint     = Settings_Current.Complaint;
            ApTerm.m_jumpComplaint = m_pathfinder.JumpComplaint;
        }