Exemple #1
0
 protected void DisableVent()
 {
     vent.ApplyAction("OnOff_Off");
     vent.ApplyAction("Depressurize_Off");
 }
Exemple #2
0
        void Main(string argument)
        {
            List <IMyBlockGroup> groups = new List <IMyBlockGroup>();

            GridTerminalSystem.GetBlockGroups(groups);

            int   num      = 0;
            int   num2     = 0;
            int   num3     = 0;
            float sum      = 0;
            float newLevel = 0;

            for (int i = 0; i < groups.Count; i++)
            {
                IMyBlockGroup group = groups[i];
                if (group.Name == tankGroup)
                {
                    List <IMyTerminalBlock> groupBlocks = new List <IMyTerminalBlock>();
                    group.GetBlocks(groupBlocks);
                    for (int j = 0; j < groupBlocks.Count; j++)
                    {
                        IMyGasTank tank = groupBlocks[j] as IMyGasTank;
                        num++;
                        sum += (float)tank.FilledRatio;
                    }
                }
            }

            if (num == 0)
            {
                newLevel = 0;
            }
            else
            {
                newLevel = sum / num;
            }

            if (state == none || (state == on && newLevel >= maxLevel) || (state == off && newLevel <= minLevel))
            {
                if (newLevel >= maxLevel)
                {
                    state = off;
                }
                else
                {
                    state = on;
                }
            }

            for (int i = 0; i < groups.Count; i++)
            {
                IMyBlockGroup group = groups[i];
                if (group.Name == generatorGroup)
                {
                    List <IMyTerminalBlock> groupBlocks = new List <IMyTerminalBlock>();
                    group.GetBlocks(groupBlocks);
                    for (int j = 0; j < groupBlocks.Count; j++)
                    {
                        IMyFunctionalBlock gen = groupBlocks[j] as IMyFunctionalBlock;
                        gen.Enabled = (state == on);
                        num2++;
                    }
                }
            }
            for (int i = 0; i < groups.Count; i++)
            {
                IMyBlockGroup group = groups[i];
                if (group.Name == ventGroup)
                {
                    List <IMyTerminalBlock> groupBlocks = new List <IMyTerminalBlock>();
                    group.GetBlocks(groupBlocks);
                    for (int j = 0; j < groupBlocks.Count; j++)
                    {
                        IMyAirVent vent = groupBlocks[j] as IMyAirVent;
                        vent.ApplyAction("Depressurize_On");
                        vent.Enabled = (state == on);
                        num3++;
                    }
                }
            }

            updateLcd(newLevel, num, num2, num3);
        }
