/// <summary> /// Create autopilot and let it find the required blocks. /// </summary> /// <param name="gts">GridTerminalSystem to use for block lookup.</param> /// <param name="basis">Only blocks on the exact same grid as this one will be used.</param> public AutoPilot(IMyGridTerminalSystem gts, IMyTerminalBlock basis, IRotationAid aid = null) { Controller = basis as IMyShipController; RotationAid = aid ?? new RotationAidSimple(); if (Controller == null) { gts.GetBlocksOfType <IMyShipController>(null, (b) => { if (b.IsFunctional && b.CubeGrid.EntityId == basis.CubeGrid.EntityId && b.CanControlShip) { Controller = b; } return(false); }); } if (Controller == null) { throw new Exception("No controller found on this grid!"); } Thrusters = new List <IMyThrust>(); gts.GetBlocksOfType(Thrusters, (t) => t.IsFunctional && t.CubeGrid.EntityId == Controller.CubeGrid.EntityId); ThrustValues = new double[Thrusters.Count]; Gyros = new List <IMyGyro>(); gts.GetBlocksOfType(Gyros, (g) => g.IsFunctional && g.CubeGrid.EntityId == Controller.CubeGrid.EntityId); }
/// <summary> /// Create autopilot using specific set of blocks. /// </summary> /// <param name="controller">Ship controller to use.</param> /// <param name="thrusters">Thrusters to use.</param> /// <param name="gyros">Gyros to use.</param> public AutoPilot(IMyShipController controller, List <IMyThrust> thrusters, List <IMyGyro> gyros, IRotationAid aid = null) : base() { Thrusters = thrusters; Gyros = gyros; Controller = controller; ThrustValues = new double[Thrusters.Count]; RotationAid = aid ?? new RotationAidSimple(); }