Add checks to avoid running docking commands in invalid state.
This commit is contained in:
parent
11298083e7
commit
3092714212
|
@ -12,40 +12,37 @@ namespace IngameScript
|
||||||
private IEnumerator<bool> _job = null;
|
private IEnumerator<bool> _job = null;
|
||||||
private MyCommandLine _cli = new MyCommandLine();
|
private MyCommandLine _cli = new MyCommandLine();
|
||||||
|
|
||||||
private List<IMyShipConnector> dockingPorts = new List<IMyShipConnector>();
|
private List<IMyShipConnector> _dockingPorts = new List<IMyShipConnector>();
|
||||||
private List<IMyThrust> thrusters = new List<IMyThrust>();
|
private ActionGroup _actionGroup;
|
||||||
private List<IMyGasTank> gasTanks = new List<IMyGasTank>();
|
|
||||||
|
|
||||||
private ActionGroup actionGroup;
|
|
||||||
|
|
||||||
public Program()
|
public Program()
|
||||||
{
|
{
|
||||||
Console = new MainConsole(this, "Docking Controller");
|
Console = new MainConsole(this, "Docking Controller");
|
||||||
actionGroup = new ActionGroup(Console, "docking");
|
_actionGroup = new ActionGroup(Console, "docking");
|
||||||
|
|
||||||
// We store a list of the dockingPorts because we will only dock if one is ready to lock.
|
// We store a list of the dockingPorts because we will only dock if one is ready to lock.
|
||||||
GridTerminalSystem.GetBlocksOfType(dockingPorts, blockFilter);
|
GridTerminalSystem.GetBlocksOfType(_dockingPorts, blockFilter);
|
||||||
|
|
||||||
foreach (IMyShipConnector dockingPort in dockingPorts)
|
foreach (IMyShipConnector dockingPort in _dockingPorts)
|
||||||
{
|
{
|
||||||
actionGroup.AddActionBlock("dock", 0, new BlockActionConnector(dockingPort, ConnectorAction.Connect));
|
_actionGroup.AddActionBlock("dock", 0, new BlockActionConnector(dockingPort, ConnectorAction.Connect));
|
||||||
actionGroup.AddActionBlock("undock", 1, new BlockActionConnector(dockingPort, ConnectorAction.Disconnect));
|
_actionGroup.AddActionBlock("undock", 1, new BlockActionConnector(dockingPort, ConnectorAction.Disconnect));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<IMyThrust> thrusters = new List<IMyThrust>();
|
List<IMyThrust> thrusters = new List<IMyThrust>();
|
||||||
GridTerminalSystem.GetBlocksOfType(thrusters, blockFilter);
|
GridTerminalSystem.GetBlocksOfType(thrusters, blockFilter);
|
||||||
foreach (IMyThrust thruster in thrusters)
|
foreach (IMyThrust thruster in thrusters)
|
||||||
{
|
{
|
||||||
actionGroup.AddActionBlock("dock", 1, new BlockActionThruster(thruster, ThrusterAction.Disable));
|
_actionGroup.AddActionBlock("dock", 1, new BlockActionThruster(thruster, ThrusterAction.Disable));
|
||||||
actionGroup.AddActionBlock("undock", 0, new BlockActionThruster(thruster, ThrusterAction.Enable));
|
_actionGroup.AddActionBlock("undock", 0, new BlockActionThruster(thruster, ThrusterAction.Enable));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<IMyGasTank> gasTanks = new List<IMyGasTank>();
|
List<IMyGasTank> gasTanks = new List<IMyGasTank>();
|
||||||
GridTerminalSystem.GetBlocksOfType(gasTanks, blockFilter);
|
GridTerminalSystem.GetBlocksOfType(gasTanks, blockFilter);
|
||||||
foreach (IMyGasTank gasTank in gasTanks)
|
foreach (IMyGasTank gasTank in gasTanks)
|
||||||
{
|
{
|
||||||
actionGroup.AddActionBlock("dock", 1, new BlockActionGasTank(gasTank, GasTankAction.Stockpile));
|
_actionGroup.AddActionBlock("dock", 1, new BlockActionGasTank(gasTank, GasTankAction.Stockpile));
|
||||||
actionGroup.AddActionBlock("undock", 0, new BlockActionGasTank(gasTank, GasTankAction.Dispense));
|
_actionGroup.AddActionBlock("undock", 0, new BlockActionGasTank(gasTank, GasTankAction.Dispense));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,18 +50,27 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
if (argument != "")
|
if (argument != "")
|
||||||
{
|
{
|
||||||
_cli.TryParse(argument);
|
if (_job != null)
|
||||||
if (_cli.ArgumentCount == 0)
|
|
||||||
{
|
|
||||||
Console.Print("Error: Must pass an argument, 'dock' or 'undock'.");
|
|
||||||
}
|
|
||||||
else if (_job != null)
|
|
||||||
{
|
{
|
||||||
Console.Print("Already performing a docking action.");
|
Console.Print("Already performing a docking action.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_job = actionGroup.RunAction(_cli.Argument(0).ToLower());
|
_cli.TryParse(argument);
|
||||||
|
if (_cli.ArgumentCount == 0)
|
||||||
|
{
|
||||||
|
Console.Print("Error: Must pass an argument, 'dock' or 'undock'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string action = _cli.Argument(0).ToLower();
|
||||||
|
|
||||||
|
if (action == "dock" && !readyToDock())
|
||||||
|
{
|
||||||
|
Console.Print("No docking port in a dockable state.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_job = _actionGroup.RunAction(_cli.Argument(0).ToLower());
|
||||||
Runtime.UpdateFrequency = UpdateFrequency.Update10;
|
Runtime.UpdateFrequency = UpdateFrequency.Update10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,5 +93,14 @@ namespace IngameScript
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool readyToDock()
|
||||||
|
{
|
||||||
|
foreach (IMyShipConnector dockingPort in _dockingPorts)
|
||||||
|
{
|
||||||
|
if (dockingPort.Status == MyShipConnectorStatus.Connectable) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user