Пример #1
0
        public static bool CheckHummingbirdComponents(IMyShipMergeBlock baseplate, ref IMyShipConnector connector, ref IMyMotorStator turretRotor, ref List <IMyTerminalBlock> PartsScratchpad, ref string status)
        {
            var releaseOther = GridTerminalHelper.OtherMergeBlock(baseplate);

            if (releaseOther == null || !releaseOther.IsFunctional || !releaseOther.Enabled)
            {
                return(false);
            }

            PartsScratchpad.Clear();

            var gotParts = GridTerminalHelper.Base64BytePosToBlockList(releaseOther.CustomData, releaseOther, ref PartsScratchpad);

            if (!gotParts)
            {
                return(false);
            }

            foreach (var block in PartsScratchpad)
            {
                if (!block.IsFunctional)
                {
                    return(false);
                }
                if (block is IMyMotorStator)
                {
                    turretRotor = (IMyMotorStator)block;
                }
                if (block is IMyShipConnector)
                {
                    connector = (IMyShipConnector)block;
                }
            }
            return(true);
        }
Пример #2
0
        public void Main(string argument, UpdateType updateSource)
        {
            DummyTube = new TorpedoTube(1, new TorpedoSubsystem(null));
            DummyTube.LoadedTorpedo = new Torpedo();

            if (argument == "ALL")
            {
                GetParts(true);
            }
            else if (argument == "HUMMINGBIRD")
            {
                GetPartsHummingbird();
            }
            else if (argument == "LANDPEDO")
            {
                GetPartsLandpedo();
            }
            else
            {
                GetParts();
            }

            if (argument == "LOAD")
            {
                List <IMyTerminalBlock> b = new List <IMyTerminalBlock>();
                GridTerminalHelper.Base64BytePosToBlockList(Base.CustomData, Base, ref b);
                Echo(b.Count().ToString());
            }
            else
            {
                string output;
                if (CheckTorpedo(DummyTube.LoadedTorpedo, out output))
                {
                    Me.GetSurface(0).ContentType = ContentType.TEXT_AND_IMAGE;
                    Me.GetSurface(0).FontSize    = 10;
                    Me.GetSurface(0).FontColor   = Color.Green;
                    Me.GetSurface(0).WriteText("AOK");
                    SaveTorpedo();
                }
                else
                {
                    Me.GetSurface(0).ContentType = ContentType.TEXT_AND_IMAGE;
                    Me.GetSurface(0).FontSize    = 10;
                    Me.GetSurface(0).FontColor   = Color.Red;
                    Me.GetSurface(0).WriteText("ERR");
                }

                Echo(output);
            }

            DummyTube = null;
            PartsOfInterest.Clear();
            Base = null;
        }
Пример #3
0
        void GetPartsLandpedo()
        {
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(null, CollectAllPartsLandpedo);

            var sb = new StringBuilder();

            sb.AppendLine(GridTerminalHelper.BlockListBytePosToBase64(PartsOfInterest, Connector));
            sb.AppendLine(GridTerminalHelper.BlockBytePosToBase64(Projector, Connector));
            sb.AppendLine(GridTerminalHelper.BlockBytePosToBase64(Base, Connector));
            Connector.CustomData = sb.ToString();
        }
