]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix AI vision occlusion (#31341)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 23 Aug 2024 05:57:57 +0000 (15:57 +1000)
committerGitHub <noreply@github.com>
Fri, 23 Aug 2024 05:57:57 +0000 (23:57 -0600)
Forgot to do this, but how tf do doors work then.

Content.Shared/Silicons/StationAi/StationAiVisionSystem.cs

index c1f5d98afdb7178fc9b0dbd59f7cc389a8fe85a0..33771cb963a517640dc8ca7b666939e8785b0d10 100644 (file)
@@ -95,12 +95,7 @@ public sealed class StationAiVisionSystem : EntitySystem
             // Get all other relevant tiles.
             while (tileEnumerator.MoveNext(out var tileRef))
             {
-                var tileBounds = _lookup.GetLocalBounds(tileRef.GridIndices, grid.Comp.TileSize).Enlarged(-0.05f);
-
-                _occluders.Clear();
-                _lookup.GetLocalEntitiesIntersecting(grid.Owner, tileBounds, _occluders, LookupFlags.Static);
-
-                if (_occluders.Count > 0)
+                if (IsOccluded(grid, tileRef.GridIndices))
                 {
                     _opaque.Add(tileRef.GridIndices);
                 }
@@ -125,6 +120,25 @@ public sealed class StationAiVisionSystem : EntitySystem
         return TargetFound;
     }
 
+    private bool IsOccluded(Entity<MapGridComponent> grid, Vector2i tile)
+    {
+        var tileBounds = _lookup.GetLocalBounds(tile, grid.Comp.TileSize).Enlarged(-0.05f);
+        _occluders.Clear();
+        _lookup.GetLocalEntitiesIntersecting(grid.Owner, tileBounds, _occluders, LookupFlags.Static);
+        var anyOccluders = false;
+
+        foreach (var occluder in _occluders)
+        {
+            if (!occluder.Comp.Enabled)
+                continue;
+
+            anyOccluders = true;
+            break;
+        }
+
+        return anyOccluders;
+    }
+
     /// <summary>
     /// Gets a byond-equivalent for tiles in the specified worldAABB.
     /// </summary>
@@ -160,12 +174,7 @@ public sealed class StationAiVisionSystem : EntitySystem
 
         while (tileEnumerator.MoveNext(out var tileRef))
         {
-            var tileBounds = _lookup.GetLocalBounds(tileRef.GridIndices, grid.Comp.TileSize).Enlarged(-0.05f);
-
-            _occluders.Clear();
-            _lookup.GetLocalEntitiesIntersecting(grid.Owner, tileBounds, _occluders, LookupFlags.Static);
-
-            if (_occluders.Count > 0)
+            if (IsOccluded(grid, tileRef.GridIndices))
             {
                 _opaque.Add(tileRef.GridIndices);
             }
@@ -181,12 +190,7 @@ public sealed class StationAiVisionSystem : EntitySystem
             if (_viewportTiles.Contains(tileRef.GridIndices))
                 continue;
 
-            var tileBounds = _lookup.GetLocalBounds(tileRef.GridIndices, grid.Comp.TileSize).Enlarged(-0.05f);
-
-            _occluders.Clear();
-            _lookup.GetLocalEntitiesIntersecting(grid.Owner, tileBounds, _occluders, LookupFlags.Static);
-
-            if (_occluders.Count > 0)
+            if (IsOccluded(grid, tileRef.GridIndices))
             {
                 _opaque.Add(tileRef.GridIndices);
             }