示例#1
0
        public Program()
        {
            autoMode = false;

            IMyBlockGroup reactorGroup = GridTerminalSystem.GetBlockGroupWithName(REACTORS_GRP);

            reactorGroup.GetBlocksOfType(reactors);

            IMyBlockGroup batteryGroup = GridTerminalSystem.GetBlockGroupWithName(BATTERIES_GRP);

            batteryGroup.GetBlocksOfType(batteries);

            panel = GridTerminalSystem.GetBlockWithName(PANEL_NAME) as IMyTextPanel;
        }
示例#2
0
        public DrillTower Build(StaticState.DrillTowerDef definition)
        {
            gridTerminalSystem.GetBlockGroupWithName(definition.PistonGroupName)?.GetBlocksOfType(local_static_pistons);
            gridTerminalSystem.GetBlockGroupWithName(definition.DrillGroupName)?.GetBlocksOfType(local_static_drills);
            gridTerminalSystem.GetBlockGroupWithName(definition.DrillClampsGroupName)?.GetBlocksOfType(local_static_clamps);
            gridTerminalSystem.GetBlocksOfType(local_static_floodlights, b => b.CustomName == definition.FloodlightsName);
            var rotor   = gridTerminalSystem.GetBlockWithName(definition.RotorName) as IMyMotorStator;
            var display = gridTerminalSystem.GetBlockWithName(definition.DisplayName) as IMyTextPanel;

            var stacks = new PistonTopology().GetPistonStacks(local_static_pistons);
            var drills = new DrillHead(local_static_drills.ToArray());
            var clamps = new ClampGroup(local_static_clamps.ToArray());
            var lights = new LightGroup(local_static_floodlights.ToArray());

            return(new DrillTower(stacks, drills, clamps, rotor, lights, display));
        }
示例#3
0
        private void Safeguard_Check()
        {
            Echo("Running SafeGuard check..");
            if (GridTerminalSystem == null)
            {
                throw new ArgumentNullException("Passed GTS reference was null.");
            }
            // Validate welder config
            var blocks = GridTerminalSystem.GetBlockGroupWithName(WelderConfig.WelderGroupName);

            if (blocks == null)
            {
                throw new ArgumentException("Welder block group was not found.");
            }
            List <IMyShipWelder> pistons = new List <IMyShipWelder>();

            blocks.GetBlocksOfType(pistons);
            if (pistons.Count != WelderList.Count)
            {
                WelderList = pistons;
            }
            // Validate welder config end

            // Make sure all welders have the same configuration
            ApplyConfig();
            Echo("OK.");
        }
示例#4
0
        public WelderController(GridProgramRef gridProgramRef, WelderConfig welderConfig)
        {
            // Safe guard: Throw an exception if GridTerminalSystem is null
            if (gridProgramRef.GridTerminalSystem == null)
            {
                throw new ArgumentNullException("Passed GTS reference was null.");
            }
            if (gridProgramRef.Echo == null)
            {
                throw new ArgumentNullException("Passed Echo reference was null.");
            }
            // Initialize initial variables
            WelderList         = new List <IMyShipWelder>();
            GridTerminalSystem = gridProgramRef.GridTerminalSystem;
            Echo         = gridProgramRef.Echo;
            WelderConfig = welderConfig;
            // Safe guard: Throw an exception if group is non existent
            var blocks = GridTerminalSystem.GetBlockGroupWithName(WelderConfig.WelderGroupName);

            if (blocks == null)
            {
                throw new ArgumentException("Welder block group was not found.");
            }
            blocks.GetBlocksOfType(WelderList);
            ApplyConfig();
        }
        public Program()
        {
            InitLocales();

            IMyBlockGroup ingotStorageGroup = GridTerminalSystem.GetBlockGroupWithName(INGOT_STORAGE_GROUP);

            ingotStorageGroup.GetBlocksOfType(ingots);

            panel = GridTerminalSystem.GetBlockWithName(PANEL_NAME) as IMyTextPanel;
        }
示例#6
0
        static List <T> GetBlocks <T> (string groupName, bool useSubgrids = false) where T : class, IMyTerminalBlock
        {
            IMyBlockGroup group  = gridSystem.GetBlockGroupWithName(groupName);
            List <T>      blocks = new List <T>();

            group.GetBlocksOfType(blocks);
            if (!useSubgrids)
            {
                blocks.RemoveAll(block => block.CubeGrid.EntityId != gridId);
            }
            return(blocks);
        }
