Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Program()
- {
- // The constructor, called only once every session and
- // always before any other method is called. Use it to
- // initialize your script.
- //
- // The constructor is optional and can be removed if not
- // needed.
- //
- // It's recommended to set RuntimeInfo.UpdateFrequency
- // here, which will allow your script to run itself without a
- // timer block.
- }
- public void Save()
- {
- // Called when the program needs to save its state. Use
- // this method to save your state to the Storage field
- // or some other means.
- //
- // This method is optional and can be removed if not
- // needed.
- }
- // Method for finding blocks by names
- List<IMyTerminalBlock> SearchBlocksByName(string blockName) {
- var blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(blockName, blocks);
- return blocks;
- }
- public void DebugLog(IMyTextPanel console, string text)
- {
- if (console != null)
- {
- console.WriteText(text);
- }
- }
- public void Main(string argument, UpdateType updateSource)
- {
- string debug = "";
- IMyTextPanel console = GridTerminalSystem.GetBlockWithName("Text panel") as IMyTextPanel;
- var tanks = SearchBlocksByName("Oxygen Tank");
- float oxygenLevel = 1.0f;
- for (int i = 0; i < tanks.Count; i++)
- {
- IMyGasTank tank = (IMyGasTank)tanks[i];
- oxygenLevel = (oxygenLevel > (float)tank.FilledRatio ? (float)tank.FilledRatio : oxygenLevel);
- }
- var vents = SearchBlocksByName("AirHangar");
- List<IMyAirVent> airVents = new List<IMyAirVent>();
- bool pressurized = true;
- for (int i = 0; i < vents.Count; i++)
- {
- airVents.Add(vents[i] as IMyAirVent);
- }
- float level = 0.0f;
- for (int i = 0; i < airVents.Count(); i++)
- {
- level = (airVents[i].GetOxygenLevel() > level ? airVents[i].GetOxygenLevel() : level);
- if (airVents[i].GetOxygenLevel() > 0.05f)
- {
- airVents[i].ApplyAction("Depressurize_On");
- }
- }
- debug += level + "\n";
- if (level < 0.01f)
- {
- pressurized = false;
- }
- if (pressurized == false || oxygenLevel > 0.99f)
- {
- List<IMyTerminalBlock> doors = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyDoor>(doors);
- List<IMyDoor> hangarDoors = new List<IMyDoor>();
- for (int i = 0; i < doors.Count; i++)
- {
- if (doors[i].CustomName.Contains("Airtight"))
- {
- hangarDoors.Add(doors[i] as IMyDoor);
- }
- }
- for (int i = 0; i < hangarDoors.Count; i++)
- {
- hangarDoors[i].ApplyAction("Open_On");
- }
- for (int i = 0; i < airVents.Count(); i++)
- {
- airVents[i].ApplyAction("Depressurize_Off");
- }
- IMyTimerBlock time = GridTerminalSystem.GetBlockWithName("Timer Block") as IMyTimerBlock;
- time.ApplyAction("OnOff_Off");
- }
- if (console != null)
- console.WriteText(debug);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement