Skip to content

Commit 77dc497

Browse files
authored
Merge pull request #217 from FerrenF/master
Add "poweredgriddistancegreaterthan" cleanup filter.
2 parents 4ea12c6 + 6c31a26 commit 77dc497

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Essentials/Conditions/ConditionsImplementations.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ public static bool PlayerDistanceLessThan(MyCubeGrid grid, double dist)
171171
return false;
172172
}
173173

174+
[Condition("poweredgriddistancegreaterthan", "Finds grids that are farther than the given distance from other grids that are powered.")]
175+
public static bool PoweredGridDistanceGreaterThan(MyCubeGrid grid, double dist)
176+
{
177+
// Returns 'true' if the count of matched grids from a list of all grids is zero for these conditions:
178+
// the distance from grid to entity is less than dist
179+
// the grid is powered
180+
// Otherwise, returns 'false'
181+
dist *= dist;
182+
return MyEntities.GetEntities().Where(
183+
x =>
184+
(VRageMath.Vector3.DistanceSquared(x.PositionComp.GetPosition(), grid.PositionComp.GetPosition()) < dist
185+
&& (x.GetType() == typeof(MyCubeGrid))
186+
)).Cast<MyCubeGrid>().Where(y => !y.EntityId.Equals(grid.EntityId) && y.IsPowered)
187+
.Count() == 0;
188+
}
189+
174190
[Condition("centerdistancelessthan", "centerdistancegreaterthan", "Finds grids that are further than the given distance from center.")]
175191
public static bool CenterDistanceLessThan(MyCubeGrid grid, double dist)
176192
{

0 commit comments

Comments
 (0)