示例#7
0
            /// <summary>
            /// Appends blocks, from the grid, from group with the given name and type; to the end of a typed block list.
            /// </summary>
            /// <typeparam name="BlockType">Block type that is a subtype of IMyTerminalBlock</typeparam>
            /// <param name="groupName">String containing the group name.</param>
            /// <param name="blockList">List of blocks of given type.</param>
            public void AppendBlocksFromGroupName <BlockType>(string groupName, List <BlockType> blockList) where BlockType : class, IMyTerminalBlock
            {
                IMyBlockGroup    blockGroup;
                List <BlockType> blockSubList = new List <BlockType>();

                if ((blockGroup = gridTerminalSystem.GetBlockGroupWithName(groupName)) == null)
                {
                    throw new Exception("Block group with name '" + groupName + "' does not exist in this grid.");
                }
                blockGroup.GetBlocksOfType(blockSubList);
                blockList.AddRange(blockSubList);
            }
示例#8
0
            public void Airvents(bool pressurize)
            {
                var group = GridTerminalSystem.GetBlockGroupWithName(AL_AIRVENTS);

                if (group == null)
                {
                    return;
                }

                group.GetBlocks(blocks);
                for (var i = 0; i < blocks.Count; i++)
                {
                    var airvent = blocks[i] as IMyAirVent;
                    if (airvent == null)
                    {
                        continue;
                    }

                    airvent.Depressurize = !pressurize;
                }
                blocks.Clear();
            }
示例#9
0
        public MeterAction(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData, List <IMyTerminalBlock> blocks, IMyGridTerminalSystem gts, IMyProgrammableBlock me)
        {
            this.def      = def;
            this.shipData = shipData;

            if (def.textData == "")
            {
                def.textData = "OnOff";
            }

            if (def.min == 0 && def.max == 0)
            {
                UseDataMinMax = true;
            }
            else
            {
                total = def.max - def.min;
            }

            foreach (string text in def.blocks)
            {
                if (text.StartsWith("*") && text.EndsWith("*"))
                {
                    //Group.
                    var group = gts.GetBlockGroupWithName(text.Trim('*'));
                    if (group != null)
                    {
                        var groupBlocks = new List <IMyTerminalBlock>();
                        group.GetBlocks(groupBlocks);
                        foreach (var block in groupBlocks)
                        {
                            if (block.IsSameConstructAs(me))
                            {
                                this.blocks.Add(block);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var block in blocks)
                    {
                        if (block.CustomName == text)
                        {
                            this.blocks.Add(block);
                            break;
                        }
                    }
                }
            }
        }
示例#10
0
 public ConfigItem(MyIni _ini, string key, IMyGridTerminalSystem GridTerminalSystem)
 {
     this.BlockName = _ini.Get(key, "BlockName").ToString();
     this.IsGroup   = _ini.Get(key, "IsGroup").ToBoolean();
     this.Speed     = _ini.Get(key, "Speed").ToDouble(1);
     this.Disabled  = _ini.Get(key, "Disabled").ToBoolean();
     this.IsPiston  = _ini.Get(key, "IsPiston").ToBoolean();
     if (!this.IsGroup)
     {
         if (this.IsPiston)
         {
             this.Pistons.Add(GridTerminalSystem.GetBlockWithName(this.BlockName) as IMyPistonBase);
             if (Pistons.Count == 0)
             {
                 throw new Exception($"Couldn't find piston group for {key}");
             }
         }
         else
         {
             this.Rotors.Add(GridTerminalSystem.GetBlockWithName(this.BlockName) as IMyMotorStator);
             if (Rotors.Count == 0)
             {
                 throw new Exception($"Couldn't find rotor group for {key}");
             }
         }
     }
     else
     {
         IMyBlockGroup Blocks = GridTerminalSystem.GetBlockGroupWithName(this.BlockName);
         if (this.IsPiston)
         {
             Blocks.GetBlocksOfType <IMyPistonBase>(this.Pistons);
             if (Pistons.Count == 0)
             {
                 throw new Exception($"Couldn't find pistons for {key}");
             }
         }
         else
         {
             Blocks.GetBlocksOfType <IMyMotorStator>(this.Rotors);
             if (Rotors.Count == 0)
             {
                 throw new Exception($"Couldn't find rotors for {key}");
             }
         }
     }
 }
示例#11
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;
            }
        }
