void ProcessStepDockToStation()
        {
            SkipIfOrbitMode();
            SkipIfDockingConnectorAbsent();
            SkipIfDocked();
            //SkipIfNoGridNearby(); if the ship is too far from the grid this step is not going to be executed

            // start docking
            var dockingScript = FindFirstBlockOfType <IMyProgrammableBlock>(
                blk => blk.CustomName.IndexOf(DockingScriptTag, StringComparison.InvariantCultureIgnoreCase) != -1 ||
                MyIni.HasSection(blk.CustomData, DockingScriptTag) && blk.IsWorking);

            if (dockingScript == null)
            {
                EchoR("Docking script not found");
                processStep++;
                throw new PutOffExecutionException();
            }
            if (dockingScript.IsRunning)
            {
                EchoR("Docking script already running");
                processStep++;
                throw new PutOffExecutionException();
            }
            if (IsObstructed(DockingConnector.WorldMatrix.Forward, CollectSmallGrid))
            {
                EchoR("Path obstructed, waiting for docking");
                throw new PutOffExecutionException();
            }

            dockingScript.TryRun(currentWaypoint.Name);
            processStep++;
        }
Beispiel #2
0
        private void updateAirlockDisplay()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var item in airlocks)
            {
                sb.Append("\n\n" + item.Value.description());
            }
            string displayText = "[Airlock " + SpinningBar.Render() + "]\n---------------------------------------" + sb.ToString();

            System.Collections.Generic.List <IMyTextPanel> displays = new System.Collections.Generic.List <IMyTextPanel>();
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(displays, d =>
            {
                MyIni displayIni;
                if (MyIni.HasSection(d.CustomData, "airlock"))
                {
                    displayIni    = new MyIni();
                    string prefix = "";
                    if (displayIni.TryParse(d.CustomData))
                    {
                        prefix = displayIni.Get("airlock", "gridPrefix").ToString();
                        if (prefix != "")
                        {
                            prefix = prefix + "_";
                        }
                        return(gridPrefix == prefix);
                    }
                }
                return(false);
            });
            foreach (IMyTextPanel d in displays)
            {
                d.WriteText(displayText);
            }
            SpinningBar.Step();
        }
            public Logger(Program prog, string requiredIniSection, bool enforceSameCubegrid = true)
            {
                var blocks = new List <IMyTerminalBlock>();

                prog.GridTerminalSystem.GetBlocksOfType(blocks, bl =>
                {
                    var hasSection   = MyIni.HasSection(bl.CustomData, requiredIniSection);
                    var sameCubegrid = enforceSameCubegrid ? bl.CubeGrid == prog.Me.CubeGrid : true;
                    return(hasSection && sameCubegrid);
                });
                foreach (var block in blocks)
                {
                    if (block is IMyTextSurface)
                    {
                        prog.Echo($"Found text surface \"{block.CustomName}\" for logging.");
                        AddSurface((IMyTextSurface)block);
                    }
                    else if (block is IMyTextSurfaceProvider)
                    {
                        prog.Echo($"Found text surface provider \"{block.CustomName}\" for logging.");
                        AddSurface(((IMyTextSurfaceProvider)block).GetSurface(0));
                    }
                }
                if (surfaces.Count == 0)
                {
                    prog.Echo("Warning: Couldn't find any displays during logger initialization!");
                }
            }
Beispiel #4
0
        bool SubProcessCheckRemainingBatteryCapacity(StringWrapper log)
        {
            var batteries = new List <IMyBatteryBlock>();

            GridTerminalSystem.GetBlocksOfType(batteries, blk => CollectSameConstruct(blk) && blk.IsFunctional && blk.Enabled);
            if (batteries.Count() > 0)
            {
                float remainingCapacity = RemainingBatteryCapacity(batteries);
                if (remainingCapacity < CriticalBatteryCapacity)
                {
                    log.Append("Critical power detected");
                    criticalBatteryCapacityDetected = true;
                    var timerblocks = new List <IMyTimerBlock>();
                    GridTerminalSystem.GetBlocksOfType(timerblocks, tb => MyIni.HasSection(tb.CustomData, TriggerOnCriticalCurrentDetectedTag));
                    timerblocks.ForEach(tb => tb.Trigger());

                    // disable blocks with DisableOnEmergencyTag
                    DisableBlocks(blk => MyIni.HasSection(blk.CustomData, DisableOnEmergencyTag));
                    informationTerminals.Text = string.Format("Critical power detected");
                }
                else if (criticalBatteryCapacityDetected)
                {
                    criticalBatteryCapacityDetected = false;
                    var timerblocks = new List <IMyTimerBlock>();
                    GridTerminalSystem.GetBlocksOfType(timerblocks, tb => MyIni.HasSection(tb.CustomData, TriggerOnNormalCurrentReestablishedTag));
                    timerblocks.ForEach(tb => tb.Trigger());

                    // enable blocks with DisableOnEmergencyTag
                    EnableBlocks(blk => MyIni.HasSection(blk.CustomData, DisableOnEmergencyTag));
                }

                log.Append(string.Format("Battery capacity: {0}%", Math.Round(remainingCapacity * 100, 0)));
            }
            return(true);
        }
