Go back to automatically resetting once O2 levels are normalized.
This commit is contained in:
parent
d5775df58a
commit
4be70bdfdb
|
@ -1,6 +1,5 @@
|
||||||
using Sandbox.ModAPI.Ingame;
|
using Sandbox.ModAPI.Ingame;
|
||||||
using SpaceEngineers.Game.ModAPI.Ingame;
|
using SpaceEngineers.Game.ModAPI.Ingame;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using VRageMath;
|
using VRageMath;
|
||||||
|
|
||||||
|
@ -11,7 +10,17 @@ namespace IngameScript
|
||||||
public class AirZone
|
public class AirZone
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
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>();
|
public List<IMyAirVent> Vents { get; } = new List<IMyAirVent>();
|
||||||
|
|
||||||
private Program _program;
|
private Program _program;
|
||||||
|
@ -61,31 +70,14 @@ namespace IngameScript
|
||||||
// TODO: support for arbitrary (sub-)sequences here could be powerful
|
// TODO: support for arbitrary (sub-)sequences here could be powerful
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
_console.Print("Resetting sensor.");
|
|
||||||
Triggered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This enumerator should run forever.
|
// This enumerator should run forever.
|
||||||
public IEnumerator<bool> Monitor()
|
public IEnumerator<bool> Monitor()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
foreach (IMyAirVent vent in Vents)
|
|
||||||
{
|
|
||||||
if (vent.GetOxygenLevel() < TriggerLevel) Triggered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add informational lights per-zone
|
|
||||||
if (Triggered == true)
|
if (Triggered == true)
|
||||||
{
|
{
|
||||||
_console.Print($"Low pressure alarm triggered.");
|
_console.Print($"Low pressure alarm triggered.");
|
||||||
foreach (IMyLightingBlock light in _lights)
|
|
||||||
{
|
|
||||||
light.Enabled = true;
|
|
||||||
light.Color = Color.Red;
|
|
||||||
}
|
|
||||||
|
|
||||||
// close the doors
|
// close the doors
|
||||||
IEnumerator<bool> job = _sequencer.RunSequence(true);
|
IEnumerator<bool> job = _sequencer.RunSequence(true);
|
||||||
|
@ -98,7 +90,7 @@ namespace IngameScript
|
||||||
}
|
}
|
||||||
job.Dispose();
|
job.Dispose();
|
||||||
|
|
||||||
while (Triggered) yield return true;
|
while (Triggered) { yield return true; }
|
||||||
|
|
||||||
// unlock the doors, but we'll leave them closed.
|
// unlock the doors, but we'll leave them closed.
|
||||||
foreach (IMyDoor door in _doors) { door.Enabled = true; }
|
foreach (IMyDoor door in _doors) { door.Enabled = true; }
|
||||||
|
@ -113,6 +105,28 @@ namespace IngameScript
|
||||||
yield return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,6 @@ namespace IngameScript
|
||||||
public MyIni Ini { get; } = new MyIni();
|
public MyIni Ini { get; } = new MyIni();
|
||||||
public IConsole Console { get; private set; }
|
public IConsole Console { get; private set; }
|
||||||
|
|
||||||
private MyCommandLine _cli = new MyCommandLine();
|
|
||||||
private Dictionary<string, AirZone> _zones = new Dictionary<string, AirZone>();
|
private Dictionary<string, AirZone> _zones = new Dictionary<string, AirZone>();
|
||||||
private List<IEnumerator<bool>> _jobs = new List<IEnumerator<bool>>();
|
private List<IEnumerator<bool>> _jobs = new List<IEnumerator<bool>>();
|
||||||
private List<IMyTextSurface> _displays = new List<IMyTextSurface>();
|
private List<IMyTextSurface> _displays = new List<IMyTextSurface>();
|
||||||
|
@ -32,16 +31,12 @@ namespace IngameScript
|
||||||
Ini.TryParse(block.CustomData);
|
Ini.TryParse(block.CustomData);
|
||||||
string[] zones = new string[] { };
|
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)
|
if (block is IMyTextSurface)
|
||||||
{
|
{
|
||||||
Console.Print($"Adding monitoring display '{block.CustomName}'");
|
Console.Print($"Adding monitoring display '{block.CustomName}'");
|
||||||
_displays.Add(block as IMyTextSurface);
|
_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();
|
int displayIndex = Ini.Get("airMonitor", "display").ToInt32();
|
||||||
IMyTextSurfaceProvider provider = block as IMyTextSurfaceProvider;
|
IMyTextSurfaceProvider provider = block as IMyTextSurfaceProvider;
|
||||||
|
@ -54,12 +49,11 @@ namespace IngameScript
|
||||||
_displays.Add(provider.GetSurface(displayIndex));
|
_displays.Add(provider.GetSurface(displayIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (block is IMyGasTank)
|
else if (block is IMyGasTank)
|
||||||
{
|
{
|
||||||
_oxygenTanks.Add(block as IMyGasTank);
|
_oxygenTanks.Add(block as IMyGasTank);
|
||||||
}
|
}
|
||||||
|
else if (Ini.Get("airMonitor", "zones").ToString() != "")
|
||||||
if (Ini.Get("airMonitor", "zones").ToString() != "")
|
|
||||||
{
|
{
|
||||||
zones = Ini.Get("airMonitor", "zones").ToString().Split(',');
|
zones = Ini.Get("airMonitor", "zones").ToString().Split(',');
|
||||||
}
|
}
|
||||||
|
@ -67,6 +61,9 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
zones = new string[] { Ini.Get("airMonitor", "zone").ToString() };
|
zones = new string[] { Ini.Get("airMonitor", "zone").ToString() };
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Console.Print($"Failed to add block {block.CustomName}");
|
||||||
|
}
|
||||||
|
|
||||||
foreach (string zone in zones)
|
foreach (string zone in zones)
|
||||||
{
|
{
|
||||||
|
@ -93,47 +90,15 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
Console.UpdateTickCount();
|
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)
|
foreach (IEnumerator job in _jobs)
|
||||||
{
|
{
|
||||||
if (job.MoveNext()) continue;
|
if (job.MoveNext()) continue;
|
||||||
Console.Print("WARNING: Monitoring job exited. Zone no longer being monitored.");
|
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();
|
_updateDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ namespace IngameScript
|
||||||
|
|
||||||
private float _targetOxygenLevel = 0.0F;
|
private float _targetOxygenLevel = 0.0F;
|
||||||
|
|
||||||
private const int CooldownTicks = 120;
|
private const int CooldownTicks = 12;
|
||||||
private const int SealTimeoutTicks = 30;
|
private const int SealTimeoutTicks = 30;
|
||||||
|
|
||||||
public Airlock(string name, Program _program)
|
public Airlock(string name, Program _program)
|
||||||
|
|
|
@ -36,7 +36,6 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
if (Running) yield break;
|
if (Running) yield break;
|
||||||
Running = true;
|
Running = true;
|
||||||
_program.Console.Print("DEBUG: Piston Starting");
|
|
||||||
|
|
||||||
float targetValue = _stowPosition;
|
float targetValue = _stowPosition;
|
||||||
float lastValue = -1;
|
float lastValue = -1;
|
||||||
|
@ -44,10 +43,8 @@ namespace IngameScript
|
||||||
_piston.MoveToPosition(targetValue, _velocity);
|
_piston.MoveToPosition(targetValue, _velocity);
|
||||||
|
|
||||||
while (lastValue != _piston.CurrentPosition)
|
while (lastValue != _piston.CurrentPosition)
|
||||||
// Math.Abs(_piston.CurrentPosition - targetValue) > 0.01 ||
|
|
||||||
{
|
{
|
||||||
lastValue = _piston.CurrentPosition;
|
lastValue = _piston.CurrentPosition;
|
||||||
_program.Console.Print(_piston.Status.ToString());
|
|
||||||
yield return true;
|
yield return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user