public void Main(string argument)
        {
            Echo(@"You can find help in CustomData");
            if (argument.Trim().Length > 0)
            {
                NewBlockName = argument;
            }
            Echo(string.Format(@"new Blocknames: ""{0}""", NewBlockName));

            if (NewBlockName.Trim().Length > 0)
            {
                List <IMyTerminalBlock> NewBlocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(NewBlocks, (b => Me.CubeGrid.Equals(b.CubeGrid) && !LastKnownBlocks.Contains(b)));
                foreach (IMyTerminalBlock Block in NewBlocks)
                {
                    UpdateName(Block);
                }
            }
            else
            {
                Echo("script canceled: new block must not be empty.");
            }

            GridTerminalSystem.GetBlocks(LastKnownBlocks);
        }
        private bool RenameBlocksCommand(IReadOnlyList <string> arguments)
        {
            string replacement = arguments[1].Trim();
            uint   count       = 0U;

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(arguments[0].Trim());
            GridTerminalSystem.GetBlocks(blocks);
            foreach (IMyTerminalBlock block in blocks)
            {
                if (regex.IsMatch(block.CustomName))
                {
                    block.CustomName = regex.Replace(block.CustomName, replacement);
                    ++count;
                }
            }
            blocks.Clear();
            if (count == 0U)
            {
                Log("No occurences found.");
            }
            if (count == 1U)
            {
                Log("Replaced one occurence.");
            }
            else
            {
                Log("Replaced " + count + " occurences.");
            }
            return(true);
        }
public void Main(string argument)
{
    if (firstrun)
    {
        firstrun = false;
        List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();
        GridTerminalSystem.GetBlocks(blocks);

        foreach (var block in blocks)
        {
            if (block is IMyCameraBlock)
            {
                camera = (IMyCameraBlock)block;
            }

            if (block is IMyTextPanel)
            {
                lcd = (IMyTextPanel)block;
            }
        }

        camera.EnableRaycast = true;
    }

    if (camera.CanScan(SCAN_DISTANCE))
    {
        info = camera.Raycast(SCAN_DISTANCE, PITCH, YAW);
    }

    sb.Clear();
    Echo("EntityID: " + info.EntityId);

    Echo("Name: " + info.Name);

    Echo("Type: " + info.Type);

    Echo("Velocity: " + info.Velocity.ToString("0.000"));

    Echo("Relationship: " + info.Relationship);

    Echo("Size: " + info.BoundingBox.Size.ToString("0.000"));

    Echo("Position: " + info.Position.ToString("0.000"));

    if (info.HitPosition.HasValue)
    {
        Echo("Hit: " + info.HitPosition.Value.ToString("0.000"));

        Echo("Distance: " + Vector3D.Distance(camera.GetPosition(), info.HitPosition.Value).ToString("0.00"));
    }


    Echo("Range: " + camera.AvailableScanRange.ToString());

    /*
     * lcd.WritePublicText(sb.ToString());
     * lcd.ShowPrivateTextOnScreen();
     * lcd.ShowPublicTextOnScreen();
     */
}
Пример #4
0
        public void Main(string argument, UpdateType updateSource)
        {
            Dictionary <string, object> inputs = Me.GetProperty("ControlModule.Inputs")?.As <Dictionary <string, object> >()?.GetValue(Me);

            if (inputs != null)
            {
                blocks.Clear();
                foreach (long key in spritesPreviewers.Keys)
                {
                    missingSpritePreviewers.Add(key);
                }
                GridTerminalSystem.GetBlocks(blocks);
                foreach (IMyTerminalBlock block in blocks)
                {
                    if (block is IMyTextPanel)
                    {
                        IMyTextPanel text_panel = (IMyTextPanel)block;
                        if (text_panel.CustomData.Trim() == "previewSprites")
                        {
                            if (!(spritesPreviewers.ContainsKey(text_panel.EntityId)))
                            {
                                List <string> sprites = new List <string>();
                                text_panel.GetSprites(sprites);
                                spritesPreviewers.Add(text_panel.EntityId, new SpritesPreviewer(text_panel, sprites));
                            }
                            missingSpritePreviewers.Remove(text_panel.EntityId);
                        }
                    }
                }
                foreach (long key in missingSpritePreviewers)
                {
                    spritesPreviewers.Remove(key);
                }
                missingSpritePreviewers.Clear();
                foreach (string input in inputs.Keys)
                {
                    if (spritesPreviewersKeyInputActions.ContainsKey(input))
                    {
                        SpritesPreviewerKeyInputActionDelegate sprites_previewers_key_input_action = spritesPreviewersKeyInputActions[input];
                        foreach (SpritesPreviewer sprite_previewer in spritesPreviewers.Values)
                        {
                            sprites_previewers_key_input_action(sprite_previewer);
                        }
                    }
                }
                foreach (SpritesPreviewer sprite_previewer in spritesPreviewers.Values)
                {
                    string selected_sprite = sprite_previewer.SelectedSprite;
                    if (selected_sprite != null)
                    {
                        sprite_previewer.TextPanel.ContentType = ContentType.SCRIPT;
                        using (MySpriteDrawFrame sprite_draw_frame = sprite_previewer.TextPanel.DrawFrame())
                        {
                            sprite_draw_frame.Add(MySprite.CreateSprite(selected_sprite, sprite_previewer.TextPanel.SurfaceSize * 0.5f, sprite_previewer.TextPanel.SurfaceSize * sprite_previewer.ZoomFactor));
                            sprite_draw_frame.Add(MySprite.CreateText(selected_sprite, "DEBUG", Color.White, 1.0f, TextAlignment.CENTER));
                        }
                    }
                }
            }
        }
