Beispiel #1
0
        public Program()
        {
            m_Cockpit = GridTerminalSystem.GetBlockWithName(CockpitName) as IMyCockpit;

            m_CockpitBatteryDamagePanel           = m_Cockpit.GetSurface(IntegrityBatteryDisplayIndex);
            m_CockpitBatteryDamagePanel.Alignment = VRage.Game.GUI.TextPanel.TextAlignment.CENTER;
            GridTerminalSystem.GetBlocksOfType(m_Batteries, a => a is IMyBatteryBlock && a.IsSameConstructAs(m_Cockpit));

            m_CockpitCargoPanel           = m_Cockpit.GetSurface(CargoCheckDisplayIndex);
            m_CockpitCargoPanel.Alignment = VRage.Game.GUI.TextPanel.TextAlignment.CENTER;

            m_Gyros = new List <IMyGyro>();
            GridTerminalSystem.GetBlocksOfType(m_Gyros, a => a.IsSameConstructAs(m_Cockpit));

            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(allBlocks, a => a.IsSameConstructAs(m_Cockpit));
            foreach (var block in allBlocks)
            {
                m_AllBlocks.Add(new KeyValuePair <IMyTerminalBlock, IMySlimBlock>(block, block.CubeGrid.GetCubeBlock(block.Position)));
            }

            m_Connector = GridTerminalSystem.GetBlockWithName(ConnectorName) as IMyShipConnector;

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
Beispiel #2
0
            public AdvanceControlShip(IMyCockpit cockpit)
            {
                m_shipControl = cockpit;
                m_cockpit     = cockpit;
                m_remote      = null;

                Matrix cockOrientation = new Matrix();

                m_shipControl.Orientation.GetMatrix(out cockOrientation);
                rotation_Bcockpit_2_Bship = cockOrientation;
                rotation_Bship_2_Bcockpit = MatrixD.Transpose(rotation_Bcockpit_2_Bship); //Transpose is quicker than invert, and equivalent in this case

                if (USE_DEBUG)
                {
                    lcd1 = m_cockpit.GetSurface(0);
                    setFont(lcd1);
                    if (m_cockpit.SurfaceCount > 1)
                    {
                        lcd2 = m_cockpit.GetSurface(1);
                        setFont(lcd2);
                    }
                    if (m_cockpit.SurfaceCount > 2)
                    {
                        lcd3 = m_cockpit.GetSurface(2);
                        setFont(lcd3);
                    }
                }
            }
Beispiel #3
0
        public Program()
        {
            m_Cockpit = GridTerminalSystem.GetBlockWithName(CockpitName) as IMyCockpit;

            m_CockpitBatteryDamagePanel             = m_Cockpit.GetSurface(IntegrityBatteryDisplayIndex);
            m_CockpitBatteryDamagePanel.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
            m_CockpitBatteryDamagePanel.Alignment   = VRage.Game.GUI.TextPanel.TextAlignment.CENTER;

            GridTerminalSystem.GetBlocksOfType(m_Batteries, a => a is IMyBatteryBlock && a.IsSameConstructAs(m_Cockpit) && a.CustomName != BIOSBatteryName);
            m_BIOSBattery = GridTerminalSystem.GetBlockWithName(BIOSBatteryName) as IMyBatteryBlock;

            GridTerminalSystem.GetBlocksOfType(m_Cargos, a => a is IMyCargoContainer && a.IsSameConstructAs(m_Cockpit));

            m_CockpitCargoPanel             = m_Cockpit.GetSurface(CargoCheckDisplayIndex);
            m_CockpitCargoPanel.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
            m_CockpitCargoPanel.Alignment   = VRage.Game.GUI.TextPanel.TextAlignment.CENTER;
            m_CockpitCargoPanel.FontSize    = 2.5f;

            m_Gyros = new List <IMyGyro>();
            GridTerminalSystem.GetBlocksOfType(m_Gyros, a => a.IsSameConstructAs(m_Cockpit));

            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(allBlocks, a => a.IsSameConstructAs(m_Cockpit));
            foreach (var block in allBlocks)
            {
                m_AllBlocks.Add(new KeyValuePair <IMyTerminalBlock, IMySlimBlock>(block, block.CubeGrid.GetCubeBlock(block.Position)));
            }

            m_Connector = GridTerminalSystem.GetBlockWithName(ConnectorName) as IMyShipConnector;

            m_Hinge = GridTerminalSystem.GetBlockWithName(ToolieHingeName) as IMyMotorStator;

            Runtime.UpdateFrequency = UpdateFrequency.Update1;
        }
        public void Initialise()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;

            List <IMyCockpit> cockpits = new List <IMyCockpit>();

            GridTerminalSystem.GetBlocksOfType <IMyCockpit>(cockpits);
            cockpit = cockpits.FirstOrDefault();


            //Instantiate Cargo Tracking
            cargoScreen = cockpit.GetSurface(int.Parse(argument.Split(' ')[1]));

            inventories = new List <IMyInventory>();

            foreach (var item in blocks.Where(x => x.HasInventory))
            {
                inventories.Add(item.GetInventory());
            }
            Echo("Inventories found: " + inventories.Count());

            //Instantiate Rotation tracking
            angleScreen = cockpit.GetSurface(int.Parse(argument.Split(' ')[2]));

            rightRotor = blocks.Where(x => x.CustomData.Contains(argument.Split(' ')[0]) && x is IMyMotorAdvancedStator).First() as IMyMotorAdvancedStator;
            Echo((rightRotor != null ? "Rotor found" : "Rotor NOT found"));
        }
