示例#1
0
        public void ResumeFromSave(Builder_Autopilot builder)
        {
            using (lock_execution.AcquireExclusiveUsing())
            {
                m_navSet.OnStartOfCommands();
                Log.DebugLog("resume: " + builder.Commands + ", current: " + builder.CurrentCommand, Logger.severity.DEBUG);
                m_autopilotActions = m_commands.GetActions(builder.Commands);

                while (m_autopilotActions.CurrentIndex < builder.CurrentCommand - 1 && m_autopilotActions.MoveNext())
                {
                    m_autopilotActions.Current.Invoke(m_pathfinder);
                    Log.DebugLog("fast forward: " + m_autopilotActions.CurrentIndex);

                    // clear navigators' levels
                    for (AllNavigationSettings.SettingsLevelName levelName = AllNavigationSettings.SettingsLevelName.NavRot; levelName < AllNavigationSettings.SettingsLevelName.NavWay; levelName++)
                    {
                        AllNavigationSettings.SettingsLevel settingsAtLevel = m_navSet.GetSettingsLevel(levelName);
                        if (settingsAtLevel.NavigatorMover != null || settingsAtLevel.NavigatorRotator != null)
                        {
                            Log.DebugLog("clear " + levelName);
                            m_navSet.OnTaskComplete(levelName);
                            break;
                        }
                    }
                }
                if (m_autopilotActions.MoveNext())
                {
                    m_autopilotActions.Current.Invoke(m_pathfinder);
                }

                // clear wait
                m_navSet.OnTaskComplete(AllNavigationSettings.SettingsLevelName.NavWay);

                EnemyFinder finder = m_navSet.Settings_Current.EnemyFinder;
                if (finder != null)
                {
                    if (builder.EngagerOriginalEntity != 0L)
                    {
                        if (!MyAPIGateway.Entities.TryGetEntityById(builder.EngagerOriginalEntity, out finder.m_originalDestEntity))
                        {
                            Log.AlwaysLog("Failed to restore original destination enitity for enemy finder: " + builder.EngagerOriginalEntity, Logger.severity.WARNING);
                            finder.m_originalDestEntity = null;
                        }
                        else
                        {
                            Log.DebugLog("Restored original destination enitity for enemy finder: " + finder.m_originalDestEntity.getBestName());
                        }
                    }
                    if (builder.EngagerOriginalPosition.IsValid())
                    {
                        finder.m_originalPosition = builder.EngagerOriginalPosition;
                        Log.DebugLog("Restored original position for enemy finder: " + builder.EngagerOriginalPosition);
                    }
                }
            }
        }
示例#2
0
 private void HandleMessage(Message msg)
 {
     using (lock_execution.AcquireExclusiveUsing())
     {
         m_autopilotActions = m_commands.GetActions(msg.Content);
         m_navSet.OnStartOfCommands();
         m_mover.MoveAndRotateStop(false);
         m_mover.SetControl(true);
     }
 }
示例#3
0
        /// <summary>
        /// Run the autopilot
        /// </summary>
        private void UpdateThread()
        {
            if (!lock_execution.TryAcquireExclusive())
            {
                return;
            }
            try
            {
                if (Globals.UpdateCount > m_nextCustomInfo)
                {
                    m_nextCustomInfo = Globals.UpdateCount + 10ul;
                    UpdateCustomInfo();
                }

                switch (m_state)
                {
                case State.Disabled:
                    if (CheckControl())
                    {
                        m_state = State.Enabled;
                    }
                    return;

                case State.Enabled:
                    if (CheckControl())
                    {
                        break;
                    }
                    m_state = State.Disabled;
                    return;

                case State.Player:
                    // wait for player to give back control, do not reset
                    if (MyAPIGateway.Players.GetPlayerControllingEntity(m_controlledGrid) == null)
                    {
                        m_state = State.Enabled;
                    }
                    return;

                case State.Halted:
                    if (!m_block.AutopilotControl || Globals.ElapsedTime > m_endOfHalt)
                    {
                        m_state = State.Disabled;
                    }
                    return;

                case State.Closed:
                    return;

                default:
                    throw new Exception("Case not implemented: " + m_state);
                }

                if (MyAPIGateway.Players.GetPlayerControllingEntity(m_controlledGrid) != null)
                {
                    m_state = State.Player;
                    return;
                }

                EnemyFinder ef = m_navSet.Settings_Current.EnemyFinder;
                if (ef != null)
                {
                    ef.Update();
                }

                if (m_navSet.Settings_Current.WaitUntil > Globals.ElapsedTime)
                {
                    return;
                }

                if (MoveAndRotate())
                {
                    return;
                }

                if (m_autopilotActions != null)
                {
                    while (true)
                    {
                        if (!m_autopilotActions.MoveNext())
                        {
                            Log.DebugLog("finder: " + m_navSet.Settings_Current.EnemyFinder);
                            m_autopilotActions = null;
                            return;
                        }
                        m_autopilotActions.Current.Invoke(m_pathfinder);
                        if (m_navSet.Settings_Current.WaitUntil > Globals.ElapsedTime)
                        {
                            Log.DebugLog("now waiting until " + m_navSet.Settings_Current.WaitUntil);
                            return;
                        }
                        if (m_navSet.Settings_Current.NavigatorMover != null)
                        {
                            Log.DebugLog("now have a navigator mover: " + m_navSet.Settings_Current.NavigatorMover);
                            return;
                        }
                    }
                }

                if (RotateOnly())
                {
                    return;
                }

                TimeSpan nextInstructions = m_previousInstructions + TimeSpan.FromSeconds(m_navSet.Settings_Current.Complaint != InfoString.StringId.None || ef != null ? 60d : 1d);
                if (nextInstructions > Globals.ElapsedTime)
                {
                    Log.DebugLog("Delaying instructions until " + nextInstructions, Logger.severity.INFO);
                    m_navSet.Settings_Task_NavWay.WaitUntil = nextInstructions;
                    return;
                }
                Log.DebugLog("enqueing instructions", Logger.severity.DEBUG);
                m_previousInstructions = Globals.ElapsedTime;

                m_autopilotActions = m_commands.GetActions();

                if (m_autopilotActions == null || m_autopilotActions.IsEmpty)
                {
                    ReleaseControlledGrid();
                }
                m_navSet.OnStartOfCommands();
                m_mover.MoveAndRotateStop(false);

                if (m_commands.HasSyntaxErrors)
                {
                    m_navSet.Settings_Task_NavWay.WaitUntil = Globals.ElapsedTime + TimeSpan.FromMinutes(1d);
                }
            }
            catch (Exception ex)
            {
                Log.AlwaysLog("Commands: " + m_commands.Commands, Logger.severity.DEBUG);
                Log.AlwaysLog("Exception: " + ex, Logger.severity.ERROR);
                m_state = State.Halted;
            }
            finally
            { lock_execution.ReleaseExclusive(); }
        }