Пример #5
0
 public Program()
 {
     Runtime.UpdateFrequency = UpdateFrequency.Update10;
     GridTerminalSystem.GetBlocks(blocks);
     foreach (IMyTerminalBlock block in blocks)
     {
         IMyTextSurfaceProvider surfaceProvider = block as IMyTextSurfaceProvider;
         if (null != surfaceProvider)
         {
             surfaceProviders.Add(surfaceProvider);
         }
     }
     foreach (IMyTextSurfaceProvider prov in surfaceProviders)
     {
         int count = prov.SurfaceCount;
         for (int i = 0; i < count; i++)
         {
             IMyTextSurface surface = prov.GetSurface(i);
             surface.ContentType = ContentType.SCRIPT;
             surface.Script      = "None";
             surfaces.Add(surface);
         }
     }
     //Runtime.UpdateFrequency = UpdateFrequency.Update100;
 }
        public void Main()
        {
            elapsedTime += Runtime.TimeSinceLastRun.TotalSeconds;
            while (elapsedTime >= animationTime)
            {
                elapsedTime -= animationTime;
                direction    = !direction;
            }
            float time      = (float)((direction ? (animationTime - elapsedTime) : elapsedTime) / animationTime);
            float intensity = MathHelper.Lerp(beginIntensity, endIntensity, time);
            Color color     = Color.Lerp(beginColor, endColor, time);

            GridTerminalSystem.GetBlocks(blocks);
            foreach (IMyTerminalBlock block in blocks)
            {
                if (block is IMyLightingBlock)
                {
                    IMyLightingBlock lighting_block = (IMyLightingBlock)block;
                    lighting_block.Intensity = intensity;
                    lighting_block.Color     = color;
                }
                else if (block is IMyReflectorLight)
                {
                    IMyReflectorLight reflector_light = (IMyReflectorLight)block;
                    reflector_light.Intensity = intensity;
                    reflector_light.Color     = color;
                }
            }
        }
 /// <summary>
 /// Populates the trackedInventories list
 /// </summary>
 private void GetTrackedInventories()
 {
     trackedInventories = new List <IMyInventory>();
     tempBlockList      = new List <IMyTerminalBlock>();
     if (!trackAll)
     {
         GridTerminalSystem.SearchBlocksOfName(itemTrackTag, tempBlockList);
     }
     else
     {
         GridTerminalSystem.GetBlocks(tempBlockList);
     }
     for (int blockIndex = 0; blockIndex < tempBlockList.Count; blockIndex++)
     {
         var block = tempBlockList[blockIndex];
         if (!block.HasInventory)
         {
             continue;
         }
         for (int invIndex = 0; invIndex < block.InventoryCount; invIndex++)
         {
             var inventory = block.GetInventory(invIndex);
             trackedInventories.Add(inventory);
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Returns a list of all of the blocks that have inventories.
        /// </summary>
        /// <returns>A list of all blocks that have inventories. Only blocks on the same grid are considered.</returns>
        private List <IMyTerminalBlock> GetAllInventoryBlocks()
        {
            var output = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(output);
            output = output.Where(block => block.InventoryCount > 0 && block.CubeGrid.IsSameConstructAs(Me.CubeGrid)).ToList();

            return(output);
        }
Пример #9
0
    public Program()
    {
        allBlocks = new List <IMyTerminalBlock>();
        rPistons  = new List <IMyPistonBase>();
        vPistons  = new List <IMyPistonBase>();
        drills    = new List <IMyShipDrill>();
        cargo     = new List <IMyInventory>();

        GridTerminalSystem.GetBlocks(allBlocks);
        foreach (IMyTerminalBlock block in allBlocks)
        {
            IMyPistonBase piston = block as IMyPistonBase;
            if (piston != null)
            {
                if (piston.CustomName.Contains("[R]"))
                {
                    rPistons.Add(piston);
                }
                if (piston.CustomName.Contains("[V]"))
                {
                    vPistons.Add(piston);
                }
            }

            IMyShipDrill drill = block as IMyShipDrill;
            if (drill != null)
            {
                drills.Add(drill);
            }

            IMyInventory cont = block.GetInventory();
            if (cont != null)
            {
                if (!block.CustomName.Contains("Stone Ejector"))
                {
                    cargo.Add(cont);
                }
            }

            IMyMotorAdvancedStator rot = block as IMyMotorAdvancedStator;
            if (rot != null)
            {
                rotor = rot;
            }

            /*IMyTextPanel tp = block as IMyTextPanel;
             * if (tp != null)
             * {
             *  lcd = tp;
             * }*/
        }
        InitMiner();

        Runtime.UpdateFrequency = UpdateFrequency.Update1;
    }
        // Returns all blocks that have an inventory on the same grid as parentGridBlock
        private List <IMyEntity> GetInventoryBlocks(IMyTerminalBlock parentGridBlock)
        {
            var blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(blocks);
            return(blocks.Where(
                       b => b.CubeGrid == parentGridBlock.CubeGrid &&
                       (b.HasInventory || b.InventoryCount > 0) &&
                       b.IsFunctional
                       ).ToList <IMyEntity>());
        }
Пример #11
0
        public void Main(string argument, UpdateType updateSource)
        {
            // The main entry point of the script, invoked every time
            // one of the programmable block's Run actions are invoked,
            // or the script updates itself. The updateSource argument
            // describes where the update came from. Be aware that the
            // updateSource is a  bitfield  and might contain more than
            // one update type.
            //
            // The method itself is required, but the arguments above
            // can be removed if not needed.
            if (firstrun)
            {
                firstrun = false;
                List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocks(blocks);

                foreach (var block in blocks)
                {
                    if (block is IMyCargoContainer)//&& block.CustomName.Contains("Scanner Camera"))
                    {
                        cargos.Add((IMyCargoContainer)block);
                    }
                    if (block is IMyTextPanel && block.CustomName == "Graph Display")
                    {
                        lcd = (IMyTextPanel)block;
                    }
                    if (block is IMyShipDrill)
                    {
                        drills.Add((IMyShipDrill)block);
                    }
                }
            }
            foreach (IMyCargoContainer cargo in cargos)
            {
                IMyInventory InventoryCargo = cargo.GetInventory(0);
                float        percentFull    = isFull(InventoryCargo);
                long         max            = InventoryCargo.MaxVolume.RawValue;
                sb.Append(String.Format("{0,-40}", cargo.CustomName));
                sb.Append(graphSB(percentFull, max));
                sb.AppendLine();
            }
            foreach (IMyShipDrill drill in drills)
            {
                IMyInventory drillInventory = drill.GetInventory(0);
                float        percentFull    = isFull(drillInventory);
                long         max            = drillInventory.MaxVolume.RawValue;
                sb.Append(String.Format("{0,-40}", drill.CustomName));
                sb.Append(graphSB(percentFull, max));
                sb.AppendLine();
            }
            lcd.WriteText(sb.ToString());
            sb.Clear();
        }
        void UpdateInventory()
        {
            ClearGlobalInventory();
            ParseCustomData();
            List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(blocks);
            foreach (IMyTerminalBlock block in blocks)
            {
                UpdateInventory(block);
            }
        }
Пример #13
0
        public void UserInput(string argument)
        {
            var command = argument.Split(' ');

            if (command.Length < 2)
            {
                return;
            }

            if (command[0] != "RESET")
            {
                return;
            }

            ConfigHolder.Set(PriorityConfigKey, $"{GridTerminalSystem.GetBlocks().Count()}");
            ConfigHolder.Set(NameConfigKey, Me.CubeGrid.CustomName);

            switch (command[1])
            {
            case "SAFE":
            {
                ConfigHolder.Set(BroadcastEnabledConfigKey, "false");
                ConfigHolder.Set(IgnorePriorityConfigKey, "true");
                ConfigHolder.Set(IgnoreNameConfigKey, "true");
                break;
            }

            case "NORMAL":
            {
                ConfigHolder.Set(BroadcastEnabledConfigKey, "true");
                ConfigHolder.Set(IgnorePriorityConfigKey, "false");
                ConfigHolder.Set(IgnoreNameConfigKey, "false");
                break;
            }

            case "OBSTINATE":
            {
                ConfigHolder.Set(BroadcastEnabledConfigKey, "true");
                ConfigHolder.Set(IgnorePriorityConfigKey, "true");
                ConfigHolder.Set(IgnoreNameConfigKey, "false");
                break;
            }

            default:
            {
                EchoManager.Print($"Template {command[1]} does not exist");
                return;
            }
            }

            EchoManager.Print($"Reset configuration to the template {command[1]}");
            ConfigHolder.Save();
        }
        public void Main(string argument)
        {
            var blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(blocks);
            //var grouped = blocks.GroupBy(bk => bk.GetType().Name.Substring(2));
            var grouped = blocks.GroupBy(bk => bk.CubeGrid.CustomName);

            foreach (var item in grouped)
            {
                Echo($"{item.Count().ToString().PadLeft(4, ' ')} {item.Key}");
            }
        }
Пример #15
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (_resourceTextPanel == null)
            {
                _resourceTextPanel = (IMyTextSurface)GridTerminalSystem.GetBlockWithName("资源统计面板");
            }
            var terminalBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(terminalBlocks);
            terminalBlocks = terminalBlocks.Where(m => m.HasInventory).ToList();
            _resourceDetection.UpdateInventory(terminalBlocks);
            Color  lcdColor;
            string lcdText = _resourceDetection.GetText(out lcdColor);

            _resourceTextPanel.FontColor = lcdColor;
            _resourceTextPanel.WriteText(lcdText);
            var batteryBlocks = new List <IMyBatteryBlock>();

            GridTerminalSystem.GetBlocksOfType(batteryBlocks);
            List <IMyBatteryBlock> baseBatteryBlocks  = batteryBlocks.Where(m => m.CustomName.Equals(BaseBatteryName)).ToList();
            List <IMyBatteryBlock> otherBatteryBlocks = batteryBlocks.Where(m => !m.CustomName.Equals(BaseBatteryName)).ToList();

            if (_upTextPanel == null)
            {
                _upTextPanel = Me.GetSurface(0);
            }
            if (_downTextPanel == null)
            {
                _downTextPanel = Me.GetSurface(1);
            }
            if (_electricPowerDetection == null)
            {
                _electricPowerDetection = new ElectricPowerDetection();
            }
            _electricPowerDetection.Init(baseBatteryBlocks, otherBatteryBlocks);
            _electricPowerDetection.AutomaticManagement();
            terminalBlocks = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType <IMyCargoContainer>(terminalBlocks);
            if (_volumeDetection == null)
            {
                _volumeDetection = new VolumeDetection();
            }
            _volumeDetection.UpdateInfo(terminalBlocks);
            lcdText  = _electricPowerDetection.GetText();
            lcdText += _volumeDetection.GetText();
            _upTextPanel.WriteText(lcdText);
            lcdText = _electricPowerDetection.GetGuidText(out lcdColor);
            _downTextPanel.FontColor = lcdColor;
            _downTextPanel.WriteText(lcdText);
        }
Пример #16
0
        double brakeDist = 5;    //UNIT?



        /* * * * *
        * SETUP *
        * * * * */
        public Program()
        {
            //we need to load storage first for the debug value
            loadStorage();
            bool canRun = true;

            loadCustomData();

            try
            {
                //fetching blocks
                forward = Me.WorldMatrix.Forward;
                List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocks(blocks);
                getAntenna(ref blocks, out antenna);
                getTextPanels(ref blocks, out screens);
                getController(ref blocks, out controller);
                getWheels(ref blocks, out wheels);
                getThrusters(ref blocks, out thrustersForward, out thrustersBackward);

                Runtime.UpdateFrequency = freq;

                //if there is the controller missing we cannot do anything
                // PANIC I REPEAT PANIC
                if (controller == null)
                {
                    writeLog("There is no controller. Please add a Remote Control or Cockpit to this grid and recompile.", true);
                    canRun = false;
                }

                if (antenna == null)
                {
                    writeLog("There is no antenna. Please add an antenna to this grid and recompile", true);
                    canRun = false;
                }
                else
                {
                    name = antenna.HudText;
                }


                if (!canRun)
                {
                    Me.Enabled = false;
                }
            } catch (Exception e)
            {
                writeLog("woop woop\n" + e.Message + "\n" + e.StackTrace, true);
            }
        }
Пример #17
0
        //Get blocks -> foreach (var block in blocks) {moduleX.CheckBlock(block);}

        // MAIN PROGRAM LOOP //
        public void Main(string argument, UpdateType updateSource)
        {
            // The main entry point of the script, invoked every time
            // one of the programmable block's Run actions are invoked,
            // or the script updates itself. The updateSource argument
            // describes where the update came from. Be aware that the
            // updateSource is a  bitfield  and might contain more than
            // one update type.
            //
            // The method itself is required, but the arguments above
            // can be removed if not needed.

            ProfilerGraph();

            if (FirstRun == true || argument == (string)"refresh")
            {
                FirstRun = false;
                GridTerminalSystem.GetBlocks(BlockCache);
            }

            MyIniParseResult result;

            int TotalBlocks = BlockCache.Count;

            //MyIniParseResult result;

            for (int i = 0; i < TotalBlocks; i++)
            {
                var hangDoor = BlockCache[i] as IMyAirtightHangarDoor;

                // its a door and its open so close it.
                if (hangDoor != null && hangDoor.OpenRatio > 0.9)
                {
                    // if door is grouped under miner-1 close it and nothing else
                    MyIni.HasSection(hangDoor.CustomData, "drone");
                    if (_ini.TryParse(hangDoor.CustomData, out result) && _ini.Get("drone", "name").ToString().ToLower() == (string)"miner-1")
                    {
                        hangDoor.CloseDoor();
                    }
                }
                else
                {
                }
            }

            // Loop through Drone Pannels and display data fields on screen
            Echo("Program init");
        }
Пример #18
0
        public void Main(string argument, UpdateType updateType)
        {
            Interpreter.GridName = Me.CubeGrid.CustomName;
            string code = Get_Custom_Data();

            List <IMyTerminalBlock> allBlocks = new List <IMyTerminalBlock> ();

            GridTerminalSystem.GetBlocks(allBlocks);

            if (code.Length > 0)
            {
                Interpreter.Interprete(code);

                Modify_Block(allBlocks);
            }
        }
Пример #19
0
        void GetBlockLists()
        {
            DjConfig.allBlocks.Clear();
            DjConfig.filteredBlocks.Clear();
            DjConfig.sensorBlocks.Clear();
            DjConfig.textBlocks.Clear();
            DjConfig.filteredBlocks.Clear();

            GridTerminalSystem.GetBlocks(DjConfig.allBlocks);


            DjConfig.filteredBlocks.AddRange(DjConfig.allBlocks.Where(s => s.CustomName.StartsWith(DjConfig.roomKeyword)));

            DjConfig.sensorBlocks.AddRange(DjConfig.filteredBlocks.OfType <IMySensorBlock>());
            DjConfig.textBlocks.AddRange(DjConfig.filteredBlocks.OfType <IMyTextPanel>());
        }
Пример #20
0
 private void Print(string text, string tag = "")
 {
     if ((text != null) && (tag != null))
     {
         GridTerminalSystem.GetBlocks(blocks);
         foreach (IMyTerminalBlock block in blocks)
         {
             if ((block is IMyTextPanel) && (block.CustomData.Trim() == tag))
             {
                 IMyTextPanel text_panel = (IMyTextPanel)block;
                 text_panel.WriteText(text, true);
                 text_panel.WriteText("\n", true);
             }
         }
     }
 }
Пример #21
0
        public Program()
        {
            GridTerminalSystem.GetBlocks(gridBlocks);
            controlBlock = gridBlocks.Find(x => x.CustomName.Contains("[MAIN]")); //FIND MAIN COCKPIT TAGGED [MAIN]
            if (controlBlock == null)
            {
                Echo(" !!! No cockpit with [MAIN] tag found" + EOL +
                     "See README part of code"); // CHECK FOR EXCEPTION AND EXPLAIN
            }
            foreach (IMyTerminalBlock _block in gridBlocks)
            {
                // Search for LCDs
                if (_block is IMyTextPanel)
                {
                    if (_block.CustomName.Contains("[INFO]"))
                    {
                        infoLcd = _block as IMyTextPanel;
                    }
                    if (_block.CustomName.Contains("[DEBUG]"))
                    {
                        debugLcd = _block as IMyTextPanel;
                    }
                }

                // Search for Thrusters:
                if (_block is IMyThrust && _block.WorldMatrix.Forward == controlBlock.WorldMatrix.Forward
                    )                                             //if nozzle has same direction as cockpit
                {
                    reverseIonThrusters.Add(_block as IMyThrust); // add this one to a list
                    reverseThrustersForce +=
                        (_block as IMyThrust).MaxEffectiveThrust; // and add it's max force into float
                }

                // Search for Cargo containers, Connectors and Drills:
                if (_block is IMyCargoContainer || _block is IMyShipConnector || _block is IMyShipDrill)
                {
                    cargoContainers.Add(_block as IMyTerminalBlock);
                }
            }

            Echo("ALL TAGGED BLOCKS FOUND" + EOL + "SCRIPT IS ACTIVE" + EOL + EOL + "by " + author);
            if (debugLcd != null)
            {
                Echo("Optional DEBUG panel found");
            }
            Runtime.UpdateFrequency = UpdateFrequency.Update10; // Perform 10 times per second
        }
Пример #22
0
        public void Main(string _argument, UpdateType updateSource)
        {
            counter++;
            Echo("Run: " + counter);

            blocks = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocks(blocks);

            if (updateSource == UpdateType.Terminal)
            {
                if (!string.IsNullOrEmpty(_argument))
                {
                    Echo(argument);
                    argument = _argument;
                }

                Initialise();
            }

            Write("Piston Status: " + piston1.Status, 8);

            Vector3D currentPos = piston1.Top.GetPosition();

            Write("Cur Post: " + currentPos, 9);
            Write("Last position: " + lastPos.IsValid() + " | " + lastPos, 10);
            Write("Last Pos Set: " + lastPosSet, 11);
            Write("Dist Difference: " + Vector3D.Distance(lastPos, currentPos), 12);
            Write("Piston Ext Range: " + piston1.CurrentPosition, 13);

            if (piston1.Status == PistonStatus.Extending)
            {
                if (Vector3D.Distance(lastPos, currentPos) < DISTANCE_DIFF && lastPosSet && piston1.CurrentPosition > 5)
                {
                    piston1.MaxLimit = piston1.CurrentPosition;
                }
                else
                {
                    lastPos    = currentPos;
                    lastPosSet = true;
                }
            }
            else if (piston1.Status == PistonStatus.Retracting)
            {
                piston1.MaxLimit = 10.0f;
                lastPosSet       = false;
            }
        }
Пример #23
0
        /// <summary>
        /// Storage info of the ship. Requers a key, which is writtin into the Custom name of an object, in order to locate each specific Object
        /// </summary>
        private void Storage_Status(LCDPos _position)
        {
            List <IMyInventory> Storage = new List <IMyInventory> ();

            VRage.MyFixedPoint MaxVolume     = 0;
            VRage.MyFixedPoint CurrentVolume = 0;

            #region Collecting associated Inventories
            List <IMyTerminalBlock> AllBlocks = new List <IMyTerminalBlock> ();
            GridTerminalSystem.GetBlocks(AllBlocks);

            if (Storage.Count <= 0)
            {
                for (int i = 0; i < AllBlocks.Count; i++)
                {
                    if (AllBlocks [i].CustomName.Contains(STORAGE_KEY))
                    {
                        Storage.Add((IMyInventory)AllBlocks [i].GetInventory());

                        MaxVolume     += AllBlocks [i].GetInventory().MaxVolume;
                        CurrentVolume += AllBlocks [i].GetInventory().CurrentVolume;
                    }
                }
            }
            else
            {
                Echo("No storage units on this ship");
            }
            #endregion

            //  Formula V / MV * 100 = P
            double Percentage = (((double)CurrentVolume / (double)MaxVolume) * 100);

            if (Percentage >= 50 && G_capacityAlert != true)
            {
                G_HUD [(int)_position].WritePublicText("\n<---VEHICLE IS HEAVY!--->", true);     //  In case the ships Storage Capacity reaches a point where the ship is less manuverable.
                G_HUD [(int)_position].SetValue("FontColor", G_alertColor [0]);
                G_capacityAlert = true;
            }
            else if (Percentage <= 49 && G_capacityAlert == true)
            {
                G_HUD [(int)_position].SetValue("FontColor", G_alertColor [1]);
                G_capacityAlert = false;
            }
            G_HUD [(int)_position].WritePublicText("\n<Volume>: " + Percentage.ToString("F") + "%", true);
        }
Пример #24
0
        public void Main(string argument, UpdateType updateType)
        {
            if (LCD == null)
            {
                LCD = GridTerminalSystem.GetBlockWithName("LCD - Inventory") as IMyTextPanel;
            }
            if (blocks == null)
            {
                blocks = new List <IMyTerminalBlock> ();
                GridTerminalSystem.GetBlocks(blocks);
            }

            List <Item> items = new List <Item> ();

            if (blocks != null && blocks.Count != 0)
            {
                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks [i].HasInventory)
                    {
                        for (int j = 0; j < blocks [i].GetInventory().GetItems().Count; j++)
                        {
                            var item = blocks [i].GetInventory().GetItems() [j];

                            if (items.Exists(element => element.Name == item.Content.SubtypeName))
                            {
                                items.Find(element => element.Name == item.Content.SubtypeName).Amount += item.Amount;
                            }
                            else
                            {
                                items.Add(new Item(item.Content.SubtypeName, item.Amount));
                            }
                        }
                    }
                }
            }

            string output = String.Empty;

            for (int i = 0; i < items.Count; i++)
            {
                output += $"{items[i].ToString()}\n";
            }

            LCD.WritePublicText(output);
        }