Beispiel #5
0
        public void Main(string argument, UpdateType updateSource)
        {
            System.Collections.Generic.List <IMyTextPanel> displays = new System.Collections.Generic.List <IMyTextPanel>();
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(displays, d => MyIni.HasSection(d.CustomData, "energy"));
            string           report1 = display1.Render(energyInfo1);
            string           report2 = display2.Render(energyInfo2);
            MyIni            menuIni = new MyIni();
            MyIniParseResult br;

            foreach (IMyTextPanel d in displays)
            {
                if (menuIni.TryParse(d.CustomData, out br))
                {
                    string group = menuIni.Get("energy", "group").ToString();
                    if (group.Equals("1"))
                    {
                        d.WriteText(report1);
                    }
                    else if (group.Equals("2"))
                    {
                        d.WriteText(report2);
                    }
                }
            }
            SpinningBar.Step();
        }
Beispiel #6
0
        bool SubProcessDisableBroadcasting()
        {
            var antenna = FindFirstBlockOfType <IMyRadioAntenna>(blk => MyIni.HasSection(blk.CustomData, ScriptPrefixTag));

            antenna.EnableBroadcasting = false;

            return(true);
        }
Beispiel #7
0
        private void Setup()
        {
            _groupList.Clear();

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

            // Find all blocks with a "[LandingPad]" section in custom data.
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, block => MyIni.HasSection(block.CustomData, MyConstants.SectionName) && block.IsSameConstructAs(Me));

            // Step through each block and determine groups
            foreach (IMyTerminalBlock block in blocks)
            {
                // parse the custom data for the block
                MyIniParseResult parsedIniResult;
                if (_data.TryParse(block.CustomData, out parsedIniResult))
                {
                    MyConfiguration blockConfig = new MyConfiguration(_data);

                    // Get the Group value.
                    string groupName = blockConfig.GroupName;

                    // If there is no group specified and if this is a text panel, use that as a main panel,
                    // otherwise continue with next block.
                    if (blockConfig.GroupName == MyConstants.DefaultGroupName)
                    {
                        IMyTextPanel lcdPanel = block as IMyTextPanel;
                        if (lcdPanel != null)
                        {
                            DisplayPanel panel = new DisplayPanel(_groupList, lcdPanel);
                            _mainPanels.Add(panel);
                        }

                        continue;
                    }
                    ;

                    // If group does not exist, add a new group with this name.
                    if (!_groupList.Exists(x => x.GroupName == groupName))
                    {
                        LandingPadGroup landingLightGroup = new LandingPadGroup(groupName);
                        _groupList.Add(landingLightGroup);
                    }

                    // Get the group for this block it should be added to.
                    LandingPadGroup group = _groupList.Find(x => x.GroupName == groupName);

                    AddBlockToGroup(group, block, blockConfig);
                }
            }


            // All block should now be assigned.
            // Configure the individual blocks for each group.
            foreach (LandingPadGroup group in _groupList)
            {
                group.ConfigureBlocks();
            }
        }
