Exemplo n.º 1
0
        string AirTightCheck(IMyBlockGroup ventBlocks, IMyTextSurface disp)
        {
            List <IMyAirVent> airVents = new List <IMyAirVent>();

            ventBlocks.GetBlocksOfType <IMyAirVent>(airVents);

            Color         fontColor = new Color(0, 150, 0);
            StringBuilder sb        = new StringBuilder();

            sb.AppendLine("Air Integrity Status");
            sb.AppendLine("--------------------");
            foreach (IMyAirVent av in airVents)
            {
                VentStatus ventStatus = av.Status;

                sb.AppendLine($"{av.CustomName}: {ventStatus.ToString()}");
                if (ventStatus == VentStatus.Depressurized || ventStatus == VentStatus.Depressurizing)
                {
                    disp.FontColor = Color.Red;
                }
                else
                {
                    disp.FontColor = fontColor;
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
 public AirlockConstruct(ISelector <IMyDoor> innerDoor, ISelector <IMyDoor> outerDoor, ISelector <IMyAirVent> vent)
 {
     _innerDoor         = innerDoor.GetBlock();
     _outerDoor         = outerDoor.GetBlock();
     _vent              = vent.GetBlock();
     _status            = _vent.Status;
     _enabled           = _vent.Enabled;
     CycleAction        = new ScriptableAction(() => Cycle());
     PressurizeAction   = new ScriptableAction(() => Cycle(true));
     DepressurizeAction = new ScriptableAction(() => Cycle(false));
     _triggers.Add(new IntervalTrigger(300).Then(new ScriptableAction(Update)));
 }
Exemplo n.º 3
0
 private void DepressurizeSequence()
 {
     if (_vent.GetOxygenLevel() == 0)
     {
         _outerDoor.Enabled = true;
         _outerDoor.OpenDoor();
         _status = VentStatus.Depressurized;
     }
     else if (_innerDoor.Status == DoorStatus.Closed)
     {
         _innerDoor.Enabled = false;
         _vent.Depressurize = true;
     }
 }
Exemplo n.º 4
0
 private void PressurizeSequence()
 {
     if (_vent.Status == VentStatus.Pressurized)
     {
         _outerDoor.Enabled = false;
         _innerDoor.Enabled = true;
         _innerDoor.OpenDoor();
         _status = VentStatus.Pressurized;
     }
     else if (_outerDoor.Status == DoorStatus.Closed)
     {
         _outerDoor.Enabled = _vent.Depressurize = false;
     }
 }
Exemplo n.º 5
0
 private void UpdateEnabled()
 {
     if (_vent.Enabled != _enabled)
     {
         _enabled = _vent.Enabled;
         if (_enabled)
         {
             _outerDoor.CloseDoor();
             _status = VentStatus.Pressurizing;
         }
         else
         {
             _innerDoor.Enabled = _outerDoor.Enabled = true;
         }
     }
 }
Exemplo n.º 6
0
 private void Cycle(bool?pressurize = null)
 {
     if (_status == VentStatus.Depressurizing || _status == VentStatus.Pressurizing || pressurize == AirlockHasPressure || !_enabled)
     {
         return;
     }
     if (pressurize ?? !AirlockHasPressure)
     {
         _status = VentStatus.Pressurizing;
         _outerDoor.CloseDoor();
     }
     else
     {
         _status = VentStatus.Depressurizing;
         _innerDoor.CloseDoor();
     }
 }
Exemplo n.º 7
0
            public override string ToText(MonitorContent content)
            {
                switch (content.Subtype)
                {
                case "stat": return(EnumToText((int)VentStatus, VentStatus.ToString(), content));

                case "pressurized": return(BoolToText(Pressurized, "Pressurized", "", content));

                case "depressurized": return(BoolToText(Depressurized, "Depressurized", "", content));

                case "can": return(BoolToText(CanPressurize, "Can Pressurize", "", content));

                case "mode": return(BoolToText(Depressurize, "Depressurize", "Pressurize", content));

                case "enable": return(BoolToText(PressurizationEnabled, "Pressurization Enabled", "", content));

                default: return(base.ToText(content));
                }
            }
Exemplo n.º 8
0
            private void Staging(ActionMachine action)
            {
                bool state = true;

                switch (action)
                {
                case ActionMachine.Open:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        block.OpenDoor();
                        if (block.OpenRatio < 1 - Epsilon)
                        {
                            state = false;
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = true;
                    }
                    break;

                case ActionMachine.OpenInt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.OpenDoor();
                            if (block.OpenRatio < 1 - Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = true;
                    }
                    break;

                case ActionMachine.OpenExt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.OpenDoor();
                            if (block.OpenRatio < 1 - Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = true;
                    }
                    break;

                case ActionMachine.Close:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        block.CloseDoor();
                        if (block.OpenRatio > 0 + Epsilon)
                        {
                            state = false;
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = false;
                    }
                    break;

                case ActionMachine.CloseInt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.CloseDoor();
                            if (block.OpenRatio > 0 + Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = false;
                    }
                    break;

                case ActionMachine.CloseExt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.CloseDoor();
                            if (block.OpenRatio > 0 + Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = false;
                    }
                    break;

                case ActionMachine.Lock:
                    doors.ForEach(delegate(IMyDoor block) {
                        block.ApplyAction("OnOff_Off");
                    });
                    Stage++;
                    break;

                case ActionMachine.LockInt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.ApplyAction("OnOff_Off");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.LockExt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.ApplyAction("OnOff_Off");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.Unlock:
                    doors.ForEach(delegate(IMyDoor block) {
                        block.ApplyAction("OnOff_On");
                    });
                    Stage++;
                    break;

                case ActionMachine.UnlockInt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.ApplyAction("OnOff_On");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.UnlockExt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.ApplyAction("OnOff_On");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.Pressure:
                    airvent.ApplyAction("Depressurize_Off");
                    state = true;
                    airvent.ForEach(delegate(IMyAirVent block) {
                        VentStatus status = block.Status;
                        if (block.GetOxygenLevel() < 1 - Epsilon)
                        {
                            state = false;
                        }
                        WriteText($"Status:{status}", true);
                        WriteText($"Pressure:{block.GetOxygenLevel() * 100}", true);
                    });
                    if (state)
                    {
                        Stage++;
                    }
                    break;

                case ActionMachine.Depressure:
                    airvent.ApplyAction("Depressurize_On");
                    state = true;
                    airvent.ForEach(delegate(IMyAirVent block) {
                        VentStatus status = block.Status;
                        if (block.GetOxygenLevel() > 0 + Epsilon)
                        {
                            state = false;
                        }
                        WriteText($"Status:{status}", true);
                        WriteText($"Pressure:{block.GetOxygenLevel() * 100}", true);
                    });
                    if (state)
                    {
                        Stage++;
                    }
                    break;

                case ActionMachine.Sleep:
                    Sleep--;
                    WriteText($"Sleep:{Sleep}", true);
                    if (Sleep <= 0)
                    {
                        Stage++;
                    }
                    break;

                case ActionMachine.SleepInit:
                    Sleep = program.MyProperty.timer;
                    Stage++;
                    break;

                case ActionMachine.Start:
                    State = StateMachine.Running;
                    Stage++;
                    break;

                case ActionMachine.Stop:
                    State = StateMachine.Stop;
                    Sleep = 0;
                    Stage++;
                    break;

                case ActionMachine.Terminated:
                    Stage++;
                    break;

                case ActionMachine.TerminatedInt:
                    Stage++;
                    break;

                case ActionMachine.TerminatedExt:
                    Stage++;
                    break;
                }
            }
Exemplo n.º 9
0
        public void Main(string argument, UpdateType updateSource)
        {
            try {
                bool shouldOpenTanks     = true;
                bool shouldRunGenerators = true;

                //todo: change O2 to o2
                //TODO: Add the h2o2 generator and turn off when in the middle fo pressurizing or depressurizing



                // Tank fill level
                //------------------
                // Tank fill will override the vent status
                double fillLevel = CheckTankStatus();
                if (fillLevel < TANK_O2_MIN / 100.0)
                {
                    shouldOpenTanks = true;
                }
                else if (fillLevel > TANK_O2_MAX / 100.0)
                {
                    shouldOpenTanks = false;
                }


                // Pressurization systems
                //------------------------
                //make all of vents the same (allows changing just one vent)
                SetVents(DesiredVentStatusIsPressurize());
                VentStatus ventStatus = GetVentStatus(vents[0]);
                //When pressurizing or depressurizing, force the generators off and the tanks open
                switch (ventStatus)
                {
                case VentStatus.Depressurizing:
                    shouldOpenTanks     = true;
                    shouldRunGenerators = false;
                    break;

                case VentStatus.Pressurizing:
                    shouldOpenTanks     = true;
                    shouldRunGenerators = false;
                    break;
                }

                // Lights
                //--------
                if (ventStatus == VentStatus.Pressurized)
                {
                    SetLightColor(greenColor);
                }
                else
                {
                    SetLightColor(redColor);
                }


                // Set the O2 tanks and generators
                //---------------------------------
                SetOxygenProduction(shouldOpenTanks);
                SetGenerators(shouldRunGenerators);



                // Display info
                //--------------
                int    tankPercentage = (int)(CheckTankStatus() * 100);
                string o2Production   = "Off";
                if (shouldOpenTanks)
                {
                    o2Production = "On";
                }

                string pressurized = "---";
                if (ventStatus == VentStatus.Pressurized)
                {
                    pressurized = "YES";
                }
                else if (ventStatus == VentStatus.Pressurizing)
                {
                    pressurized = "PRESSURIZING";
                }
                else if (ventStatus == VentStatus.Depressurized)
                {
                    pressurized = "NO";
                }
                else if (ventStatus == VentStatus.Depressurizing)
                {
                    pressurized = "DEPRESSURIZING";
                }

                string generators = "Off";
                if (shouldRunGenerators)
                {
                    generators = "On";
                }


                text.Clear();
                text.Append("Life Support System Status\n\n");

                text.Append("Tank level: " + tankPercentage + "%\n");
                text.Append("O2 Production: " + o2Production + "\n");
                text.Append("Pressurized: " + pressurized + "\n");
                text.Append("Generators: " + generators + "\n");


                panelManager.SetText(text.ToString(), false);
            }
            catch (Exception e) {
                // Dump the exception content to the
                Echo("An error occurred during script execution.");
                Echo($"Exception: {e}\n---");

                // Rethrow the exception to make the programmable block halt execution properly
                throw;
            }
        }