Пример #25
0
    public Program()
    {
        allBlocks = new List <IMyTerminalBlock>();
        //cargo = new List<IMyInventory>();
        rPistons = new List <IMyPistonBase>();
        vPistons = new List <IMyPistonBase>();

        GridTerminalSystem.GetBlocks(allBlocks);
        foreach (IMyTerminalBlock block in allBlocks)
        {
            IMyPistonBase piston = block as IMyPistonBase;
            if (piston != null)
            {
                if (piston.CustomName.Contains(RADIAL_PISTON_TAG))
                {
                    rPistons.Add(piston);
                }
                if (piston.CustomName.Contains(VERTICAL_PISTON_TAG))
                {
                    vPistons.Add(piston);
                }
            }

            IMyShipDrill drill = block as IMyShipDrill;
            if (drill != null)
            {
                drills = drill;
            }

            IMyInventory cont = block.GetInventory();
            if (cont != null)
            {
                if (block.CustomName.Contains("Cargo"))
                {
                    cargo = cont;
                }
            }

            IMyMotorAdvancedStator rot = block as IMyMotorAdvancedStator;
            if (rot != null)
            {
                rotor = rot;
            }
        }
        Runtime.UpdateFrequency = UpdateFrequency.Update100;
    }
Пример #26
0
        private void getMass()
        {
            GridTerminalSystem.GetBlocks(blocks);
            float mass = 0.0f;

            foreach (var block in blocks)
            {
                mass += block.Mass;
            }
            if (mass > 1000)
            {
                println($"Mass: { mass / 1000 }T");
            }
            else
            {
                println($"Mass: { mass } kg");
            }
        }