Beispiel #5
0
        public Program()
        {
            tmpLst = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType <IMyCockpit>(tmpLst, (b) => (b.IsSameConstructAs(Me) && b.CustomName.Contains(COCKPIT_NAME)));
            if (tmpLst.Count > 0)
            {
                myCockpit = tmpLst[0] as IMyCockpit;
                lcd       = myCockpit.GetSurface(4);
            }
            else
            {
                Echo("No Main Cockpit");
            }

            hovers = new List <IMyThrust>();
            GridTerminalSystem.GetBlocksOfType <IMyThrust>(hovers, (b) =>
                                                           (b.IsSameConstructAs(Me) &&
                                                            (b.Orientation.Forward == Base6Directions.GetOppositeDirection(myCockpit.Orientation.Up))));

            minHoversHeight = hovers[0].GetMinimum <float>("Hover_MinHeight");
            maxHoversHeight = hovers[0].GetMaximum <float>("Hover_MinHeight");

            lcd.WriteText("...");

            if (!bool.TryParse(Storage, out show))
            {
                show = true;
            }

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
Beispiel #6
0
        public Program()
        {
            cockpit = GridTerminalSystem.GetBlockWithName(NAME_COCKPIT) as IMyCockpit;
            if (cockpit != null)
            {
                Echo("init OK");
                Echo("SurfaceCount: " + cockpit.SurfaceCount);

                lcd             = cockpit.GetSurface(0); // or 1
                lcd.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;

                Echo("OxygenCapacity: " + cockpit.OxygenCapacity);
                Echo("OxygenFilledRatio: " + cockpit.OxygenFilledRatio);

                // гравитация, вектор указывает на центр планеты
                Vector3D gravityVector = cockpit.GetNaturalGravity();
                stringBuilder.Append("\ngravityVector: ").Append(gravityVector.Length())
                .Append("\n  X: ").Append(gravityVector.X)
                .Append("\n  Y:").Append(gravityVector.Y)
                .Append("\n  Z:").Append(gravityVector.Z);
                Echo(stringBuilder.ToString());

                // масса корабля
                float PhysicalMass = cockpit.CalculateShipMass().PhysicalMass;
                Echo("PhysicalMass: " + PhysicalMass);

                Runtime.UpdateFrequency = UpdateFrequency.Update1;
            }
            else
            {
                Echo("init ERROR");
            }
        }
Beispiel #7
0
        void initCockpit(out IMyCockpit cockpit, out IMyTextSurface topLeft, out IMyTextSurface topRight, out IMyTextSurface keyboard)
        {
            var cockpits = new List <IMyCockpit>();

            this.GridTerminalSystem.GetBlocksOfType(cockpits, c => c.CubeGrid == this.Me.CubeGrid);
            if (cockpits.Count == 0)
            {
                throw new ArgumentException("No cockpit found");
            }

            cockpit = cockpits[0];
            topLeft = topRight = keyboard = null;
            for (int i = 0; i < cockpit.SurfaceCount; ++i)
            {
                IMyTextSurface surface = cockpit.GetSurface(i);
                if (surface.DisplayName == "Top Left Screen")
                {
                    topLeft = surface;
                }
                else if (surface.DisplayName == "Top Right Screen")
                {
                    topRight = surface;
                }
                else if (surface.DisplayName == "Keyboard")
                {
                    keyboard = surface;
                }
            }
        }
Beispiel #8
0
        public Program()
        {
            if (Me.CustomData.Length < 4)
            {
                Echo("Error, Input custom data!");
                return;
            }

            customData = Me.CustomData.Split('\n');
            cockpit    = GridTerminalSystem.GetBlockWithName(customData[0]) as IMyCockpit;
            screen     = int.Parse(customData[1]);
            for (var i = 0; i < customData.Length; i++)
            {
                if (i > 1)
                {
                    calcBlocks.Add(GridTerminalSystem.GetBlockWithName(customData[i]));
                }
            }
            _drawingSurfaceCapacity             = cockpit.GetSurface(screen);
            _drawingSurfaceCapacity.ContentType = ContentType.SCRIPT;
            Runtime.UpdateFrequency             = UpdateFrequency.Update10;
            _viewportCapacity = new RectangleF(
                (_drawingSurfaceCapacity.TextureSize - _drawingSurfaceCapacity.SurfaceSize) / 2f,
                _drawingSurfaceCapacity.SurfaceSize);
        }
        public Program()
        {
            cockpit = GridTerminalSystem.GetBlockWithName(NAME_COCKPIT) as IMyCockpit;
            GridTerminalSystem.GetBlocksOfType <IMyGyro>(gyroList);

            if (cockpit != null)
            {
                Echo("cockpit OK");
                lcd             = cockpit.GetSurface(0); // or 1
                lcd.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
            }
            else
            {
                Echo("cockpit ERROR");
            }

            if (gyroList.Count() > 0)
            {
                Echo("gyro OK");
            }
            else
            {
                Echo("gyro ERROR");
            }

            if (gyroList.Count() > 0 && cockpit != null)
            {
                Runtime.UpdateFrequency = UpdateFrequency.Update1;
            }
            else
            {
                Runtime.UpdateFrequency = UpdateFrequency.None;
            }
        }
Beispiel #10
0
        public Program()
        {
            commands["cycle"]  = Cycle;
            commands["enable"] = Enable;

            cockpit = GridTerminalSystem.GetBlockWithName("Fighter Cockpit") as IMyCockpit;
            camera  = GridTerminalSystem.GetBlockWithName("Proximity Camera") as IMyCameraBlock;
            camera.EnableRaycast = true;

            proximityLCD = cockpit.GetSurface(2);
            altitudeLCD  = cockpit.GetSurface(3);

            hinges  = new List <IMyMotorStator>();
            pistons = new List <IMyPistonBase>();
            GridTerminalSystem.GetBlockGroupWithName("Landing Gear Hinges").GetBlocksOfType(hinges);
            GridTerminalSystem.GetBlockGroupWithName("Landing Gear Pistons").GetBlocksOfType(pistons);

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
Beispiel #11
0
 public Program()
 {
     cockpit                 = (IMyCockpit)GridTerminalSystem.GetBlockWithName("drill_cockpit");
     piston_y                = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("piston_y");
     piston_z                = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("piston_z");
     rotor                   = (IMyMotorStator)GridTerminalSystem.GetBlockWithName("circle_rotor");
     cockpit_lcd             = (IMyTextSurface)cockpit.GetSurface(4);
     cockpit_lcd.ContentType = ContentType.TEXT_AND_IMAGE;
     Runtime.UpdateFrequency = UpdateFrequency.Update10;
 }
        public Program()
        {
            cockpit                 = (IMyCockpit)GridTerminalSystem.GetBlockWithName("manipulator_cockpit");
            cockpit_lcd             = (IMyTextSurface)cockpit.GetSurface(4);
            cockpit_lcd.ContentType = ContentType.TEXT_AND_IMAGE;

            roll_rotor  = (IMyMotorStator)GridTerminalSystem.GetBlockWithName("roll_rotor");
            pitch_rotor = (IMyMotorStator)GridTerminalSystem.GetBlockWithName("pitch_rotor");

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
Beispiel #13
0
        private bool CollectBlocks(IMyTerminalBlock block)
        {
            if (Me.CubeGrid.EntityId != block.CubeGrid.EntityId)
            {
                return(false);
            }

            if (block is IMyCockpit && block.CustomName.Contains("[SPINMINER]"))
            {
                Cockpit = (IMyCockpit)block;
                Displays.Add(Cockpit.GetSurface(0));
            }
            return(false);
        }
Beispiel #14
0
            public Spaceship(IMyGridTerminalSystem system, IMyIntergridCommunicationSystem igc)
            {
                this.system = system;
                this.igc    = igc;

                cpu = FindRunningPB(system);

                control   = FindBlockOfType <IMyRemoteControl>(system, this, Settings.TAG);
                connector = FindBlockOfType <IMyShipConnector>(system, this, Settings.TAG);
                debug     = FindBlockOfType <IMyTextPanel>(system, this, Settings.TAG);
                if (debug == null)
                {
                    IMyCockpit cockpit = FindBlockOfType <IMyCockpit>(system, this, Settings.TAG);
                    if (cockpit.SurfaceCount > 0)
                    {
                        debug = cockpit.GetSurface(0);
                    }
                }
                debug.Font        = "Monospace";
                debug.ContentType = ContentType.TEXT_AND_IMAGE;

                /*
                 *  screen = cockpit.GetSurface(0);
                 *  screen.ContentType = ContentType.SCRIPT;
                 *  MySpriteDrawFrame frame = screen.DrawFrame();
                 *
                 *
                 *  frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", new Vector2(0, 0), new Vector2(512, 512), Color.Black));
                 *  frame.Add(MySprite.CreateText("Ftiaxe Me!!!", "DEBUG", Color.White));
                 *  frame.Dispose();
                 */

                listener = igc.RegisterBroadcastListener(Settings.COMM_CHANNEL);
                listener = igc.RegisterBroadcastListener(Settings.COMM_CHANNEL);
                listener.SetMessageCallback(Settings.COMM_CHANNEL);
                thrusters = new ThrustersManager(this, control, system);

                autopilot = new Autopilot(this, control, FindBlockOfType <IMyGyro>(system, this));
                cas       = new CollisionAvoidanceSystem(this);
                fd        = new FlightDirector(this);

                if (connector.Status == MyShipConnectorStatus.Connected)
                {
                    flags = SpaceshipFlags.Dock;
                }
                else
                {
                    flags = SpaceshipFlags.Idle;
                }
            }
Beispiel #15
0
 void SetCockpitScreenText(IMyCockpit cockpit, int screenNumber, string text)
 {
     try
     {
         if (screenNumber + 1 <= cockpit.SurfaceCount)
         {
             IMyTextSurface lcdControl = cockpit.GetSurface(screenNumber);
             lcdControl.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
             lcdControl.WriteText(text);
         }
     }
     catch
     {
     }
 }
Beispiel #16
0
        void ParseCockpitConfigData(IMyCockpit cockpit)
        {
            if (!cockpit.CustomData.Contains(sectionTag))
            {
                cockpit.CustomData += $"[{sectionTag}]\n{cockpitRangeFinderKey}={cockpitRangeFinderSurface}\n";
            }
            MyIniParseResult result;

            myIni.TryParse(cockpit.CustomData, sectionTag, out result);

            if (!string.IsNullOrEmpty(myIni.Get(sectionTag, cockpitRangeFinderKey).ToString()))
            {
                cockpitRangeFinderSurface = myIni.Get(sectionTag, cockpitRangeFinderKey).ToInt32();

                SURFACES.Add(cockpit.GetSurface(cockpitRangeFinderSurface));
            }
        }
Beispiel #17
0
        Program()
        {
            gts = GridTerminalSystem;

            cockpit  = gts.GetBlockWithName(COCKPIT) as IMyCockpit;
            sound    = gts.GetBlockGroupWithName(SOUND) as IMySoundBlock;
            radar    = new Radar(RADAR);
            arta     = new Artillery(ARTA, cockpit, 1200, 900);
            Torpedos = new List <Torpedo>();
            InitializeTorpedos();
            WolfPackDelays = new List <int>();
            lcd            = gts.GetBlockWithName(LCD) as IMyTextPanel;
            if (lcd == null)
            {
                lcd = cockpit.GetSurface(0) as IMyTextPanel;
            }
        }
Beispiel #18
0
        public Program()
        {
            m_Cockpit = GridTerminalSystem.GetBlockWithName("Aquila Cockpit") as IMyCockpit;

            m_BatteryIntegrityDisplay = m_Cockpit.GetSurface(BatteryIntegrityDisplayIndex);
            GridTerminalSystem.GetBlocksOfType(m_Batteries, a => a is IMyBatteryBlock);
            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(allBlocks);
            foreach (var block in allBlocks)
            {
                m_AllBlocks.Add(new KeyValuePair <IMyTerminalBlock, IMySlimBlock>(block, block.CubeGrid.GetCubeBlock(block.Position)));
            }

            m_Gyros = new List <IMyGyro>();
            GridTerminalSystem.GetBlocksOfType(m_Gyros, a => a.IsSameConstructAs(m_Cockpit));

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
Beispiel #19
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            var cockpits = new List <IMyCockpit>();

            this.GridTerminalSystem.GetBlocksOfType(cockpits, c => c.CubeGrid == this.Me.CubeGrid);
            IMyCockpit cockpit = cockpits.First();

            this.manager = Process.CreateManager(this.Echo);
            var ct     = new CoordinatesTransformer(cockpit, this.manager);
            var logger = new Logger(this.manager, cockpit.GetSurface(0), new Color(0, 39, 15), new Color(27, 228, 33), this.Echo, 1.0f);

            this.cmd = new CommandLine("Small welder", logger.Log, this.manager);
            var ini    = new IniWatcher(this.Me, this.manager);
            var wc     = new WheelsController(this.cmd, cockpit, this.GridTerminalSystem, ini, this.manager, ct);
            var ac     = new ArmController(ini, this, this.cmd, cockpit, wc, this.manager);
            var client = new ConnectionClient(ini, this.GridTerminalSystem, this.IGC, this.cmd, this.manager, logger.Log);
            var ah     = new PilotAssist(this.GridTerminalSystem, ini, logger.Log, this.manager, wc);

            ah.AddBraker(client);
        }
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update1;
            rotorBase   = GetBlock <IMyMotorStator>("RotorBase");
            hingeBase   = GetBlock <IMyMotorStator>("HingeBase");
            rotorMiddle = GetBlock <IMyMotorStator>("RotorMiddle");
            hingeEnd    = GetBlock <IMyMotorStator>("HingeEnd");
            IMyCockpit cockpit = GetBlock <IMyCockpit>("Controller");

            controller      = cockpit;
            controllerPanel = cockpit.GetSurface(0);
            debugPanel      = GetBlock <IMyTextSurface>("DebugPanel");

            targetPosition = hingeEnd.GetPosition() - hingeBase.GetPosition();

            if (Math.Abs(Vector3D.Distance(hingeBase.GetPosition(), rotorMiddle.GetPosition()) -
                         Vector3D.Distance(rotorMiddle.GetPosition(), hingeEnd.GetPosition())) > 0.1)
            {
                throw new Exception("Arms have different lengths.");
            }

            armLength = Vector3D.Distance(hingeBase.GetPosition(), rotorMiddle.GetPosition());

            hingeBaseSign   = -Math.Sign(Vector3D.Dot(targetPosition, hingeBase.WorldMatrix.Forward));
            rotorMiddleSign = -Math.Sign(Vector3D.Dot(hingeBase.WorldMatrix.Right, rotorMiddle.WorldMatrix.Up)) *
                              hingeBaseSign;
            Vector3D rotorMiddleToBase = hingeBase.GetPosition() - rotorMiddle.GetPosition();

            rotorMiddleOffset = AngleTowards(rotorMiddle, hingeEnd, Vector3D.Normalize(rotorMiddleToBase));

            pidRotor.Init(1, 0.5, 0.01);
            pidBase.Init(1, 0.5, 0.01);
            pidMid.Init(1, 0.5, 0.01);

            locked = true;
        }
Beispiel #21
0
        public Program()
        {
            IMyCockpit cockpit = GridTerminalSystem.GetBlockWithName("Janne c**k") as IMyCockpit;

            _PanelTextSurface             = cockpit.GetSurface(0);
            _PanelTextSurface.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
            _PanelTextSurface.FontSize    = 2;
            _PanelTextSurface.Alignment   = VRage.Game.GUI.TextPanel.TextAlignment.CENTER;

            Runtime.UpdateFrequency = UpdateFrequency.None;

            _Sorter    = GridTerminalSystem.GetBlockWithName("Janne Sort") as IMyConveyorSorter;
            _Connector = GridTerminalSystem.GetBlockWithName("Janne Connector") as IMyShipConnector;

            _ItemList = new List <MyInventoryItemFilter>()
            {
                new MyInventoryItemFilter("MyObjectBuilder_Ore/Stone", false)
            };
            _ItemListNone = new List <MyInventoryItemFilter>();

            _Connector.ThrowOut = false;
            _Sorter.SetFilter(MyConveyorSorterMode.Blacklist, _ItemListNone);
            _PanelTextSurface.WriteText("Not throwing out\nAllow all");
        }
Beispiel #22
0
        public Program()
        {
            LogScreen = Me.GetSurface(0);
            if (LogScreen != null)
            {
                LogScreen.ContentType = ContentType.TEXT_AND_IMAGE;
            }
            SavedState.TryParse(Storage);

            Pilot = new AutoPilot(GridTerminalSystem, Me);
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(null, (b) =>
            {
                if (b.CubeGrid != Me.CubeGrid)
                {
                    return(false);
                }
                if (b is IMyCockpit && b.IsFunctional)
                {
                    Cockpit = b as IMyCockpit;
                }
                if ((b is IMyCameraBlock) &&
                    b.IsFunctional &&
                    (Pilot.Controller.WorldMatrix.Forward.Dot(b.WorldMatrix.Forward) > 0.9))
                {
                    Front = b as IMyCameraBlock;
                }
                else if (b.BlockDefinition.TypeIdString == "MyObjectBuilder_ShipConnector" &&
                         b.BlockDefinition.SubtypeName != "ConnectorSmall" &&
                         b.IsFunctional)
                {
                    Connector = b as IMyShipConnector;
                }
                else if (b is IMyBatteryBlock)
                {
                    Batteries.Add(b as IMyBatteryBlock);
                }
                if (b.InventoryCount > 0 &&
                    !(b is IMyConveyorSorter) &&
                    b.BlockDefinition.SubtypeName != "ConnectorSmall")
                {
                    StorageBlocks.Add(b);
                }
                return(false);
            });
            if (Cockpit == null)
            {
                throw new Exception("Cockpit not found.");
            }
            if (Connector == null)
            {
                throw new Exception("Connector not found.");
            }
            if (Front == null)
            {
                throw new Exception("Front camera not found.");
            }

            StorageBlocks.Sort((a, b) => ((double)b.GetInventory(0).MaxVolume).CompareTo((double)a.GetInventory(0).MaxVolume));

            Front.EnableRaycast = true;

            Middle = Cockpit.GetSurface(0);
            Left   = Cockpit.GetSurface(1);
            Right  = Cockpit.GetSurface(2);

            Middle.ContentType = ContentType.TEXT_AND_IMAGE;
            Middle.Font        = "Monospace";
            Middle.FontSize    = 1.5f;

            Left.ContentType = ContentType.TEXT_AND_IMAGE;
            Left.Font        = "Debug";
            Left.FontSize    = 2.0f;

            Right.ContentType = ContentType.TEXT_AND_IMAGE;
            Right.Font        = "Debug";
            Right.FontSize    = 2.0f;

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
        public void Main(string argument, UpdateType updateSource)
        {
            // SETUP

            craneCabin     = GridTerminalSystem.GetBlockWithName(cabinName) as IMyCockpit;
            craneRotor     = GridTerminalSystem.GetBlockWithName(rotorName) as IMyMotorAdvancedStator;
            craneConnector = GridTerminalSystem.GetBlockWithName(connectorName) as IMyShipConnector;
            cranePiston    = GridTerminalSystem.GetBlockWithName(pistonName) as IMyPistonBase;

            if (callPanels.Count == 0)
            {
                List <IMyButtonPanel> tempPanels = new List <IMyButtonPanel>();
                GridTerminalSystem.GetBlocksOfType(tempPanels, tempPanel => tempPanel.CustomName.Contains(callPanelName));

                for (int key = 0; key < tempPanels.Count; key++)
                {
                    IMyTextSurfaceProvider panelLCD = (IMyTextSurfaceProvider)tempPanels[key];

                    if (panelLCD.GetSurface(0) != null)
                    {
                        callPanels.Add(tempPanels[key]);
                    }
                }
            }

            if (areaStatusPanels.Count == 0)
            {
                GridTerminalSystem.GetBlocksOfType(areaStatusPanels, tempPanel => tempPanel.CustomName.Contains(areaStatusPanelName));
            }

            if (craneCabin != null)
            {
                pistonMonitor    = craneCabin.GetSurface(1);
                connectorMonitor = craneCabin.GetSurface(2);
                rotorMonitor     = craneCabin.GetSurface(3);
            }

            // END SETUP

            if (argument != "" && callOverride == null)
            {
                if (craneConnector == null || cranePiston == null || craneRotor == null)
                {
                    return;
                }

                callOverride = Math.Min(Math.Max((int.Parse(argument) * 45) - 180, -135), 135);
                UpdateCallPanels();
                lastRotorInput  = 0;
                rotorMultiplier = 0;
                craneConnector.Disconnect();

                if (Math.Floor((craneRotor.Angle * (180 / Math.PI)) + 0.5) < callOverride)
                {
                    craneRotor.UpperLimitDeg     = (float)callOverride;
                    craneRotor.TargetVelocityRPM = 1;
                }
                else
                {
                    craneRotor.LowerLimitDeg     = (float)callOverride;
                    craneRotor.TargetVelocityRPM = -1;
                }
            }

            if ((updateSource & UpdateType.Update100) != 0)
            {
                Runtime.UpdateFrequency = craneCabin.IsUnderControl || rotorMultiplier != 0 || callOverride != null ? UpdateFrequency.Update1 | UpdateFrequency.Update100 : UpdateFrequency.Update100;
                UpdateCallPanels();
            }

            if (callOverride == null)
            {
                if ((updateSource & UpdateType.Update1) != 0 && craneCabin != null)
                {
                    pistonOutput.Length    = 0;
                    connectorOutput.Length = 0;
                    rotorOutput.Length     = 0;

                    connectorOutput.Append("\n\n\n\n");

                    if (craneCabin.IsUnderControl)
                    {
                        pistonOutput.Append("\n\n\n\nPISTON\n");
                        rotorOutput.Append("\n\n\nROTOR\n");

                        if (craneConnector != null)
                        {
                            if (craneCabin.MoveIndicator.Z > 0)
                            {
                                craneConnector.Disconnect();
                            }

                            if (craneConnector.Status == MyShipConnectorStatus.Unconnected)
                            {
                                connectorOutput.Append("DISCONNECTED");
                                connectorMonitor.FontColor = Color.Red;
                            }
                            else if (craneConnector.Status == MyShipConnectorStatus.Connected)
                            {
                                connectorOutput.Append("CONNECTED\n");
                                connectorMonitor.FontColor = Color.Green;
                                string otherName = craneConnector.OtherConnector.CustomName;
                                connectorOutput.Append(otherName.Substring(0, otherName.Length - 10));
                            }
                            else
                            {
                                connectorOutput.Append("READY");
                                connectorMonitor.FontColor = Color.Yellow;
                            }
                        }

                        if (cranePiston != null)
                        {
                            cranePiston.Velocity = (float)ClampVelocity(-craneCabin.MoveIndicator.Z, 1);

                            pistonOutput.Append("[ ");
                            pistonOutput.Append((Math.Floor(cranePiston.CurrentPosition * 10) / 10).ToString("F1"));
                            pistonOutput.Append("m ]");
                        }

                        if (craneRotor != null)
                        {
                            if (craneConnector.Status != MyShipConnectorStatus.Connected)
                            {
                                if (craneCabin.MoveIndicator.X != 0 && Math.Sign(craneCabin.MoveIndicator.X) != Math.Sign(lastRotorInput))
                                {
                                    rotorMultiplier *= -1;
                                }

                                lastRotorInput = (craneCabin.MoveIndicator.X == 0 ? lastRotorInput : craneCabin.MoveIndicator.X);
                                if (craneCabin.MoveIndicator.X != 0)
                                {
                                    rotorMultiplier = Math.Min(Math.Max(rotorMultiplier + (Math.Abs(craneCabin.MoveIndicator.X) * 0.02f), -1), 1);
                                }
                                else
                                {
                                    rotorMultiplier += Math.Max(Math.Min(Math.Abs(0 - rotorMultiplier), 0.02f), 0) * -Math.Sign(rotorMultiplier);
                                }

                                craneRotor.TargetVelocityRPM = (float)ClampVelocity(lastRotorInput, 1) * rotorMultiplier;
                            }

                            rotorOutput.Append("[ ");
                            rotorOutput.Append(Math.Floor((craneRotor.Angle * (180 / Math.PI)) + 0.5).ToString("000.##"));
                            rotorOutput.Append("° ]");
                        }
                    }
                    else
                    {
                        connectorOutput.Append("STANDING BY");
                        connectorMonitor.FontColor = Color.White;

                        if (rotorMultiplier > 0)
                        {
                            rotorMultiplier = Math.Max(rotorMultiplier - 0.02f, 0);
                        }
                        else if (rotorMultiplier < 0)
                        {
                            rotorMultiplier = Math.Min(rotorMultiplier + 0.02f, 0);
                        }
                        else
                        {
                            lastRotorInput = 0;
                        }

                        craneRotor.TargetVelocityRPM = (float)ClampVelocity(lastRotorInput, 1) * rotorMultiplier;
                    }

                    pistonMonitor.WriteText(pistonOutput, false);
                    connectorMonitor.WriteText(connectorOutput, false);
                    rotorMonitor.WriteText(rotorOutput, false);
                }
                else if (craneCabin == null)
                {
                    lastRotorInput  = 0;
                    rotorMultiplier = 0;

                    if (cranePiston != null)
                    {
                        cranePiston.Velocity = 0;
                    }

                    if (craneRotor != null)
                    {
                        craneRotor.TargetVelocityRPM = 0;
                    }
                }
            }
            else
            {
                if (craneConnector == null || cranePiston == null || craneRotor == null)
                {
                    callOverride = null;
                    UpdateCallPanels();
                    return;
                }

                if (Math.Abs((craneRotor.Angle * (180 / Math.PI)) - (float)callOverride) < 0.25)
                {
                    craneRotor.TargetVelocityRPM = 0;
                    craneRotor.UpperLimitDeg     = 135;
                    craneRotor.LowerLimitDeg     = -135;

                    cranePiston.Velocity = 1;

                    if (Math.Abs(cranePiston.CurrentPosition - cranePiston.MaxLimit) < 0.1 && craneConnector.Status == MyShipConnectorStatus.Connectable)
                    {
                        cranePiston.Velocity = 0;
                        craneConnector.Connect();
                        callOverride = null;
                        UpdateCallPanels();
                        return;
                    }
                }
                else
                {
                    cranePiston.Velocity = -1;
                }

                if (craneCabin != null)
                {
                    connectorOutput.Length = 0;
                    rotorOutput.Length     = 0;
                    pistonOutput.Length    = 0;

                    connectorOutput.Append("\n\n\n\nAUTO-DOCKING\n");
                    connectorOutput.Append(((float)callOverride).ToString("000.##"));
                    connectorOutput.Append("°");
                    connectorMonitor.FontColor = Color.Blue;

                    pistonOutput.Append("\n\n\n\nPISTON\n");
                    pistonOutput.Append("[ ");
                    pistonOutput.Append((Math.Floor(cranePiston.CurrentPosition * 10) / 10).ToString("F1"));
                    pistonOutput.Append("m ]");

                    rotorOutput.Append("\n\n\nROTOR\n");
                    rotorOutput.Append("[ ");
                    rotorOutput.Append(Math.Floor((craneRotor.Angle * (180 / Math.PI)) + 0.5).ToString("000.##"));
                    rotorOutput.Append("° ]");

                    pistonMonitor.WriteText(pistonOutput, false);
                    connectorMonitor.WriteText(connectorOutput, false);
                    rotorMonitor.WriteText(rotorOutput, false);
                }
            }
        }
Beispiel #24
0
        public void Main(string argument, UpdateType updateSource)
        {
            IList <string> splitargs = argument.Split().Select(s => s.Trim()).ToList();

            if (panel == null)
            {
                IMyCockpit seat = (IMyCockpit)GridTerminalSystem.GetBlockWithName("Rld Control Seat");
                initDiagPanel(seat.GetSurface(0));
            }

            if (angleHinges == null)
            {
                initHinges();
            }

            if (angleHinges.Count > 0)
            {
                StringBuilder output      = new StringBuilder();
                int           count       = 0;
                bool          allAtTarget = true;
                angleHinges.ForEach(i =>
                {
                    float angleDegrees = i.Angle / radiansPerDegree;
                    float angleTarget  = 0;

                    if (i.TargetVelocityRPM > 0)
                    {
                        angleTarget = i.UpperLimitDeg;
                    }
                    else if (i.TargetVelocityRPM < 0)
                    {
                        angleTarget = i.LowerLimitDeg;
                    }


                    float delta = Math.Abs(angleDegrees - angleTarget);
                    if (delta > epsilon)
                    {
                        allAtTarget = false;
                    }

                    output.Append($"{i.CustomName} : {Math.Round(angleDegrees, 3)} / {Math.Round(angleTarget, 3)} - {delta}");

                    count++;
                    if (count < angleHinges.Count)
                    {
                        output.Append("\n");
                    }
                });

                if (allAtTarget)
                {
                    angleHinges.ForEach(i =>
                    {
                        i.TargetVelocityRPM *= -1;
                    });
                }


                panel.WriteText(output.ToString());
            }
        }
        void Main(string argument)
        {
            LoadConf();

            StringBuilder   displayString = new StringBuilder();
            Action <String> write         = delegate(string s) {
                Echo(s);
                displayString.Append(s + "\n");
            };

            IMyCockpit cockpit = null;

            try {
                cockpit = GetCockPit();
                if (cockpit == null)
                {
                    return;
                }
                if (rotorYawName == null || rotorPitchName == null)
                {
                    return;
                }

                var yawy   = GridTerminalSystem.GetBlockWithName(rotorYawName) as IMyMotorAdvancedStator;
                var pitchy = GridTerminalSystem.GetBlockWithName(rotorPitchName) as IMyMotorAdvancedStator;
                if (yawy == null || pitchy == null)
                {
                    return;
                }

                var rot = cockpit.RotationIndicator;
                var mov = cockpit.MoveIndicator;

                yawy.TargetVelocityRad   = 0.4f * Math.Sign(rot.Y);
                pitchy.TargetVelocityRad = 0.4f * Math.Sign(rot.X);

                if (pistonXName != null)
                {
                    var pistonX = GridTerminalSystem.GetBlockWithName(pistonXName) as IMyExtendedPistonBase;
                    if (pistonX != null)
                    {
                        pistonX.Velocity = Math.Sign(mov.X);
                    }
                }
                if (pistonZName != null)
                {
                    var pistonZ = GridTerminalSystem.GetBlockWithName(pistonZName) as IMyExtendedPistonBase;
                    if (pistonZ != null)
                    {
                        pistonZ.Velocity = Math.Sign(mov.Z);
                    }
                }

                write($"{targetYaw:F2}");
                write($"{targetPitch:F2}");
            }
            finally {
                //var displayBlock = GridTerminalSystem.GetBlockWithName("Display") as IMyTextPanel;
                var displayBlock = cockpit.GetSurface(0);
                if (displayBlock == null)
                {
                    Echo("No item display :(");
                }
                else
                {
                    displayBlock.ContentType = ContentType.TEXT_AND_IMAGE;
                    displayBlock.Alignment   = TextAlignment.CENTER;
                    var pixelsAsFont1   = displayBlock.MeasureStringInPixels(displayString, "Debug", 1.0f);
                    var pixelsOnSurface = displayBlock.SurfaceSize;
                    var ayy             = pixelsOnSurface / pixelsAsFont1;
                    displayBlock.FontSize = Math.Min(ayy.X, ayy.Y);
                    displayBlock.FontSize = 1.8f;
                    displayBlock.WriteText(displayString, false);
                }
            }
        }