/// <summary> /// Calculates position and approach vector to dock on specific rotor top. /// </summary> /// <param name="top">Rotor top to use.</param> /// <param name="pos">Rotor top's position.</param> /// <param name="approach">Approach direction.</param> public static void CalculateApproach(IMyMotorRotor top, out Vector3D pos, out Vector3D approach) { MatrixD wm = top.WorldMatrix; pos = wm.Translation; approach = -wm.GetDirectionVector(Base6Directions.Direction.Down); }
void UnlockRotor() { IMyMotorRotor clamp = Reference as IMyMotorRotor; if (clamp.IsAttached) { clamp.Base.Detach(); } }
private void ShowErrorLights() { for (int nIndex = 0; nIndex < m_listRotor.Count; nIndex++) { IMyMotorRotor rotor = m_listRotor[nIndex]; rotor.Base.ApplyAction("OnOff_On"); } for (int nIndex = 0; nIndex < m_listRotor.Count; nIndex++) { IMyLightingBlock warningLight = m_listWarningLight[nIndex]; warningLight.Color = Color.Red; warningLight.Enabled = true; } }
private static void GetAttachedGrids(IMyCubeGrid cubeGrid, ref List <IMyCubeGrid> results, AttachedGrids type) { if (cubeGrid == null) { return; } var blocks = new List <IMySlimBlock>(); cubeGrid.GetBlocks(blocks, b => b != null && b.FatBlock != null && !b.FatBlock.BlockDefinition.TypeId.IsNull); foreach (var block in blocks) { //MyAPIGateway.Utilities.ShowMessage("Block", string.Format("{0}", block.FatBlock.BlockDefinition.TypeId)); if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorStator) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorSuspension) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorBase)) { // The MotorStator which inherits from MotorBase. IMyMotorBase motorBase = block.FatBlock as IMyMotorBase; if (motorBase == null || motorBase.Top == null) { continue; } IMyCubeGrid entityParent = motorBase.TopGrid; if (entityParent == null) { continue; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedRotor) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorRotor) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RealWheel) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Wheel)) { // The Rotor Part. IMyMotorRotor motorRotor = block.FatBlock as IMyMotorRotor; IMyCubeGrid entityParent = null; if (motorRotor == null || motorRotor.Base == null) { // Wheels appear to not properly populate the Stator property. IMyCubeBlock altBlock = Support.FindRotorBase(motorRotor.EntityId); if (altBlock == null) { continue; } entityParent = altBlock.CubeGrid; } else { entityParent = motorRotor.Base.CubeGrid; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonTop)) { // The Piston Top. IMyPistonTop pistonTop = block.FatBlock as IMyPistonTop; if (pistonTop == null || pistonTop.Piston == null) { continue; } IMyCubeGrid entityParent = pistonTop.Piston.CubeGrid; if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase)) { IMyPistonBase pistonBase = block.FatBlock as IMyPistonBase; if (pistonBase == null || pistonBase.Top == null) { continue; } IMyCubeGrid entityParent = pistonBase.TopGrid; if (entityParent == null) { continue; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ShipConnector) && type == AttachedGrids.All) { var connector = (IMyShipConnector)block.FatBlock; if (connector.Status != Sandbox.ModAPI.Ingame.MyShipConnectorStatus.Connected || connector.OtherConnector == null) { continue; } var otherGrid = (IMyCubeGrid)connector.OtherConnector.CubeGrid; if (!results.Any(e => e.EntityId == otherGrid.EntityId)) { results.Add(otherGrid); GetAttachedGrids(otherGrid, ref results, type); } } // Commented out temporarily, as it isn't been used, but may not work under 1.126. //else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LandingGear) && type == AttachedGrids.All) //{ // var landingGear = (IMyLandingGear)block.FatBlock; // if (landingGear.IsLocked == false) // continue; // var entity = landingGear.GetAttachedEntity(); // if (entity == null || !(entity is IMyCubeGrid)) // continue; // var otherGrid = (IMyCubeGrid)entity; // if (!results.Any(e => e.EntityId == otherGrid.EntityId)) // { // results.Add(otherGrid); // GetAttachedGrids(otherGrid, ref results, type); // } //} } // Loop through all other grids, find their Landing gear, and figure out if they are attached to <cubeGrid>. var allShips = new HashSet <IMyEntity>(); var checkList = results; // cannot use ref paramter in Lambada expression!?!. MyAPIGateway.Entities.GetEntities(allShips, e => e is IMyCubeGrid && !checkList.Contains(e)); //if (type == AttachedGrids.All) //{ // foreach (IMyCubeGrid ship in allShips) // { // blocks = new List<IMySlimBlock>(); // ship.GetBlocks(blocks, // b => // b != null && b.FatBlock != null && !b.FatBlock.BlockDefinition.TypeId.IsNull && // b.FatBlock is IMyLandingGear); // foreach (var block in blocks) // { // var landingGear = (IMyLandingGear)block.FatBlock; // if (landingGear.IsLocked == false) // continue; // var entity = landingGear.GetAttachedEntity(); // if (entity == null || entity.EntityId != cubeGrid.EntityId) // continue; // if (!results.Any(e => e.EntityId == ship.EntityId)) // { // results.Add(ship); // GetAttachedGrids(ship, ref results, type); // } // } // } //} }
private static void GetAttachedGrids(IMyCubeGrid cubeGrid, ref List <IMyCubeGrid> results) { if (cubeGrid == null) { return; } var blocks = new List <IMySlimBlock>(); cubeGrid.GetBlocks(blocks, b => b != null && b.FatBlock != null && !b.FatBlock.BlockDefinition.TypeId.IsNull); foreach (var block in blocks) { //MyAPIGateway.Utilities.ShowMessage("Block", string.Format("{0}", block.FatBlock.BlockDefinition.TypeId)); if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorStator) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorSuspension) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorBase)) { // The MotorStator which inherits from MotorBase. IMyMotorBase motorBase = block.FatBlock as IMyMotorBase; if (motorBase == null || motorBase.Top == null) { continue; } IMyCubeGrid entityParent = motorBase.TopGrid; if (entityParent == null) { continue; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedRotor) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorRotor) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RealWheel) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Wheel)) { // The Rotor Part. IMyMotorRotor motorRotor = block.FatBlock as IMyMotorRotor; if (motorRotor == null || motorRotor.Base == null) { continue; } IMyCubeGrid entityParent = motorRotor.Base.CubeGrid; if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonTop)) { // The Piston Top. IMyPistonTop pistonTop = block.FatBlock as IMyPistonTop; if (pistonTop == null || pistonTop.Piston == null) { continue; } IMyCubeGrid entityParent = pistonTop.Piston.CubeGrid; if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase)) { IMyPistonBase pistonBase = block.FatBlock as IMyPistonBase; if (pistonBase == null || pistonBase.Top == null) { continue; } IMyCubeGrid entityParent = pistonBase.TopGrid; if (entityParent == null) { continue; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results); } } } }
private static bool GetAttachedGridsLoopBlocks(IMySlimBlock slim) // should always return false! { IMyCubeBlock block = slim.FatBlock; if (block == null) { return(false); } //if(Constants.CLEANUP_CONNECTOR_CONNECTED) //{ // IMyShipConnector connector = block as IMyShipConnector; // if(connector != null) // { // IMyCubeGrid otherGrid = connector.OtherConnector?.CubeGrid; // if(otherGrid != null && !grids.Contains(otherGrid)) // { // grids.Add(otherGrid); // RecursiveGetAttachedGrids(otherGrid); // } // return false; // } //} IMyMotorStator rotorBase = block as IMyMotorStator; if (rotorBase != null) { IMyCubeGrid otherGrid = rotorBase.TopGrid; if (otherGrid == null || Grids.Contains(otherGrid)) { return(false); } Grids.Add(otherGrid); RecursiveGetAttachedGrids(otherGrid); return(false); } IMyMotorRotor rotorTop = block as IMyMotorRotor; if (rotorTop != null) { IMyCubeGrid otherGrid = rotorTop.Base?.CubeGrid; if (otherGrid == null || Grids.Contains(otherGrid)) { return(false); } Grids.Add(otherGrid); RecursiveGetAttachedGrids(otherGrid); return(false); } IMyPistonBase pistonBase = block as IMyPistonBase; if (pistonBase != null) { IMyCubeGrid otherGrid = pistonBase.TopGrid; if (otherGrid == null || Grids.Contains(otherGrid)) { return(false); } Grids.Add(otherGrid); RecursiveGetAttachedGrids(otherGrid); return(false); } IMyPistonTop pistonTop = block as IMyPistonTop; if (pistonTop == null) { return(false); } { IMyCubeGrid otherGrid = pistonTop.Piston?.CubeGrid; if (otherGrid == null || Grids.Contains(otherGrid)) { return(false); } Grids.Add(otherGrid); RecursiveGetAttachedGrids(otherGrid); return(false); } }
private void SetupCustomTrackingProperties() { if (Entity == null) { return; } //MyAPIGateway.Utilities.ShowMessage("step", "1"); var solarPanelEntity = (IMySolarPanel)Entity; var name = solarPanelEntity.CustomName; if (!string.IsNullOrEmpty(name)) { _autoRotate = Regex.Match(name, @"(\s{1,}|^)/AR(\s{1,}|$)", RegexOptions.IgnoreCase).Success; } else { _autoRotate = false; } //MyAPIGateway.Utilities.ShowMessage("step", "2"); //MyAPIGateway.Utilities.ShowMessage("Name", "Setup executing"); if (_autoRotate) { var blocks = new List <IMySlimBlock>(); ((IMyCubeGrid)Entity.Parent).GetBlocks(blocks, f => f.FatBlock != null && (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedRotor) || f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorRotor) || f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator) || f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorStator) || f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorBase))); //_info = blocks.Count.ToString(); //MyAPIGateway.Utilities.ShowMessage("step", "3"); if (blocks.Count != 1) { return; } if (blocks[0].FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedRotor) || blocks[0].FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorRotor)) { IMyMotorRotor motorRotor = blocks[0].FatBlock as IMyMotorRotor; if (motorRotor == null || motorRotor.Base == null) { return; } _motorBase2 = (IMyMotorStator)motorRotor; } else { _motorBase2 = (IMyMotorStator)blocks[0]; } //MyAPIGateway.Utilities.ShowMessage("step", "4"); var definition = MyDefinitionManager.Static.GetCubeBlockDefinition(_motorBase2.BlockDefinition); var motorStatorDefinition = definition as MyMotorStatorDefinition; if (motorStatorDefinition == null) { return; } } }
/// <summary> /// Constructs docking strategy for a rotor top (on ship's side). /// Remember, top attachment needs to be done on accepting side! /// </summary> /// <param name="goal">Location of the landing zone, world-space.</param> /// <param name="rotor">Rotor to use.</param> /// <param name="approach">Direction in which rotor's working end should be facing.</param> /// <param name="facing">Direction in which rotor's forward vector should be facing.</param> public DockingStrategy(Waypoint goal, IMyMotorRotor rotor, Vector3D approach, Vector3D?facing = null) : this(goal, rotor, Base6Directions.Direction.Down, Base6Directions.Direction.Forward, approach, facing) { }
bool TryLockInRotor(double distance) { IMyMotorRotor clamp = Reference as IMyMotorRotor; return(clamp.IsAttached); }
private static void GetAttachedGrids(IMyCubeGrid cubeGrid, ref List <IMyCubeGrid> results, AttachedGrids type) { if (cubeGrid == null) { return; } var blocks = new List <IMySlimBlock>(); cubeGrid.GetBlocks(blocks, b => b != null && b.FatBlock != null && !b.FatBlock.BlockDefinition.TypeId.IsNull); foreach (var block in blocks) { //MyAPIGateway.Utilities.ShowMessage("Block", string.Format("{0}", block.FatBlock.BlockDefinition.TypeId)); if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorStator) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorSuspension) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorBase)) { // The MotorStator which inherits from MotorBase. IMyMotorBase motorBase = block.FatBlock as IMyMotorBase; if (motorBase == null || motorBase.Rotor == null) { continue; } IMyCubeGrid entityParent = motorBase.RotorGrid; if (entityParent == null) { continue; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedRotor) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorRotor) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RealWheel) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Wheel)) { // The Rotor Part. IMyMotorRotor motorRotor = block.FatBlock as IMyMotorRotor; if (motorRotor == null || motorRotor.Stator == null) { continue; } IMyCubeGrid entityParent = motorRotor.Stator.CubeGrid; if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonTop)) { // The Piston Top. IMyPistonTop pistonTop = block.FatBlock as IMyPistonTop; if (pistonTop == null || pistonTop.Piston == null) { continue; } IMyCubeGrid entityParent = pistonTop.Piston.CubeGrid; if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase) || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase)) { IMyPistonBase pistonBase = block.FatBlock as IMyPistonBase; if (pistonBase == null || pistonBase.Top == null) { continue; } IMyCubeGrid entityParent = pistonBase.TopGrid; if (entityParent == null) { continue; } if (!results.Any(e => e.EntityId == entityParent.EntityId)) { results.Add(entityParent); GetAttachedGrids(entityParent, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ShipConnector) && type == AttachedGrids.All) { var connector = (IMyShipConnector)block.FatBlock; if (connector.IsConnected == false || connector.IsLocked == false || connector.OtherConnector == null) { continue; } var otherGrid = connector.OtherConnector.CubeGrid; if (!results.Any(e => e.EntityId == otherGrid.EntityId)) { results.Add(otherGrid); GetAttachedGrids(otherGrid, ref results, type); } } else if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LandingGear) && type == AttachedGrids.All) { var landingGear = (IMyLandingGear)block.FatBlock; if (landingGear.IsLocked == false) { continue; } var entity = landingGear.GetAttachedEntity(); if (entity == null || !(entity is IMyCubeGrid)) { continue; } var otherGrid = (IMyCubeGrid)entity; if (!results.Any(e => e.EntityId == otherGrid.EntityId)) { results.Add(otherGrid); GetAttachedGrids(otherGrid, ref results, type); } } } // Loop through all other grids, find their Landing gear, and figure out if they are attached to <cubeGrid>. var allShips = new HashSet <IMyEntity>(); var checkList = results; // cannot use ref paramter in Lambada expression!?!. MyAPIGateway.Entities.GetEntities(allShips, e => e is IMyCubeGrid && !checkList.Contains(e)); if (type == AttachedGrids.All) { foreach (IMyCubeGrid ship in allShips) { blocks = new List <IMySlimBlock>(); ship.GetBlocks(blocks, b => b != null && b.FatBlock != null && !b.FatBlock.BlockDefinition.TypeId.IsNull && b.FatBlock is IMyLandingGear); foreach (var block in blocks) { var landingGear = (IMyLandingGear)block.FatBlock; if (landingGear.IsLocked == false) { continue; } var entity = landingGear.GetAttachedEntity(); if (entity == null || entity.EntityId != cubeGrid.EntityId) { continue; } if (!results.Any(e => e.EntityId == ship.EntityId)) { results.Add(ship); GetAttachedGrids(ship, ref results, type); } } } } }