Пример #4
0
        void GetLayers()
        {
            //for (int i = Me.CubeGrid.Min.X; i <= Me.CubeGrid.Max.X; i++)
            //{
            //    for (int j = Me.CubeGrid.Min.Y; i <= Me.CubeGrid.Max.Y; i++)
            //    {
            //        for (int k = Me.CubeGrid.Min.Z; i <= Me.CubeGrid.Max.Z; k++)
            //        {
            //            var coord = new Vector3I(i, j, k);
            //            var blockCoord = GridTerminalHelper.TransformGridPosToBlockPos(coord, Me);
            //            var forwardLayer = Vector3I.Forward.Dot(ref coord);
            //            if (forwardLayer > 0)
            //            {
            //
            //            }
            //        }
            //    }
            //}


            var MyMax = GridTerminalHelper.TransformGridPosToBlockPos(Me.CubeGrid.Max, Me);
            var MyMin = GridTerminalHelper.TransformGridPosToBlockPos(Me.CubeGrid.Min, Me);

            int forwardMost = -Math.Min(MyMax.Dot(ref Vector3I.Forward), MyMin.Dot(ref Vector3I.Forward));

            BlocksPerLayer = new int[forwardMost + 1];

            for (int i = forwardMost; i > 0; i--)
            {
                var maxLeft = Math.Max(MyMax.Dot(ref Vector3I.Left), MyMin.Dot(ref Vector3I.Left));
                var minLeft = Math.Min(MyMax.Dot(ref Vector3I.Left), MyMin.Dot(ref Vector3I.Left));

                for (int j = maxLeft; j >= minLeft; j--)
                {
                    var maxUp = Math.Max(MyMax.Dot(ref Vector3I.Up), MyMin.Dot(ref Vector3I.Up));
                    var minUp = Math.Min(MyMax.Dot(ref Vector3I.Up), MyMin.Dot(ref Vector3I.Up));

                    for (int k = maxUp; k >= minUp; k--)
                    {
                        var localCoords = -i * Vector3I.Forward + j * Vector3I.Left + k * Vector3I.Up;
                        var globalPos   = GridTerminalHelper.TransformBlockPosToGridPos(localCoords, Me);

                        var block = Me.CubeGrid.GetCubeBlock(globalPos);
                        if (!GotBlocks.Contains(block))
                        {
                            GotBlocks.Add(block);
                            BlocksPerLayer[i] += 1;
                        }
                    }
                }
            }
        }
Пример #5
0
            public void SaveTorpedo()
            {
                IMyMechanicalConnectionBlock mech = Base as IMyMechanicalConnectionBlock;

                if (mech != null)
                {
                    Base.CustomData = GridTerminalHelper.BlockListBytePosToBase64(PartsOfInterest, mech.Top);
                }
                else
                {
                    Base.CustomData = GridTerminalHelper.BlockListBytePosToBase64(PartsOfInterest, Base);
                }
            }
        public Hummingbird Release()
        {
            releaseStage = -10;
            var bird = Hummingbird;

            Hummingbird          = null;
            turretRotor          = null;
            hummingbirdConnector = null;
            GridTerminalHelper.OtherMergeBlock(ChasisMerge).Enabled = false;
            TurretMerge.Enabled = true;

            return(bird);
        }
        bool SetupMerge(IMyTerminalBlock block)
        {
            if (block.CubeGrid.EntityId != Context.Reference.CubeGrid.EntityId)
            {
                return(false);
            }
            if (!(block is IMyShipMergeBlock))
            {
                return(false);
            }
            if (!block.CustomName.StartsWith("[RL]"))
            {
                return(false);
            }

            var merge = (IMyShipMergeBlock)block;

            merge.CustomData = GridTerminalHelper.BlockBytePosToBase64(Context.Reference, merge);
            return(false);
        }
Пример #8
0
 void SaveTorpedo()
 {
     Base.CustomData = GridTerminalHelper.BlockListBytePosToBase64(PartsOfInterest, Base);
 }
