// Docking controller script; handles docking and undocking. // Specifically, when you activate the script it will: // * Connect any Connectors whose names start with "Docking Port" that are ready to connect. // * Turn off all engines. // * Set all O2 and Hydrogen tanks to Stockpile. // * Set all batteries to Recharge. // // When you activate the script with "-undock" it will reverse all of these actions. // // TODO: None of the below switches work yet. // You can selectively disable some functionality with switches. // * "-no-refuel" to disable refueling // * "-no-recharge" to disable battery recharge // (batteries will be left in whatever state they are already in) MyCommandLine cli; List dockingPorts; List thrusters; List batteries; List tanks; public void Program() { cli = new MyCommandLine(); dockingPorts = new List(); List allConnectors = new List(); foreach(IMyShipConnector connector in allConnectors) { if (connector.CustomName.StartsWith("Docking Port")) { dockingPorts.Add(connector); } } thrusters = new List(); GridTerminalSystem.GetBlocksOfType(thrusters); batteries = new List(); GridTerminalSystem.GetBlocksOfType(batteries); tanks = new List(); GridTerminalSystem.GetBlocksOfType(tanks); } public void Main(string argument, UpdateType updateSource) { cli.TryParse(argument); if (cli.Switch("undock")) Undock(); else Dock(); } private void Dock() { foreach (IMyShipConnector dockingPort in dockingPorts) { if (dockingPort.Status == MyShipConnectorStatus.Connectable) { dockingPort.Connect(); } } foreach (IMyThrust thruster in thrusters) { thruster.Enabled = false; } foreach (IMyBatteryBlock battery in batteries) { battery.ChargeMode = ChargeMode.Recharge; } foreach (IMyGasTank tank in tanks) { tank.Stockpile = true; } } private void Undock() { foreach (IMyBatteryBlock battery in batteries) { battery.ChargeMode = ChargeMode.Recharge; } foreach (IMyGasTank tank in tanks) { tank.Stockpile = true; } foreach (IMyThrust thruster in thrusters) { thruster.Enabled = true; } foreach (IMyShipConnector dockingPort in dockingPorts) { if (dockingPort.Status == MyShipConnectorStatus.Connected) { dockingPort.Disconnect(); } } }