Пример #27
0
        public Program()
        {
            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(allBlocks);

            Lcd  = GetBlock <IMyTextSurface>(allBlocks, x => x.CustomName == "lcd controls");
            C**k = GetBlock <IMyRemoteControl>(allBlocks, x => x.CustomName.Contains("[ra c]"));
            Tip  = GetBlock <IMyTerminalBlock>(allBlocks, x => x.CustomName.Contains("[ra t]"));

            var rotationRotor = GetBlock <IMyMotorStator>(allBlocks, x => x.CustomName.Contains("[ra r]"));

            roboticArm     = new RoboticArm(allBlocks, rotationRotor, Tip);
            roboticArm.lcd = Lcd;

            Lcd.WriteText("Hello world!");

            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
        public List <IMyTerminalBlock> getBlockGroup(Argument Arg)
        {
            List <IMyTerminalBlock> Blocks = new List <IMyTerminalBlock>();

            if (Arg.group != null)
            {
                IMyBlockGroup Group = GridTerminalSystem.GetBlockGroupWithName(Arg.group);
                if (Group != null)
                {
                    Group.GetBlocks(Blocks);
                }
            }
            else
            {
                GridTerminalSystem.GetBlocks(Blocks);
            }

            return(Blocks);
        }
Пример #29
0
        //CustomData:旧名字,新名字
        public void Main()
        {
            string[] arguments = Me.CustomData.Split(',');
            if (arguments.Length != 2)
            {
                throw new ArgumentException("参数错误");
            }
            string oldName        = arguments[0];
            string newName        = arguments[1];
            var    index          = 1;
            var    terminalBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocks(terminalBlocks);
            foreach (IMyTerminalBlock terminalBlock in terminalBlocks.Where(m => m.CustomName.StartsWith(oldName)))
            {
                terminalBlock.CustomName = $"{newName}-{index++}";
            }
            Echo($"重命名完毕");
        }
Пример #30
0
        public void Main(string argument, UpdateType updateType)
        {
            string [] naming = Me.CustomData.Split(',');

            GridTerminalSystem.GetBlocks(this.blocks);

            for (int i = 0; i < this.blocks.Count; i++)
            {
                if (this.blocks [i].CubeGrid == Me.CubeGrid && !this.blocks [i].CustomName.Contains(Get_Grid_Name()))
                {
                    if (!this.blocks [i].CustomData.Contains("¤i"))
                    {
                        this.blocks [i].CustomName = Create_Name(this.blocks [i]);
                    }
                }
            }


            Echo(this.AnimationRunner.Run_Animation());
        }