Skip to content

Commit

Permalink
Fix AI vision occlusion (#31341)
Browse files Browse the repository at this point in the history
Forgot to do this, but how tf do doors work then.
  • Loading branch information
metalgearsloth authored Aug 23, 2024
1 parent 616601b commit 42078b4
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions Content.Shared/Silicons/StationAi/StationAiVisionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ public bool IsAccessible(Entity<MapGridComponent> grid, Vector2i tile, float exp
// 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);
}
Expand All @@ -125,6 +120,25 @@ public bool IsAccessible(Entity<MapGridComponent> grid, Vector2i tile, float exp
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>
Expand Down Expand Up @@ -160,12 +174,7 @@ public void GetView(Entity<MapGridComponent> grid, Box2Rotated worldBounds, Hash

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);
}
Expand All @@ -181,12 +190,7 @@ public void GetView(Entity<MapGridComponent> grid, Box2Rotated worldBounds, Hash
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);
}
Expand Down

0 comments on commit 42078b4

Please sign in to comment.