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
@@ -259,10 +259,64 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SetTemperature : IClientCommand
|
public class ClearAtmos : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "clearatmos";
|
||||||
|
public string Description => "Clear a grid of all gases.";
|
||||||
|
public string Help => "clearatmos <GridId>";
|
||||||
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length < 1) return;
|
||||||
|
if (!int.TryParse(args[0], out var id))
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Not enough arguments!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var gridId = new GridId(id);
|
||||||
|
|
||||||
|
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||||
|
|
||||||
|
if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp))
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Invalid grid ID.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
|
if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid))
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Failed to get grid entity.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!grid.HasComponent<GridAtmosphereComponent>())
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Grid doesn't have an atmosphere.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var gam = grid.GetComponent<GridAtmosphereComponent>();
|
||||||
|
|
||||||
|
var tiles = 0;
|
||||||
|
var moles = 0f;
|
||||||
|
foreach (var tile in gam)
|
||||||
|
{
|
||||||
|
if (tile.Air.Immutable) continue;
|
||||||
|
tiles++;
|
||||||
|
moles += tile.Air.TotalMoles;
|
||||||
|
tile.Air.RemoveRatio(1f);
|
||||||
|
gam.Invalidate(tile.GridIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.SendText(player, $"Removed {moles} moles from {tiles} tiles.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SetTemperature : IClientCommand
|
||||||
{
|
{
|
||||||
public string Command => "settemp";
|
public string Command => "settemp";
|
||||||
public string Description => "Sets a tile's temperature.";
|
public string Description => "Sets a tile's temperature (in kelvin).";
|
||||||
public string Help => "Usage: settemp <X> <Y> <GridId> <Temperature>";
|
public string Help => "Usage: settemp <X> <Y> <GridId> <Temperature>";
|
||||||
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||||
{
|
{
|
||||||
@@ -322,4 +376,63 @@ namespace Content.Server.Atmos
|
|||||||
gam.Invalidate(indices);
|
gam.Invalidate(indices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SetAtmosTemperature : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "setatmostemp";
|
||||||
|
public string Description => "Sets a grid's temperature (in kelvin).";
|
||||||
|
public string Help => "Usage: setatmostemp <GridId> <Temperature>";
|
||||||
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length < 2) return;
|
||||||
|
if(!int.TryParse(args[0], out var id)
|
||||||
|
|| !float.TryParse(args[1], out var temperature)) return;
|
||||||
|
|
||||||
|
var gridId = new GridId(id);
|
||||||
|
|
||||||
|
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||||
|
|
||||||
|
if (temperature < Atmospherics.TCMB)
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Invalid temperature.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp))
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Invalid grid ID.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
|
if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid))
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Failed to get grid entity.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!grid.HasComponent<GridAtmosphereComponent>())
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Grid doesn't have an atmosphere.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var gam = grid.GetComponent<GridAtmosphereComponent>();
|
||||||
|
|
||||||
|
var tiles = 0;
|
||||||
|
foreach (var tile in gam)
|
||||||
|
{
|
||||||
|
if (tile.Air == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
tiles++;
|
||||||
|
|
||||||
|
tile.Air.Temperature = temperature;
|
||||||
|
gam.Invalidate(tile.GridIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.SendText(player, $"Changed the temperature of {tiles} tiles.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Content.Server.Atmos.Reactions;
|
using Content.Server.Atmos.Reactions;
|
||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
@@ -520,9 +521,10 @@ namespace Content.Server.Atmos
|
|||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other)) return false;
|
||||||
if (ReferenceEquals(this, other)) return true;
|
if (ReferenceEquals(this, other)) return true;
|
||||||
return Equals(_moles, other._moles)
|
return _moles.SequenceEqual(other._moles)
|
||||||
&& Equals(_molesArchived, other._molesArchived)
|
&& _molesArchived.SequenceEqual(other._molesArchived)
|
||||||
&& _temperature.Equals(other._temperature)
|
&& _temperature.Equals(other._temperature)
|
||||||
|
&& ReactionResults.SequenceEqual(other.ReactionResults)
|
||||||
&& Immutable == other.Immutable
|
&& Immutable == other.Immutable
|
||||||
&& LastShare.Equals(other.LastShare)
|
&& LastShare.Equals(other.LastShare)
|
||||||
&& TemperatureArchived.Equals(other.TemperatureArchived)
|
&& TemperatureArchived.Equals(other.TemperatureArchived)
|
||||||
@@ -531,12 +533,28 @@ namespace Content.Server.Atmos
|
|||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return HashCode.Combine(_moles, _molesArchived, _temperature, Immutable, LastShare, TemperatureArchived, Volume);
|
var hashCode = new HashCode();
|
||||||
|
|
||||||
|
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
||||||
|
{
|
||||||
|
var moles = _moles[i];
|
||||||
|
var molesArchived = _molesArchived[i];
|
||||||
|
hashCode.Add(moles);
|
||||||
|
hashCode.Add(molesArchived);
|
||||||
|
}
|
||||||
|
|
||||||
|
hashCode.Add(_temperature);
|
||||||
|
hashCode.Add(TemperatureArchived);
|
||||||
|
hashCode.Add(Immutable);
|
||||||
|
hashCode.Add(LastShare);
|
||||||
|
hashCode.Add(Volume);
|
||||||
|
|
||||||
|
return hashCode.ToHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Clone()
|
public object Clone()
|
||||||
{
|
{
|
||||||
return new GasMixture()
|
var newMixture = new GasMixture()
|
||||||
{
|
{
|
||||||
_moles = (float[])_moles.Clone(),
|
_moles = (float[])_moles.Clone(),
|
||||||
_molesArchived = (float[])_molesArchived.Clone(),
|
_molesArchived = (float[])_molesArchived.Clone(),
|
||||||
@@ -546,6 +564,7 @@ namespace Content.Server.Atmos
|
|||||||
TemperatureArchived = TemperatureArchived,
|
TemperatureArchived = TemperatureArchived,
|
||||||
Volume = Volume,
|
Volume = Volume,
|
||||||
};
|
};
|
||||||
|
return newMixture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
public override string Name => "Airtight";
|
public override string Name => "Airtight";
|
||||||
|
|
||||||
private bool _airBlocked = true;
|
private bool _airBlocked = true;
|
||||||
|
private bool _fixVacuum = false;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool AirBlocked
|
public bool AirBlocked
|
||||||
@@ -33,11 +34,15 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public bool FixVacuum => _fixVacuum;
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
|
|
||||||
serializer.DataField(ref _airBlocked, "airBlocked", true);
|
serializer.DataField(ref _airBlocked, "airBlocked", true);
|
||||||
|
serializer.DataField(ref _fixVacuum, "fixVacuum", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Mobs;
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces.GameObjects;
|
using Content.Server.Interfaces.GameObjects;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
|
using Content.Shared.GameObjects;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
@@ -50,8 +51,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
if(pressure > Atmospherics.WarningLowPressure)
|
if(pressure > Atmospherics.WarningLowPressure)
|
||||||
goto default;
|
goto default;
|
||||||
|
|
||||||
// TODO ATMOS Uncomment this when saltern is pressurized
|
damageable.TakeDamage(DamageType.Brute, Atmospherics.LowPressureDamage, Owner);
|
||||||
//damageable.TakeDamage(DamageType.Brute, Atmospherics.LowPressureDamage, Owner, null);
|
|
||||||
|
|
||||||
if (status == null) break;
|
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);
|
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);
|
||||||
//damageable.TakeDamage(DamageType.Brute, damage, Owner, null);
|
|
||||||
|
|
||||||
if (status == null) break;
|
if (status == null) break;
|
||||||
|
|
||||||
|
|||||||
@@ -122,8 +122,6 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
|
|
||||||
public void RepopulateTiles()
|
public void RepopulateTiles()
|
||||||
{
|
{
|
||||||
_tiles.Clear();
|
|
||||||
|
|
||||||
foreach (var tile in _grid.GetAllTiles())
|
foreach (var tile in _grid.GetAllTiles())
|
||||||
{
|
{
|
||||||
if(!_tiles.ContainsKey(tile.GridIndices))
|
if(!_tiles.ContainsKey(tile.GridIndices))
|
||||||
@@ -160,13 +158,34 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
{
|
{
|
||||||
tile.Air = new GasMixture(GetVolumeForCells(1));
|
tile.Air = new GasMixture(GetVolumeForCells(1));
|
||||||
tile.Air.MarkImmutable();
|
tile.Air.MarkImmutable();
|
||||||
|
|
||||||
} else if (IsAirBlocked(indices))
|
} else if (IsAirBlocked(indices))
|
||||||
{
|
{
|
||||||
tile.Air = null;
|
tile.Air = null;
|
||||||
}
|
}
|
||||||
else
|
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();
|
tile.UpdateAdjacent();
|
||||||
@@ -290,7 +309,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
foreach (var dir in Cardinal())
|
foreach (var dir in Cardinal())
|
||||||
{
|
{
|
||||||
var side = indices.Offset(dir);
|
var side = indices.Offset(dir);
|
||||||
sides[dir] = GetTile(side);
|
var tile = GetTile(side);
|
||||||
|
if(tile?.Air != null)
|
||||||
|
sides[dir] = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sides;
|
return sides;
|
||||||
@@ -475,6 +496,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
if (!serializer.TryReadDataField("uniqueMixes", out List<GasMixture> uniqueMixes) ||
|
if (!serializer.TryReadDataField("uniqueMixes", out List<GasMixture> uniqueMixes) ||
|
||||||
!serializer.TryReadDataField("tiles", out Dictionary<MapIndices, int> tiles))
|
!serializer.TryReadDataField("tiles", out Dictionary<MapIndices, int> tiles))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_tiles.Clear();
|
||||||
|
|
||||||
foreach (var (indices, mix) in tiles)
|
foreach (var (indices, mix) in tiles)
|
||||||
{
|
{
|
||||||
_tiles.Add(indices, new TileAtmosphere(this, gridId, indices, (GasMixture)uniqueMixes[mix].Clone()));
|
_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)
|
} else if (serializer.Writing)
|
||||||
{
|
{
|
||||||
var uniqueMixes = new List<GasMixture>();
|
var uniqueMixes = new List<GasMixture>();
|
||||||
|
var uniqueMixHash = new Dictionary<GasMixture, int>();
|
||||||
var tiles = new Dictionary<MapIndices, int>();
|
var tiles = new Dictionary<MapIndices, int>();
|
||||||
foreach (var (indices, tile) in _tiles)
|
foreach (var (indices, tile) in _tiles)
|
||||||
{
|
{
|
||||||
if (tile.Air == null) continue;
|
if (tile.Air == null) continue;
|
||||||
|
|
||||||
|
if (uniqueMixHash.TryGetValue(tile.Air, out var index))
|
||||||
|
{
|
||||||
|
tiles[indices] = index;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
uniqueMixes.Add(tile.Air);
|
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>());
|
serializer.DataField(ref uniqueMixes, "uniqueMixes", new List<GasMixture>());
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ namespace Content.Shared.Atmos
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const float MolesCellStandard = (OneAtmosphere * CellVolume / (T20C * R));
|
public const float MolesCellStandard = (OneAtmosphere * CellVolume / (T20C * R));
|
||||||
|
|
||||||
|
public const float OxygenStandard = 0.21f;
|
||||||
|
public const float NitrogenStandard = 0.79f;
|
||||||
|
|
||||||
|
public const float OxygenMolesStandard = MolesCellStandard * OxygenStandard;
|
||||||
|
public const float NitrogenMolesStandard = MolesCellStandard * NitrogenStandard;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -176,7 +176,9 @@
|
|||||||
- fillgas
|
- fillgas
|
||||||
- listgases
|
- listgases
|
||||||
- removegas
|
- removegas
|
||||||
|
- clearatmos
|
||||||
- settemp
|
- settemp
|
||||||
|
- setatmostemp
|
||||||
CanViewVar: true
|
CanViewVar: true
|
||||||
CanAdminPlace: true
|
CanAdminPlace: true
|
||||||
CanScript: true
|
CanScript: true
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -52,6 +52,7 @@
|
|||||||
- key: enum.WiresUiKey.Key
|
- key: enum.WiresUiKey.Key
|
||||||
type: WiresBoundUserInterface
|
type: WiresBoundUserInterface
|
||||||
- type: Airtight
|
- type: Airtight
|
||||||
|
fixVacuum: true
|
||||||
adjacentAtmosphere: true
|
adjacentAtmosphere: true
|
||||||
- type: Occluder
|
- type: Occluder
|
||||||
- type: SnapGrid
|
- type: SnapGrid
|
||||||
|
|||||||
Reference in New Issue
Block a user