예제 #1
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (argument == "releaseremote")
            {
                IGC.SendBroadcastMessage("[PDCFORGE]", "");
            }
            else if (argument == "save")
            {
                if (Elevation != null && BaseMerge != null)
                {
                    var list = new List <IMyTerminalBlock>();
                    list.Add(Elevation);
                    BaseMerge.CustomData = GridTerminalHelper.BlockListBytePosToBase64(list, BaseMerge);
                }
            }
            else if (argument == "release")
            {
                while (ReleaseListener.HasPendingMessage)
                {
                    var msg = ReleaseListener.AcceptMessage();
                    if (msg.Data is string && Me.CustomName.Contains((string)msg.Data))
                    {
                        var otherMerge = GridTerminalHelper.OtherMergeBlock(TopMerge);
                        if (otherMerge != null)
                        {
                            otherMerge.Enabled = false;
                        }
                    }
                }
            }
            else
            {
                if (State == 0)
                {
                    foreach (var welder in Welders)
                    {
                        welder.Enabled = true;
                    }

                    if (Display != null)
                    {
                        Display.WriteText("STATE 0: WELDING - WAITING FOR COMPLETION");
                    }

                    if (TopProjector.RemainingBlocks == 0 && BaseProjector.RemainingBlocks == 0)
                    {
                        GraceTimer = 5;
                        State      = 1;
                    }
                }
                else if (State == 1)
                {
                    GraceTimer--;

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 1: WELDING GRACE PERIOD - {GraceTimer}");
                    }

                    if (GraceTimer <= 0)
                    {
                        foreach (var welder in Welders)
                        {
                            welder.Enabled = false;
                        }
                        BaseProjector.Enabled = false;
                        TopProjector.Enabled  = false;

                        State = 2;
                    }
                }
                else if (State == 2)
                {
                    ElevationScratchpad.Clear();
                    var block = GridTerminalHelper.Base64BytePosToBlockList(BaseMerge.CustomData, BaseMerge, ref ElevationScratchpad);

                    if (ElevationScratchpad.Count == 1)
                    {
                        Elevation = ElevationScratchpad[0];

                        if (Display != null)
                        {
                            Display.WriteText($"ELEVATION ROTOR FOUND", true);
                        }

                        Elevation.Detach();

                        var degrees = -90f * Math.PI / 180f;
                        DriveHinge(SmallHinge, (float)(degrees), 0.3f);
                        DriveHinge(LargeHinge, (float)(degrees), 1f);
                        Sweeper.TargetVelocityRPM = -10;

                        if (Display != null)
                        {
                            Display.WriteText($"STATE 2: SWINGING HINGES SMALL - {SmallHinge.Angle * 180 / Math.PI} / -90 | LARGE - {LargeHinge.Angle * 180 / Math.PI} / -90");
                        }

                        if (Math.Abs(SmallHinge.Angle - degrees) < 0.01 && Math.Abs(LargeHinge.Angle - degrees) < 0.01)
                        {
                            State = 3;
                        }
                    }
                    else
                    {
                        if (Display != null)
                        {
                            Display.WriteText($"\nCRITICAL ERROR: ELEVATION ROTOR NOT FOUND", true);
                        }
                    }
                }
                else if (State == 3)
                {
                    if (Display != null)
                    {
                        Display.WriteText($"STATE 3: ATTEMPTING ATTACH");
                    }

                    ElevationScratchpad.Clear();
                    var block = GridTerminalHelper.Base64BytePosToBlockList(BaseMerge.CustomData, BaseMerge, ref ElevationScratchpad);

                    if (ElevationScratchpad.Count == 1)
                    {
                        Elevation = ElevationScratchpad[0];

                        if (Display != null)
                        {
                            Display.WriteText($"ELEVATION ROTOR FOUND", true);
                        }

                        Elevation.Attach();

                        if (Elevation.IsAttached)
                        {
                            GridTerminalHelper.OtherMergeBlock(BaseMerge).Enabled = false;
                            State = 4;
                        }
                    }
                    else
                    {
                        if (Display != null)
                        {
                            Display.WriteText($"\nCRITICAL ERROR: ELEVATION ROTOR NOT FOUND", true);
                        }
                    }
                }
                else if (State == 4)
                {
                    var degrees = 90f * Math.PI / 180f;
                    DriveHinge(SmallHinge, (float)(degrees), 0.3f);

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 4: SWINGING SMALL HINGE - {SmallHinge.Angle * 180 / Math.PI} / 90");
                    }

                    if (Math.Abs(SmallHinge.Angle - degrees) < 0.01)
                    {
                        State = 5;
                    }
                }
                else if (State == 5)
                {
                    if (Display != null)
                    {
                        Display.WriteText($"STATE 5: COMPLETE - AWAITING PICKUP");
                    }
                    if (GridTerminalHelper.OtherMergeBlock(TopMerge) == null)
                    {
                        State      = 6;
                        GraceTimer = 5;
                    }
                }
                else if (State == 6)
                {
                    GraceTimer--;

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 6: DETACH GRACE PERIOD - {GraceTimer}");
                    }

                    if (GraceTimer <= 0)
                    {
                        State = 7;
                    }
                }
                else if (State == 7)
                {
                    var degrees  = 90f * Math.PI / 180f;
                    var degrees2 = 0;
                    DriveHinge(LargeHinge, (float)(degrees), 1f);
                    DriveHinge(SmallHinge, (float)(degrees2), 1f);
                    Sweeper.TargetVelocityRPM = 10;

                    BaseProjector.Enabled = true;
                    TopProjector.Enabled  = true;

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 7: RESETTING SMALL - {SmallHinge.Angle * 180 / Math.PI} / 0 | LARGE - {LargeHinge.Angle * 180 / Math.PI} / 90");
                    }

                    if (Math.Abs(SmallHinge.Angle - degrees2) < 0.01 && Math.Abs(LargeHinge.Angle - degrees) < 0.01)
                    {
                        State = 0;
                    }
                }
            }
        }
예제 #2
0
        public void Main()
        {
            Echo("Current Stage: " + currentStep);

            switch (currentStep)
            {
            case "STEP_1":
                if (rotor_up.IsAttached)
                {
                    piston.Velocity = -0.01f;

                    if (piston.CurrentPosition == 0)
                    {
                        currentStep = "STEP_2";
                    }
                }
                break;

            case "STEP_2":
                if (rotor_down.IsAttached)
                {
                    currentStep = "STEP_3";
                }
                else
                {
                    rotor_down.Attach();
                }
                break;

            case "STEP_3":
                if (rotor_up.IsAttached)
                {
                    rotor_up.Detach();
                }
                else
                {
                    currentStep = "STEP_4";
                }
                break;

            case "STEP_4":
                if (piston.CurrentPosition < piston.MaxLimit)
                {
                    piston.Velocity = 1f;
                }
                else
                {
                    currentStep = "STEP_5";
                }
                break;

            case "STEP_5":
                if (rotor_up.IsAttached)
                {
                    currentStep = "STEP_6";
                }
                else
                {
                    rotor_up.Attach();
                }

                break;

            case "STEP_6":
                if (rotor_down.IsAttached)
                {
                    rotor_down.Detach();
                }
                else
                {
                    currentStep = "STEP_1";
                }
                break;
            }
        }