Exemple #1
0
    protected void LoadAirlock(string baseName)
    {
        string ventName    = String.Format("Air Vent ({0} Airlock)", baseName);
        string intDoorName = String.Format("Airlock Door: Int. ({0})", baseName);
        string extDoorName = String.Format("Airlock Door: Ext. ({0})", baseName);

        vent    = (IMyAirVent)GridTerminalSystem.GetBlockWithName(ventName);
        intDoor = (IMyDoor)GridTerminalSystem.GetBlockWithName(intDoorName);
        extDoor = (IMyDoor)GridTerminalSystem.GetBlockWithName(extDoorName);

        if (vent == null)
        {
            throw new Exception("Missing airvent: " + ventName);
        }
        if (intDoor == null)
        {
            throw new Exception("Missing int. door: " + intDoorName);
        }
        if (extDoor == null)
        {
            throw new Exception("Missing ext. door: " + extDoorName);
        }

        intClosed = intDoor.OpenRatio == 0f;
        intOpened = intDoor.OpenRatio == 1f;
        extClosed = extDoor.OpenRatio == 0f;
        extOpened = extDoor.OpenRatio == 1f;

        ventLevel = vent.GetOxygenLevel();
        evacDone  = ventLevel < 0.00001;
        presDone  = ventLevel > 0.99;
    }
    public Func <bool> waitForPressure(IMyAirVent vent, bool pressurizing)
    {
        Func <bool> maxWait = waitForTicks(pressurizing ? MAX_WAIT_PRESSURIZING : MAX_WAIT_DEPRESSURIZING);

        return(() =>
        {
            double ox = vent.GetOxygenLevel();
            if (maxWait())
            {
                c_log((pressurizing ? "" : "de") + "pressurization_wait_timout (" + (ox * 100) + "% oxygen lost)");
                return true;
            }
            if (pressurizing)
            {
                if (ox >= 0.95)
                {
                    return true;
                }
            }
            else
            {
                if (ox <= 0.0001)
                {
                    return true;
                }
            }
            return false;
        });
    }
Exemple #3
0
            public void Update()
            {
                if (!IsReady())
                {
                    return;
                }

                float pr = primaryVent.GetOxygenLevel();

                if (pr > calMargin)
                {
                    ForceClose(outer);

                    if (pr < 1f - calMargin)
                    {
                        ForceClose(inner);
                    }
                    else
                    {
                        inner.Enabled = true;
                    }
                }
                else
                {
                    ForceClose(inner);
                    outer.Enabled = true;
                }
            }
Exemple #4
0
            /// <summary>
            /// Returns the average oxygen level reported by all enabled vents.
            /// </summary>
            public float AreaOxygenLevel()
            {
                float o2LevelSum = 0;
                float ventCount  = 0;

                if (area == null)
                {
                    ReportItem("Area is null. Ensure controller has a valid area and recompile.", StatusReport.Type.ERROR);
                    return(-1f);
                }

                for (int i = 0; i < area.SourceAirVentCount; i++)
                {
                    IMyAirVent sourceAirVent = area.SourceAirVent(i);

                    if (ValidateO2Level(sourceAirVent))
                    {
                        o2LevelSum += sourceAirVent.GetOxygenLevel();
                        ventCount  += 1;
                    }
                }

                for (int i = 0; i < area.StorageAirVentCount; i++)
                {
                    IMyAirVent storageAirVent = area.StorageAirVent(i);

                    if (ValidateO2Level(storageAirVent))
                    {
                        o2LevelSum += storageAirVent.GetOxygenLevel();
                        ventCount  += 1;
                    }
                }

                return(o2LevelSum / ventCount);
            }
            public VentInfo(IMyAirVent airVent, string description = "") : base(description)
            {
                Current = airVent.GetOxygenLevel();
                Max     = 1.0f;

                CanPressurize         = airVent.CanPressurize;
                Depressurize          = airVent.Depressurize;
                VentStatus            = airVent.Status;
                Pressurized           = (airVent.Status == VentStatus.Pressurized);
                Depressurized         = (airVent.Status == VentStatus.Depressurized);
                PressurizationEnabled = airVent.PressurizationEnabled;
            }