Exemple #3
0
        public HangarController(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime)
        {
            GridTerminalSystem = grid;
            Echo        = echo;
            ElapsedTime = elapsedTime;
            Me          = me;

            hangarDoors   = new List <IMyDoor> [groups.Count];
            interiorDoors = new List <IMyDoor> [groups.Count];
            exteriorDoors = new List <IMyDoor> [groups.Count];
            soundBlocks   = new List <IMySoundBlock> [groups.Count];
            warningLights = new List <IMyInteriorLight> [groups.Count];
            airVents      = new List <IMyAirVent> [groups.Count];

            hangarOpen = new Boolean[groups.Count];

            // Get list of groups on this station/ship
            List <IMyBlockGroup> BlockGroups = new List <IMyBlockGroup>();

            GridTerminalSystem.GetBlockGroups(BlockGroups);

            // Search all groups that exist for the groups with name as specified in groups list
            for (int i = 0; i < BlockGroups.Count; i++)
            {
                int pos = groups.IndexOf(BlockGroups[i].Name);
                // If name is one of our candidates...
                if (pos != -1)
                {
                    List <IMyTerminalBlock> blocks = BlockGroups[i].Blocks;

                    // Define list of blocks for each group
                    List <IMyDoor>          hangarDoorList   = new List <IMyDoor>();
                    List <IMyDoor>          interiorDoorList = new List <IMyDoor>();
                    List <IMyDoor>          exteriorDoorList = new List <IMyDoor>();
                    List <IMySoundBlock>    soundBlockList   = new List <IMySoundBlock>();
                    List <IMyInteriorLight> warningLightList = new List <IMyInteriorLight>();
                    List <IMyAirVent>       airVentList      = new List <IMyAirVent>();

                    // Go through all blocks and add to appropriate list
                    // Also initialize to a sane known state e.g. closed, on...
                    for (int j = 0; j < blocks.Count; j++)
                    {
                        IMyTerminalBlock block     = blocks[j];
                        String           blockType = block.DefinitionDisplayNameText;
                        String           blockName = block.CustomName;
                        block.ApplyAction("OnOff_On");

                        if (blockType.Equals("Airtight Hangar Door"))
                        {
                            IMyDoor item = block as IMyDoor;
                            item.ApplyAction("Open_Off");
                            hangarDoorList.Add(item);
                        }
                        else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Interior"))
                        {
                            IMyDoor item = block as IMyDoor;
                            item.ApplyAction("Open_Off");
                            interiorDoorList.Add(item);
                        }
                        else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Exterior"))
                        {
                            IMyDoor item = block as IMyDoor;
                            item.ApplyAction("Open_Off");
                            exteriorDoorList.Add(item);
                        }
                        else if (blockType.Equals("Sound Block"))
                        {
                            IMySoundBlock item = block as IMySoundBlock;
                            item.ApplyAction("StopSound");
                            item.SetValueFloat("LoopableSlider", 10);
                            soundBlockList.Add(item);
                        }
                        else if (blockType.Equals("Interior Light"))
                        {
                            IMyInteriorLight item = block as IMyInteriorLight;
                            item.ApplyAction("OnOff_Off");
                            item.SetValueFloat("Blink Interval", 1);
                            item.SetValueFloat("Blink Lenght", 50);
                            item.SetValueFloat("Blink Offset", 0);
                            item.SetValue <Color>("Color", Color.Red);
                            warningLightList.Add(item);
                        }
                        else if (blockType.Contains("Air Vent"))
                        {
                            IMyAirVent item = block as IMyAirVent;
                            item.ApplyAction("Depressurize_Off");
                            airVentList.Add(item);
                        }
                    }

                    // Some cleanup
                    hangarDoorList.TrimExcess();
                    interiorDoorList.TrimExcess();
                    exteriorDoorList.TrimExcess();
                    soundBlockList.TrimExcess();
                    warningLightList.TrimExcess();
                    airVentList.TrimExcess();

                    if (hangarDoorList.Count == 0)
                    {
                        Echo("Warning: no hangar doors detected for " + BlockGroups[i].Name);
                    }
                    else if (interiorDoorList.Count == 0)
                    {
                        Echo("Warning: no interior doors detected for " + BlockGroups[i].Name);
                    }
                    else if (soundBlockList.Count == 0)
                    {
                        Echo("Warning: no sound blocks detected for " + BlockGroups[i].Name);
                    }
                    else if (warningLightList.Count == 0)
                    {
                        Echo("Warning: no warning lights detected for " + BlockGroups[i].Name);
                    }
                    else if (airVentList.Count == 0)
                    {
                        Echo("Warning: no air vents detected for " + BlockGroups[i].Name);
                    }

                    // Now that we have populated lists add them to the correct position in the group list

                    hangarDoors[pos]   = hangarDoorList;
                    interiorDoors[pos] = interiorDoorList;
                    exteriorDoors[pos] = exteriorDoorList;
                    soundBlocks[pos]   = soundBlockList;
                    warningLights[pos] = warningLightList;
                    airVents[pos]      = airVentList;
                    hangarOpen[pos]    = false;

                    // Exterior doors have been requested to close so we set a check to lock them when they are in fact closed
                    requests.Add(new requestTicket(pos, "lockExteriorDoors"));
                }
            }
        }