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-09-06 16:11:53 +02:00
|
|
|
|
using Robust.Shared.IoC;
|
2020-08-11 22:34:37 +02:00
|
|
|
|
using Robust.Shared.Map;
|
2020-10-11 15:21:21 +02:00
|
|
|
|
using Robust.Shared.Maths;
|
2020-08-11 22:34:37 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class AtmosHelpers
|
|
|
|
|
|
{
|
2020-12-20 04:14:41 +01:00
|
|
|
|
public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
|
2020-08-11 22:34:37 +02:00
|
|
|
|
{
|
2020-09-06 16:11:53 +02:00
|
|
|
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
|
|
|
|
|
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates.GetGridId(entityManager));
|
2020-08-11 22:34:37 +02:00
|
|
|
|
|
2020-12-04 12:21:57 +01:00
|
|
|
|
return gridAtmos.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
|
|
|
|
{
|
2020-12-20 04:14:41 +01:00
|
|
|
|
return coordinates.GetTileAtmosphere(entityManager)?.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 TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId)
|
2020-08-11 22:34:37 +02:00
|
|
|
|
{
|
|
|
|
|
|
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
|
|
|
|
|
|
|
2020-12-04 12:21:57 +01:00
|
|
|
|
return gridAtmos.GetTile(indices);
|
2020-08-11 22:34:37 +02:00
|
|
|
|
}
|
2020-08-13 13:51:57 +02:00
|
|
|
|
|
2020-10-11 15:21:21 +02:00
|
|
|
|
public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId)
|
2020-08-13 13:51:57 +02:00
|
|
|
|
{
|
|
|
|
|
|
return indices.GetTileAtmosphere(gridId)?.Air;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-11 15:21:21 +02:00
|
|
|
|
public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId,
|
2020-12-20 04:14:41 +01:00
|
|
|
|
[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 = indices.GetTileAtmosphere(gridId), default);
|
2020-08-13 13:51:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-20 04:14:41 +01:00
|
|
|
|
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air)
|
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 = indices.GetTileAir(gridId), default);
|
2020-08-13 13:51:57 +02:00
|
|
|
|
}
|
2020-12-04 12:21:57 +01:00
|
|
|
|
|
|
|
|
|
|
public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null)
|
|
|
|
|
|
{
|
2020-12-20 04:14:41 +01:00
|
|
|
|
return InvalidateTileAir(transform.Coordinates);
|
2020-12-04 12:21:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|