93 lines
3.0 KiB
C#
93 lines
3.0 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 Dictionary<string, Airlock> _airlocks;
|
|
private List<IEnumerator<bool>> _jobs;
|
|
|
|
private int _tickCount = 0;
|
|
private MyCommandLine _cli;
|
|
|
|
public Program()
|
|
{
|
|
_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, airlockName);
|
|
if (!newAirlock.Functional)
|
|
{
|
|
Echo($"{airlockName} is missing one or more required blocks.");
|
|
continue;
|
|
}
|
|
_airlocks[airlockName] = newAirlock;
|
|
}
|
|
}
|
|
|
|
public void Main(string argument, UpdateType updateSource)
|
|
{
|
|
Echo($"index: {_tickCount++}");
|
|
|
|
if (updateSource == UpdateType.Trigger || updateSource == UpdateType.Terminal)
|
|
{
|
|
_cli.TryParse(argument);
|
|
if (_cli.ArgumentCount == 0) { Echo("You must provide an airlock ID."); }
|
|
else
|
|
{
|
|
string airlockName = $"Airlock{_cli.Argument(0)}";
|
|
if (!_airlocks.ContainsKey(airlockName))
|
|
{
|
|
Echo($"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--;
|
|
Echo("Airlock Cycling Complete.");
|
|
}
|
|
}
|
|
|
|
if (_jobs.Count == 0) Runtime.UpdateFrequency = UpdateFrequency.None;
|
|
}
|
|
}
|
|
}
|