private void ComputeCap() { _updateCap = false; if (ShieldComp.SubGrids.Count == 0) { UpdateSubGrids(); if (ShieldComp.SubGrids.Count == 0) { Log.Line($"SubGrids remained 0 in ComputeCap"); return; } } Vector3I center = Vector3I.Zero; foreach (var sub in ShieldComp.SubGrids.Keys) { var isRootGrid = sub == MyGrid; var subWorldCenter = sub.GridIntegerToWorld(Vector3I.Zero); var parentLocalOffset = MyGrid.WorldToGridInteger(subWorldCenter); foreach (var cube in sub.GetFatBlocks()) { var term = cube as IMyTerminalBlock; var sensor = cube as IMySensorBlock; var camera = cube as IMyCameraBlock; var light = cube as IMyLightingBlock; var sound = cube as IMySoundBlock; var buttonPanel = term != null && cube.BlockDefinition != null && cube.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_TerminalBlock); if (buttonPanel || term == null || sensor != null || sound != null || camera != null || light != null) { continue; } Vector3I translatedPos; if (!isRootGrid) { translatedPos = cube.Position + parentLocalOffset; } else { translatedPos = cube.Position; } center += translatedPos; _capcubeBoxList.Add(new CapCube { Cube = cube, Position = translatedPos }); } } BoundingBox newBox = BoundingBox.Invalid; var totalBlockCnt = _capcubeBoxList.Count; var unitLen = MyGrid.GridSize; center /= totalBlockCnt; var percentile95Th = (int)(totalBlockCnt * 0.12); ShellSort(_capcubeBoxList, center); _capcubeBoxList.RemoveRange(totalBlockCnt - percentile95Th, percentile95Th); for (int i = 0; i < _capcubeBoxList.Count; i++) { var cap = _capcubeBoxList[i]; newBox.Min = Vector3.Min(newBox.Min, cap.Cube.Min); newBox.Max = Vector3.Max(newBox.Max, cap.Cube.Max); } newBox.Min *= MyGrid.GridSize; newBox.Max *= MyGrid.GridSize; _capcubeBoxList.Clear(); var boxsArea = newBox.SurfaceArea(); if (boxsArea < 1) { boxsArea = (float)UtilsStatic.SurfaceAreaCuboid(totalBlockCnt * unitLen, unitLen, unitLen); } var surfaceArea = (float)Math.Sqrt(boxsArea); DsState.State.GridIntegrity = (surfaceArea * MagicCapRatio); }