Unique gas serialization for atmos (#1629)
* Add unique gas mixture serialization for atmos * Refactor doAfterEventArgs * Adds atmos commands * Roundstard now has correct ratio of gases * Fixed hashcode for gasmixture, better grid atmos serialization * Airlocks create gas based on adjacent tiles now. * Enables barotrauma component damage
This commit is contained in:
committed by
GitHub
parent
4fe1083bfb
commit
7293d985a5
@@ -21,6 +21,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
public override string Name => "Airtight";
|
||||
|
||||
private bool _airBlocked = true;
|
||||
private bool _fixVacuum = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool AirBlocked
|
||||
@@ -33,11 +34,15 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public bool FixVacuum => _fixVacuum;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _airBlocked, "airBlocked", true);
|
||||
serializer.DataField(ref _fixVacuum, "fixVacuum", false);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
@@ -50,8 +51,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
if(pressure > Atmospherics.WarningLowPressure)
|
||||
goto default;
|
||||
|
||||
// TODO ATMOS Uncomment this when saltern is pressurized
|
||||
//damageable.TakeDamage(DamageType.Brute, Atmospherics.LowPressureDamage, Owner, null);
|
||||
damageable.TakeDamage(DamageType.Brute, Atmospherics.LowPressureDamage, Owner);
|
||||
|
||||
if (status == null) break;
|
||||
|
||||
@@ -73,8 +73,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
|
||||
var damage = (int) MathF.Min((pressure / Atmospherics.HazardHighPressure) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
|
||||
|
||||
// TODO ATMOS Uncomment this when saltern is pressurized
|
||||
//damageable.TakeDamage(DamageType.Brute, damage, Owner, null);
|
||||
damageable.TakeDamage(DamageType.Brute, damage, Owner);
|
||||
|
||||
if (status == null) break;
|
||||
|
||||
|
||||
@@ -122,8 +122,6 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
|
||||
public void RepopulateTiles()
|
||||
{
|
||||
_tiles.Clear();
|
||||
|
||||
foreach (var tile in _grid.GetAllTiles())
|
||||
{
|
||||
if(!_tiles.ContainsKey(tile.GridIndices))
|
||||
@@ -160,13 +158,34 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
tile.Air = new GasMixture(GetVolumeForCells(1));
|
||||
tile.Air.MarkImmutable();
|
||||
|
||||
} else if (IsAirBlocked(indices))
|
||||
{
|
||||
tile.Air = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.Air ??= new GasMixture(GetVolumeForCells(1));
|
||||
var obs = GetObstructingComponent(indices);
|
||||
|
||||
if (obs != null)
|
||||
{
|
||||
if (tile.Air == null && obs.FixVacuum)
|
||||
{
|
||||
var adjacent = GetAdjacentTiles(indices);
|
||||
tile.Air = new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
|
||||
|
||||
var ratio = 1f / adjacent.Count;
|
||||
|
||||
foreach (var (direction, adj) in adjacent)
|
||||
{
|
||||
var mix = adj.Air.RemoveRatio(ratio);
|
||||
tile.Air.Merge(mix);
|
||||
adj.Air.Merge(mix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tile.Air ??= new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
|
||||
}
|
||||
|
||||
tile.UpdateAdjacent();
|
||||
@@ -290,7 +309,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
foreach (var dir in Cardinal())
|
||||
{
|
||||
var side = indices.Offset(dir);
|
||||
sides[dir] = GetTile(side);
|
||||
var tile = GetTile(side);
|
||||
if(tile?.Air != null)
|
||||
sides[dir] = tile;
|
||||
}
|
||||
|
||||
return sides;
|
||||
@@ -475,6 +496,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
if (!serializer.TryReadDataField("uniqueMixes", out List<GasMixture> uniqueMixes) ||
|
||||
!serializer.TryReadDataField("tiles", out Dictionary<MapIndices, int> tiles))
|
||||
return;
|
||||
|
||||
_tiles.Clear();
|
||||
|
||||
foreach (var (indices, mix) in tiles)
|
||||
{
|
||||
_tiles.Add(indices, new TileAtmosphere(this, gridId, indices, (GasMixture)uniqueMixes[mix].Clone()));
|
||||
@@ -483,12 +507,22 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
} else if (serializer.Writing)
|
||||
{
|
||||
var uniqueMixes = new List<GasMixture>();
|
||||
var uniqueMixHash = new Dictionary<GasMixture, int>();
|
||||
var tiles = new Dictionary<MapIndices, int>();
|
||||
foreach (var (indices, tile) in _tiles)
|
||||
{
|
||||
if (tile.Air == null) continue;
|
||||
|
||||
if (uniqueMixHash.TryGetValue(tile.Air, out var index))
|
||||
{
|
||||
tiles[indices] = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
uniqueMixes.Add(tile.Air);
|
||||
tiles[indices] = uniqueMixes.Count - 1;
|
||||
var newIndex = uniqueMixes.Count - 1;
|
||||
uniqueMixHash[tile.Air] = newIndex;
|
||||
tiles[indices] = newIndex;
|
||||
}
|
||||
|
||||
serializer.DataField(ref uniqueMixes, "uniqueMixes", new List<GasMixture>());
|
||||
|
||||
Reference in New Issue
Block a user