]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Cleanup warning in `GridInRange` (#37699)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 22 May 2025 01:28:42 +0000 (21:28 -0400)
committerGitHub <noreply@github.com>
Thu, 22 May 2025 01:28:42 +0000 (21:28 -0400)
Cleanup warning in GridInRange

Content.Shared/Random/Rules/GridInRange.cs

index dfe57b93757340bc55bee092c0536f3e71c87cd4..bdc0cedf731505e99767a283b5714c96a8ab6cda 100644 (file)
@@ -1,5 +1,6 @@
 using System.Numerics;
 using Robust.Shared.Map;
+using Robust.Shared.Map.Components;
 
 namespace Content.Shared.Random.Rules;
 
@@ -11,6 +12,8 @@ public sealed partial class GridInRangeRule : RulesRule
     [DataField]
     public float Range = 10f;
 
+    private List<Entity<MapGridComponent>> _grids = [];
+
     public override bool Check(EntityManager entManager, EntityUid uid)
     {
         if (!entManager.TryGetComponent(uid, out TransformComponent? xform))
@@ -29,10 +32,10 @@ public sealed partial class GridInRangeRule : RulesRule
         var worldPos = transform.GetWorldPosition(xform);
         var gridRange = new Vector2(Range, Range);
 
-        foreach (var _ in mapManager.FindGridsIntersecting(xform.MapID, new Box2(worldPos - gridRange, worldPos + gridRange)))
-        {
+        _grids.Clear();
+        mapManager.FindGridsIntersecting(xform.MapID, new Box2(worldPos - gridRange, worldPos + gridRange), ref _grids);
+        if (_grids.Count > 0)
             return !Inverted;
-        }
 
         return Inverted;
     }