diff --git a/AirMonitor/AirZone.cs b/AirMonitor/AirZone.cs index cf1521e..ab9f003 100644 --- a/AirMonitor/AirZone.cs +++ b/AirMonitor/AirZone.cs @@ -1,6 +1,5 @@ using Sandbox.ModAPI.Ingame; using SpaceEngineers.Game.ModAPI.Ingame; -using System.Collections; using System.Collections.Generic; using VRageMath; @@ -11,7 +10,17 @@ namespace IngameScript public class AirZone { public string Name { get; private set; } - public bool Triggered { get; set; } = false; + public bool Triggered + { + get + { + foreach (IMyAirVent vent in Vents) + { + if (vent.GetOxygenLevel() < TriggerLevel) return true; + } + return false; + } + } public List Vents { get; } = new List(); private Program _program; @@ -61,31 +70,14 @@ namespace IngameScript // TODO: support for arbitrary (sub-)sequences here could be powerful } - public void Reset() - { - _console.Print("Resetting sensor."); - Triggered = false; - } - // This enumerator should run forever. public IEnumerator Monitor() { while (true) { - foreach (IMyAirVent vent in Vents) - { - if (vent.GetOxygenLevel() < TriggerLevel) Triggered = true; - } - - // TODO: add informational lights per-zone if (Triggered == true) { _console.Print($"Low pressure alarm triggered."); - foreach (IMyLightingBlock light in _lights) - { - light.Enabled = true; - light.Color = Color.Red; - } // close the doors IEnumerator job = _sequencer.RunSequence(true); @@ -98,7 +90,7 @@ namespace IngameScript } job.Dispose(); - while (Triggered) yield return true; + while (Triggered) { yield return true; } // unlock the doors, but we'll leave them closed. foreach (IMyDoor door in _doors) { door.Enabled = true; } @@ -113,6 +105,28 @@ namespace IngameScript yield return true; } } + + public void SetLights() + { + bool warning = false; + foreach (IMyAirVent vent in Vents) + { + if (vent.GetOxygenLevel() < TriggerLevel) + { + warning = true; + break; + } + } + foreach (IMyLightingBlock light in _lights) + { + if (warning) + { + light.Enabled = true; + light.Color = Color.Red; + } + else light.Color = Color.White; + } + } } } } \ No newline at end of file diff --git a/AirMonitor/Program.cs b/AirMonitor/Program.cs index 10f6529..f4865dd 100644 --- a/AirMonitor/Program.cs +++ b/AirMonitor/Program.cs @@ -13,7 +13,6 @@ namespace IngameScript public MyIni Ini { get; } = new MyIni(); public IConsole Console { get; private set; } - private MyCommandLine _cli = new MyCommandLine(); private Dictionary _zones = new Dictionary(); private List> _jobs = new List>(); private List _displays = new List(); @@ -32,16 +31,12 @@ namespace IngameScript Ini.TryParse(block.CustomData); string[] zones = new string[] { }; - // TODO: how do we display text on e.g. decorative console blocks? - // They have configurable screens but the docs say they don't implement this. - // Meanwhile *every* functional block seems to implement IMyTextSurfaceProvider... - // It'd probably be safe to just check SurfaceCount... experiment with this later if (block is IMyTextSurface) { Console.Print($"Adding monitoring display '{block.CustomName}'"); _displays.Add(block as IMyTextSurface); } - if (Ini.Get("airMonitor", "display").ToString() != "") + else if (Ini.Get("airMonitor", "display").ToString() != "") { int displayIndex = Ini.Get("airMonitor", "display").ToInt32(); IMyTextSurfaceProvider provider = block as IMyTextSurfaceProvider; @@ -54,12 +49,11 @@ namespace IngameScript _displays.Add(provider.GetSurface(displayIndex)); } } - if (block is IMyGasTank) + else if (block is IMyGasTank) { _oxygenTanks.Add(block as IMyGasTank); } - - if (Ini.Get("airMonitor", "zones").ToString() != "") + else if (Ini.Get("airMonitor", "zones").ToString() != "") { zones = Ini.Get("airMonitor", "zones").ToString().Split(','); } @@ -67,6 +61,9 @@ namespace IngameScript { zones = new string[] { Ini.Get("airMonitor", "zone").ToString() }; } + else { + Console.Print($"Failed to add block {block.CustomName}"); + } foreach (string zone in zones) { @@ -93,47 +90,15 @@ namespace IngameScript { Console.UpdateTickCount(); - if (argument != "") - { - _cli.TryParse(argument); - if (_cli.Switch("reset") || _cli.Switch("trigger")) - { - List zonesToControl; - if (_cli.ArgumentCount == 0) zonesToControl = _zones.Keys.ToList(); - else zonesToControl = new List(); - for (int i = 0; i < _cli.ArgumentCount; i++) - { - string zone = _cli.Argument(i); - if (!_zones.ContainsKey(zone)) - { - Console.Print($"Ignoring non-existent zone '{zone}'"); - continue; - } - zonesToControl.Add(zone); - } - - foreach (string zone in zonesToControl) - { - if (_cli.Switch("reset")) - { - Console.Print($"Resetting {zone}."); - _zones[zone].Reset(); - } - if (_cli.Switch("trigger")) - { - Console.Print($"Manually triggering {zone}."); - _zones[zone].Triggered = true; - } - } - } - } - foreach (IEnumerator job in _jobs) { if (job.MoveNext()) continue; Console.Print("WARNING: Monitoring job exited. Zone no longer being monitored."); } + // Light indicators should be set/unset independent of the triggered states and actions. + foreach (AirZone zone in _zones.Values) zone.SetLights(); + _updateDisplays(); } diff --git a/Airlock/Airlock.cs b/Airlock/Airlock.cs index 0cb214e..ba6d355 100644 --- a/Airlock/Airlock.cs +++ b/Airlock/Airlock.cs @@ -83,7 +83,7 @@ namespace IngameScript private float _targetOxygenLevel = 0.0F; - private const int CooldownTicks = 120; + private const int CooldownTicks = 12; private const int SealTimeoutTicks = 30; public Airlock(string name, Program _program) diff --git a/Mixins/Sequencer/SequenceablePiston.cs b/Mixins/Sequencer/SequenceablePiston.cs index 4336e33..433f120 100644 --- a/Mixins/Sequencer/SequenceablePiston.cs +++ b/Mixins/Sequencer/SequenceablePiston.cs @@ -36,7 +36,6 @@ namespace IngameScript { if (Running) yield break; Running = true; - _program.Console.Print("DEBUG: Piston Starting"); float targetValue = _stowPosition; float lastValue = -1; @@ -44,10 +43,8 @@ namespace IngameScript _piston.MoveToPosition(targetValue, _velocity); while (lastValue != _piston.CurrentPosition) -// Math.Abs(_piston.CurrentPosition - targetValue) > 0.01 || { lastValue = _piston.CurrentPosition; - _program.Console.Print(_piston.Status.ToString()); yield return true; }