Exemple #1
0
        public static void GooeyProgram(MyShipController block)
        {
            AutopilotCommands cmds = AutopilotCommands.GetOrCreate(block);

            if (cmds != null)
            {
                cmds.StartGooeyProgramming();
            }
        }
Exemple #2
0
        public TextPanelMonitor GetTextPanelMonitor(IMyTerminalBlock autopilot, AutopilotCommands autoCmds)
        {
            string panelName = m_panelName.ToString();

            IMyTextPanel textPanel       = null;
            int          bestMatchLength = int.MaxValue;

            foreach (IMyCubeGrid grid in Attached.AttachedGrid.AttachedGrids((IMyCubeGrid)autopilot.CubeGrid, Attached.AttachedGrid.AttachmentKind.Permanent, true))
            {
                CubeGridCache cache = CubeGridCache.GetFor(grid);
                if (cache == null)
                {
                    continue;
                }
                foreach (IMyTextPanel panel in cache.BlocksOfType(typeof(MyObjectBuilder_TextPanel)))
                {
                    if (!((IMyCubeBlock)autopilot).canControlBlock((IMyCubeBlock)panel))
                    {
                        continue;
                    }

                    string name = panel.DisplayNameText;
                    if (name.Length < bestMatchLength && name.Contains(panelName))
                    {
                        textPanel       = panel;
                        bestMatchLength = name.Length;
                        if (name.Length == panelName.Length)
                        {
                            return(new TextPanelMonitor(textPanel, autoCmds, m_identifier.ToString()));
                        }
                    }
                }
            }

            if (textPanel == null)
            {
                return(null);
            }

            return(new TextPanelMonitor(textPanel, autoCmds, m_identifier.ToString()));
        }
Exemple #3
0
        /// <summary>
        /// Creates an Autopilot for the given ship controller.
        /// </summary>
        /// <param name="block">The ship controller to use</param>
        public ShipAutopilot(IMyCubeBlock block)
        {
            this.m_block      = new ShipControllerBlock(block, HandleMessage);
            this.m_pathfinder = new Pathfinder(m_block);
            this.m_commands   = AutopilotCommands.GetOrCreate(m_block.Terminal);
            this.m_block.CubeBlock.OnClosing += CubeBlock_OnClosing;

            int start = block.DisplayNameText.IndexOf('[') + 1, end = block.DisplayNameText.IndexOf(']');

            if (start > 0 && end > start)
            {
                m_block.AutopilotTerminal.AutopilotCommandsText = new StringBuilder(block.DisplayNameText.Substring(start, end - start).Trim());
                int    lengthBefore = start - 1;
                string nameBefore   = lengthBefore > 0 ? m_block.Terminal.DisplayNameText.Substring(0, lengthBefore) : string.Empty;
                end++;
                int    lengthAfter = m_block.Terminal.DisplayNameText.Length - end;
                string nameAfter   = lengthAfter > 0 ? m_block.Terminal.DisplayNameText.Substring(end, lengthAfter) : string.Empty;
                m_block.Terminal.CustomName = (nameBefore + nameAfter).Trim();
            }

            Log.DebugLog("Created autopilot for: " + block.DisplayNameText);
            Registrar.Add(block, this);
        }
