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 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 void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||
{
|
||||
@@ -322,4 +376,63 @@ namespace Content.Server.Atmos
|
||||
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
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Content.Server.Interfaces;
|
||||
@@ -520,9 +521,10 @@ namespace Content.Server.Atmos
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return Equals(_moles, other._moles)
|
||||
&& Equals(_molesArchived, other._molesArchived)
|
||||
return _moles.SequenceEqual(other._moles)
|
||||
&& _molesArchived.SequenceEqual(other._molesArchived)
|
||||
&& _temperature.Equals(other._temperature)
|
||||
&& ReactionResults.SequenceEqual(other.ReactionResults)
|
||||
&& Immutable == other.Immutable
|
||||
&& LastShare.Equals(other.LastShare)
|
||||
&& TemperatureArchived.Equals(other.TemperatureArchived)
|
||||
@@ -531,12 +533,28 @@ namespace Content.Server.Atmos
|
||||
|
||||
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()
|
||||
{
|
||||
return new GasMixture()
|
||||
var newMixture = new GasMixture()
|
||||
{
|
||||
_moles = (float[])_moles.Clone(),
|
||||
_molesArchived = (float[])_molesArchived.Clone(),
|
||||
@@ -546,6 +564,7 @@ namespace Content.Server.Atmos
|
||||
TemperatureArchived = TemperatureArchived,
|
||||
Volume = Volume,
|
||||
};
|
||||
return newMixture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user