From 5109d1d853a405d1460eb7dffd62d247623d968b Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Thu, 4 Mar 2021 13:07:10 +0100 Subject: [PATCH] Adds fixgridatmos command for mapping and admining --- .../Atmos/IGridAtmosphereComponent.cs | 2 + .../Commands/Atmos/FillGasCommand.cs | 5 +- Content.Server/Commands/Atmos/FixGridAtmos.cs | 74 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 Content.Server/Commands/Atmos/FixGridAtmos.cs diff --git a/Content.Server/Atmos/IGridAtmosphereComponent.cs b/Content.Server/Atmos/IGridAtmosphereComponent.cs index 2405b56859..6b6ffdb3d5 100644 --- a/Content.Server/Atmos/IGridAtmosphereComponent.cs +++ b/Content.Server/Atmos/IGridAtmosphereComponent.cs @@ -155,6 +155,8 @@ namespace Content.Server.Atmos /// float GetVolumeForCells(int cellCount); + void RepopulateTiles(); + /// /// Returns a dictionary of adjacent TileAtmospheres. /// diff --git a/Content.Server/Commands/Atmos/FillGasCommand.cs b/Content.Server/Commands/Atmos/FillGasCommand.cs index 0b095eebb6..2fa9768959 100644 --- a/Content.Server/Commands/Atmos/FillGasCommand.cs +++ b/Content.Server/Commands/Atmos/FillGasCommand.cs @@ -1,5 +1,6 @@ #nullable enable using Content.Server.Administration; +using Content.Server.Atmos; using Content.Server.GameObjects.Components.Atmos; using Content.Shared.Administration; using Content.Shared.Atmos; @@ -42,13 +43,13 @@ namespace Content.Server.Commands.Atmos return; } - if (!grid.HasComponent()) + if (!grid.HasComponent()) { shell.WriteLine("Grid doesn't have an atmosphere."); return; } - var gam = grid.GetComponent(); + var gam = grid.GetComponent(); foreach (var tile in gam) { diff --git a/Content.Server/Commands/Atmos/FixGridAtmos.cs b/Content.Server/Commands/Atmos/FixGridAtmos.cs new file mode 100644 index 0000000000..01ead99b72 --- /dev/null +++ b/Content.Server/Commands/Atmos/FixGridAtmos.cs @@ -0,0 +1,74 @@ +#nullable enable +using Content.Server.Administration; +using Content.Server.Atmos; +using Content.Server.GameObjects.Components.Atmos; +using Content.Shared.Administration; +using Content.Shared.Atmos; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Map; + +namespace Content.Server.Commands.Atmos +{ + [AdminCommand(AdminFlags.Debug)] + public class FixGridAtmos : IConsoleCommand + { + public string Command => "fixgridatmos"; + public string Description => "Makes every tile on a grid have a roundstart gas mix."; + public string Help => $"{Command} "; + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length == 0) + { + shell.WriteError("Not enough arguments."); + return; + } + + var mapManager = IoCManager.Resolve(); + var entityManager = IoCManager.Resolve(); + + var mixture = new GasMixture(Atmospherics.CellVolume) { Temperature = Atmospherics.T20C }; + mixture.AdjustMoles(Gas.Oxygen, Atmospherics.OxygenMolesStandard); + mixture.AdjustMoles(Gas.Nitrogen, Atmospherics.NitrogenMolesStandard); + + foreach (var gid in args) + { + // I like offering detailed error messages, that's why I don't use one of the extension methods. + if (!int.TryParse(gid, out var i) || i <= 0) + { + shell.WriteError($"Invalid grid ID \"{gid}\"."); + continue; + } + + if (!mapManager.TryGetGrid(new GridId(i), out var grid)) + { + shell.WriteError($"Grid \"{i}\" doesn't exist."); + continue; + } + + if (!entityManager.TryGetEntity(grid.GridEntityId, out var entity)) + { + shell.WriteError($"Grid entity for grid \"{i}\" doesn't exist."); + continue; + } + + var gridAtmosphere = new GridAtmosphereComponent() {Owner = entity}; + + // Inject dependencies manually or a NRE will eat your face. + IoCManager.InjectDependencies(gridAtmosphere); + + entityManager.ComponentManager.AddComponent(entity, gridAtmosphere, true); + + gridAtmosphere.RepopulateTiles(); + + foreach (var tile in gridAtmosphere) + { + tile.Air = (GasMixture) mixture.Clone(); + tile.Air.Volume = gridAtmosphere.GetVolumeForCells(1); + tile.Invalidate(); + } + } + } + } +}