Skip to content

Instantly share code, notes, and snippets.

@awstanley
Created January 4, 2015 23:56
Show Gist options
  • Save awstanley/d9ea49f7b0f65119b9e7 to your computer and use it in GitHub Desktop.
Save awstanley/d9ea49f7b0f65119b9e7 to your computer and use it in GitHub Desktop.
Current working draft of autonomous docking code shutdown sequence. Untested.
// OnOff code seems to be global
ITerminalAction GetOnOffAction(IMyTerminalBlock block, bool enable)
{
ITerminalAction Action;
if (enable)
{
Action = block.GetActionWithName("Toggle block On");
}
else
{
Action = block.GetActionWithName("Toggle block Off");
}
return Action;
}
// Set all by type
void SetBlockStateByType<T>(bool enable)
{
var blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<T>(blocks);
if(blocks.Count > 0)
{
ITerminalAction Action = GetOnOffAction(blocks[0], enable);
foreach(IMyTerminalBlock target in blocks)
{
Action.Apply(target);
}
}
}
// We want a remote (or local) control block with enough access to do what we want
IMyShipController GetFlightControl()
{
var blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyShipController>(blocks);
foreach (IMyShipController block in blocks)
{
if(block.ControlThrusters && block.HandBrake && block.DampenersOverride && block.ControlWheels)
{
return block;
}
}
return null;
}
// Set the state
void SetDockedState(bool enable)
{
IMyShipController remote = GetFlightControl();
if(remote == null)
{
SetBlockStateByType<IMyThrust>(enable);
}
else
{
// When we get on and off as distinct actions we'll be golden,
// until then toggle unless you store state somewhere.
remote.GetActionWithName("Inertia dampeners On/Off").Apply(remote);
remote.GetActionWithName("Control thrusters On/Off").Apply(remote);
}
// Kill the gyro (or gyro array)
SetBlockStateByType<IMyGyro>(enable);
// Depending on your vessel you may want to power down weapons...
SetBlockStateByType<IMySmallGatlingGun>(enable);
SetBlockStateByType<IMyLargeGatlingTurret>(enable);
SetBlockStateByType<IMySmallMissileLauncher>(enable);
SetBlockStateByType<IMySmallMissileLauncherReload>(enable);
SetBlockStateByType<IMyLargeMissileTurret>(enable);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment