diff --git a/Content.Server/Fluids/EntitySystems/PuddleDebugDebugOverlaySystem.cs b/Content.Server/Fluids/EntitySystems/PuddleDebugDebugOverlaySystem.cs index ac967b3c201..859f2d80a67 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleDebugDebugOverlaySystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleDebugDebugOverlaySystem.cs @@ -13,9 +13,11 @@ public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySyst [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly PuddleSystem _puddle = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMapSystem _map = default!; - private readonly HashSet _playerObservers = new(); - private List> _grids = new(); + private readonly HashSet _playerObservers = []; + private List> _grids = []; public bool ToggleObserver(ICommonSession observer) { @@ -55,7 +57,8 @@ public override void Update(float frameTime) var transform = EntityManager.GetComponent(entity); - var worldBounds = Box2.CenteredAround(transform.WorldPosition, + + var worldBounds = Box2.CenteredAround(_transform.GetWorldPosition(transform), new Vector2(LocalViewRange, LocalViewRange)); _grids.Clear(); @@ -69,14 +72,14 @@ public override void Update(float frameTime) if (!Exists(gridUid)) continue; - foreach (var uid in grid.Comp.GetAnchoredEntities(worldBounds)) + foreach (var uid in _map.GetAnchoredEntities(gridUid, grid, worldBounds)) { PuddleComponent? puddle = null; TransformComponent? xform = null; if (!Resolve(uid, ref puddle, ref xform, false)) continue; - var pos = xform.Coordinates.ToVector2i(EntityManager, _mapManager); + var pos = xform.Coordinates.ToVector2i(EntityManager, _mapManager, _transform); var vol = _puddle.CurrentVolume(uid, puddle); data.Add(new PuddleDebugOverlayData(pos, vol)); } diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs index c0e8847ae98..c03e6f593c6 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs @@ -41,7 +41,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem { [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly SharedMapSystem _map = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly ITileDefinitionManager _tileDefMan = default!; @@ -124,7 +124,7 @@ private void OnPuddleSpread(Entity entity, ref SpreadNeighborsE foreach (var neighbor in args.NeighborFreeTiles) { var split = overflow.SplitSolution(spillAmount); - TrySpillAt(neighbor.Grid.GridTileToLocal(neighbor.Tile), split, out _, false); + TrySpillAt(_map.GridTileToLocal(neighbor.Tile.GridUid, neighbor.Grid, neighbor.Tile.GridIndices), split, out _, false); args.Updates--; if (args.Updates <= 0) @@ -612,13 +612,14 @@ public bool TrySpillAt(EntityCoordinates coordinates, Solution solution, out Ent return false; } - if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid)) + var gridUid = coordinates.GetGridUid(EntityManager); + if (!TryComp(gridUid, out var mapGrid)) { puddleUid = EntityUid.Invalid; return false; } - return TrySpillAt(mapGrid.GetTileRef(coordinates), solution, out puddleUid, sound); + return TrySpillAt(_map.GetTileRef(gridUid.Value, mapGrid, coordinates), solution, out puddleUid, sound); } /// @@ -657,7 +658,7 @@ public bool TrySpillAt(TileRef tileRef, Solution solution, out EntityUid puddleU // Let's not spill to invalid grids. var gridId = tileRef.GridUid; - if (!_mapManager.TryGetGrid(gridId, out var mapGrid)) + if (!TryComp(gridId, out var mapGrid)) { puddleUid = EntityUid.Invalid; return false; @@ -678,7 +679,7 @@ public bool TrySpillAt(TileRef tileRef, Solution solution, out EntityUid puddleU // Get normalized co-ordinate for spill location and spill it in the centre // TODO: Does SnapGrid or something else already do this? - var anchored = mapGrid.GetAnchoredEntitiesEnumerator(tileRef.GridIndices); + var anchored = _map.GetAnchoredEntitiesEnumerator(gridId, mapGrid, tileRef.GridIndices); var puddleQuery = GetEntityQuery(); var sparklesQuery = GetEntityQuery(); @@ -703,7 +704,7 @@ public bool TrySpillAt(TileRef tileRef, Solution solution, out EntityUid puddleU return true; } - var coords = mapGrid.GridTileToLocal(tileRef.GridIndices); + var coords = _map.GridTileToLocal(gridId, mapGrid, tileRef.GridIndices); puddleUid = EntityManager.SpawnEntity("Puddle", coords); EnsureComp(puddleUid); if (TryAddSolution(puddleUid, solution, sound)) @@ -740,7 +741,7 @@ public bool TryGetPuddle(TileRef tile, out EntityUid puddleUid) if (!TryComp(tile.GridUid, out var grid)) return false; - var anc = grid.GetAnchoredEntitiesEnumerator(tile.GridIndices); + var anc = _map.GetAnchoredEntitiesEnumerator(tile.GridUid, grid, tile.GridIndices); var puddleQuery = GetEntityQuery(); while (anc.MoveNext(out var ent)) diff --git a/Content.Server/Fluids/EntitySystems/SmokeSystem.cs b/Content.Server/Fluids/EntitySystems/SmokeSystem.cs index cb6f9c13ef1..ae170842a0c 100644 --- a/Content.Server/Fluids/EntitySystems/SmokeSystem.cs +++ b/Content.Server/Fluids/EntitySystems/SmokeSystem.cs @@ -13,7 +13,7 @@ using Content.Shared.FixedPoint; using Content.Shared.Smoking; using Robust.Server.GameObjects; -using Robust.Shared.Map; +using Robust.Shared.Map.Components; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Events; @@ -35,7 +35,7 @@ public sealed class SmokeSystem : EntitySystem // If I could do it all again this could probably use a lot more of puddles. [Dependency] private readonly IAdminLogManager _logger = default!; [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly SharedMapSystem _map = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly AppearanceSystem _appearance = default!; @@ -45,7 +45,6 @@ public sealed class SmokeSystem : EntitySystem [Dependency] private readonly SharedBroadphaseSystem _broadphase = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; - [Dependency] private readonly TransformSystem _transform = default!; private EntityQuery _smokeQuery; private EntityQuery _smokeAffectedQuery; @@ -137,7 +136,7 @@ private void OnSmokeSpread(Entity entity, ref SpreadNeighborsEve return; } - if (!args.NeighborFreeTiles.Any()) + if (args.NeighborFreeTiles.Count == 0) return; TryComp(entity, out var timer); @@ -146,10 +145,10 @@ private void OnSmokeSpread(Entity entity, ref SpreadNeighborsEve var smokePerSpread = entity.Comp.SpreadAmount / Math.Max(1, args.NeighborFreeTiles.Count); foreach (var neighbor in args.NeighborFreeTiles) { - var coords = neighbor.Grid.GridTileToLocal(neighbor.Tile); + var coords = _map.GridTileToLocal(neighbor.Tile.GridUid, neighbor.Grid, neighbor.Tile.GridIndices); var ent = Spawn(prototype.ID, coords); var spreadAmount = Math.Max(0, smokePerSpread); - entity.Comp.SpreadAmount -= args.NeighborFreeTiles.Count(); + entity.Comp.SpreadAmount -= args.NeighborFreeTiles.Count; StartSmoke(ent, solution.Clone(), timer?.Lifetime ?? entity.Comp.Duration, spreadAmount); @@ -305,10 +304,10 @@ private void ReactOnTile(EntityUid uid, SmokeComponent? component = null, Transf if (!_solutionContainerSystem.ResolveSolution(uid, SmokeComponent.SolutionName, ref component.Solution, out var solution) || !solution.Any()) return; - if (!_mapManager.TryGetGrid(xform.GridUid, out var mapGrid)) + if (!TryComp(xform.GridUid, out var mapGrid)) return; - var tile = mapGrid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager, _transform)); + var tile = _map.GetTileRef(xform.GridUid.Value, mapGrid, xform.Coordinates); foreach (var reagentQuantity in solution.Contents.ToArray()) { diff --git a/Content.Server/Spreader/KudzuSystem.cs b/Content.Server/Spreader/KudzuSystem.cs index 49698ea6735..dc176ebc2a6 100644 --- a/Content.Server/Spreader/KudzuSystem.cs +++ b/Content.Server/Spreader/KudzuSystem.cs @@ -10,6 +10,7 @@ public sealed class KudzuSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly SharedMapSystem _map = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly DamageableSystem _damageable = default!; @@ -28,15 +29,12 @@ private void OnDamageChanged(EntityUid uid, KudzuComponent component, DamageChan { // Every time we take any damage, we reduce growth depending on all damage over the growth impact // So the kudzu gets slower growing the more it is hurt. - int growthDamage = (int) (args.Damageable.TotalDamage / component.GrowthHealth); + var growthDamage = (int) (args.Damageable.TotalDamage / component.GrowthHealth); if (growthDamage > 0) { - GrowingKudzuComponent? growing; - if (!TryComp(uid, out growing)) - { - growing = AddComp(uid); + if (!EnsureComp(uid, out _)) component.GrowthLevel = 3; - } + component.GrowthLevel = Math.Max(1, component.GrowthLevel - growthDamage); if (EntityManager.TryGetComponent(uid, out var appearance)) { @@ -69,7 +67,7 @@ private void OnKudzuSpread(EntityUid uid, KudzuComponent component, ref SpreadNe foreach (var neighbor in args.NeighborFreeTiles) { - var neighborUid = Spawn(prototype, neighbor.Grid.GridTileToLocal(neighbor.Tile)); + var neighborUid = Spawn(prototype, _map.GridTileToLocal(neighbor.Tile.GridUid, neighbor.Grid, neighbor.Tile.GridIndices)); DebugTools.Assert(HasComp(neighborUid)); DebugTools.Assert(HasComp(neighborUid)); DebugTools.Assert(Comp(neighborUid).Id == KudzuGroup); diff --git a/Content.Server/Spreader/SpreadNeighborsEvent.cs b/Content.Server/Spreader/SpreadNeighborsEvent.cs index 0cee55b5880..022ef49f33a 100644 --- a/Content.Server/Spreader/SpreadNeighborsEvent.cs +++ b/Content.Server/Spreader/SpreadNeighborsEvent.cs @@ -1,4 +1,5 @@ using Robust.Shared.Collections; +using Robust.Shared.Map; using Robust.Shared.Map.Components; namespace Content.Server.Spreader; @@ -10,7 +11,7 @@ namespace Content.Server.Spreader; [ByRefEvent] public record struct SpreadNeighborsEvent { - public ValueList<(MapGridComponent Grid, Vector2i Tile)> NeighborFreeTiles; + public ValueList<(MapGridComponent Grid, TileRef Tile)> NeighborFreeTiles; public ValueList Neighbors; /// diff --git a/Content.Server/Spreader/SpreaderSystem.cs b/Content.Server/Spreader/SpreaderSystem.cs index ad3033a14bb..269d35d12ff 100644 --- a/Content.Server/Spreader/SpreaderSystem.cs +++ b/Content.Server/Spreader/SpreaderSystem.cs @@ -18,9 +18,9 @@ namespace Content.Server.Spreader; /// public sealed class SpreaderSystem : EntitySystem { - [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly SharedMapSystem _map = default!; /// /// Cached maximum number of updates per spreader prototype. This is applied per-grid. @@ -31,7 +31,7 @@ public sealed class SpreaderSystem : EntitySystem /// Remaining number of updates per grid & prototype. /// // TODO PERFORMANCE Assign each prototype to an index and convert dictionary to array - private Dictionary> _gridUpdates = new(); + private readonly Dictionary> _gridUpdates = []; public const float SpreadCooldownSeconds = 1; @@ -57,7 +57,7 @@ private void OnPrototypeReload(PrototypesReloadedEventArgs obj) private void SetupPrototypes() { - _prototypeUpdates = new Dictionary(); + _prototypeUpdates = []; foreach (var proto in _prototype.EnumeratePrototypes()) { _prototypeUpdates.Add(proto.ID, proto.UpdatesPerSecond); @@ -80,9 +80,9 @@ private void OnGridInit(GridInitializeEvent ev) EnsureComp(ev.EntityUid); } - private void OnTerminating(EntityUid uid, EdgeSpreaderComponent component, ref EntityTerminatingEvent args) + private void OnTerminating(Entity entity, ref EntityTerminatingEvent args) { - var neighbors = GetSpreadableNeighbors(uid); + var neighbors = GetSpreadableNeighbors(entity); foreach (var neighbor in neighbors) { @@ -163,7 +163,7 @@ public override void Update(float frameTime) } } - private void Spread(EntityUid uid, TransformComponent xform, string prototype, ref int updates) + private void Spread(EntityUid uid, TransformComponent xform, ProtoId prototype, ref int updates) { GetNeighbors(uid, xform, prototype, out var freeTiles, out _, out var neighbors); @@ -181,18 +181,18 @@ private void Spread(EntityUid uid, TransformComponent xform, string prototype, r /// /// Gets the neighboring node data for the specified entity and the specified node group. /// - public void GetNeighbors(EntityUid uid, TransformComponent transform, string prototype, out ValueList<(MapGridComponent Grid, Vector2i Tile)> freeTiles, out ValueList occupiedTiles, out ValueList neighbors) + public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId prototype, out ValueList<(MapGridComponent, TileRef)> freeTiles, out ValueList occupiedTiles, out ValueList neighbors) { // TODO remove occupiedTiles -- its currently unused and just slows this method down. - DebugTools.Assert(_prototype.HasIndex(prototype)); - freeTiles = new ValueList<(MapGridComponent Grid, Vector2i Tile)>(); - occupiedTiles = new ValueList(); - neighbors = new ValueList(); + DebugTools.Assert(_prototype.HasIndex(prototype)); + freeTiles = []; + occupiedTiles = []; + neighbors = []; - if (!_mapManager.TryGetGrid(transform.GridUid, out var grid)) + if (!TryComp(comp.GridUid, out var grid)) return; - var tile = grid.TileIndicesFor(transform.Coordinates); + var tile = _map.TileIndicesFor(comp.GridUid.Value, grid, comp.Coordinates); var spreaderQuery = GetEntityQuery(); var airtightQuery = GetEntityQuery(); var dockQuery = GetEntityQuery(); @@ -201,10 +201,10 @@ public void GetNeighbors(EntityUid uid, TransformComponent transform, string pro var blockedAtmosDirs = AtmosDirection.Invalid; // Due to docking ports they may not necessarily be opposite directions. - var neighborTiles = new ValueList<(MapGridComponent grid, Vector2i Indices, AtmosDirection OtherDir, AtmosDirection OurDir)>(); + var neighborTiles = new ValueList<(EntityUid entity, MapGridComponent grid, Vector2i Indices, AtmosDirection OtherDir, AtmosDirection OurDir)>(); // Check if anything on our own tile blocking that direction. - var ourEnts = grid.GetAnchoredEntitiesEnumerator(tile); + var ourEnts = _map.GetAnchoredEntitiesEnumerator(comp.GridUid.Value, grid, tile); while (ourEnts.MoveNext(out var ent)) { @@ -215,7 +215,7 @@ public void GetNeighbors(EntityUid uid, TransformComponent transform, string pro xformQuery.TryGetComponent(dock.DockedWith, out var dockedXform) && TryComp(dockedXform.GridUid, out var dockedGrid)) { - neighborTiles.Add((dockedGrid, dockedGrid.CoordinatesToTile(dockedXform.Coordinates), xform.LocalRotation.ToAtmosDirection(), dockedXform.LocalRotation.ToAtmosDirection())); + neighborTiles.Add((ent.Value, dockedGrid, _map.CoordinatesToTile(ent.Value, dockedGrid, dockedXform.Coordinates), xform.LocalRotation.ToAtmosDirection(), dockedXform.LocalRotation.ToAtmosDirection())); } // If we're on a blocked tile work out which directions we can go. @@ -225,7 +225,7 @@ public void GetNeighbors(EntityUid uid, TransformComponent transform, string pro continue; } - foreach (var value in new[] { AtmosDirection.North, AtmosDirection.East, AtmosDirection.South, AtmosDirection.West}) + foreach (var value in new[] { AtmosDirection.North, AtmosDirection.East, AtmosDirection.South, AtmosDirection.West }) { if ((value & airtight.AirBlockedDirection) == 0x0) continue; @@ -242,20 +242,20 @@ public void GetNeighbors(EntityUid uid, TransformComponent transform, string pro var direction = (Direction) (i * 2); var atmosDir = direction.ToAtmosDirection(); var neighborPos = SharedMapSystem.GetDirection(tile, direction); - neighborTiles.Add((grid, neighborPos, atmosDir, atmosDir.GetOpposite())); + neighborTiles.Add((comp.GridUid.Value, grid, neighborPos, atmosDir, atmosDir.GetOpposite())); } - foreach (var (neighborGrid, neighborPos, ourAtmosDir, otherAtmosDir) in neighborTiles) + foreach (var (neighborEnt, neighborGrid, neighborPos, ourAtmosDir, otherAtmosDir) in neighborTiles) { // This tile is blocked to that direction. if ((blockedAtmosDirs & ourAtmosDir) != 0x0) continue; - if (!neighborGrid.TryGetTileRef(neighborPos, out var tileRef) || tileRef.Tile.IsEmpty) + if (!_map.TryGetTileRef(neighborEnt, neighborGrid, neighborPos, out var tileRef) || tileRef.Tile.IsEmpty) continue; var directionEnumerator = - neighborGrid.GetAnchoredEntitiesEnumerator(neighborPos); + _map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos); var occupied = false; while (directionEnumerator.MoveNext(out var ent)) @@ -278,7 +278,7 @@ public void GetNeighbors(EntityUid uid, TransformComponent transform, string pro var oldCount = occupiedTiles.Count; directionEnumerator = - neighborGrid.GetAnchoredEntitiesEnumerator(neighborPos); + _map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos); while (directionEnumerator.MoveNext(out var ent)) { @@ -294,7 +294,7 @@ public void GetNeighbors(EntityUid uid, TransformComponent transform, string pro } if (oldCount == occupiedTiles.Count) - freeTiles.Add((neighborGrid, neighborPos)); + freeTiles.Add((neighborGrid, tileRef)); } } @@ -308,20 +308,23 @@ public List GetSpreadableNeighbors(EntityUid uid, AirtightComponent? var neighbors = new List(); Vector2i tile; + EntityUid ent; MapGridComponent? grid; if (position == null) { var transform = Transform(uid); - if (!_mapManager.TryGetGrid(transform.GridUid, out grid) || TerminatingOrDeleted(transform.GridUid.Value)) + if (!TryComp(transform.GridUid, out grid) || TerminatingOrDeleted(transform.GridUid.Value)) return neighbors; - tile = grid.TileIndicesFor(transform.Coordinates); + tile = _map.TileIndicesFor(transform.GridUid.Value, grid, transform.Coordinates); + ent = transform.GridUid.Value; } else { - if (!_mapManager.TryGetGrid(position.Value.Grid, out grid)) + if (!TryComp(position.Value.Grid, out grid)) return neighbors; tile = position.Value.Tile; + ent = position.Value.Grid; } var spreaderQuery = GetEntityQuery(); @@ -333,13 +336,13 @@ public List GetSpreadableNeighbors(EntityUid uid, AirtightComponent? continue; var directionEnumerator = - grid.GetAnchoredEntitiesEnumerator(SharedMapSystem.GetDirection(tile, direction.ToDirection())); + _map.GetAnchoredEntitiesEnumerator(ent, grid, SharedMapSystem.GetDirection(tile, direction.ToDirection())); - while (directionEnumerator.MoveNext(out var ent)) + while (directionEnumerator.MoveNext(out var entity)) { - DebugTools.Assert(Transform(ent.Value).Anchored); - if (spreaderQuery.HasComponent(ent) && !TerminatingOrDeleted(ent.Value)) - neighbors.Add(ent.Value); + DebugTools.Assert(Transform(entity.Value).Anchored); + if (spreaderQuery.HasComponent(entity) && !TerminatingOrDeleted(entity.Value)) + neighbors.Add(entity.Value); } }