diff --git a/Content.Server/Atmos/TileAtmosphere.cs b/Content.Server/Atmos/TileAtmosphere.cs
index 18927a772e..eba6ad9c20 100644
--- a/Content.Server/Atmos/TileAtmosphere.cs
+++ b/Content.Server/Atmos/TileAtmosphere.cs
@@ -67,7 +67,7 @@ namespace Content.Server.Atmos
public float HeatCapacity { get; set; } = 1f;
[ViewVariables]
- public float ThermalConductivity => Tile?.Tile.GetContentTileDefinition().ThermalConductivity ?? 0.05f;
+ public float ThermalConductivity { get; set; } = 0.05f;
[ViewVariables]
public bool Excited { get; set; }
@@ -112,8 +112,13 @@ namespace Content.Server.Atmos
[ViewVariables]
public GasMixture Air { get; set; }
+ [ViewVariables, UsedImplicitly]
+ private int _blockedAirflow => (int)BlockedAirflow;
+
+ public AtmosDirection BlockedAirflow { get; set; } = AtmosDirection.Invalid;
+
[ViewVariables]
- public bool BlocksAir => _gridAtmosphereComponent.IsAirBlocked(GridIndices);
+ public bool BlocksAllAir => BlockedAirflow == AtmosDirection.All;
public TileAtmosphere(GridAtmosphereComponent atmosphereComponent, GridId gridIndex, MapIndices gridIndices, GasMixture mixture = null, bool immutable = false)
{
@@ -868,12 +873,12 @@ namespace Content.Server.Atmos
private void FinishSuperconduction()
{
// Conduct with air on my tile if I have it
- if (!BlocksAir)
+ if (!BlocksAllAir)
{
_temperature = Air.TemperatureShare(ThermalConductivity, _temperature, HeatCapacity);
}
- FinishSuperconduction(BlocksAir ? _temperature : Air.Temperature);
+ FinishSuperconduction(BlocksAllAir ? _temperature : Air.Temperature);
}
private void FinishSuperconduction(float temperature)
@@ -887,9 +892,9 @@ namespace Content.Server.Atmos
private void NeighborConductWithSource(TileAtmosphere other)
{
- if (BlocksAir)
+ if (BlocksAllAir)
{
- if (!other.BlocksAir)
+ if (!other.BlocksAllAir)
{
other.TemperatureShareOpenToSolid(this);
}
@@ -902,7 +907,7 @@ namespace Content.Server.Atmos
return;
}
- if (!other.BlocksAir)
+ if (!other.BlocksAllAir)
{
other.Air.TemperatureShare(Air, Atmospherics.WindowHeatTransferCoefficient);
}
@@ -953,7 +958,7 @@ namespace Content.Server.Atmos
public AtmosDirection ConductivityDirections()
{
- if(BlocksAir)
+ if(BlocksAllAir)
{
if(_archivedCycle < _gridAtmosphereComponent.UpdateCounter)
Archive(_gridAtmosphereComponent.UpdateCounter);
@@ -1150,7 +1155,7 @@ namespace Content.Server.Atmos
_adjacentTiles[direction.ToIndex()] = adjacent;
adjacent?.UpdateAdjacent(direction.GetOpposite());
- if (adjacent != null && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
+ if (adjacent != null && !BlockedAirflow.HasFlag(direction) && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
{
_adjacentBits |= direction;
}
@@ -1161,7 +1166,7 @@ namespace Content.Server.Atmos
{
_adjacentTiles[direction.ToIndex()] = _gridAtmosphereComponent.GetTile(GridIndices.Offset(direction.ToDirection()));
- if (!_gridAtmosphereComponent.IsAirBlocked(GridIndices.Offset(direction.ToDirection()), direction.GetOpposite()))
+ if (!BlockedAirflow.HasFlag(direction) && !_gridAtmosphereComponent.IsAirBlocked(GridIndices.Offset(direction.ToDirection()), direction.GetOpposite()))
{
_adjacentBits |= direction;
}
diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs
index a485659b6e..0d203f3330 100644
--- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs
+++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs
@@ -9,10 +9,12 @@ using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Shared.Atmos;
using Content.Shared.Maps;
+using Robust.Server.GameObjects.EntitySystems.TileLookup;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Map;
using Robust.Shared.GameObjects.Components.Transform;
+using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
@@ -223,20 +225,19 @@ namespace Content.Server.GameObjects.Components.Atmos
}
else
{
- var obs = GetObstructingComponent(indices);
-
- if (obs != null)
+ if (tile.Air == null && NeedsVacuumFixing(indices))
{
- if (tile.Air == null && obs.FixVacuum)
- {
- FixVacuum(tile.GridIndices);
- }
+ FixVacuum(tile.GridIndices);
}
tile.Air ??= new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
}
AddActiveTile(tile);
+ tile.BlockedAirflow = GetBlockedDirections(indices);
+
+ // TODO ATMOS: Query all the contents of this tile (like walls) and calculate the correct thermal conductivity
+ tile.ThermalConductivity = tile.Tile?.Tile.GetContentTileDefinition().ThermalConductivity ?? 0.5f;
tile.UpdateAdjacent();
tile.UpdateVisuals();
@@ -283,6 +284,7 @@ namespace Content.Server.GameObjects.Components.Atmos
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void AddActiveTile(TileAtmosphere? tile)
{
+ // TODO ATMOS Optimization: Cache the grid Id for faster superconduction. Do the same for all the other ones.
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return;
if (tile?.GridIndex != mapGrid.Grid.Index) return;
tile.Excited = true;
@@ -404,8 +406,16 @@ namespace Content.Server.GameObjects.Components.Atmos
///
public bool IsAirBlocked(MapIndices indices, AtmosDirection direction = AtmosDirection.All)
{
- var ac = GetObstructingComponent(indices);
- return ac != null && ac.AirBlocked && ac.AirBlockedDirection.HasFlag(direction);
+ foreach (var obstructingComponent in GetObstructingComponents(indices))
+ {
+ if (!obstructingComponent.AirBlocked)
+ continue;
+
+ if (obstructingComponent.AirBlockedDirection.HasFlag(direction))
+ return true;
+ }
+
+ return false;
}
///
@@ -769,17 +779,45 @@ namespace Content.Server.GameObjects.Components.Atmos
return true;
}
- private AirtightComponent? GetObstructingComponent(MapIndices indices)
+ private IEnumerable GetObstructingComponents(MapIndices indices)
{
- if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return default;
+ if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return Enumerable.Empty();
- foreach (var v in mapGrid.Grid.GetSnapGridCell(indices, SnapGridOffset.Center))
+ var gridLookup = EntitySystem.Get();
+
+ var list = new List();
+
+ foreach (var v in gridLookup.GetEntitiesIntersecting(mapGrid.GridIndex, indices))
{
- if (v.Owner.TryGetComponent(out var ac))
- return ac;
+ if (v.TryGetComponent(out var ac))
+ list.Add(ac);
}
- return null;
+ return list;
+ }
+
+ private bool NeedsVacuumFixing(MapIndices indices)
+ {
+ var value = false;
+
+ foreach (var airtightComponent in GetObstructingComponents(indices))
+ {
+ value |= airtightComponent.FixVacuum;
+ }
+
+ return value;
+ }
+
+ private AtmosDirection GetBlockedDirections(MapIndices indices)
+ {
+ var value = AtmosDirection.Invalid;
+
+ foreach (var airtightComponent in GetObstructingComponents(indices))
+ {
+ value |= airtightComponent.AirBlockedDirection;
+ }
+
+ return value;
}
public void Dispose()