Beispiel #8
0
        private void RefreshBlockList()
        {
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(_blocksWithInventory, block =>
                                                                  block.HasInventory && block.IsSameConstructAs(Me) &&
                                                                  (!_optInWithTag || MyIni.HasSection(block.CustomData, _tagName)));

            _inventories.Clear();
            _inventories.AddRange(_blocksWithInventory.SelectMany(block => Enumerable.Range(0, block.InventoryCount).Select(block.GetInventory)));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DebugTerminal"/> class.
 /// </summary>
 /// <param name="program">The program<see cref="Program"/>.</param>
 /// <param name="map">The map<see cref="Map"/>.</param>
 public DisplayTerminal(Program program, Func<IMyTerminalBlock, bool> collect = null) : base(program)
 {
     if (collect != null)
     {
         this.collect = collect;
     } else
     {
         this.collect = blk => MyIni.HasSection(blk.CustomData, DisplayTerminalTag);
     }
 }
Beispiel #10
0
            private void CreateConfig()
            {
                if (MyIni.HasSection(_program.Me.CustomData, _scriptName))
                {
                    return;
                }

                _ini.Clear();
                _config.SetupDefaults();
                _program.Me.CustomData = _ini.ToString();
            }
Beispiel #11
0
 void SkipIfCriticalBatteryDetected(IMyTerminalBlock block = null)
 {
     if (criticalBatteryCapacityDetected)
     {
         if (block == null || MyIni.HasSection(block.CustomData, DisableOnEmergencyTag))
         {
             processStep++;
             throw new PutOffExecutionException();
         }
     }
 }
Beispiel #12
0
            private IMyShipConnector GetFreeDockingPort()
            {
                IMyShipConnector        dockingPort = Drone.Grid().GetBlockWithName("Docking Port 1") as IMyShipConnector;
                List <IMyShipConnector> connectors  = new List <IMyShipConnector>();

                Drone.Grid().GetBlocksOfType <IMyShipConnector>(connectors, connector =>
                {
                    return(MyIni.HasSection(connector.CustomData, "docking_port") && connector.Status == MyShipConnectorStatus.Unconnected);
                });

                return(connectors.FirstOrDefault());
            }
Beispiel #13
0
        private IEnumerable <ResourceDisplay> InitResourceDisplays(IEnumerable <Container> containers)
        {
            List <IMyTextPanel> panels = new List <IMyTextPanel>();

            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(panels, panel => MyIni.HasSection(panel.CustomData, ResourceDisplay.resources) && this.Me.CubeGrid == panel.CubeGrid);
            List <ResourceDisplay> resourceDisplays = new List <ResourceDisplay>();

            foreach (IMyTextPanel panel in panels)
            {
                resourceDisplays.Add(new ResourceDisplay(panel, containers));
            }
            return(resourceDisplays);
        }
Beispiel #14
0
            /// <summary>
            /// The Collect.
            /// </summary>
            /// <param name="terminal">The terminal<see cref="IMyTextPanel"/>.</param>
            /// <returns>The <see cref="bool"/>.</returns>
            public override bool Collect(IMyTerminalBlock terminal)
            {
                // Collect this.
                bool isSolarmap = terminal.IsSameConstructAs(Program.Me) &&
                                  MyIni.HasSection(terminal.CustomData, Program.ScriptPrefixTag) &&
                                  (terminal is IMyTextPanel || terminal is IMyTextSurfaceProvider) &&
                                  terminal.IsWorking &&
                                  terminal != Program.Me;

                //program.EchoR(string.Format("Collecting {0} {1}", terminal.CustomName, isSolarmap));

                // Return.
                return(isSolarmap);
            }
Beispiel #15
0
            public override bool Collect(IMyTextPanel terminal)
            {
                // To be collected.
                bool isSolarmap = terminal.IsSameConstructAs(program.Me) && MyIni.HasSection(terminal.CustomData, "SolarMap");

                // Set content type.
                if (isSolarmap)
                {
                    terminal.ContentType = ContentType.SCRIPT;
                    terminal.Script      = "";                // Resets any mistakes that the user might have done.
                }

                return(isSolarmap);
            }
Beispiel #16
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");
        }