Пример #9
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (argument == "THRUSTERDETACH")
            {
                IMyTerminalBlock ThrusterControl = null;
                List <MyTuple <IMyThrust, int> > DetachThrusters = new List <MyTuple <IMyThrust, int> >();

                List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, t => t.CubeGrid == Me.CubeGrid);

                foreach (var block in blocks)
                {
                    if (block.CustomName.Contains("[TRPT]"))
                    {
                        ThrusterControl = block;
                    }

                    IMyThrust thrust = block as IMyThrust;
                    if (thrust != null)
                    {
                        var tagindex = block.CustomName.IndexOf("[TRP");
                        if (tagindex == -1)
                        {
                            continue;
                        }

                        var indexTagEnd = block.CustomName.IndexOf(']', tagindex);
                        if (indexTagEnd == -1)
                        {
                            continue;
                        }

                        int index;
                        var numString = block.CustomName.Substring(tagindex + 4, indexTagEnd - tagindex - 4);
                        if (!int.TryParse(numString, out index))
                        {
                            continue;
                        }

                        DetachThrusters.Add(MyTuple.Create(thrust, index));
                    }
                }

                if (ThrusterControl == null)
                {
                    Error("No [TRPT] tagged block for ThrusterDetachControl");
                    return;
                }

                MyIni IniParser = new MyIni();
                IniParser.TryParse(ThrusterControl.CustomData);
                IniParser.DeleteSection("Torpedo");

                StringBuilder thrusterData = new StringBuilder();

                for (int i = 0; i < DetachThrusters.Count; ++i)
                {
                    var position = GridTerminalHelper.BlockBytePosToBase64(DetachThrusters[i].Item1, ThrusterControl);
                    thrusterData.Append(DetachThrusters[i].Item2 + "^" + position + ((i != DetachThrusters.Count - 1) ? "," : ""));
                }

                IniParser.Set("Torpedo", "ThrusterReleases", thrusterData.ToString());
                ThrusterControl.CustomData = IniParser.ToString();

                Info("Thruster Control: " + thrusterData.ToString());
                return;
            }

            BuildProxyTubes();

            foreach (var tube in ProxyTubes)
            {
                GetParts(tube);
            }

            if (argument == "LOAD")
            {
                List <IMyTerminalBlock> b = new List <IMyTerminalBlock>();
                for (int i = 0; i < ProxyTubes.Count; ++i)
                {
                    ProxyTube tube = ProxyTubes[i];
                    IMyMechanicalConnectionBlock mech = tube.Base as IMyMechanicalConnectionBlock;
                    if (mech != null)
                    {
                        GridTerminalHelper.Base64BytePosToBlockList(tube.Base.CustomData, mech.Top, ref b);
                    }
                    else
                    {
                        GridTerminalHelper.Base64BytePosToBlockList(tube.Base.CustomData, tube.Base, ref b);
                    }

                    Echo("Tube" + i + ": " + b.Count().ToString());
                }
            }
            else
            {
                StringBuilder builder = new StringBuilder(256);
                bool          aok     = true;
                for (int i = 0; i < ProxyTubes.Count; ++i)
                {
                    ProxyTube tube = ProxyTubes[i];
                    string    output;
                    if (tube.CheckTorpedo(out output))
                    {
                        tube.SaveTorpedo();
                        builder.AppendLine(i.ToString() + " [AOK] :");
                        builder.Append(output);
                    }
                    else
                    {
                        builder.AppendLine(i.ToString() + " [ERR] :");
                        builder.Append(output);
                        aok = false;
                        break;
                    }
                }
                if (aok)
                {
                    Info(builder.ToString());
                }
                else
                {
                    Error(builder.ToString());
                }
            }
            ProxyTubes.Clear();
        }
Пример #10
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100;

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(null, CollectParts);

            StatusBuilder.Clear();
            var AOK = true;

            if (SmallHinge == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("SMALL HINGE NOT FOUND!");
            }
            if (LargeHinge == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("LARGE HINGE NOT FOUND!");
            }
            if (Sweeper == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("SWEEPER NOT FOUND!");
            }
            if (BaseProjector == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("BASE PROJECTOR NOT FOUND!");
            }
            if (TopProjector == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("TOP PROJECTOR NOT FOUND!");
            }
            if (TopMerge == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("TOP MERGE NOT FOUND!");
            }
            if (BaseMerge == null)
            {
                AOK = false;
                StatusBuilder.AppendLine("BASE MERGE NOT FOUND!");
            }

            if (Welders.Count < 5)
            {
                AOK = false;
                StatusBuilder.AppendLine("NOT ENOUGH WELDERS!");
            }

            if (Display != null)
            {
                Display.ContentType = ContentType.TEXT_AND_IMAGE;
                Display.WriteText(StatusBuilder.ToString());
            }

            if (!AOK)
            {
                Echo(StatusBuilder.ToString());
                Runtime.UpdateFrequency = UpdateFrequency.None;
            }
            else
            {
                var baseOtherMerge = GridTerminalHelper.OtherMergeBlock(BaseMerge);
                var topOtherMerge  = GridTerminalHelper.OtherMergeBlock(TopMerge);
                if (topOtherMerge != null && baseOtherMerge == null)
                {
                    State = 4;
                }
            }

            ReleaseListener = IGC.RegisterBroadcastListener("[PDCFORGE]");
            ReleaseListener.SetMessageCallback("release");
        }
