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); }
public void Main(string argument, UpdateType updateSource) { string pressurizationType; if (updateSource == UpdateType.Trigger) { //Determine which side the user is entering and ensure all doors are closed calibration(); pressurizationType = ActivatedSensor.CustomData; state = getRequestedPressure(pressurizationType); //Adjust lighting to show that the room is undergoing a pressure change changeLightProperties(Red, 0.75f); SpinningLight.Enabled = true; Echo("Lights modified"); OppositeSensor.Enabled = false; //Change the room pressure based on which sensor was tripped if (state == PressureStates.Positive) { Vent.Depressurize = false; Echo("Room pressurizing"); } else if (state == PressureStates.Negative) { Vent.Depressurize = true; Echo("Room depressurizing"); } Runtime.UpdateFrequency = UpdateFrequency.Update100; } else if (updateSource == UpdateType.Update100) { //This allows the script to execute every 300 ticks instead of the stock 100 Update100Runs++; Echo(FinishedCycle.ToString()); if (Update100Runs % 3 == 0 && !FinishedCycle) { Echo("i-runs: " + Update100Runs.ToString()); if (isAirlockPressurized(state)) { //Change the lights to green to indicate it is finished cycling changeLightProperties(Green, 0.85f); SpinningLight.Enabled = false; //Open the door on the other side to allow exit IMyDoor oppositeDoor = getOppositeDoor(); oppositeDoor.OpenDoor(); Echo($"{oppositeDoor.CustomName} opened"); FinishedCycle = true; Update100Runs = 0; } else { Echo("ERROR"); } } else if (Update100Runs % 5 == 0 && FinishedCycle) { changeLightProperties(NormalColor, 1.5f); OppositeSensor.Enabled = true; Echo("Reset to beginning"); //The script doesn't need to run anymore so disable further runs Runtime.UpdateFrequency = UpdateFrequency.None; Update100Runs = 0; } } }