Beispiel #1
0
        public override void Move()
        {
            Log.DebugLog("m_gridFinder == null", Logger.severity.FATAL, condition: m_gridFinder == null);
            Log.DebugLog("m_navSet == null", Logger.severity.FATAL, condition: m_navSet == null);
            Log.DebugLog("m_mover == null", Logger.severity.FATAL, condition: m_mover == null);
            Log.DebugLog("m_navBlock == null", Logger.severity.FATAL, condition: m_navBlock == null);

            m_gridFinder.Update();

            if (m_gridFinder.Grid == null)
            {
                Log.DebugLog("searching");
                m_mover.StopMove();

                // only timeout if (Grid == null), ship could simply be waiting its turn
                if (Globals.ElapsedTime > m_searchTimeoutAt)
                {
                    Log.DebugLog("Search timed out", Logger.severity.INFO);
                    m_navSet.OnTaskComplete(m_settingLevel);
                    UnreserveTarget();
                    m_mover.StopMove();
                    m_mover.StopRotate();
                    return;
                }

                if (m_landingState > LandingState.Approach)
                {
                    Log.DebugLog("Decreasing landing state from " + m_landingState + " to " + LandingState.Approach, Logger.severity.DEBUG);
                    m_landingState = LandingState.Approach;
                }

                return;
            }
            else
            {
                m_searchTimeoutAt = Globals.ElapsedTime + SearchTimeout;

                if (!m_gridFinder.Grid.isRecent())
                {
                    m_pathfinder.MoveTo(m_gridFinder.Grid);
                    return;
                }

                if (m_gridFinder.Block != null)
                {
                    m_destination = Destination.FromWorld(m_gridFinder.Block, m_navSet.Settings_Current.DestinationOffset.ToWorld(m_gridFinder.Block));
                }
                else
                {
                    IMyCubeGrid   grid  = (IMyCubeGrid)m_gridFinder.Grid.Entity;
                    CubeGridCache cache = CubeGridCache.GetFor(grid);
                    if (cache == null)
                    {
                        return;
                    }
                    m_previousCell = cache.GetClosestOccupiedCell(m_navBlock.WorldPosition, m_previousCell);
                    m_destination  = Destination.FromWorld(grid, grid.GridIntegerToWorld(m_previousCell));
                }

                if (m_landingState > LandingState.Approach)
                {
                    Move_Land();
                    return;
                }

                if (m_landingState == LandingState.None && m_navSet.Settings_Current.Stay_In_Formation)
                {
                    Log.DebugLog("Maintaining offset position from target", condition: m_navSet.DistanceLessThanDestRadius());
                    m_pathfinder.MoveTo(destinations: m_destination);
                    return;
                }

                if (m_navSet.DistanceLessThanDestRadius())
                {
                    if (m_landingState == LandingState.None)
                    {
                        if (m_targetBlock != null && m_targetBlock.Forward.HasValue ? m_navSet.DirectionMatched() : m_navBlock.Physics.AngularVelocity.LengthSquared() < 0.01f)
                        {
                            Log.DebugLog("Arrived at target", Logger.severity.INFO);
                            m_navSet.OnTaskComplete(m_settingLevel);
                            UnreserveTarget();
                            m_mover.StopRotate();
                        }
                        m_mover.StopMove();
                        return;
                    }

                    Move_Land();
                    return;
                }

                m_pathfinder.MoveTo(destinations: m_destination);
            }
        }
Beispiel #2
0
        private void Move_Grind()
        {
            if (m_stage < Stage.Grind)
            {
                Log.DebugLog("Now grinding", Logger.severity.DEBUG);
                //m_navSet.OnTaskComplete_NavMove();
                m_stage = Stage.Grind;
                //m_navSet.Settings_Task_NavMove.PathfinderCanChangeCourse = false;
                EnableGrinders(true);
            }

            CubeGridCache cache = CubeGridCache.GetFor(m_enemy);

            if (cache == null)
            {
                return;
            }
            m_previousCell = cache.GetClosestOccupiedCell(m_controlBlock.CubeGrid.GetCentre(), m_previousCell);
            IMySlimBlock block = m_enemy.GetCubeBlock(m_previousCell);

            if (block == null)
            {
                Log.DebugLog("No block found at cell position: " + m_previousCell, Logger.severity.INFO);
                return;
            }
            //Log.DebugLog("block: " + block);
            m_targetPosition = m_enemy.GridIntegerToWorld(m_enemy.GetCubeBlock(m_previousCell).Position);
            //Log.DebugLog("cellPosition: " + m_previousCell + ", block: " + m_enemy.GetCubeBlock(m_previousCell) + ", world: " + m_targetPosition);

            if (m_navSet.Settings_Current.DistanceAngle > MaxAngleRotate)
            {
                if (m_pathfinder.RotateCheck.ObstructingEntity != null)
                {
                    Log.DebugLog("Extricating ship from target");
                    m_navSet.Settings_Task_NavMove.SpeedMaxRelative = float.MaxValue;
                    Destination dest = Destination.FromWorld(m_enemy, m_targetPosition + m_navGrind.WorldMatrix.Backward * 100f);
                    m_pathfinder.MoveTo(destinations: dest);
                }
                else
                {
                    Log.DebugLog("Waiting for angle to match");
                    m_pathfinder.HoldPosition(m_enemy);
                }
                return;
            }

            Vector3D grindPosition = m_navGrind.WorldPosition;
            float    distSq        = (float)Vector3D.DistanceSquared(m_targetPosition, grindPosition);
            float    offset        = m_grinderOffset + m_enemy.GridSize;
            float    offsetEpsilon = offset + 5f;

            if (distSq > offsetEpsilon * offsetEpsilon)
            {
                Vector3D targetToGrinder = grindPosition - m_targetPosition;
                targetToGrinder.Normalize();

                //Log.DebugLog("far away(" + distSq + "), moving to " + (m_targetPosition + targetToGrinder * offset));
                m_navSet.Settings_Task_NavMove.SpeedMaxRelative = float.MaxValue;
                Destination dest = Destination.FromWorld(m_enemy, m_targetPosition + targetToGrinder * offset);
                m_pathfinder.MoveTo(destinations: dest);
            }
            else
            {
                //Log.DebugLog("close(" + distSq + "), moving to " + m_targetPosition);
                m_navSet.Settings_Task_NavMove.SpeedMaxRelative = 1f;
                Destination dest = Destination.FromWorld(m_enemy, m_targetPosition);
                m_pathfinder.MoveTo(destinations: dest);
            }
        }