Beispiel #17
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100;

            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(StatusMonitors, lcd => MyIni.HasSection(lcd.CustomData, "status_monitor") && lcd.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyBatteryBlock>(Batteries, battery => battery.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyGasTank>(FuelTanks, tank => BlockUtils.IsHydrogenTank(tank) && tank.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyGasTank>(OxygenTanks, tank => BlockUtils.IsOxygenTank(tank) && tank.IsSameConstructAs(Me));

            GridTerminalSystem.GetBlocksOfType <IMyGravityGenerator>(GravityGenerators, gravity => gravity.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyRefinery>(Refineries, refinery => refinery.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyAssembler>(Assemblers, assembler => assembler.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyGasGenerator>(GasGenerators, gasGenerator => gasGenerator.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyRadioAntenna>(Antennas, antenna => antenna.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyOreDetector>(OreDetectors, detector => detector.IsSameConstructAs(Me));
        }
        void ProcessStepDoAfterDocking()
        {
            SkipIfOrbitMode();
            //SkipIfNoGridNearby();  // if the ship is connected the station is not counted

            var timerBlocks = new List <IMyTimerBlock>();

            GridTerminalSystem.GetBlocksOfType(timerBlocks, blk => MyIni.HasSection(blk.CustomData, TriggerAfterDockingTag) && CollectSameConstruct(blk));
            timerBlocks.ForEach(timerBlock => timerBlock.Trigger());

            var blocks = new List <IMyFunctionalBlock>();

            GridTerminalSystem.GetBlocksOfType(blocks, blk => MyIni.HasSection(blk.CustomData, ToggleAfterDockingTag) && CollectSameConstruct(blk));
            blocks.ForEach(blk => blk.Enabled = !blk.Enabled);

            processStep++;
        }
Beispiel #19
0
        public void Main(string argument, UpdateType updateSource)
        {
            MyIni            _ini = new MyIni();
            MyIniParseResult result;

            if (!_ini.TryParse(Me.CustomData, out result))
            {
                Echo("c'è un problema: " + result.Success + " " + result.Error);
            }
            else
            {
                List <IMyTerminalBlock> blocks   = new List <IMyTerminalBlock>();
                List <IMyTextPanel>     displays = new List <IMyTextPanel>();
                string blockName = _ini.Get("entity", "name").ToString();
                GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(displays, d => MyIni.HasSection(d.CustomData, "resource"));
                GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, v => v.CustomName.Equals(blockName));
                Echo(blockName);
                if (blocks.Count > 0)
                {
                    IMyTerminalBlock block = blocks[0];
                    if (block.HasInventory)
                    {
                        List <MyInventoryItem> items     = new List <MyInventoryItem>();
                        IMyInventory           inventory = block.GetInventory();
                        inventory.GetItems(items);
                        StringBuilder allDescriptions = new StringBuilder();
                        foreach (MyInventoryItem item in items)
                        {
                            allDescriptions.AppendLine(item.Type.TypeId + "," + item.Type.SubtypeId + ":" + item.Amount.ToString());
                        }
                        foreach (IMyTextPanel display in displays)
                        {
                            display.WriteText(allDescriptions);
                        }
                    }
                    else
                    {
                        Echo("Il blocco \"" + blockName + "\" non ha inventario");
                    }
                }
                else
                {
                    Echo("Nessun blocco \"" + blockName + "\" trovato");
                }
            }
        }
        void ProcessStepDoBeforeUndocking()
        {
            SkipIfOrbitMode();
            SkipIfNoGridNearby();

            var timerBlocks = new List <IMyTimerBlock>();

            GridTerminalSystem.GetBlocksOfType(timerBlocks, blk => MyIni.HasSection(blk.CustomData, TriggerBeforeUndockingTag) && CollectSameConstruct(blk));
            timerBlocks.ForEach(timerBlock => timerBlock.Trigger());

            var blocks = new List <IMyFunctionalBlock>();

            GridTerminalSystem.GetBlocksOfType(blocks, blk => MyIni.HasSection(blk.CustomData, ToggleBeforeUndockingTag) && CollectSameConstruct(blk));
            blocks.ForEach(blk => blk.Enabled = !blk.Enabled);

            processStep++;
        }
Beispiel #21
0
        public void Main(string argument, UpdateType updateSource)
        {
            System.Collections.Generic.List <IMyTextPanel> displays = new System.Collections.Generic.List <IMyTextPanel>();
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(displays, d => MyIni.HasSection(d.CustomData, "resource"));

            Echo(string.Format("resource display found: {0}", displays.Count));

            string           report  = display.Show(resourceInfo);
            MyIni            menuIni = new MyIni();
            MyIniParseResult br;

            foreach (IMyTextPanel d in displays)
            {
                if (menuIni.TryParse(d.CustomData, out br))
                {
                    d.WriteText(report);
                }
            }
        }
Beispiel #22
0
            private void FetchSurfaces()
            {
                _surfaceProviders.FindBlocks(true, block =>
                {
                    if (!(block is IMyTextSurfaceProvider))
                    {
                        return(false);
                    }

                    if (!MyIni.HasSection(block.CustomData, _scriptName))
                    {
                        return(false);
                    }

                    RegisteredProvider registeredProvider;
                    if (!_registeredProviders.ContainsKey(block.EntityId))
                    {
                        registeredProvider = new RegisteredProvider(_context, block, _ini, _scriptName);
                        _registeredProviders.Add(block.EntityId, registeredProvider);
                    }
                    else
                    {
                        registeredProvider = _registeredProviders[block.EntityId];
                    }

                    if (block == _program.Me)
                    {
                        registeredProvider.SetScreenHandlerForSurface(ExcavOSScreen.SCREEN_NAME, 0);
                    }
                    else
                    {
                        registeredProvider.LoadConfig(block.CustomData);
                    }

                    if (!registeredProvider.HasSurfaces())
                    {
                        _registeredProviders.Remove(block.EntityId);
                    }

                    return(true);
                });
            }
Beispiel #23
0
        private Menu SwitchMenu()
        {
            MyIni menuIni = new MyIni();
            Menu  menu    = new Menu("Active Systems");

            System.Collections.Generic.List <IMyFunctionalBlock> blocks = new System.Collections.Generic.List <IMyFunctionalBlock>();
            GridTerminalSystem.GetBlocksOfType <IMyFunctionalBlock>(blocks, b => MyIni.HasSection(b.CustomData, "switchable"));
            blocks.Sort(delegate(IMyFunctionalBlock b1, IMyFunctionalBlock b2) {
                return(b1.CustomName.CompareTo(b2.CustomName));
            });
            foreach (IMyFunctionalBlock b in blocks)
            {
                MyIniParseResult br;
                if (menuIni.TryParse(b.CustomData, out br) && menuIni.Get("switchable", "spinning").ToBoolean())
                {
                    menu.AddItem(new BlockSwitcher(b, true));
                }
                else
                {
                    menu.AddItem(new BlockSwitcher(b));
                }
            }
            return(menu);
        }
Beispiel #24
0
        void ProcessStepDetectGridsUsingCamera()
        {
            var cameras = new List <IMyCameraBlock>();

            GridTerminalSystem.GetBlocksOfType(cameras, blk => blk.IsSameConstructAs(Me) && MyIni.HasSection(blk.CustomData, ScriptPrefixTag));
            foreach (var camera in cameras)
            {
                camera.EnableRaycast = true;
                //EchoR($"raycast scan range: {camera.AvailableScanRange}");
                if (camera.CanScan(CameraScanRange))
                {
                    var detectedGrid = camera.Raycast(CameraScanRange, 0, 0);
                    if (!detectedGrid.IsEmpty())
                    {
                        //EchoR($"detected: {detectedGrid.Name}");
                        CelestialMap.AddGPSPosition(detectedGrid.Name, detectedGrid.Position);
                    }
                }
            }
        }
Beispiel #25
0
        public void Main(string argument, UpdateType updateType)
        {
            if ((updateType & UpdateType.Trigger) != 0)
            {
                Airlock airlock = new Airlock();
                // Parse Arguments
                if (CommandLine.TryParse(argument))
                {
                    airlock.DoorSide    = CommandLine.Argument(0);
                    airlock.AirlockName = CommandLine.Argument(1);
                }

                // Get a list of all doors for this script
                GridTerminalSystem.GetBlocksOfType <IMyDoor>(airlock.Doors, door => MyIni.HasSection(door.CustomData, "AirlockScript"));
                // Get a list of all airvents for this script
                GridTerminalSystem.GetBlocksOfType <IMyAirVent>(airlock.AirVents, vent => MyIni.HasSection(vent.CustomData, "AirlockScript"));
                // Get a list of all lights for this script
                GridTerminalSystem.GetBlocksOfType <IMyLightingBlock>(airlock.Lights, vent => MyIni.HasSection(vent.CustomData, "AirlockScript"));
                // Get a list of all lights for this script
                GridTerminalSystem.GetBlocksOfType <IMySoundBlock>(airlock.SoundBlocks, vent => MyIni.HasSection(vent.CustomData, "AirlockScript"));

                // Go through each door in the list until the custom data matches with the inputed arguments
                foreach (IMyDoor door in airlock.Doors)
                {
                    MyIniParseResult result;
                    if (!ini.TryParse(door.CustomData, out result))
                    {
                        throw new Exception(result.ToString());
                    }

                    if (ini.Get("AirlockScript", "AirlockName").ToString() == airlock.AirlockName)
                    {
                        // If the airlock was triggered by the sensor, determine which door needs to close
                        // Door side passed in should be the door currently open.
                        if (airlock.DoorSide == "Sensor")
                        {
                            if (door.OpenRatio == 1)
                            {
                                airlock.DoorSide = ini.Get("AirlockScript", "DoorSide").ToString();
                            }
                        }
                        if (ini.Get("AirlockScript", "DoorSide").ToString() == airlock.DoorSide)
                        {
                            airlock.OpenDoors.Add(door);
                        }
                        else
                        {
                            airlock.ClosedDoors.Add(door);
                        }
                    }
                }

                foreach (IMyAirVent vent in airlock.AirVents)
                {
                    MyIniParseResult result;
                    if (!ini.TryParse(vent.CustomData, out result))
                    {
                        throw new Exception(result.ToString());
                    }

                    if (ini.Get("AirlockScript", "AirlockName").ToString() == airlock.AirlockName)
                    {
                        airlock.ThisAirlockAirVents.Add(vent);
                    }
                }

                foreach (IMyLightingBlock light in airlock.Lights)
                {
                    MyIniParseResult result;
                    if (!ini.TryParse(light.CustomData, out result))
                    {
                        throw new Exception(result.ToString());
                    }

                    if (ini.Get("AirlockScript", "AirlockName").ToString() == airlock.AirlockName)
                    {
                        airlock.AirlockLights.Add(light);
                    }
                }

                foreach (IMySoundBlock sb in airlock.SoundBlocks)
                {
                    MyIniParseResult result;
                    if (!ini.TryParse(sb.CustomData, out result))
                    {
                        throw new Exception(result.ToString());
                    }

                    if (ini.Get("AirlockScript", "AirlockName").ToString() == airlock.AirlockName)
                    {
                        airlock.AirlockSoundBlocks.Add(sb);
                    }
                }
                Airlocks.Add(airlock);
            }
            if ((updateType & UpdateType.Update10) != 0 && Airlocks.Count() > 0)
            {
                foreach (Airlock airlock in Airlocks)
                {
                    airlock.AirlockSwitch();
                    if (airlock.Step == 0)
                    {
                        AirlockClearList.Add(airlock);
                    }
                }
                foreach (Airlock airlock in AirlockClearList)
                {
                    Airlocks.Remove(airlock);
                }
                AirlockClearList.Clear();
            }
        }
Beispiel #26
0
        void ProcessStepDetectGridsUsingSensor()
        {
            var sensors = new List <IMySensorBlock>();

            GridTerminalSystem.GetBlocksOfType(sensors, blk => blk.IsSameConstructAs(Me) && MyIni.HasSection(blk.CustomData, ScriptPrefixTag));
            foreach (var sensor in sensors)
            {
                var detectedGrids = new List <MyDetectedEntityInfo>();
                sensor.DetectedEntities(detectedGrids);
                foreach (var grid in detectedGrids)
                {
                    CelestialMap.AddGPSPosition(grid.Name, grid.Position);
                }
            }
        }
Beispiel #27
0
        public Program()
        {
            try
            {
                UpdateSettings();
                ResetDisplay();

                this.remote = GridTerminalSystem.GetBlockOfType <IMyRemoteControl>(rm => rm.CubeGrid == Me.CubeGrid && MyIni.HasSection(rm.CustomData, REFERENCE_RM));

                if (remote == null)
                {
                    throw new InvalidOperationException("Missile MUST have a remote. (That is forward facing)");
                }
                LogLine($"Found remote {remote.CustomName}");

                this.separator = GridTerminalSystem.GetBlockOfType <IMyShipMergeBlock>(mb => mb.CubeGrid == Me.CubeGrid && MyIni.HasSection(mb.CustomData, SEPARATOR_MARKER));
                if (this.separator != null)
                {
                    LogLine($"Found separator merge-block {separator.CustomName}");
                }
                else
                {
                    LogLine($"Warning: No separator block found. Missile can launch without one, but if you do have a separator, add a [{SEPARATOR_MARKER}] line to its custom data.");
                }

                this.statusLogger = new Logger(this, STATUS_DISPLAY_SECTION, true);

                GridTerminalSystem.GetBlocksOfType(allThrusters, th => th.CubeGrid == Me.CubeGrid);

                foreach (var thruster in allThrusters)
                {
                    if (thruster.WorldMatrix.Forward == remote.WorldMatrix.Backward)
                    {
                        fwdThrusters.Add(thruster);
                        LogLine($"Found forward thruster {thruster.CustomName}");
                    }
                    if (thruster.WorldMatrix.Forward == remote.WorldMatrix.Up)
                    {
                        downThrusters.Add(thruster);
                        LogLine($"Found down thruster {thruster.CustomName}");
                    }
                    thruster.Enabled = false;
                    thruster.ThrustOverridePercentage = 0;
                }

                GridTerminalSystem.GetBlocksOfType(warheads, b => b.CubeGrid == Me.CubeGrid);
                LogLine($"Found {warheads.Count} warheads.");

                foreach (var warhead in warheads)
                {
                    warhead.IsArmed = false;
                }

                GridTerminalSystem.GetBlocksOfType(gyros, b => b.CubeGrid == Me.CubeGrid);
                foreach (var gyro in gyros)
                {
                    gyro.Enabled = false;
                }

                GridTerminalSystem.GetBlocksOfType(antennas, b => b.CubeGrid == Me.CubeGrid && MyIni.HasSection(b.CustomData, MISSILE_ANTENNA));
                foreach (var ant in antennas)
                {
                    ant.Enabled    = false;
                    ant.Radius     = 50000f;
                    ant.CustomName = $"{uuid} Antenna";
                }

                LogLine("Missile is ready to launch");
                LogStatus("Missile: Pre-flight");
                this.msgHandler = CreateMessageHandler();
                IGC.SendBroadcast(new RegisterMissileCommand()
                {
                    UUID = uuid
                });
            }
            catch (Exception ex)
            {
                LogLine($"[{uuid}] Program() expection: {ex}\nStacktrace: \n{ex.StackTrace}");
            }
        }
Beispiel #28
0
 static public Predicate WithSection(string name)
 => new Predicate(subject => MyIni.HasSection(subject.CustomData, name));
Beispiel #29
0
        private void Setup()
        {
            bool isValid = true;

            Inventories.Clear();
            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(allBlocks, block => block.HasInventory);

            foreach (var block in allBlocks)
            {
                for (var i = 0; i < block.InventoryCount; i++)
                {
                    Inventories.Add(new InventoryManager(block.GetInventory(i)));
                }
            }

            var ini = new MyIni();
            MyIniParseResult result;
            var panels = new List <IMyTextPanel>();

            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(panels, panel => MyIni.HasSection(panel.CustomData, panelSectionName));
            foreach (var panel in panels)
            {
                if (!ini.TryParse(panel.CustomData, out result))
                {
                    Echo("Invalid configuration for panel " + panel.DisplayNameText);
                    isValid = false;
                    continue;
                }

                if (ini.ContainsKey(panelSectionName, componentKeyName))
                {
                    var index  = ini.Get(panelSectionName, componentKeyName).ToInt16();
                    var dPanel = ComponentPanels.FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        ComponentPanels.Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
                else if (ini.ContainsKey(panelSectionName, oreKeyName))
                {
                    var index  = ini.Get(panelSectionName, oreKeyName).ToInt16();
                    var dPanel = OrePanels.FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        OrePanels.Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
                else if (ini.ContainsKey(panelSectionName, ingotKeyName))
                {
                    var index  = ini.Get(panelSectionName, ingotKeyName).ToInt16();
                    var dPanel = IngotsPanels.FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        IngotsPanels.Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }

                panel.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
            }

            if (ComponentPanels.Count + OrePanels.Count + IngotsPanels.Count == 0)
            {
                Echo("No valid panels found for display");
                isValid = false;
            }

            if (!isValid)
            {
                Runtime.UpdateFrequency = UpdateFrequency.None;
            }

            ComponentPanels.Sort();
            IngotsPanels.Sort();
            OrePanels.Sort();
        }
Beispiel #30
0
        bool SubProcessActivateEmergencyPower(StringWrapper log)
        {
            var generators = new List <IMyPowerProducer>();

            GridTerminalSystem.GetBlocksOfType(generators, blk => CollectSameConstruct(blk) && MyIni.HasSection(blk.CustomData, EmergencyPowerTag));

            if (criticalBatteryCapacityDetected)
            {
                log.Append("Emergency power on");
                generators.ForEach(blk => blk.Enabled = true);
            }
            else
            {
                generators.ForEach(blk => blk.Enabled = false);
            }
            return(true);
        }