[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<ICommonSession> _playerObservers = new();
- private List<Entity<MapGridComponent>> _grids = new();
+ private readonly HashSet<ICommonSession> _playerObservers = [];
+ private List<Entity<MapGridComponent>> _grids = [];
public bool ToggleObserver(ICommonSession observer)
{
var transform = EntityManager.GetComponent<TransformComponent>(entity);
- var worldBounds = Box2.CenteredAround(transform.WorldPosition,
+
+ var worldBounds = Box2.CenteredAround(_transform.GetWorldPosition(transform),
new Vector2(LocalViewRange, LocalViewRange));
_grids.Clear();
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));
}
{
[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!;
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)
return false;
}
- if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid))
+ var gridUid = coordinates.GetGridUid(EntityManager);
+ if (!TryComp<MapGridComponent>(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);
}
/// <summary>
// Let's not spill to invalid grids.
var gridId = tileRef.GridUid;
- if (!_mapManager.TryGetGrid(gridId, out var mapGrid))
+ if (!TryComp<MapGridComponent>(gridId, out var mapGrid))
{
puddleUid = EntityUid.Invalid;
return false;
// 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<PuddleComponent>();
var sparklesQuery = GetEntityQuery<EvaporationSparkleComponent>();
return true;
}
- var coords = mapGrid.GridTileToLocal(tileRef.GridIndices);
+ var coords = _map.GridTileToLocal(gridId, mapGrid, tileRef.GridIndices);
puddleUid = EntityManager.SpawnEntity("Puddle", coords);
EnsureComp<PuddleComponent>(puddleUid);
if (TryAddSolution(puddleUid, solution, sound))
if (!TryComp<MapGridComponent>(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<PuddleComponent>();
while (anc.MoveNext(out var ent))
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;
// 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!;
[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<SmokeComponent> _smokeQuery;
private EntityQuery<SmokeAffectedComponent> _smokeAffectedQuery;
return;
}
- if (!args.NeighborFreeTiles.Any())
+ if (args.NeighborFreeTiles.Count == 0)
return;
TryComp<TimedDespawnComponent>(entity, out var timer);
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);
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<MapGridComponent>(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())
{
{
[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!;
{
// 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<GrowingKudzuComponent>(uid);
+ if (!EnsureComp<GrowingKudzuComponent>(uid, out _))
component.GrowthLevel = 3;
- }
+
component.GrowthLevel = Math.Max(1, component.GrowthLevel - growthDamage);
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
{
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<EdgeSpreaderComponent>(neighborUid));
DebugTools.Assert(HasComp<ActiveEdgeSpreaderComponent>(neighborUid));
DebugTools.Assert(Comp<EdgeSpreaderComponent>(neighborUid).Id == KudzuGroup);
using Robust.Shared.Collections;
+using Robust.Shared.Map;
using Robust.Shared.Map.Components;
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<EntityUid> Neighbors;
/// <summary>
/// </summary>
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!;
/// <summary>
/// Cached maximum number of updates per spreader prototype. This is applied per-grid.
/// Remaining number of updates per grid & prototype.
/// </summary>
// TODO PERFORMANCE Assign each prototype to an index and convert dictionary to array
- private Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = new();
+ private readonly Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = [];
public const float SpreadCooldownSeconds = 1;
private void SetupPrototypes()
{
- _prototypeUpdates = new Dictionary<string, int>();
+ _prototypeUpdates = [];
foreach (var proto in _prototype.EnumeratePrototypes<EdgeSpreaderPrototype>())
{
_prototypeUpdates.Add(proto.ID, proto.UpdatesPerSecond);
EnsureComp<SpreaderGridComponent>(ev.EntityUid);
}
- private void OnTerminating(EntityUid uid, EdgeSpreaderComponent component, ref EntityTerminatingEvent args)
+ private void OnTerminating(Entity<EdgeSpreaderComponent> entity, ref EntityTerminatingEvent args)
{
- var neighbors = GetSpreadableNeighbors(uid);
+ var neighbors = GetSpreadableNeighbors(entity);
foreach (var neighbor in neighbors)
{
}
}
- private void Spread(EntityUid uid, TransformComponent xform, string prototype, ref int updates)
+ private void Spread(EntityUid uid, TransformComponent xform, ProtoId<EdgeSpreaderPrototype> prototype, ref int updates)
{
GetNeighbors(uid, xform, prototype, out var freeTiles, out _, out var neighbors);
/// <summary>
/// Gets the neighboring node data for the specified entity and the specified node group.
/// </summary>
- public void GetNeighbors(EntityUid uid, TransformComponent transform, string prototype, out ValueList<(MapGridComponent Grid, Vector2i Tile)> freeTiles, out ValueList<Vector2i> occupiedTiles, out ValueList<EntityUid> neighbors)
+ public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId<EdgeSpreaderPrototype> prototype, out ValueList<(MapGridComponent, TileRef)> freeTiles, out ValueList<Vector2i> occupiedTiles, out ValueList<EntityUid> neighbors)
{
// TODO remove occupiedTiles -- its currently unused and just slows this method down.
- DebugTools.Assert(_prototype.HasIndex<EdgeSpreaderPrototype>(prototype));
- freeTiles = new ValueList<(MapGridComponent Grid, Vector2i Tile)>();
- occupiedTiles = new ValueList<Vector2i>();
- neighbors = new ValueList<EntityUid>();
+ DebugTools.Assert(_prototype.HasIndex(prototype));
+ freeTiles = [];
+ occupiedTiles = [];
+ neighbors = [];
- if (!_mapManager.TryGetGrid(transform.GridUid, out var grid))
+ if (!TryComp<MapGridComponent>(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<EdgeSpreaderComponent>();
var airtightQuery = GetEntityQuery<AirtightComponent>();
var dockQuery = GetEntityQuery<DockingComponent>();
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))
{
xformQuery.TryGetComponent(dock.DockedWith, out var dockedXform) &&
TryComp<MapGridComponent>(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.
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;
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))
var oldCount = occupiedTiles.Count;
directionEnumerator =
- neighborGrid.GetAnchoredEntitiesEnumerator(neighborPos);
+ _map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos);
while (directionEnumerator.MoveNext(out var ent))
{
}
if (oldCount == occupiedTiles.Count)
- freeTiles.Add((neighborGrid, neighborPos));
+ freeTiles.Add((neighborGrid, tileRef));
}
}
var neighbors = new List<EntityUid>();
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<EdgeSpreaderComponent>();
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);
}
}