Add reference sensor support.
This commit is contained in:
parent
f57243d699
commit
85ce54ad1d
|
@ -61,6 +61,8 @@ namespace IngameScript
|
|||
|
||||
public bool Cycling { get; private set; } = false;
|
||||
|
||||
public IMyAirVent ReferenceVent { get; set; }
|
||||
|
||||
private bool DoorOpened
|
||||
{
|
||||
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 PrefixedConsole _console;
|
||||
private MyIni _ini;
|
||||
|
@ -92,7 +81,6 @@ namespace IngameScript
|
|||
private List<IMyLightingBlock> _lights;
|
||||
private IMyGasTank _oxygenTank;
|
||||
private IMyAirVent _airVent;
|
||||
private IMyAirVent _airSensor;
|
||||
// private List<IMyTextSurface> _displays;
|
||||
|
||||
private const int CooldownTicks = 120;
|
||||
|
@ -136,16 +124,10 @@ namespace IngameScript
|
|||
// Precondition: _ini.TryParse() should be called on the block before calling this function.
|
||||
private void addVent(IMyAirVent vent)
|
||||
{
|
||||
if (_ini.Get("airlock", "ventRole").ToString() == "cycling" && _airVent == null)
|
||||
{
|
||||
if (_airVent == null) {
|
||||
_airVent = vent;
|
||||
return;
|
||||
}
|
||||
if (_ini.Get("airlock", "ventRole").ToString() == "reference" && _airSensor == null)
|
||||
{
|
||||
_airSensor = vent;
|
||||
return;
|
||||
}
|
||||
_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.
|
||||
// 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}");
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
_innerDoor.Enabled = false;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Sandbox.ModAPI.Ingame;
|
||||
using SpaceEngineers.Game.ModAPI.Ingame;
|
||||
using System.Collections.Generic;
|
||||
using VRage.Game.ModAPI.Ingame.Utilities;
|
||||
|
||||
|
@ -23,10 +24,25 @@ namespace IngameScript
|
|||
_airlocks = new Dictionary<string, Airlock>();
|
||||
|
||||
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)
|
||||
{
|
||||
_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();
|
||||
if (!_airlocks.ContainsKey(airlockName))
|
||||
{
|
||||
|
@ -34,11 +50,10 @@ namespace IngameScript
|
|||
}
|
||||
|
||||
_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.PrintLower($"Airlock Controller\nTotal Ticks: 0");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user