示例#12
0
        private void Safeguard_Check()
        {
            Echo("Running SafeGuard check..");
            if (GridTerminalSystem == null)
            {
                throw new ArgumentNullException("Passed GTS reference was null.");
            }
            // Validate piston config
            var blocks = GridTerminalSystem.GetBlockGroupWithName(PistonGroupName);

            if (blocks == null)
            {
                throw new ArgumentException("Piston block group was not found.");
            }
            List <IMyPistonBase> pistons = new List <IMyPistonBase>();

            blocks.GetBlocksOfType(pistons);
            if (pistons.Count != PistonList.Count)
            {
                PistonList = pistons;
            }
            // Validate piston config end

            // Validate motor config
            if (MotorConfig.MotorSpeed < 0)
            {
                throw new ArgumentException("MotorConfig: Velocity must be a signed number.");
            }
            if (MotorConfig.MotorMaxElevation < 0)
            {
                throw new ArgumentException("MotorConfig: Max elevation must be a signed number.");
            }
            if (MotorConfig.MotorMinElevation < 0)
            {
                throw new ArgumentException("MotorConfig: Min elevation must be a signed number.");
            }
            // Validate motor config end

            // Make sure all pistons have the same configuration
            ApplyConfig();
            Echo("OK.");
        }
示例#13
0
        public PlatformMotor(GridProgramRef gridProgramRef, string pistonGroupName, MotorConfig motorConfig)
        {
            // Safe guard: Throw an exception if GridTerminalSystem is null
            if (gridProgramRef.GridTerminalSystem == null)
            {
                throw new ArgumentNullException("Passed GTS reference was null.");
            }
            if (gridProgramRef.Echo == null)
            {
                throw new ArgumentNullException("Passed Echo reference was null.");
            }
            // Initialize initial variables
            PistonGroupName    = pistonGroupName;
            PistonList         = new List <IMyPistonBase>();
            MotorState         = MotorState.Idle;
            GridTerminalSystem = gridProgramRef.GridTerminalSystem;
            Echo        = gridProgramRef.Echo;
            MotorConfig = motorConfig;
            // Validate motor config
            if (MotorConfig.MotorSpeed < 0)
            {
                throw new ArgumentException("MotorConfig: Velocity must be a signed number.");
            }
            if (MotorConfig.MotorMaxElevation < 0)
            {
                throw new ArgumentException("MotorConfig: Max elevation must be a signed number.");
            }
            if (MotorConfig.MotorMinElevation < 0)
            {
                throw new ArgumentException("MotorConfig: Min elevation must be a signed number.");
            }
            // Validate motor config end
            // Safe guard: Throw an exception if group is non existent
            var blocks = GridTerminalSystem.GetBlockGroupWithName(PistonGroupName);

            if (blocks == null)
            {
                throw new ArgumentException("Piston block group was not found.");
            }
            blocks.GetBlocksOfType(PistonList);
            ApplyConfig();
        }
示例#14
0
 /// <summary>
 /// Получение блоков контейнера для учёта объектов
 /// </summary>
 /// <param name="terminalSystem">GridTerminalSystem</param>
 /// <param name="Me">Me</param>
 /// <param name="group">(опционально)группа блоков контейнеров</param>
 /// <param name="tagContainer">(опционально) тег контейнеров</param>
 /// <param name="tagExclude">(опционально) исключение контейнеров при общем поиске</param>
 void GetCargoBlocks(IMyGridTerminalSystem terminalSystem, IMyProgrammableBlock Me, string group = "", string tagContainer = "", string tagExclude = "исключить")
 {
     Warning = "";
     _containers.Clear();
     if (group != string.Empty)
     {
         var groupCargo = terminalSystem.GetBlockGroupWithName(group);
         if (groupCargo != null)
         {
             groupCargo.GetBlocksOfType <IMyCargoContainer>(_containers);
         }
     }
     else if (tagContainer != string.Empty)
     {
         terminalSystem.GetBlocksOfType(_containers, x => x.CubeGrid == Me.CubeGrid && x.CustomName.ToLower().Contains(tagContainer.ToLower()));
     }
     if (_containers.Count == 0)
     {
         terminalSystem.GetBlocksOfType(_containers, x => x.CubeGrid == Me.CubeGrid && !x.CustomName.ToLower().Contains(tagExclude.ToLower()));
     }
 }
 public void ReplaceInGroup(string target, string replacement, string blockGroupName)
 {
     ReplaceInGroup(target, replacement, gridTerminalSystem.GetBlockGroupWithName(blockGroupName));
 }