Skip to content

Commit a612075

Browse files
committed
Update ConditionsImplementations.cs
Added condition: "poweredgriddistancegreaterthan". This condition finds grids that are farther than x distance from nearby powered grids.
1 parent bc5234f commit a612075

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎Essentials/Conditions/ConditionsImplementations.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ 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 is zero for these conditions:
178+
// the distance from grid to entity is less than dist
179+
// the grid is unpowered
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)))).Cast<MyCubeGrid>().Where(y => !y.EntityId.Equals(grid.EntityId) && !y.IsPowered)
186+
.Count() == 0;
187+
}
188+
174189
[Condition("centerdistancelessthan", "centerdistancegreaterthan", "Finds grids that are further than the given distance from center.")]
175190
public static bool CenterDistanceLessThan(MyCubeGrid grid, double dist)
176191
{

0 commit comments

Comments
 (0)