Go back to automatically resetting once O2 levels are normalized.

This commit is contained in:
Anna Rose 2025-02-12 01:00:44 -05:00
parent d5775df58a
commit 4be70bdfdb
4 changed files with 44 additions and 68 deletions

View File

@ -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<IMyAirVent> Vents { get; } = new List<IMyAirVent>();
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<bool> 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<bool> 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;
}
}
}
}
}

View File

@ -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<string, AirZone> _zones = new Dictionary<string, AirZone>();
private List<IEnumerator<bool>> _jobs = new List<IEnumerator<bool>>();
private List<IMyTextSurface> _displays = new List<IMyTextSurface>();
@ -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<string> zonesToControl;
if (_cli.ArgumentCount == 0) zonesToControl = _zones.Keys.ToList();
else zonesToControl = new List<string>();
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();
}

View File

@ -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)

View File

@ -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;
}