Support for non-fulltile firelocks!

This commit is contained in:
Víctor Aguilera Puerto
2020-08-30 15:00:40 +02:00
parent c137d1bc16
commit 52e98e29d7
5 changed files with 95 additions and 74 deletions

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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,11 +36,19 @@ 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();
}
}
[ViewVariables]
@@ -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);
}
}
}

View File

@@ -209,20 +209,11 @@ namespace Content.Server.GameObjects.Components.Atmos
}
private void Revalidate()
{
foreach (var indices in _invalidatedCoords.ToArray())
{
Revalidate(indices);
}
_invalidatedCoords.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Revalidate(MapIndices indices)
{
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return;
foreach (var indices in _invalidatedCoords.ToArray())
{
var tile = GetTile(indices);
if (tile == null)
@@ -270,6 +261,15 @@ namespace Content.Server.GameObjects.Components.Atmos
}
}
_invalidatedCoords.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UpdateAdjacentBits(MapIndices indices)
{
GetTile(indices)?.UpdateAdjacent();
}
/// <inheritdoc />
public void FixVacuum(MapIndices indices)
{
@@ -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 />

View File

@@ -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 { }
}