81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using Sandbox.ModAPI.Ingame;
|
|
using System.Collections.Generic;
|
|
using VRage.Game.ModAPI.Ingame.Utilities;
|
|
|
|
namespace IngameScript
|
|
{
|
|
public partial class Program : MyGridProgram
|
|
{
|
|
private Dictionary<string, Airlock> _airlocks;
|
|
private List<IEnumerator<bool>> _jobs;
|
|
|
|
private int _tickCount = 0;
|
|
private MyCommandLine _cli;
|
|
private Console _console;
|
|
|
|
public Program()
|
|
{
|
|
_console = new Console(this);
|
|
_cli = new MyCommandLine();
|
|
_jobs = new List<IEnumerator<bool>>();
|
|
_airlocks = new Dictionary<string, Airlock>();
|
|
|
|
List<IMyDoor> doors = new List<IMyDoor>();
|
|
GridTerminalSystem.GetBlocksOfType(doors);
|
|
foreach (IMyDoor door in doors)
|
|
{
|
|
if (!door.CustomName.StartsWith("Airlock")) continue;
|
|
string airlockName = door.CustomName.Split(' ')[0];
|
|
if (_airlocks.ContainsKey(airlockName)) continue;
|
|
Airlock newAirlock = new Airlock(this, _console, airlockName);
|
|
if (!newAirlock.Functional)
|
|
{
|
|
_console.Print($"{airlockName} is missing one or more required blocks.");
|
|
continue;
|
|
}
|
|
_airlocks[airlockName] = newAirlock;
|
|
}
|
|
|
|
_console.Print($"Found {_airlocks.Count} airlocks.");
|
|
}
|
|
|
|
public void Main(string argument, UpdateType updateSource)
|
|
{
|
|
_console.PrintLower($"Total Ticks: {_tickCount++}");
|
|
|
|
if (updateSource == UpdateType.Trigger || updateSource == UpdateType.Terminal)
|
|
{
|
|
_cli.TryParse(argument);
|
|
if (_cli.ArgumentCount == 0) { _console.Print("You must provide an airlock ID."); }
|
|
else
|
|
{
|
|
string airlockName = $"Airlock{_cli.Argument(0)}";
|
|
if (!_airlocks.ContainsKey(airlockName))
|
|
{
|
|
_console.Print($"Invalid airlock ID {_cli.Argument(0)}");
|
|
}
|
|
else
|
|
{
|
|
_jobs.Add(_airlocks[airlockName].CycleAirlock());
|
|
Runtime.UpdateFrequency |= UpdateFrequency.Update1;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < _jobs.Count; i++)
|
|
{
|
|
IEnumerator<bool> job = _jobs[i];
|
|
if (!job.MoveNext())
|
|
{
|
|
job.Dispose();
|
|
_jobs.Remove(job);
|
|
i--;
|
|
_console.Print("Job Removed From Queue.");
|
|
}
|
|
}
|
|
|
|
if (_jobs.Count == 0) Runtime.UpdateFrequency = UpdateFrequency.None;
|
|
}
|
|
}
|
|
}
|