From af863789951b5fc05ed09267f2087fc5920f51fa Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Date: Tue, 23 Nov 2021 12:22:18 +0100 Subject: [PATCH] Log explosive depressurization. (#5474) --- .../AtmosphereSystem.Monstermos.cs | 18 ++++++++++++++---- .../Atmos/EntitySystems/AtmosphereSystem.cs | 2 ++ Content.Shared/Administration/Logs/LogType.cs | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs index a34d7b9ec1..0b3d85a40a 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Content.Server.Atmos.Components; using Content.Server.Doors.Components; +using Content.Shared.Administration.Logs; using Content.Shared.Atmos; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -16,6 +17,11 @@ namespace Content.Server.Atmos.EntitySystems { [Dependency] private readonly IRobustRandom _robustRandom = default!; + /// + /// Threshold for logging explosive depressurization. + /// + private const float DepressurizationLogThreshold = Atmospherics.MolesCellStandard * 10; + private readonly TileAtmosphereComparer _monstermosComparer = new(); private readonly TileAtmosphere?[] _equalizeTiles = new TileAtmosphere[Atmospherics.MonstermosHardTileLimit]; @@ -360,7 +366,7 @@ namespace Content.Server.Atmos.EntitySystems const int limit = Atmospherics.MonstermosHardTileLimit; - var totalGasesRemoved = 0f; + var totalMolesRemoved = 0f; var queueCycle = ++gridAtmosphere.EqualizationQueueCycleControl; var tileCount = 0; @@ -447,7 +453,7 @@ namespace Content.Server.Atmos.EntitySystems var otherTile2 = otherTile.AdjacentTiles[otherTile.MonstermosInfo.CurrentTransferDirection.ToIndex()]; if (otherTile2?.Air == null) continue; var sum = otherTile2.Air.TotalMoles; - totalGasesRemoved += sum; + totalMolesRemoved += sum; otherTile.MonstermosInfo.CurrentTransferAmount += sum; otherTile2.MonstermosInfo.CurrentTransferAmount += otherTile.MonstermosInfo.CurrentTransferAmount; otherTile.PressureDifference = otherTile.MonstermosInfo.CurrentTransferAmount; @@ -471,10 +477,14 @@ namespace Content.Server.Atmos.EntitySystems var gridPhysics = EntityManager.GetComponent(mapGrid.GridEntityId); // TODO ATMOS: Come up with better values for these. - gridPhysics.ApplyLinearImpulse(direction * totalGasesRemoved * gridPhysics.Mass); - gridPhysics.ApplyAngularImpulse(Vector2.Cross(tile.GridIndices - gridPhysics.LocalCenter, direction) * totalGasesRemoved); + gridPhysics.ApplyLinearImpulse(direction * totalMolesRemoved * gridPhysics.Mass); + gridPhysics.ApplyAngularImpulse(Vector2.Cross(tile.GridIndices - gridPhysics.LocalCenter, direction) * totalMolesRemoved); } + if(totalMolesRemoved > DepressurizationLogThreshold) + _adminLog.Add(LogType.ExplosiveDepressurization, LogImpact.High, + $"Explosive depressurization removed {totalMolesRemoved} moles from {tileCount} tiles starting from position {tile.GridIndices:position} on grid ID {tile.GridIndex:grid}"); + Array.Clear(_depressurizeTiles, 0, Atmospherics.MonstermosHardTileLimit); Array.Clear(_depressurizeSpaceTiles, 0, Atmospherics.MonstermosHardTileLimit); Array.Clear(_depressurizeProgressionOrder, 0, Atmospherics.MonstermosHardTileLimit * 2); diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs index 1a467ddacb..b977d883e8 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs @@ -1,3 +1,4 @@ +using Content.Server.Administration.Logs; using Content.Server.Atmos.Components; using Content.Server.NodeContainer.EntitySystems; using Content.Server.Temperature.Components; @@ -18,6 +19,7 @@ namespace Content.Server.Atmos.EntitySystems public partial class AtmosphereSystem : SharedAtmosphereSystem { [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly AdminLogSystem _adminLog = default!; private const float ExposedUpdateDelay = 1f; private float _exposedTimer = 0f; diff --git a/Content.Shared/Administration/Logs/LogType.cs b/Content.Shared/Administration/Logs/LogType.cs index 0da00c4213..9e301166d8 100644 --- a/Content.Shared/Administration/Logs/LogType.cs +++ b/Content.Shared/Administration/Logs/LogType.cs @@ -15,6 +15,7 @@ public enum LogType Verb = 19, ShuttleCalled = 8, ShuttleRecalled = 9, + ExplosiveDepressurization = 10, ChemicalReaction = 17, ReagentEffect = 18, }