Exemple #4
0
            public StaticVariables()
            {
                Logger.DebugLog("entered", Logger.severity.TRACE);
                TerminalControlHelper.EnsureTerminalControlCreated <MyCockpit>();
                TerminalControlHelper.EnsureTerminalControlCreated <MyRemoteControl>();

                AddControl(new MyTerminalControlSeparator <MyShipController>()
                {
                    Enabled = ShipAutopilot.IsAutopilotBlock, Visible = ShipAutopilot.IsAutopilotBlock
                });

                autopilotControl = new MyTerminalControlCheckbox <MyShipController>("ArmsAp_OnOff", MyStringId.GetOrCompute("ARMS Autopilot"), MyStringId.GetOrCompute("Enable ARMS Autopilot"));
                new ValueSync <bool, AutopilotTerminal>(autopilotControl, "value_autopilotControl");
                AddControl(autopilotControl);
                AddAction(new MyTerminalAction <MyShipController>("ArmsAp_OnOff", new StringBuilder("ARMS Autopilot On/Off"), @"Textures\GUI\Icons\Actions\Toggle.dds")
                {
                    Action = ToggleAutopilotControl
                });
                AddAction(new MyTerminalAction <MyShipController>("ArmsAp_On", new StringBuilder("ARMS Autopilot On"), @"Textures\GUI\Icons\Actions\SwitchOn.dds")
                {
                    Action = block => SetAutopilotControl(block, true)
                });
                AddAction(new MyTerminalAction <MyShipController>("ArmsAp_Off", new StringBuilder("ARMS Autopilot Off"), @"Textures\GUI\Icons\Actions\SwitchOff.dds")
                {
                    Action = block => SetAutopilotControl(block, false)
                });

                autopilotCommands = new MyTerminalControlTextbox <MyShipController>("ArmsAp_Commands", MyStringId.GetOrCompute("Autopilot Commands"), MyStringId.NullOrEmpty);
                new StringBuilderSync <AutopilotTerminal>(autopilotCommands, (autopilot) => autopilot.value_autopilotCommands, (autopilot, value) => {
                    autopilot.value_autopilotCommands = value;
                    AutopilotCommands.GetOrCreate(autopilot.m_block)?.OnCommandsChanged();
                });
                AddControl(autopilotCommands);

                MyTerminalControlButton <MyShipController> gooeyProgram = new MyTerminalControlButton <MyShipController>("ArmsAp_GuiProgram", MyStringId.GetOrCompute("Program Autopilot"), MyStringId.GetOrCompute("Interactive programming for autopilot"), GooeyProgram);

                gooeyProgram.Enabled = ShipAutopilot.IsAutopilotBlock;
                AddControl(gooeyProgram);

                AddPropertyAndSync <ShipAutopilot.State, Enum>("ArmsAp_Status", out autopilotStatus, "value_autopilotStatus");

                FieldInfo value_autopilotFlags = typeof(AutopilotTerminal).GetField("value_autopilotFlags", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                autopilotFlags = new ValueSync <AutopilotFlags, AutopilotTerminal>("ArmsAp_AutopilotFlags", GenerateGetter <AutopilotFlags>(value_autopilotFlags), GenerateSetter <AutopilotFlags>(value_autopilotFlags), false);
                foreach (AutopilotFlags flag in Enum.GetValues(typeof(AutopilotFlags)))
                {
                    if (flag != 0)
                    {
                        AddPropertyAndSync(flag);
                    }
                }

                AddPropertyAndSync <Pathfinder.State, Enum>("ArmsAp_PathStatus", out pathfinderState, "value_pathfinderState");
                AddPropertyAndSync <GridFinder.ReasonCannotTarget, Enum>("ArmsAp_ReasonCannotTarget", out reasonCannotTarget, "value_reasonCannotTarget");
                AddPropertyAndSync <InfoString.StringId, Enum>("ArmsAp_Complaint", out complaint, "value_complaint");
                AddPropertyAndSync <InfoString.StringId_Jump, Enum>("ArmsAp_JumpComplaint", out jumpComplaint, "value_jumpComplaint");
                AddPropertyAndSync("ArmsAp_WaitUntil", out waitUntil, "value_waitUntil");
                AddPropertyAndSyncEntityId("ArmsAp_BlockedBy", out blockedBy, "value_blockedBy");

                FieldInfo value_distance = typeof(AutopilotTerminal).GetField("value_distance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                distance = new ValueSync <long, AutopilotTerminal>("ArmsAp_Distance", GenerateGetter <long>(value_distance), GenerateSetter <long>(value_distance), false);
                MyTerminalControlProperty <MyShipController, float> linearDistance = new MyTerminalControlProperty <MyShipController, float>("ArmsAp_LinearDistance")
                {
                    Getter = GetLinearDistance
                };

                AddControl(linearDistance, false);
                MyTerminalControlProperty <MyShipController, float> angularDistance = new MyTerminalControlProperty <MyShipController, float>("ArmsAp_AngularDistance")
                {
                    Getter = GetAngularDistance
                };

                AddControl(angularDistance, false);

                AddPropertyAndSyncEntityId("ArmsAp_EnemyFinderBestTarget", out enemyFinderBestTarget, "value_enemyFinderBestTarget");
                AddPropertyAndSync("ArmsAp_WelderUnfinishedBlocks", out welderUnfinishedBlocks, "value_welderUnfinishedBlocks");
                AddPropertyAndSync("ArmsAp_NavigatorMover", out prevNavMover, "value_prevNavMover");
                AddPropertyAndSync("ArmsAp_NavigatorRotator", out prevNavRotator, "value_prevNavRotator");
                AddPropertyAndSync("ArmsAp_NavigatorMoverInfo", out prevNavMoverInfo, "value_prevNavMoverInfo");
                AddPropertyAndSync("ArmsAp_NavigatorRotatorInfo", out prevNavRotatorInfo, "value_prevNavRotatorInfo");
            }