Add reference sensor support.

This commit is contained in:
Anna Rose 2025-02-10 20:30:33 -05:00
parent f57243d699
commit 85ce54ad1d
2 changed files with 38 additions and 28 deletions

View File

@ -61,6 +61,8 @@ namespace IngameScript
public bool Cycling { get; private set; } = false; public bool Cycling { get; private set; } = false;
public IMyAirVent ReferenceVent { get; set; }
private bool DoorOpened private bool DoorOpened
{ {
get get
@ -69,19 +71,6 @@ namespace IngameScript
} }
} }
// Returns false if we are in a state where we can't or don't need to balance
private bool balanceOxygen()
{
if (_innerDoor.Status == DoorStatus.Closed || _outerDoor.Status == DoorStatus.Open || OxygenBalanced) { return false; }
_console.Print($"{_name}: Balancing Oxygen Tank");
// Configure the vent to suck in Oxygen.
_airVent.Depressurize = true;
_airVent.Enabled = true;
return true;
}
private string _name; private string _name;
private PrefixedConsole _console; private PrefixedConsole _console;
private MyIni _ini; private MyIni _ini;
@ -92,7 +81,6 @@ namespace IngameScript
private List<IMyLightingBlock> _lights; private List<IMyLightingBlock> _lights;
private IMyGasTank _oxygenTank; private IMyGasTank _oxygenTank;
private IMyAirVent _airVent; private IMyAirVent _airVent;
private IMyAirVent _airSensor;
// private List<IMyTextSurface> _displays; // private List<IMyTextSurface> _displays;
private const int CooldownTicks = 120; private const int CooldownTicks = 120;
@ -136,16 +124,10 @@ namespace IngameScript
// Precondition: _ini.TryParse() should be called on the block before calling this function. // Precondition: _ini.TryParse() should be called on the block before calling this function.
private void addVent(IMyAirVent vent) private void addVent(IMyAirVent vent)
{ {
if (_ini.Get("airlock", "ventRole").ToString() == "cycling" && _airVent == null) if (_airVent == null) {
{
_airVent = vent; _airVent = vent;
return; return;
} }
if (_ini.Get("airlock", "ventRole").ToString() == "reference" && _airSensor == null)
{
_airSensor = vent;
return;
}
_console.Print($"Couldn't add air vent '{vent.CustomName}'"); _console.Print($"Couldn't add air vent '{vent.CustomName}'");
} }
@ -232,9 +214,9 @@ namespace IngameScript
// When depressurizing, check the external pressure and only depressurize to that value. // When depressurizing, check the external pressure and only depressurize to that value.
// TODO: test this for floating point errors // TODO: test this for floating point errors
if (_airVent.Depressurize && _airSensor != null) if (_airVent.Depressurize && ReferenceVent != null)
{ {
targetOxygenLevel = _airSensor.GetOxygenLevel(); targetOxygenLevel = ReferenceVent.GetOxygenLevel();
_console.Print($"Set depressurization target to {targetOxygenLevel}"); _console.Print($"Set depressurization target to {targetOxygenLevel}");
} }
} }
@ -295,6 +277,19 @@ namespace IngameScript
// } // }
// } // }
// Returns false if we are in a state where we can't or don't need to balance
private bool balanceOxygen()
{
if (_innerDoor.Status == DoorStatus.Closed || _outerDoor.Status == DoorStatus.Open || OxygenBalanced) { return false; }
_console.Print($"{_name}: Balancing Oxygen Tank");
// Configure the vent to suck in Oxygen.
_airVent.Depressurize = true;
_airVent.Enabled = true;
return true;
}
private void lockDoors() private void lockDoors()
{ {
_innerDoor.Enabled = false; _innerDoor.Enabled = false;

View File

@ -1,4 +1,5 @@
using Sandbox.ModAPI.Ingame; using Sandbox.ModAPI.Ingame;
using SpaceEngineers.Game.ModAPI.Ingame;
using System.Collections.Generic; using System.Collections.Generic;
using VRage.Game.ModAPI.Ingame.Utilities; using VRage.Game.ModAPI.Ingame.Utilities;
@ -23,10 +24,25 @@ namespace IngameScript
_airlocks = new Dictionary<string, Airlock>(); _airlocks = new Dictionary<string, Airlock>();
List<IMyTerminalBlock> airlockBlocks = new List<IMyTerminalBlock>(); List<IMyTerminalBlock> airlockBlocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => _ini.ContainsSection("airlock")); GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => MyIni.HasSection(block.CustomData, "airlock"));
IMyAirVent referenceVent = null;
foreach (IMyTerminalBlock block in airlockBlocks) foreach (IMyTerminalBlock block in airlockBlocks)
{ {
_ini.TryParse(block.CustomData, "airlock"); _ini.TryParse(block.CustomData, "airlock");
// TODO: redundant reference vents would be awesome. Everyone loves redundancy
if (block is IMyAirVent && _ini.Get("airlock", "reference").ToBoolean())
{
if (referenceVent != null) {
_console.Print("Found multiple reference vents. Only the first one will be used.");
continue;
}
referenceVent = block as IMyAirVent;
_console.Print($"Found reference vent {block.CustomName}.");
continue;
}
string airlockName = _ini.Get("airlock", "id").ToString(); string airlockName = _ini.Get("airlock", "id").ToString();
if (!_airlocks.ContainsKey(airlockName)) if (!_airlocks.ContainsKey(airlockName))
{ {
@ -34,11 +50,10 @@ namespace IngameScript
} }
_airlocks[airlockName].AddBlock(block); _airlocks[airlockName].AddBlock(block);
// TODO: it would be most convenient to just delete non-functional Airlocks... but maybe they're worth
// keeping around for warnings.
} }
if (referenceVent != null) foreach (Airlock airlock in _airlocks.Values) { airlock.ReferenceVent = referenceVent; }
_console.Print($"Found {_airlocks.Count} airlocks."); _console.Print($"Found {_airlocks.Count} airlocks.");
_console.PrintLower($"Airlock Controller\nTotal Ticks: 0"); _console.PrintLower($"Airlock Controller\nTotal Ticks: 0");
} }