private bool GetStatorRotor(IMyCubeGrid grid, out IMyMotorStator Stator, IMyMotorStator IgnoreStator = null) { CubeGridCache cache = CubeGridCache.GetFor(grid); // first stator that are found that are not working // returned if a working set is not found IMyMotorStator offStator = null; foreach (MyObjectBuilderType type in types_Rotor) { foreach (IMyMotorRotor rotor in cache.BlocksOfType(type)) { if (!FaceBlock.canControlBlock(rotor)) { Log.DebugLog("Cannot control: " + rotor.nameWithId()); continue; } Stator = (IMyMotorStator)rotor.Base; if (Stator == null || Stator == IgnoreStator) { continue; } if (IgnoreStator != null && !ArePerpendicular(IgnoreStator, Stator)) { Log.DebugLog("Not perpendicular: " + IgnoreStator.nameWithId() + " & " + Stator.nameWithId()); continue; } if (Stator.IsWorking) { return(true); } else if (offStator == null) { offStator = Stator; } } } if (offStator != null) { Stator = offStator; return(true); } Stator = null; return(false); }
/// <summary> /// Gets the closest occupied cell. /// </summary> public Vector3I GetClosestOccupiedCell(Vector3I startCell, Vector3I previousCell) { Vector3I closestCell = previousCell; int closestDistance = CubeGrid.GetCubeBlock(closestCell) != null?previousCell.DistanceSquared(startCell) - 2 : int.MaxValue; CubeGridCache cache = CubeGridCache.GetFor(CubeGrid); if (cache == null) { return(closestCell); } foreach (Vector3I cell in cache.OccupiedCells()) { int dist = cell.DistanceSquared(startCell); if (dist < closestDistance) { closestCell = cell; closestDistance = dist; } } return(closestCell); }