Support for non-fulltile firelocks!
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.GameObjects.Components.Atmos.Piping;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Content.Shared.Atmos;
|
||||
@@ -48,7 +49,7 @@ namespace Content.Server.Atmos
|
||||
/// Revalidates indices immediately.
|
||||
/// </summary>
|
||||
/// <param name="indices"></param>
|
||||
void Revalidate(MapIndices indices);
|
||||
void UpdateAdjacentBits(MapIndices indices);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an active tile so it becomes processed every update until it becomes inactive.
|
||||
@@ -117,6 +118,7 @@ namespace Content.Server.Atmos
|
||||
/// Returns a tile.
|
||||
/// </summary>
|
||||
/// <param name="indices"></param>
|
||||
/// <param name="createSpace"></param>
|
||||
/// <returns></returns>
|
||||
TileAtmosphere GetTile(MapIndices indices, bool createSpace = true);
|
||||
|
||||
@@ -124,17 +126,19 @@ namespace Content.Server.Atmos
|
||||
/// Returns a tile.
|
||||
/// </summary>
|
||||
/// <param name="coordinates"></param>
|
||||
/// <param name="createSpace"></param>
|
||||
/// <returns></returns>
|
||||
TileAtmosphere GetTile(GridCoordinates coordinates, bool createSpace = true);
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the tile in question is air-blocked.
|
||||
/// This could be due to a wall, an airlock, etc.
|
||||
/// Also see AirtightComponent.
|
||||
/// <seealso cref="AirtightComponent"/>
|
||||
/// </summary>
|
||||
/// <param name="indices"></param>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool IsAirBlocked(MapIndices indices);
|
||||
bool IsAirBlocked(MapIndices indices, AtmosDirection direction);
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the tile in question is space.
|
||||
|
||||
@@ -1122,7 +1122,7 @@ namespace Content.Server.Atmos
|
||||
_adjacentTiles[direction.ToIndex()] = adjacent;
|
||||
adjacent?.UpdateAdjacent(direction.GetOpposite());
|
||||
|
||||
if (adjacent != null && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices))
|
||||
if (adjacent != null && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
|
||||
{
|
||||
_adjacentBits |= direction;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
@@ -22,6 +23,8 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
|
||||
public override string Name => "Airtight";
|
||||
|
||||
[ViewVariables]
|
||||
private int _airBlockedDirection;
|
||||
private bool _airBlocked = true;
|
||||
private bool _fixVacuum = false;
|
||||
|
||||
@@ -33,10 +36,18 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
_airBlocked = value;
|
||||
|
||||
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
|
||||
{
|
||||
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID)?.Revalidate(snapGrid.Position);
|
||||
}
|
||||
UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
public AtmosDirection AirBlockedDirection
|
||||
{
|
||||
get => (AtmosDirection)_airBlockedDirection;
|
||||
set
|
||||
{
|
||||
_airBlockedDirection = (int) value;
|
||||
|
||||
UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,16 +60,16 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
|
||||
serializer.DataField(ref _airBlocked, "airBlocked", true);
|
||||
serializer.DataField(ref _fixVacuum, "fixVacuum", true);
|
||||
serializer.DataField(ref _airBlockedDirection, "airBlockedDirection", (int)AtmosDirection.All, WithFormat.Flags<AtmosDirectionFlags>());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// Using the SnapGrid is critical for the performance of the room builder, and thus if
|
||||
// it is absent the component will not be airtight. A warning is much easier to track
|
||||
// down than the object magically not being airtight, so log one if the SnapGrid component
|
||||
// is missing.
|
||||
// Using the SnapGrid is critical for performance, and thus if it is absent the component
|
||||
// will not be airtight. A warning is much easier to track down than the object magically
|
||||
// not being airtight, so log one if the SnapGrid component is missing.
|
||||
if (!Owner.EnsureComponent(out SnapGridComponent _))
|
||||
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition.ToString()} didn't have a {nameof(SnapGridComponent)}");
|
||||
|
||||
@@ -87,13 +98,10 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
snapGrid.OnPositionChanged -= OnTransformMove;
|
||||
}
|
||||
|
||||
if (_fixVacuum)
|
||||
{
|
||||
var mapIndices = Owner.Transform.GridPosition.ToMapIndices(_mapManager);
|
||||
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID)?.FixVacuum(mapIndices);
|
||||
}
|
||||
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
|
||||
|
||||
UpdatePosition();
|
||||
if (_fixVacuum)
|
||||
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2);
|
||||
}
|
||||
|
||||
private void OnTransformMove()
|
||||
@@ -109,13 +117,18 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
var mapIndices = Owner.Transform.GridPosition.ToMapIndices(_mapManager);
|
||||
UpdatePosition(Owner.Transform.GridID, mapIndices);
|
||||
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
|
||||
UpdatePosition(Owner.Transform.GridID, snapGrid.Position);
|
||||
}
|
||||
|
||||
private void UpdatePosition(GridId gridId, MapIndices pos)
|
||||
{
|
||||
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId)?.Invalidate(pos);
|
||||
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
|
||||
|
||||
if (gridAtmos == null) return;
|
||||
|
||||
gridAtmos.UpdateAdjacentBits(pos);
|
||||
gridAtmos.Invalidate(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,64 +210,64 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
|
||||
private void Revalidate()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return;
|
||||
|
||||
foreach (var indices in _invalidatedCoords.ToArray())
|
||||
{
|
||||
Revalidate(indices);
|
||||
var tile = GetTile(indices);
|
||||
|
||||
if (tile == null)
|
||||
{
|
||||
tile = new TileAtmosphere(this, mapGrid.Grid.Index, indices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C});
|
||||
_tiles[indices] = tile;
|
||||
}
|
||||
|
||||
if (IsSpace(indices))
|
||||
{
|
||||
tile.Air = new GasMixture(GetVolumeForCells(1));
|
||||
tile.Air.MarkImmutable();
|
||||
_tiles[indices] = tile;
|
||||
|
||||
} else if (IsAirBlocked(indices))
|
||||
{
|
||||
tile.Air = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var obs = GetObstructingComponent(indices);
|
||||
|
||||
if (obs != null)
|
||||
{
|
||||
if (tile.Air == null && obs.FixVacuum)
|
||||
{
|
||||
FixVacuum(tile.GridIndices);
|
||||
}
|
||||
}
|
||||
|
||||
tile.Air ??= new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
|
||||
}
|
||||
|
||||
AddActiveTile(tile);
|
||||
tile.UpdateAdjacent();
|
||||
tile.UpdateVisuals();
|
||||
|
||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||
{
|
||||
var direction = (AtmosDirection) (1 << i);
|
||||
var otherIndices = indices.Offset(direction.ToDirection());
|
||||
var otherTile = GetTile(otherIndices);
|
||||
AddActiveTile(otherTile);
|
||||
otherTile?.UpdateAdjacent(direction.GetOpposite());
|
||||
}
|
||||
}
|
||||
|
||||
_invalidatedCoords.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Revalidate(MapIndices indices)
|
||||
public void UpdateAdjacentBits(MapIndices indices)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return;
|
||||
|
||||
var tile = GetTile(indices);
|
||||
|
||||
if (tile == null)
|
||||
{
|
||||
tile = new TileAtmosphere(this, mapGrid.Grid.Index, indices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C});
|
||||
_tiles[indices] = tile;
|
||||
}
|
||||
|
||||
if (IsSpace(indices))
|
||||
{
|
||||
tile.Air = new GasMixture(GetVolumeForCells(1));
|
||||
tile.Air.MarkImmutable();
|
||||
_tiles[indices] = tile;
|
||||
|
||||
} else if (IsAirBlocked(indices))
|
||||
{
|
||||
tile.Air = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var obs = GetObstructingComponent(indices);
|
||||
|
||||
if (obs != null)
|
||||
{
|
||||
if (tile.Air == null && obs.FixVacuum)
|
||||
{
|
||||
FixVacuum(tile.GridIndices);
|
||||
}
|
||||
}
|
||||
|
||||
tile.Air ??= new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
|
||||
}
|
||||
|
||||
AddActiveTile(tile);
|
||||
tile.UpdateAdjacent();
|
||||
tile.UpdateVisuals();
|
||||
|
||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||
{
|
||||
var direction = (AtmosDirection) (1 << i);
|
||||
var otherIndices = indices.Offset(direction.ToDirection());
|
||||
var otherTile = GetTile(otherIndices);
|
||||
AddActiveTile(otherTile);
|
||||
otherTile?.UpdateAdjacent(direction.GetOpposite());
|
||||
}
|
||||
GetTile(indices)?.UpdateAdjacent();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -413,10 +413,10 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsAirBlocked(MapIndices indices)
|
||||
public bool IsAirBlocked(MapIndices indices, AtmosDirection direction = AtmosDirection.All)
|
||||
{
|
||||
var ac = GetObstructingComponent(indices);
|
||||
return ac != null && ac.AirBlocked;
|
||||
return ac != null && ac.AirBlocked && ac.AirBlockedDirection.HasFlag(direction);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Atmos
|
||||
{
|
||||
/// <summary>
|
||||
/// The reason we use this over <see cref="Direction"/> is that we are going to do some heavy bitflag usage.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum AtmosDirection : byte
|
||||
[Flags, Serializable]
|
||||
[FlagsFor(typeof(AtmosDirectionFlags))]
|
||||
public enum AtmosDirection
|
||||
{
|
||||
Invalid = 0,
|
||||
North = 1 << 0,
|
||||
@@ -86,4 +88,6 @@ namespace Content.Shared.Atmos
|
||||
return direction | other;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AtmosDirectionFlags { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user