public static void FindNext(MyEntityCyclingOrder order, ref float metric, ref long entityId, bool findLarger, CyclingOptions options) { Metric current = new Metric() { Value = metric, EntityId = entityId }; Metric start = findLarger ? Metric.Max : Metric.Min; Metric result = start; Metric extreme = start; foreach (var entity in MyEntities.GetEntities()) { if (options.Enabled) { MyCubeGrid grid = entity as MyCubeGrid; if (options.OnlyLargeGrids && (grid == null || grid.GridSizeEnum != MyCubeSize.Large)) { continue; } if (options.OnlySmallGrids && (grid == null || grid.GridSizeEnum != MyCubeSize.Small)) { continue; } } var newMetric = new Metric(GetMetric(order, entity), entity.EntityId); if (newMetric.Value == 0) { continue; } if (findLarger) { if (newMetric > current && newMetric < result) { result = newMetric; } if (newMetric < extreme) { extreme = newMetric; } } else { if (newMetric < current && newMetric > result) { result = newMetric; } if (newMetric > extreme) { extreme = newMetric; } } } if (result == start) { result = extreme; } metric = result.Value; entityId = result.EntityId; }
public static void FindNext(MyEntityCyclingOrder order, ref float metric, ref long entityId, bool findLarger, CyclingOptions options) { Metric metric2 = new Metric { Value = metric, EntityId = entityId }; Metric metric3 = findLarger ? Metric.Max : Metric.Min; Metric metric4 = metric3; Metric metric5 = metric3; foreach (MyEntity entity in MyEntities.GetEntities()) { if (options.Enabled) { MyCubeGrid grid = entity as MyCubeGrid; if (options.OnlyLargeGrids) { if (grid == null) { continue; } if (grid.GridSizeEnum != MyCubeSize.Large) { continue; } } if (options.OnlySmallGrids && ((grid == null) || (grid.GridSizeEnum != MyCubeSize.Small))) { continue; } } Metric metric7 = new Metric(GetMetric(order, entity), entity.EntityId); if (metric7.Value != 0f) { if (findLarger) { if ((metric7 > metric2) && (metric7 < metric4)) { metric4 = metric7; } if (metric7 < metric5) { metric5 = metric7; } } else { if ((metric7 < metric2) && (metric7 > metric4)) { metric4 = metric7; } if (metric7 > metric5) { metric5 = metric7; } } } } if (metric4 == metric3) { metric4 = metric5; } metric = metric4.Value; entityId = metric4.EntityId; }