IEnumerable <int> UnlockFromConnector() { ConnectorLockInfo = ""; var lst = new List <IMyTerminalBlock>(); var isLocked = false; foreach (var b in GetBlocksOfType(lst, this, "connector", Me, MultiMix_IgnoreBlocks, true)) { if (MyShipConnectorStatus.Connected == (b as IMyShipConnector).Status) { isLocked = true; } } if (!isLocked) { ConnectorUnlockInfo = "Not locked"; yield return(2000); ConnectorUnlockInfo = ""; yield break; } ConnectorUnlockInfo = "Attempting unlock"; foreach (var b in GetBlocksOfType(lst, this, "battery", Me)) { (b as IMyBatteryBlock).OnlyDischarge = true; } var rc = GetShipController(); if (null != rc) { rc.DampenersOverride = true; } yield return(10); var atmosphere = -1f; foreach (var b in GetBlocksOfType(lst, this, "parachute", Me)) { var p = b as IMyParachute; if (p.IsWorking) { atmosphere = Math.Max(atmosphere, p.Atmosphere); } } ThrustFlags tf = atmosphere > 0.5 ? ThrustFlags.Atmospheric : ThrustFlags.Ion; SetEnabled(GetThrustBlocks(lst, tf, this, Me), true); yield return(100); foreach (var b in GetBlocksOfType(lst, this, "landinggear", Me)) { (b as IMyLandingGear).Unlock(); } foreach (var b in GetBlocksOfType(lst, this, "connector", Me, MultiMix_IgnoreBlocks, true)) { (b as IMyShipConnector).Disconnect(); } yield return(100); SetEnabled(GetBlocksOfType(lst, this, "connector", Me, MultiMix_IgnoreBlocks, true), false); SetEnabled(GetBlocksOfType(lst, this, "weapons", Me), true); ConnectorUnlockInfo = "Successful unlock"; yield return(5000); ConnectorUnlockInfo = ""; }
public void AddMenu(MenuManager menuMgr) { if (1 > GetThrustBlocks(ThrustFlags.All, Pgm, Me).Count) { return; // No thrusters found } const int p = 16; // padding MenuItem tt; menuMgr.Add( tt = Menu("Engine/Thrust settings").Add( Menu(() => GetText(1, "All Thrusters", p)) .Collect(this) .Enter("toggleEngines", () => tsToggle(ThrustFlags.All)) .Left(() => tsEnable(ThrustFlags.All, true)) .Right(() => tsEnable(ThrustFlags.All, false)), Menu("Engine types").Add( Menu(() => GetText(1, "Atmospheric", p + 0)) .Collect(this) .Enter("toggleAtmos", () => tsToggle(ThrustFlags.Atmospheric)) .Left(() => tsEnable(ThrustFlags.Atmospheric, true)) .Right(() => tsEnable(ThrustFlags.Atmospheric, false)), Menu(() => GetText(1, "Ion", p + 8)) .Collect(this) .Enter("toggleIon", () => tsToggle(ThrustFlags.Ion)) .Left(() => tsEnable(ThrustFlags.Ion, true)) .Right(() => tsEnable(ThrustFlags.Ion, false)), Menu(() => GetText(1, "Hydrogen", p + 2)) .Collect(this) .Enter("toggleHydro", () => tsToggle(ThrustFlags.Hydrogen)) .Left(() => tsEnable(ThrustFlags.Hydrogen, true)) .Right(() => tsEnable(ThrustFlags.Hydrogen, false)) ) ) ); if (null == Pgm.GetShipController()) { menuMgr.WarningText += "\n ShipController missing. Some features unavailable!"; } else { MenuItem md = Menu("Directions"); MenuItem mo = Menu("Override thrust"); int[] pad = new[] { p + 2, p + 1, p + 3, p + 1, p + 2, p + 0 }; int i = 0; foreach (string txt in Pgm.DIRECTIONS) { ThrustFlags tf = (ThrustFlags)(1 << i); int j = i++; md.Add( Menu(() => GetText(1, txt, pad[j])) .Collect(this) .Enter("toggle" + txt, () => tsToggle(tf)) .Left(() => tsEnable(tf, true)) .Right(() => tsEnable(tf, false)) ); mo.Add( Menu(() => GetText(2, txt, pad[j])) .Collect(this) .Enter("thrust" + txt, () => tsPower(tf, 100f)) .Left(() => tsPower(tf, -1)) .Right(() => tsPower(tf, 1)) .Back(() => tsPower(tf, 0)) ); } tt.Add(md, mo); } }
public static List <IMyTerminalBlock> GetThrustBlocks(List <IMyTerminalBlock> lst, ThrustFlags flgs, Program pgm, IMyTerminalBlock myGrid = null, IMyTerminalBlock dirRefBlk = null) { // Default return value is an empty list lst.Clear(); var engineTypes = flgs & ThrustFlags.AllEngines; if (ThrustFlags.AllEngines == engineTypes) { // When 'all engine types', then use value zero engineTypes = 0; } var engineSizes = flgs & ThrustFlags.AllSizes; if (ThrustFlags.AllSizes == engineSizes) { // When 'all engine sizes', then use value zero engineSizes = 0; } var thrustDirs = flgs & ThrustFlags.AllDirections; if (ThrustFlags.AllDirections == thrustDirs) { // When 'all thrust directions', then use value zero thrustDirs = 0; } if (0 < thrustDirs && null == dirRefBlk) { // Requested specific thrust-direction(s), but missing a 'directionReferenceBlock' for orientation return(lst); } // Collect the thrust-blocks which matches criteria of the thrust-flags requested pgm.GridTerminalSystem.GetBlocksOfType <IMyThrust>(lst, thr => { if (!SameGrid(myGrid, thr)) { // Requested that thruster should be on same grid as the ´myGrid´ block, but it was not return(false); } if (0 < engineSizes) { // If thruster-block has more than 4 cubes, then it is (probably) a large thruster var isLarge = (thr.Max - thr.Min).Size > 4; if (isLarge) { if (0 == (engineSizes & ThrustFlags.Large)) { // Thruster is (probably) 'large', but it was not requested return(false); } } else if (0 == (engineSizes & ThrustFlags.Small)) { // Thruster is (probably) 'small', but it was not requested return(false); } } if (0 < engineTypes) { if (SubtypeContains(thr, "Atmo")) { if (0 == (engineTypes & ThrustFlags.Atmospheric)) { // Thruster is (probably) 'atmospheric', but it was not requested return(false); } } else if (SubtypeContains(thr, "Hydr")) { if (0 == (engineTypes & ThrustFlags.Hydrogen)) { // Thruster is (probably) 'hydrogen', but it was not requested return(false); } } else if (0 == (engineTypes & ThrustFlags.Ion)) { // Thruster is (probably) 'ion', but it was not requested return(false); } } if (0 == thrustDirs) { // All/any direction is requested return(true); } // Calculate direction of thrust-block according to supplied reference-block. int blkDir = (int)dirRefBlk.Orientation.TransformDirectionInverse(thr.Orientation.TransformDirection(Base6Directions.Direction.Forward)); return(0 != ((int)thrustDirs & (1 << blkDir))); // Is direction accepted? }); return(lst); }
public void CollectBlock(IMyTerminalBlock blk) { if (!SameGrid(myGrid, blk) || !blk.IsFunctional) { return; } var thr = blk as IMyThrust; if (null == thr) { return; } ThrustFlags flgs = 0; if (SubtypeContains(blk, "Atmos")) { flgs |= ThrustFlags.Atmospheric; } else if (SubtypeContains(blk, "Hydro")) { flgs |= ThrustFlags.Hydrogen; } else { flgs |= ThrustFlags.Ion; } if (null != dirRefBlk) { // Calculate direction of thrust-block according to supplied reference-block. int blkDir = (int)dirRefBlk.Orientation.TransformDirectionInverse(thr.Orientation.TransformDirection(Base6Directions.Direction.Forward)); flgs |= (ThrustFlags)(1 << blkDir); } Inc("All Thrusters", thr); if (flgs.HasFlag(ThrustFlags.Atmospheric)) { Inc("Atmospheric", thr); } if (flgs.HasFlag(ThrustFlags.Hydrogen)) { Inc("Hydrogen", thr); } if (flgs.HasFlag(ThrustFlags.Ion)) { Inc("Ion", thr); } if (flgs.HasFlag(ThrustFlags.Front)) { Inc("Front", thr); } if (flgs.HasFlag(ThrustFlags.Back)) { Inc("Back", thr); } if (flgs.HasFlag(ThrustFlags.Left)) { Inc("Left", thr); } if (flgs.HasFlag(ThrustFlags.Right)) { Inc("Right", thr); } if (flgs.HasFlag(ThrustFlags.Top)) { Inc("Top", thr); } if (flgs.HasFlag(ThrustFlags.Bottom)) { Inc("Bottom", thr); } }
public static List <IMyTerminalBlock> GetThrustBlocks(ThrustFlags flgs, Program pgm, IMyTerminalBlock myGrid = null, IMyTerminalBlock dirRefBlk = null) { return(GetThrustBlocks(new List <IMyTerminalBlock>(), flgs, pgm, myGrid, dirRefBlk)); }