From 97a603b0b6a4c75c4a2c3e19eb57522558550b68 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Fri, 4 Sep 2020 12:22:33 +0200 Subject: [PATCH] Add UnsimulatedGridAtmosphereComponent and a command to add it (#2019) * Add UnsimulatedGridAtmosphereComponent * Override prytile, repopulate, invalidate and revalidate * Attributes --- Content.Server/Atmos/AtmosCommands.cs | 70 +++++++++++- .../Atmos/GridAtmosphereComponent.cs | 79 +++++++------- .../UnsimulatedGridAtmosphereComponent.cs | 103 ++++++++++++++++++ 3 files changed, 206 insertions(+), 46 deletions(-) create mode 100644 Content.Server/GameObjects/Components/Atmos/UnsimulatedGridAtmosphereComponent.cs diff --git a/Content.Server/Atmos/AtmosCommands.cs b/Content.Server/Atmos/AtmosCommands.cs index 1db4ac0dc0..60b8fecd81 100644 --- a/Content.Server/Atmos/AtmosCommands.cs +++ b/Content.Server/Atmos/AtmosCommands.cs @@ -17,11 +17,21 @@ namespace Content.Server.Atmos { public string Command => "addatmos"; public string Description => "Adds atmos support to a grid."; - public string Help => "addatmos "; + public string Help => $"{Command} "; + public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args) { - if (args.Length < 1) return; - if(!int.TryParse(args[0], out var id)) return; + if (args.Length < 1) + { + shell.SendText(player, Help); + return; + } + + if (!int.TryParse(args[0], out var id)) + { + shell.SendText(player, $"{args[0]} is not a valid integer."); + return; + } var gridId = new GridId(id); @@ -29,7 +39,7 @@ namespace Content.Server.Atmos if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp)) { - shell.SendText(player, "Invalid grid ID."); + shell.SendText(player, $"{gridId} is not a valid grid id."); return; } @@ -41,7 +51,7 @@ namespace Content.Server.Atmos return; } - if (grid.HasComponent()) + if (grid.HasComponent()) { shell.SendText(player, "Grid already has an atmosphere."); return; @@ -53,6 +63,56 @@ namespace Content.Server.Atmos } } + public class AddUnsimulatedAtmos : IClientCommand + { + public string Command => "addunsimulatedatmos"; + public string Description => "Adds unimulated atmos support to a grid."; + public string Help => $"{Command} "; + + public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args) + { + if (args.Length < 1) + { + shell.SendText(player, Help); + return; + } + + if (!int.TryParse(args[0], out var id)) + { + shell.SendText(player, $"{args[0]} is not a valid integer."); + return; + } + + var gridId = new GridId(id); + + var mapMan = IoCManager.Resolve(); + + if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp)) + { + shell.SendText(player, $"{gridId} is not a valid grid id."); + return; + } + + var entMan = IoCManager.Resolve(); + + if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid)) + { + shell.SendText(player, "Failed to get grid entity."); + return; + } + + if (grid.HasComponent()) + { + shell.SendText(player, "Grid already has an atmosphere."); + return; + } + + grid.AddComponent(); + + shell.SendText(player, $"Added unsimulated atmosphere to grid {id}."); + } + } + public class ListGases : IClientCommand { public string Command => "listgases"; diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs index d89fdd973f..907a7b278c 100644 --- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs @@ -14,10 +14,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components.Map; using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.Interfaces.Map; -using Robust.Shared.Interfaces.Timing; -using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -72,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Atmos private double _excitedGroupLastProcess; [ViewVariables] - private readonly Dictionary _tiles = new Dictionary(1000); + protected readonly Dictionary Tiles = new Dictionary(1000); [ViewVariables] private readonly HashSet _activeTiles = new HashSet(1000); @@ -156,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Atmos } /// - public void PryTile(MapIndices indices) + public virtual void PryTile(MapIndices indices) { if (!Owner.TryGetComponent(out IMapGridComponent? mapGridComponent)) return; if (IsSpace(indices) || IsAirBlocked(indices)) return; @@ -177,17 +174,17 @@ namespace Content.Server.GameObjects.Components.Atmos RepopulateTiles(); } - public void RepopulateTiles() + public virtual void RepopulateTiles() { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; foreach (var tile in mapGrid.Grid.GetAllTiles()) { - if(!_tiles.ContainsKey(tile.GridIndices)) - _tiles.Add(tile.GridIndices, new TileAtmosphere(this, tile.GridIndex, tile.GridIndices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C})); + if(!Tiles.ContainsKey(tile.GridIndices)) + Tiles.Add(tile.GridIndices, new TileAtmosphere(this, tile.GridIndex, tile.GridIndices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C})); } - foreach (var (_, tile) in _tiles.ToArray()) + foreach (var (_, tile) in Tiles.ToArray()) { tile.UpdateAdjacent(); tile.UpdateVisuals(); @@ -195,12 +192,12 @@ namespace Content.Server.GameObjects.Components.Atmos } /// - public void Invalidate(MapIndices indices) + public virtual void Invalidate(MapIndices indices) { _invalidatedCoords.Add(indices); } - private void Revalidate() + protected virtual void Revalidate() { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; @@ -212,14 +209,14 @@ namespace Content.Server.GameObjects.Components.Atmos if (tile == null) { tile = new TileAtmosphere(this, mapGrid.Grid.Index, indices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C}); - _tiles[indices] = tile; + Tiles[indices] = tile; } if (IsSpace(indices)) { tile.Air = new GasMixture(GetVolumeForCells(1)); tile.Air.MarkImmutable(); - _tiles[indices] = tile; + Tiles[indices] = tile; } else if (IsAirBlocked(indices)) { @@ -257,18 +254,18 @@ namespace Content.Server.GameObjects.Components.Atmos } /// - public void FixVacuum(MapIndices indices) + public virtual void FixVacuum(MapIndices indices) { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; var tile = GetTile(indices); if (tile?.GridIndex != mapGrid.Grid.Index) return; var adjacent = GetAdjacentTiles(indices); tile.Air = new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C}; - _tiles[indices] = tile; + Tiles[indices] = tile; var ratio = 1f / adjacent.Count; - foreach (var (direction, adj) in adjacent) + foreach (var (_, adj) in adjacent) { var mix = adj.Air.RemoveRatio(ratio); tile.Air.Merge(mix); @@ -278,7 +275,7 @@ namespace Content.Server.GameObjects.Components.Atmos /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddActiveTile(TileAtmosphere? tile) + public virtual void AddActiveTile(TileAtmosphere? tile) { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; if (tile?.GridIndex != mapGrid.Grid.Index) return; @@ -288,7 +285,7 @@ namespace Content.Server.GameObjects.Components.Atmos /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RemoveActiveTile(TileAtmosphere? tile) + public virtual void RemoveActiveTile(TileAtmosphere? tile) { if (tile == null) return; _activeTiles.Remove(tile); @@ -298,7 +295,7 @@ namespace Content.Server.GameObjects.Components.Atmos /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHotspotTile(TileAtmosphere? tile) + public virtual void AddHotspotTile(TileAtmosphere? tile) { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; if (tile?.GridIndex != mapGrid.Grid.Index || tile?.Air == null) return; @@ -307,20 +304,20 @@ namespace Content.Server.GameObjects.Components.Atmos /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RemoveHotspotTile(TileAtmosphere? tile) + public virtual void RemoveHotspotTile(TileAtmosphere? tile) { if (tile == null) return; _hotspotTiles.Remove(tile); } - public void AddSuperconductivityTile(TileAtmosphere? tile) + public virtual void AddSuperconductivityTile(TileAtmosphere? tile) { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; if (tile?.GridIndex != mapGrid.Grid.Index) return; _superconductivityTiles.Add(tile); } - public void RemoveSuperconductivityTile(TileAtmosphere? tile) + public virtual void RemoveSuperconductivityTile(TileAtmosphere? tile) { if (tile == null) return; _superconductivityTiles.Remove(tile); @@ -328,7 +325,7 @@ namespace Content.Server.GameObjects.Components.Atmos /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHighPressureDelta(TileAtmosphere? tile) + public virtual void AddHighPressureDelta(TileAtmosphere? tile) { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; if (tile?.GridIndex != mapGrid.Grid.Index) return; @@ -337,21 +334,21 @@ namespace Content.Server.GameObjects.Components.Atmos /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool HasHighPressureDelta(TileAtmosphere tile) + public virtual bool HasHighPressureDelta(TileAtmosphere tile) { return _highPressureDelta.Contains(tile); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddExcitedGroup(ExcitedGroup excitedGroup) + public virtual void AddExcitedGroup(ExcitedGroup excitedGroup) { _excitedGroups.Add(excitedGroup); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RemoveExcitedGroup(ExcitedGroup excitedGroup) + public virtual void RemoveExcitedGroup(ExcitedGroup excitedGroup) { _excitedGroups.Remove(excitedGroup); } @@ -387,7 +384,7 @@ namespace Content.Server.GameObjects.Components.Atmos { if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return null; - if (_tiles.TryGetValue(indices, out var tile)) return tile; + if (Tiles.TryGetValue(indices, out var tile)) return tile; // We don't have that tile! if (IsSpace(indices) && createSpace) @@ -440,7 +437,7 @@ namespace Content.Server.GameObjects.Components.Atmos } /// - public void Update(float frameTime) + public virtual void Update(float frameTime) { _timer += frameTime; @@ -540,7 +537,7 @@ namespace Content.Server.GameObjects.Components.Atmos UpdateCounter++; } - public bool ProcessTileEqualize(bool resumed = false) + public virtual bool ProcessTileEqualize(bool resumed = false) { _stopwatch.Restart(); @@ -567,7 +564,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - public bool ProcessActiveTiles(bool resumed = false) + public virtual bool ProcessActiveTiles(bool resumed = false) { _stopwatch.Restart(); @@ -594,7 +591,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - public bool ProcessExcitedGroups(bool resumed = false) + public virtual bool ProcessExcitedGroups(bool resumed = false) { _stopwatch.Restart(); @@ -628,7 +625,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - public bool ProcessHighPressureDelta(bool resumed = false) + public virtual bool ProcessHighPressureDelta(bool resumed = false) { _stopwatch.Restart(); @@ -658,7 +655,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - private bool ProcessHotspots(bool resumed = false) + protected virtual bool ProcessHotspots(bool resumed = false) { _stopwatch.Restart(); @@ -685,7 +682,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - private bool ProcessSuperconductivity(bool resumed = false) + protected virtual bool ProcessSuperconductivity(bool resumed = false) { _stopwatch.Restart(); @@ -712,7 +709,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - private bool ProcessPipeNets(bool resumed = false) + protected virtual bool ProcessPipeNets(bool resumed = false) { _stopwatch.Restart(); @@ -739,7 +736,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - private bool ProcessPipeNetDevices(bool resumed = false) + protected virtual bool ProcessPipeNetDevices(bool resumed = false) { _stopwatch.Restart(); @@ -796,11 +793,11 @@ namespace Content.Server.GameObjects.Components.Atmos !serializer.TryReadDataField("tiles", out Dictionary? tiles)) return; - _tiles.Clear(); + Tiles.Clear(); foreach (var (indices, mix) in tiles!) { - _tiles.Add(indices, new TileAtmosphere(this, gridId, indices, (GasMixture)uniqueMixes![mix].Clone())); + Tiles.Add(indices, new TileAtmosphere(this, gridId, indices, (GasMixture)uniqueMixes![mix].Clone())); Invalidate(indices); } } @@ -809,7 +806,7 @@ namespace Content.Server.GameObjects.Components.Atmos var uniqueMixes = new List(); var uniqueMixHash = new Dictionary(); var tiles = new Dictionary(); - foreach (var (indices, tile) in _tiles) + foreach (var (indices, tile) in Tiles) { if (tile.Air == null) continue; @@ -832,7 +829,7 @@ namespace Content.Server.GameObjects.Components.Atmos public IEnumerator GetEnumerator() { - return _tiles.Values.GetEnumerator(); + return Tiles.Values.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() @@ -841,7 +838,7 @@ namespace Content.Server.GameObjects.Components.Atmos } /// - public void BurnTile(MapIndices gridIndices) + public virtual void BurnTile(MapIndices gridIndices) { // TODO ATMOS } diff --git a/Content.Server/GameObjects/Components/Atmos/UnsimulatedGridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/UnsimulatedGridAtmosphereComponent.cs new file mode 100644 index 0000000000..b421ff9800 --- /dev/null +++ b/Content.Server/GameObjects/Components/Atmos/UnsimulatedGridAtmosphereComponent.cs @@ -0,0 +1,103 @@ +#nullable enable +using System; +using Content.Server.Atmos; +using Content.Shared.Atmos; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Components.Map; +using Robust.Shared.Map; + +namespace Content.Server.GameObjects.Components.Atmos +{ + [RegisterComponent] + [ComponentReference(typeof(IGridAtmosphereComponent))] + [ComponentReference(typeof(GridAtmosphereComponent))] + [Serializable] + public class UnsimulatedGridAtmosphereComponent : GridAtmosphereComponent, IGridAtmosphereComponent + { + public override string Name => "UnsimulatedGridAtmosphere"; + + public override void PryTile(MapIndices indices) { } + + public override void RepopulateTiles() + { + if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; + + foreach (var tile in mapGrid.Grid.GetAllTiles()) + { + if(!Tiles.ContainsKey(tile.GridIndices)) + Tiles.Add(tile.GridIndices, new TileAtmosphere(this, tile.GridIndex, tile.GridIndices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C})); + } + } + + public override void Invalidate(MapIndices indices) { } + + protected override void Revalidate() { } + + public override void FixVacuum(MapIndices indices) { } + + public override void AddActiveTile(TileAtmosphere? tile) { } + + public override void RemoveActiveTile(TileAtmosphere? tile) { } + + public override void AddHotspotTile(TileAtmosphere? tile) { } + + public override void RemoveHotspotTile(TileAtmosphere? tile) { } + + public override void AddSuperconductivityTile(TileAtmosphere? tile) { } + + public override void RemoveSuperconductivityTile(TileAtmosphere? tile) { } + + public override void AddHighPressureDelta(TileAtmosphere? tile) { } + + public override bool HasHighPressureDelta(TileAtmosphere tile) + { + return false; + } + + public override void AddExcitedGroup(ExcitedGroup excitedGroup) { } + + public override void RemoveExcitedGroup(ExcitedGroup excitedGroup) { } + + public override void Update(float frameTime) { } + + public override bool ProcessTileEqualize(bool resumed = false) + { + return false; + } + + public override bool ProcessActiveTiles(bool resumed = false) + { + return false; + } + + public override bool ProcessExcitedGroups(bool resumed = false) + { + return false; + } + + public override bool ProcessHighPressureDelta(bool resumed = false) + { + return false; + } + + protected override bool ProcessHotspots(bool resumed = false) + { + return false; + } + + protected override bool ProcessSuperconductivity(bool resumed = false) + { + return false; + } + + protected override bool ProcessPipeNets(bool resumed = false) + { + return false; + } + + protected override bool ProcessPipeNetDevices(bool resumed = false) + { + return false; + } + } +}