2020-08-13 13:51:57 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2020-12-13 15:00:49 +00:00
|
|
|
|
using Content.Shared.Atmos;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-11 22:34:37 +02:00
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class AtmosHelpers
|
|
|
|
|
|
{
|
2021-04-13 13:17:10 +02:00
|
|
|
|
public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates)
|
2020-08-11 22:34:37 +02:00
|
|
|
|
{
|
2021-04-13 13:17:10 +02:00
|
|
|
|
return EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates).GetTile(coordinates);
|
2020-08-11 22:34:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:03:27 +03:00
|
|
|
|
public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
|
2020-08-13 13:51:57 +02:00
|
|
|
|
{
|
2021-04-13 13:17:10 +02:00
|
|
|
|
return coordinates.GetTileAtmosphere()?.Air;
|
2020-08-13 13:51:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-20 04:14:41 +01:00
|
|
|
|
public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere)
|
2020-08-13 13:51:57 +02:00
|
|
|
|
{
|
2020-08-18 13:32:18 +02:00
|
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
2020-12-20 04:14:41 +01:00
|
|
|
|
return !Equals(atmosphere = coordinates.GetTileAtmosphere(), default);
|
2020-08-13 13:51:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-20 04:14:41 +01:00
|
|
|
|
public static bool TryGetTileAir(this EntityCoordinates coordinates, [NotNullWhen(true)] out GasMixture? air, IEntityManager? entityManager = null)
|
2020-08-13 13:51:57 +02:00
|
|
|
|
{
|
2020-08-18 13:32:18 +02:00
|
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
2020-12-20 04:14:41 +01:00
|
|
|
|
return !Equals(air = coordinates.GetTileAir(entityManager), default);
|
2020-08-13 13:51:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-13 15:00:49 +00:00
|
|
|
|
public static bool IsTileAirProbablySafe(this EntityCoordinates coordinates)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Note that oxygen mix isn't checked, but survival boxes make that not necessary.
|
|
|
|
|
|
var air = coordinates.GetTileAir();
|
|
|
|
|
|
if (air == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (air.Pressure <= Atmospherics.WarningLowPressure)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (air.Pressure >= Atmospherics.WarningHighPressure)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (air.Temperature <= 260)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (air.Temperature >= 360)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-20 04:14:41 +01:00
|
|
|
|
public static bool InvalidateTileAir(this EntityCoordinates coordinates)
|
2020-12-04 12:21:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (!coordinates.TryGetTileAtmosphere(out var tileAtmos))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-08 17:36:59 +01:00
|
|
|
|
tileAtmos.Invalidate();
|
2020-12-04 12:21:57 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2020-08-11 22:34:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|