Fix spreaders not re-spreading on deletion (#42016)

* Fix spreaders not re-spreading on deletion

* Rename another variable for clarity
This commit is contained in:
Nemanja 2025-12-23 16:52:42 -05:00 committed by GitHub
parent 402cc65477
commit 503052bca7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -295,35 +295,38 @@ public sealed class SpreaderSystem : EntitySystem
/// This function activates all spreaders that are adjacent to a given entity. This also activates other spreaders /// This function activates all spreaders that are adjacent to a given entity. This also activates other spreaders
/// on the same tile as the current entity (for thin airtight entities like windoors). /// on the same tile as the current entity (for thin airtight entities like windoors).
/// </summary> /// </summary>
public void ActivateSpreadableNeighbors(EntityUid uid, (EntityUid Grid, Vector2i Tile)? position = null) public void ActivateSpreadableNeighbors(EntityUid origin, (EntityUid Grid, Vector2i Tile)? position = null)
{ {
Vector2i tile; Vector2i tile;
EntityUid ent; EntityUid gridUid;
MapGridComponent? grid; MapGridComponent? gridComp;
if (position == null) if (position == null)
{ {
var transform = Transform(uid); var transform = Transform(origin);
if (!TryComp(transform.GridUid, out grid) || TerminatingOrDeleted(transform.GridUid.Value)) if (!TryComp(transform.GridUid, out gridComp) || TerminatingOrDeleted(transform.GridUid.Value))
return; return;
tile = _map.TileIndicesFor(transform.GridUid.Value, grid, transform.Coordinates); tile = _map.TileIndicesFor(transform.GridUid.Value, gridComp, transform.Coordinates);
ent = transform.GridUid.Value; gridUid = transform.GridUid.Value;
} }
else else
{ {
if (!TryComp(position.Value.Grid, out grid)) if (!TryComp(position.Value.Grid, out gridComp))
return; return;
(ent, tile) = position.Value; (gridUid, tile) = position.Value;
} }
var anchored = _map.GetAnchoredEntitiesEnumerator(ent, grid, tile); var anchored = _map.GetAnchoredEntitiesEnumerator(gridUid, gridComp, tile);
while (anchored.MoveNext(out var entity)) while (anchored.MoveNext(out var entity))
{ {
if (entity == ent) // Don't re-activate the terminating entity
if (entity == origin)
continue; continue;
DebugTools.Assert(Transform(entity.Value).Anchored); DebugTools.Assert(Transform(entity.Value).Anchored);
if (_query.HasComponent(ent) && !TerminatingOrDeleted(entity.Value))
// Activate any edge spreaders that are non-terminating
if (_query.HasComponent(entity) && !TerminatingOrDeleted(entity))
EnsureComp<ActiveEdgeSpreaderComponent>(entity.Value); EnsureComp<ActiveEdgeSpreaderComponent>(entity.Value);
} }
@ -331,12 +334,14 @@ public sealed class SpreaderSystem : EntitySystem
{ {
var direction = (AtmosDirection) (1 << i); var direction = (AtmosDirection) (1 << i);
var adjacentTile = SharedMapSystem.GetDirection(tile, direction.ToDirection()); var adjacentTile = SharedMapSystem.GetDirection(tile, direction.ToDirection());
anchored = _map.GetAnchoredEntitiesEnumerator(ent, grid, adjacentTile); anchored = _map.GetAnchoredEntitiesEnumerator(gridUid, gridComp, adjacentTile);
while (anchored.MoveNext(out var entity)) while (anchored.MoveNext(out var entity))
{ {
DebugTools.Assert(Transform(entity.Value).Anchored); DebugTools.Assert(Transform(entity.Value).Anchored);
if (_query.HasComponent(ent) && !TerminatingOrDeleted(entity.Value))
// Activate any edge spreaders that are non-terminating
if (_query.HasComponent(entity) && !TerminatingOrDeleted(entity))
EnsureComp<ActiveEdgeSpreaderComponent>(entity.Value); EnsureComp<ActiveEdgeSpreaderComponent>(entity.Value);
} }
} }