Exemple #6
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;
     }
 }
        public bool isAirlockPressurized(PressureStates state)
        {
            float oxygen = Vent.GetOxygenLevel();

            if (state == PressureStates.Positive && oxygen != 1.0f)
            {
                return(false);
            }
            else if (state == PressureStates.Negative && oxygen > 0.000000006f)
            {
                return(false);
            }

            return(true);
        }
        private VentStatus GetVentStatus(IMyAirVent vent)
        {
            if (vent.Status != VentStatus.Depressurizing) // don't trust depressurizing. It could be depressurized
            {
                return(vent.Status);
            }

            if (vent.GetOxygenLevel() < 0.01)
            {
                return(VentStatus.Depressurized);
            }
            else
            {
                return(VentStatus.Depressurizing);
            }
        }
            public void topOffBay(IMyAirVent vent)
            {
                if (!vent.CanPressurize)
                {
                    Echo("Hangar is not airtight");
                    return;
                }

                ITerminalAction action;

                if (vent.GetOxygenLevel() <= topOffThreshold)
                {
                    action            = vent.GetActionWithName("OnOff_On");
                    vent.Depressurize = false;
                }
                else
                {
                    action = vent.GetActionWithName("OnOff_Off");
                }
                action.Apply(vent);
            }
Exemple #10
0
        // Process all requests - main thread (think while(true) in a microprocessor)
        // Note this assume a 1Hz clock cycle from a timer block
        public void mainLoop()
        {
            Echo("Hangar status:");
            for (int i = 0; i < hangarOpen.Length; i++)
            {
                Echo("[" + groups[i] + "]: " + (hangarOpen[i] ? "Open" : "Closed"));
            }
            // Go through backwards so we can remove stuff without screwing our loop up
            // Note we must also use RemoveAt() for the same reason
            // Luckily this isn't Java!
            for (int i = requests.Count - 1; i >= 0; i--)
            {
                requestTicket req     = requests[i];
                int           groupNo = req.groupNum;

                // For stuff that must be processed immediately
                if (!req.timed)
                {
                    switch (req.action)
                    {
                    case "toggle":
                    {
                        // Case where hangar is depressurised: repressurize
                        if (hangarOpen[groupNo])
                        {
                            goto case "close";
                        }
                        else
                        {
                            goto case "open";
                        }
                    }

                    // Start open procedure
                    case "open":
                    {
                        // Flash lights, play warning sound
                        foreach (IMyInteriorLight light in warningLights[groupNo])
                        {
                            light.ApplyAction("OnOff_On");
                        }
                        foreach (IMySoundBlock sound in soundBlocks[groupNo])
                        {
                            sound.SetValueFloat("LoopableSlider", numberSecondsBeforeOpen + 2);
                            sound.ApplyAction("PlaySound");
                        }

                        requests.RemoveAt(i);

                        //Make sure interior doors are on so we can close them
                        foreach (IMyDoor door in interiorDoors[groupNo])
                        {
                            door.ApplyAction("OnOff_On");
                        }

                        // Lock the interior doors after some time
                        requests.Add(new requestTicket(groupNo, "lockInterior_delay", true, numberSecondsBeforeOpen - 1));
                        break;
                    }

                    // Start close procedure
                    case "close":
                    {
                        // Make sure lights are on (they should still be but just in case)
                        foreach (IMyInteriorLight light in warningLights[groupNo])
                        {
                            light.ApplyAction("OnOff_On");
                        }
                        // Play sound
                        foreach (IMySoundBlock sound in soundBlocks[groupNo])
                        {
                            sound.SetValueFloat("LoopableSlider", numberSecondsBeforeClose);
                            sound.ApplyAction("PlaySound");
                        }

                        requests.RemoveAt(i);

                        //Make sure all outside doors have power so we can close them
                        foreach (IMyDoor door in hangarDoors[groupNo])
                        {
                            door.ApplyAction("OnOff_On");
                        }
                        foreach (IMyDoor door in exteriorDoors[groupNo])
                        {
                            door.ApplyAction("OnOff_On");
                        }

                        // Schedule close request
                        requests.Add(new requestTicket(groupNo, "close_delay", true, numberSecondsBeforeClose));
                        break;
                    }

                    // Check pressurization and unlock interior doors/turn off emer. lights if OK
                    case "checkPressurize":
                    {
                        // Get first airvent; they should all be in the room and hence have the same pressure
                        IMyAirVent airvent = airVents[groupNo][0];
                        if (airvent.GetOxygenLevel() > 0.99)
                        {
                            // Ok we're pressurized, turn lights off and enable interior doors
                            foreach (IMyInteriorLight light in warningLights[groupNo])
                            {
                                light.ApplyAction("OnOff_Off");
                            }
                            foreach (IMyDoor door in interiorDoors[groupNo])
                            {
                                door.ApplyAction("OnOff_On");
                            }
                            hangarOpen[groupNo] = false;

                            requests.RemoveAt(i);
                        }
                        break;
                    }

                    // Lock all exterior doors
                    case "lockExteriorDoors":
                    {
                        // Check door status
                        Boolean doorClosed = true;
                        foreach (IMyDoor door in exteriorDoors[groupNo])
                        {
                            // If door is still closing or open...
                            if (door.OpenRatio != 0)
                            {
                                door.ApplyAction("Open_Off");
                                doorClosed = false;
                            }
                            else
                            {
                                door.ApplyAction("OnOff_Off");
                            }
                        }
                        if (doorClosed)
                        {
                            requests.RemoveAt(i);
                        }
                        break;
                    }

                    // Lock interior doors
                    case "lockInterior":
                    {
                        // Check door status
                        Boolean doorClosed = true;
                        foreach (IMyDoor door in interiorDoors[groupNo])
                        {
                            // If door is still closing or open...
                            if (door.OpenRatio != 0)
                            {
                                door.ApplyAction("Open_Off");
                                doorClosed = false;
                            }
                            else
                            {
                                door.ApplyAction("OnOff_Off");
                            }
                        }
                        if (doorClosed)
                        {
                            requests.RemoveAt(i);
                            // Doors now locked, move onto opening main doors
                            requests.Add(new requestTicket(groupNo, "open_delay"));
                        }
                        break;
                    }

                    case "open_delay":
                    {
                        // Make sure all outside doors turn on
                        foreach (IMyDoor door in exteriorDoors[groupNo])
                        {
                            door.ApplyAction("OnOff_On");
                        }
                        foreach (IMyDoor door in hangarDoors[groupNo])
                        {
                            door.ApplyAction("OnOff_On");
                        }

                        requests.RemoveAt(i);
                        // Queue new request to open doors soon
                        // This is because we can't turn on and open a door at the same time - game ignore the open request
                        requests.Add(new requestTicket(groupNo, "open_delay2"));
                        break;
                    }

                    case "open_delay2":
                    {
                        // Actually open all outside doors now
                        foreach (IMyDoor door in exteriorDoors[groupNo])
                        {
                            door.ApplyAction("Open_On");
                        }
                        foreach (IMyDoor door in hangarDoors[groupNo])
                        {
                            door.ApplyAction("Open_On");
                        }
                        hangarOpen[groupNo] = true;
                        requests.RemoveAt(i);
                        break;
                    }
                    }
                }
                // Deal with delayed stuff
                else
                {
                    int timeLeft = req.timeRemainingInSeconds;
                    // If it's not time yet just decrement the counter
                    if (timeLeft > 0)
                    {
                        // Replace request with new one with one less second
                        requests[i] = new requestTicket(groupNo, req.action, true, timeLeft - 1);
                    }
                    else
                    {
                        switch (req.action)
                        {
                        // Close outside doors
                        case "close_delay":
                        {
                            foreach (IMyDoor door in exteriorDoors[groupNo])
                            {
                                door.ApplyAction("Open_Off");
                            }
                            foreach (IMyDoor door in hangarDoors[groupNo])
                            {
                                door.ApplyAction("Open_Off");
                            }

                            requests.RemoveAt(i);
                            // Set events to unlock inside door when pressurized and make sure exterior doors are closed so we can actually pressurize
                            requests.Add(new requestTicket(groupNo, "checkPressurize"));
                            requests.Add(new requestTicket(groupNo, "lockExteriorDoors"));
                            break;
                        }

                        // Lock interior doors - or at least schedule the procedure
                        case "lockInterior_delay":

                        {
                            requests.RemoveAt(i);
                            requests.Add(new requestTicket(groupNo, "lockInterior"));
                            break;
                        }
                        }
                    }
                }
            }
        }
            private void DrawAirventInfos(float posX, float posY, Color stateColor, bool isWorking, IMyAirVent airvent, out MySprite airventText, out MySprite divider, out MySprite statusTitle, out MySprite statusInfo, out MySprite oxygenTitle, out MySprite oxygenInfo, out MySprite pressurizeTitle, out MySprite pressurizeInfo)
            {
                string name = airvent.CustomName;

                if (name.Length > 17)
                {
                    name  = name.Substring(0, 14);
                    name += "...";
                }

                airventText          = MySprite.CreateText(name, "Debug", Constants.COLOR_WHITE, 0.8f, TextAlignment.LEFT);
                airventText.Position = new Vector2(posX - 83, posY - 25);

                Vector2 d_pos  = new Vector2(posX + 17, posY);
                Vector2 d_size = new Vector2(199, 2);

                divider       = MySprite.CreateSprite("SquareSimple", d_pos, d_size);
                divider.Color = Constants.COLOR_GREEN;

                statusTitle          = MySprite.CreateText("Status", "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.LEFT);
                statusTitle.Position = new Vector2(posX - 116, posY + 2);

                string airventStatus = "";
                Color  textColor     = Constants.COLOR_WHITE;

                if (!airvent.IsFunctional)
                {
                    airventStatus = "BROKEN";
                    textColor     = Constants.COLOR_RED;
                }
                else if (!airvent.IsWorking)
                {
                    airventStatus = "NOT WORKING";
                    textColor     = Constants.COLOR_RED;
                }
                else if (!airvent.CanPressurize)
                {
                    airventStatus = "LEAK";
                    textColor     = Constants.COLOR_RED;
                }
                else
                {
                    airventStatus = "OPTIMAL";
                }

                statusInfo          = MySprite.CreateText(airventStatus, "Debug", textColor, 0.5f, TextAlignment.LEFT);
                statusInfo.Position = new Vector2(posX - 116, posY + 16);

                oxygenTitle          = MySprite.CreateText("Oxygen", "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.CENTER);
                oxygenTitle.Position = new Vector2(posX, posY + 2);

                oxygenInfo          = MySprite.CreateText((airvent.GetOxygenLevel() * 100).ToString("0.0"), "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.CENTER);
                oxygenInfo.Position = new Vector2(posX, posY + 16);

                pressurizeTitle          = MySprite.CreateText("Action", "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.RIGHT);
                pressurizeTitle.Position = new Vector2(posX + 116, posY + 2);

                string action = "";

                if (airvent.Depressurize)
                {
                    action = "Depressurizing";
                }
                else
                {
                    action = "Pressurizing";
                }
                pressurizeInfo          = MySprite.CreateText(action, "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.RIGHT);
                pressurizeInfo.Position = new Vector2(posX + 116, posY + 16);
            }
Exemple #12
0
        private void ControlDoors()
        {
            IMyAirtightSlideDoor insideDoor  = GridTerminalSystem.GetBlockWithName("AirLock SlidingDoor In") as IMyAirtightSlideDoor;
            IMyAirtightSlideDoor outsideDoor = GridTerminalSystem.GetBlockWithName("AirLock SlidingDoor Out") as IMyAirtightSlideDoor;
            IMyAirVent           airVent     = GridTerminalSystem.GetBlockWithName("AirLock Vent") as IMyAirVent;

            if (insideDoor == null || outsideDoor == null || airVent == null)
            {
                return;
            }

            _PanelTextSurface.WriteText(String.Format(
                                            "Inside door ticks: {0}\nOutside door ticks: {1}\nPressure: {2}",
                                            _InsideDoorTicks,
                                            _OutsideDoorTicks,
                                            airVent.GetOxygenLevel()
                                            ));



            if (_InsideDoorTicks != -1)
            {
                --_InsideDoorTicks;
            }

            if (_OutsideDoorTicks != -1)
            {
                --_OutsideDoorTicks;
            }

            if (_InsideDoorTicks == 0)
            {
                insideDoor.CloseDoor();
                _InsideDoorTicks  = -1;
                _DoorNeedsClosing = false;
            }

            if (_OutsideDoorTicks == 0)
            {
                outsideDoor.CloseDoor();
                _OutsideDoorTicks = -1;
                _DoorNeedsClosing = false;
            }

            if (insideDoor.Status == DoorStatus.Closed &&
                outsideDoor.Status == DoorStatus.Closed &&
                airVent.GetOxygenLevel() == 0.0f)
            {
                insideDoor.Enabled  = true;
                outsideDoor.Enabled = true;
                _InsideDoorTicks    = -1;
                _OutsideDoorTicks   = -1;
                _DoorNeedsClosing   = false;
            }

            if (outsideDoor.Status == DoorStatus.Open || outsideDoor.Status == DoorStatus.Opening)
            {
                insideDoor.CloseDoor();
                insideDoor.Enabled = false;

                if (!_DoorNeedsClosing)
                {
                    _OutsideDoorTicks = DOOR_DELAY;
                    _DoorNeedsClosing = true;
                }
            }

            if (insideDoor.Status == DoorStatus.Open || insideDoor.Status == DoorStatus.Opening)
            {
                outsideDoor.CloseDoor();
                outsideDoor.Enabled = false;
                if (!_DoorNeedsClosing)
                {
                    _InsideDoorTicks  = DOOR_DELAY;
                    _DoorNeedsClosing = true;
                }
            }
        }
            public void ControlDoors()
            {
                if (_InsideDoorTicks != -1)
                {
                    --_InsideDoorTicks;
                }

                if (_OutsideDoorTicks != -1)
                {
                    --_OutsideDoorTicks;
                }

                if (_InsideDoorTicks == 0)
                {
                    _InsideDoor.CloseDoor();
                    _InsideDoorTicks  = -1;
                    _DoorNeedsClosing = false;
                }

                if (_OutsideDoorTicks == 0)
                {
                    _OutsideDoor.CloseDoor();
                    _OutsideDoorTicks = -1;
                    _DoorNeedsClosing = false;
                }

                if (_InsideDoor.Status == DoorStatus.Closed &&
                    _OutsideDoor.Status == DoorStatus.Closed &&
                    _AirVent.GetOxygenLevel() == 0.0f)
                {
                    _InsideDoor.Enabled  = true;
                    _OutsideDoor.Enabled = true;
                    _InsideDoorTicks     = -1;
                    _OutsideDoorTicks    = -1;
                    _DoorNeedsClosing    = false;
                }

                if (_OutsideDoor.Status == DoorStatus.Open || _OutsideDoor.Status == DoorStatus.Opening)
                {
                    _InsideDoor.CloseDoor();
                    _InsideDoor.Enabled = false;

                    if (!_DoorNeedsClosing)
                    {
                        _OutsideDoorTicks = DOOR_DELAY;
                        _DoorNeedsClosing = true;
                    }
                }

                if (_InsideDoor.Status == DoorStatus.Open || _InsideDoor.Status == DoorStatus.Opening)
                {
                    _OutsideDoor.CloseDoor();
                    _OutsideDoor.Enabled = false;

                    if (!_DoorNeedsClosing)
                    {
                        _InsideDoorTicks  = DOOR_DELAY;
                        _DoorNeedsClosing = true;
                    }
                }
            }
Exemple #14
0
            public void ControlDoors(IMyProgrammableBlock owner)
            {
                if (_InsideDoorTicks != -1)
                {
                    --_InsideDoorTicks;
                }

                if (_OutsideDoorTicks != -1)
                {
                    --_OutsideDoorTicks;
                }

                if (_InsideDoorTicks == 0)
                {
                    _InsideDoor.CloseDoor();
                    _InsideDoorTicks  = -1;
                    _DoorNeedsClosing = false;
                }

                if (_OutsideDoorTicks == 0)
                {
                    _OutsideDoor.CloseDoor();
                    _OutsideDoorTicks = -1;
                    _DoorNeedsClosing = false;
                }

                int storedOxygenPercentage = Int32.Parse(owner.CustomData);

                if (_InsideDoor.Status == DoorStatus.Closed &&
                    _OutsideDoor.Status == DoorStatus.Closed &&
                    (storedOxygenPercentage > 95 || _AirVent.GetOxygenLevel() == 0.0f))
                {
                    _InsideDoor.Enabled  = true;
                    _OutsideDoor.Enabled = true;
                    _InsideDoorTicks     = -1;
                    _OutsideDoorTicks    = -1;
                    _DoorNeedsClosing    = false;
                }

                if (_OutsideDoor.Status == DoorStatus.Open || _OutsideDoor.Status == DoorStatus.Opening)
                {
                    _InsideDoor.CloseDoor();
                    _InsideDoor.Enabled = false;

                    if (!_DoorNeedsClosing)
                    {
                        _OutsideDoorTicks = DOOR_DELAY;
                        _DoorNeedsClosing = true;
                    }
                }

                if (_InsideDoor.Status == DoorStatus.Open || _InsideDoor.Status == DoorStatus.Opening)
                {
                    _OutsideDoor.CloseDoor();
                    _OutsideDoor.Enabled = false;

                    if (!_DoorNeedsClosing)
                    {
                        _InsideDoorTicks  = DOOR_DELAY;
                        _DoorNeedsClosing = true;
                    }
                }
            }
Exemple #15
0
 public static float getPressure(IMyAirVent vanToCheck)
 {
     return(vanToCheck.GetOxygenLevel() * 100);
 }
 public float GetOxygenLevel()
 {
     return(vent.GetOxygenLevel());
 }
Exemple #17
0
            public void update(TimeSpan elapsedTime)
            {
                bool pressurized = vent.GetOxygenLevel() >= PRESSURIZATION_UPPER_LIMIT;

                if (light != null)
                {
                    light.SetValue("Color", pressurized ? pressurizedColor : depressurizedColor);
                }
                string status = vent.CustomData;

                if (status == S_SETUP)
                {
                    setup();
                }
                else if (status == S_FINISHING_SETUP)
                {
                    finishingSetup(elapsedTime);
                }
                else if (status == S_EXIT_START)
                {
                    exitStart();
                }
                else if (status == S_ENTER_START)
                {
                    enterStart();
                }
                else if (status == S_EXIT_PREPARING)
                {
                    exitPreparing();
                }
                else if (status == S_ENTER_PREPARING)
                {
                    enterPreparing();
                }
                else if (status == S_EXIT_FIRST_DOOR_OPEN)
                {
                    exitFirstDoorOpen(elapsedTime);
                }
                else if (status == S_ENTER_FIRST_DOOR_OPEN)
                {
                    enterFirstDoorOpen(elapsedTime);
                }
                else if (status == S_EXIT_FIRST_DOOR_CLOSING)
                {
                    exitFirstDoorClosing(elapsedTime);
                }
                else if (status == S_ENTER_FIRST_DOOR_CLOSING)
                {
                    enterFirstDoorClosing(elapsedTime);
                }
                else if (status == S_EXIT_START_CHANGING_PRESSURE)
                {
                    exitStartChangingPressure();
                }
                else if (status == S_ENTER_START_CHANGING_PRESSURE)
                {
                    enterStartChangingPressure();
                }
                else if (status == S_EXIT_CHANGING_PRESSURE)
                {
                    exitChangingPressure();
                }
                else if (status == S_ENTER_CHANGING_PRESSURE)
                {
                    enterChangingPressure();
                }
                else if (status == S_EXIT_SECOND_DOOR_OPEN)
                {
                    exitSecondDoorOpen(elapsedTime);
                }
                else if (status == S_ENTER_SECOND_DOOR_OPEN)
                {
                    enterSecondDoorOpen(elapsedTime);
                }
                else if (status == S_EXIT_SECOND_DOOR_CLOSING)
                {
                    exitClosingSecondDoor(elapsedTime);
                }
                else if (status == S_ENTER_SECOND_DOOR_CLOSING)
                {
                    enterClosingSecondDoor(elapsedTime);
                }
                else if (status != S_ERR)
                {
                    idle();
                }
            }