Esempio n. 1
0
        public override void Move()
        {
            m_finder.Update();
            m_mover.StopMove();

            if (m_finder.Grid == null)
            {
                m_mover.StopMove();
                m_currentGrid = null;

                if (Globals.UpdateCount >= m_timeoutAt)
                {
                    Log.DebugLog("Search timed out", Logger.severity.INFO);
                    m_navSet.OnTaskComplete_NavMove();
                }

                return;
            }

            if (m_currentGrid == null || m_finder.Grid.Entity != m_currentGrid.Entity)
            {
                Log.DebugLog("grid changed from " + m_finder.Grid.Entity.getBestName() + " to " + m_finder.Grid.Entity.getBestName(), Logger.severity.INFO);
                m_currentGrid = m_finder.Grid;
                GetDamagedBlocks();
            }

            IMySlimBlock repairable = FindClosestRepairable();

            if (repairable == null)
            {
                Log.DebugLog("failed to find a repairable block", Logger.severity.DEBUG);
                GetDamagedBlocks();
                if (m_shopAfter)
                {
                    CreateShopper();
                }
                m_navSet.OnTaskComplete_NavMove();
                m_navSet.WelderUnfinishedBlocks       = m_damagedBlocks.Count + m_projectedBlocks.Count;
                m_navSet.Settings_Commands.Complaint |= InfoString.StringId.WelderNotFinished;
                return;
            }

            m_damagedBlocks.Remove(repairable);
            new WeldBlock(m_pathfinder, m_navSet, m_navWeld, repairable);
        }
Esempio n. 2
0
        public override void Move()
        {
            if (m_gridFinder != null)
            {
                //Log.DebugLog("updating grid finder", "Move()");
                m_gridFinder.Update();

                // if grid finder picks a new entity, have to set OrbitEntity to null first or altitude will be incorrect
                if (m_gridFinder.Grid == null || OrbitEntity != m_gridFinder.Grid)
                {
                    Log.DebugLog("no grid found");
                    OrbitEntity = null;
                    m_mover.StopMove();
                    return;
                }
                if (OrbitEntity == null)
                {
                    Log.DebugLog("found grid: " + m_gridFinder.Grid.Entity.DisplayName);
                    OrbitEntity = m_gridFinder.Grid.Entity;
                    CalcFakeOrbitSpeedForce();
                }
            }

            Vector3D targetCentre = OrbitEntity.GetCentre() + m_targetPositionOffset;

            m_faceDirection = Vector3.Reject(targetCentre - m_navBlock.WorldPosition, m_orbitAxis);
            float       alt            = m_faceDirection.Normalize();
            Vector3     orbitDirection = m_faceDirection.Cross(m_orbitAxis);
            Destination dest           = new Destination(OrbitEntity, m_targetPositionOffset - m_faceDirection * Altitude);

            float speed = alt > Altitude?
                          Math.Max(1f, OrbitSpeed - alt + Altitude) :
                              OrbitSpeed;

            Vector3 addVelocity = orbitDirection * speed;

            if (!m_flyTo && !(OrbitEntity is MyPlanet))
            {
                Vector3 fakeOrbitVelocity; Vector3.Multiply(ref m_faceDirection, OrbitSpeed * OrbitSpeed / Altitude, out fakeOrbitVelocity);
                Vector3.Add(ref addVelocity, ref fakeOrbitVelocity, out addVelocity);
            }

            m_pathfinder.MoveTo(destinations: dest, addToVelocity: addVelocity);
        }
Esempio n. 3
0
        public override void Move()
        {
            if (m_navGrind.FunctionalBlocks == 0)
            {
                Log.DebugLog("No functional grinders remaining", Logger.severity.INFO);
                m_navSet.OnTaskComplete_NavRot();
                m_stage = Stage.Terminated;
                return;
            }

            if (GrinderFull())
            {
                Log.DebugLog("Grinders are full", Logger.severity.INFO);
                m_navSet.OnTaskComplete_NavRot();
                m_stage = Stage.Terminated;
                return;
            }

            m_finder.Update();
            m_currentTarget = m_finder.Grid;

            if (m_currentTarget == null)
            {
                m_mover.StopMove();
                if (Globals.ElapsedTime >= m_timeoutAt)
                {
                    Log.DebugLog("Search timed out");
                    m_navSet.OnTaskComplete_NavRot();
                    m_stage = Stage.Terminated;
                }
                return;
            }

            m_timeoutAt = Globals.ElapsedTime + SearchTimeout;
            if (CheckIntercept())
            {
                return;
            }

            Move_Grind();
        }
Esempio n. 4
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);
            }
        }