102 lines
3.4 KiB
C#
102 lines
3.4 KiB
C#
using Sandbox.Game.EntityComponents;
|
|
using Sandbox.ModAPI.Ingame;
|
|
using Sandbox.ModAPI.Interfaces;
|
|
using SpaceEngineers.Game.ModAPI.Ingame;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using VRage;
|
|
using VRage.Collections;
|
|
using VRage.Game;
|
|
using VRage.Game.Components;
|
|
using VRage.Game.GUI.TextPanel;
|
|
using VRage.Game.ModAPI.Ingame;
|
|
using VRage.Game.ModAPI.Ingame.Utilities;
|
|
using VRage.Game.ObjectBuilders.Definitions;
|
|
using VRageMath;
|
|
|
|
namespace IngameScript
|
|
{
|
|
public partial class Program : MyGridProgram
|
|
{
|
|
private MyIni _ini;
|
|
private Console _console;
|
|
private MyCommandLine _cli;
|
|
private Dictionary<string, AirZone> _zones;
|
|
private List<IEnumerator<bool>> _jobs;
|
|
private int _totalTicks = 0;
|
|
|
|
public Program()
|
|
{
|
|
_cli = new MyCommandLine();
|
|
_ini = new MyIni();
|
|
_console = new Console(this, _ini);
|
|
_zones = new Dictionary<string, AirZone>();
|
|
_jobs = new List<IEnumerator<bool>>();
|
|
|
|
// Find all tagged objects and build out zones
|
|
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
|
|
GridTerminalSystem.GetBlocksOfType(blocks, block => MyIni.HasSection(block.CustomData, "airMonitor"));
|
|
foreach (IMyTerminalBlock block in blocks)
|
|
{
|
|
_ini.TryParse(block.CustomData);
|
|
string[] zones = new string[] { };
|
|
if (_ini.Get("airMonitor", "zones").ToString() != "")
|
|
{
|
|
zones = _ini.Get("airMonitor", "zones").ToString().Split(',');
|
|
}
|
|
else if (_ini.Get("airMonitor", "zone").ToString() != "")
|
|
{
|
|
zones = new string[] { _ini.Get("airMonitor", "zone").ToString() };
|
|
}
|
|
|
|
foreach (string zone in zones)
|
|
{
|
|
if (!_zones.ContainsKey(zone))
|
|
{
|
|
_zones[zone] = new AirZone(zone, _ini, _console);
|
|
}
|
|
_zones[zone].AddBlock(block);
|
|
}
|
|
}
|
|
|
|
_console.Print($"Found {_zones.Count} zones.");
|
|
foreach (AirZone zone in _zones.Values)
|
|
{
|
|
_jobs.Add(zone.Monitor());
|
|
}
|
|
Runtime.UpdateFrequency |= UpdateFrequency.Update100;
|
|
}
|
|
|
|
public void Main(string argument, UpdateType updateSource)
|
|
{
|
|
_console.PrintLower($"Air Monitor\nTotal Ticks: {++_totalTicks}");
|
|
if (argument != "")
|
|
{
|
|
_cli.TryParse(argument);
|
|
if (_cli.Switch("reset"))
|
|
{
|
|
for (int i = 0; i < _cli.ArgumentCount; i++)
|
|
{
|
|
string zone = _cli.Argument(i);
|
|
_console.Print($"Resetting {zone}.");
|
|
if (_zones.ContainsKey(zone))
|
|
{
|
|
_zones[zone].Triggered = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (IEnumerator job in _jobs)
|
|
{
|
|
if (job.MoveNext()) continue;
|
|
_console.Print("WARNING: Monitoring job exited. Zone no longer being monitored.");
|
|
}
|
|
}
|
|
}
|
|
}
|