Пример #11
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;
                    }
                }
            }
        }
Пример #12
0
        public void CheckLandpedo()
        {
            statusBuilder.Clear();
            if (Landpedo != null)
            {
                return;
            }

            if (Connector != null)
            {
                if (!Connector.IsWorking)
                {
                    return;
                }
                if (Connector.Status == MyShipConnectorStatus.Unconnected)
                {
                    return;
                }
                if (Connector.Status == MyShipConnectorStatus.Connectable)
                {
                    Connector.Connect();
                }

                if (Connector.Status != MyShipConnectorStatus.Connected)
                {
                    return;
                }

                var other = Connector.OtherConnector;
                var lines = other.CustomData.Split('\n');
                // Parts
                // Projector
                // Merge

                IMyProjector      projector = null;
                IMyShipMergeBlock merge     = null;


                if (GridTerminalHelper.Base64BytePosToBlockList(lines[1], other, ref PartScratchpad))
                {
                    projector = PartScratchpad[0] as IMyProjector;
                }

                PartScratchpad.Clear();
                if (GridTerminalHelper.Base64BytePosToBlockList(lines[2], other, ref PartScratchpad))
                {
                    merge = PartScratchpad[0] as IMyShipMergeBlock;
                }

                if (projector != null && merge != null)
                {
                    projector.Enabled = true;
                    merge.Enabled     = false;
                }

                PartScratchpad.Clear();
                if (!GridTerminalHelper.Base64BytePosToBlockList(lines[0], other, ref PartScratchpad))
                {
                    return;
                }

                Landpedo          = Landpedo.GetLandpedo(PartScratchpad);
                projector.Enabled = false;
            }
            else
            {
            }
        }
        public void Update()
        {
            if (!setup)
            {
                setup           = true;
                Piston.Velocity = 0.2f;

                if (!Hummingbird.CheckHummingbirdComponents(ChasisMerge, ref hummingbirdConnector, ref turretRotor, ref PartScratchpad, ref status))
                {
                    return;
                }

                if (Hummingbird.CheckHummingbirdComponents(TurretMerge, ref hummingbirdConnector, ref turretRotor, ref PartScratchpad, ref status))
                {
                    turretRotor.Detach();
                    releaseStage    = 1;
                    Piston.Velocity = -0.2f;
                    return;
                }

                if (turretRotor != null)
                {
                    Hummingbird = Hummingbird.GetHummingbird(turretRotor, Host.Context.Terminal.GetBlockGroupWithName(Hummingbird.GroupName));
                    if (Hummingbird.Gats.Count == 0)
                    {
                        Hummingbird         = null;
                        TurretMerge.Enabled = true;
                        return;
                    }
                    releaseStage             = 20;
                    turretRotor.Displacement = 0.11f;
                    return;
                }
            }


            if (releaseStage > 1 && releaseStage < 20)
            {
                releaseStage++;
            }
            if (releaseStage == 5)
            {
            }
            else if (releaseStage == 7)
            {
            }
            else if (releaseStage == 8)
            {
                GridTerminalHelper.OtherMergeBlock(TurretMerge).Enabled = false;
                TurretMerge.Enabled = false;
            }
            else if (releaseStage == 9)
            {
                turretRotor.Attach();
            }
            else if (releaseStage == 10)
            {
                Piston.Velocity = 0.2f;
            }
            else if (releaseStage > 11 && Piston.CurrentPosition == Piston.MaxLimit)
            {
                turretRotor.Displacement = 0.11f;
                Hummingbird = Hummingbird.GetHummingbird(turretRotor, Host.Context.Terminal.GetBlockGroupWithName(Hummingbird.GroupName));
            }
        }