Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve GetInStation filter #33405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions Content.Server/Station/Systems/StationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,19 @@ public Filter GetInOwningStation(EntityUid source, float range = 32f)
/// </summary>
public Filter GetInStation(StationDataComponent dataComponent, float range = 32f)
{
// Could also use circles if you wanted.
var bounds = new ValueList<Box2>(dataComponent.Grids.Count);
var filter = Filter.Empty();
var mapIds = new ValueList<MapId>();
var xformQuery = GetEntityQuery<TransformComponent>();

// First collect all valid map IDs where station grids exist
foreach (var gridUid in dataComponent.Grids)
{
if (!TryComp(gridUid, out MapGridComponent? grid) ||
!xformQuery.TryGetComponent(gridUid, out var xform))
if (!xformQuery.TryGetComponent(gridUid, out var xform))
continue;

var mapId = xform.MapID;
var position = _transform.GetWorldPosition(xform, xformQuery);
var bound = grid.LocalAABB.Enlarged(range).Translated(position);

bounds.Add(bound);
if (!mapIds.Contains(mapId))
{
mapIds.Add(xform.MapID);
}
mapIds.Add(mapId);
}

foreach (var session in Filter.GetAllPlayers(_player))
Expand All @@ -245,10 +237,35 @@ public Filter GetInStation(StationDataComponent dataComponent, float range = 32f
if (!mapIds.Contains(mapId))
continue;

// Check if the player is directly on any station grid
var transform = xform;
while (transform.ParentUid != EntityUid.Invalid)
{
var gridUid = transform.GridUid;
if (gridUid != null && dataComponent.Grids.Contains(gridUid.Value))
{
filter.AddPlayer(session);
break;
}

transform = xformQuery.GetComponent(transform.ParentUid);
}
MilonPL marked this conversation as resolved.
Show resolved Hide resolved

// If player not already in filter, then check range from any grid bounds
if (filter.Recipients.Contains(session))
continue;

var position = _transform.GetWorldPosition(xform, xformQuery);

foreach (var bound in bounds)
foreach (var gridUid in dataComponent.Grids)
{
if (!TryComp(gridUid, out MapGridComponent? grid) ||
!xformQuery.TryGetComponent(gridUid, out var gridXform))
continue;

var gridPos = _transform.GetWorldPosition(gridXform, xformQuery);
var bound = grid.LocalAABB.Enlarged(range).Translated(gridPos);

MilonPL marked this conversation as resolved.
Show resolved Hide resolved
if (!bound.Contains(position))
continue;

Expand Down
Loading