Files
wwdpublic/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Utils.cs
SimpleStation14 2138b8ac18 Mirror 26441: Fix atmos NaN error (#449)
## Mirror of PR #26441: [Fix atmos NaN
error](https://github.com/space-wizards/space-station-14/pull/26441)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `fdb4a61487db9fc67714c913832427063abdea42`

PR opened by <img
src="https://avatars.githubusercontent.com/u/60421075?v=4"
width="16"/><a href="https://github.com/ElectroJr"> ElectroJr</a> at
2024-03-26 04:27:08 UTC - merged at 2024-03-26 04:44:56 UTC

---

PR changed 16 files with 43 additions and 25 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> - Fixes a bug I introduced in #22521 that caused the temperature to be
set to `NaN`. I don't know for sure, but I assume this is causing the
current atmos issues
> - Fixes `FixVacuum` not working after #22521
> - Removes some redundant yaml that was setting FixVacuum to its
default value
> 
> 🆑
> - fix: Fixed an atmos bug, which was (probably) causing atmospherics
on the station to behave incorrectly.


</details>

Co-authored-by: SimpleStation14 <Unknown>
2024-06-13 15:30:31 -04:00

109 lines
3.6 KiB
C#

using System.Runtime.CompilerServices;
using Content.Server.Atmos.Components;
using Content.Server.Maps;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Components;
using Content.Shared.Maps;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
namespace Content.Server.Atmos.EntitySystems;
public partial class AtmosphereSystem
{
/// <summary>
/// Gets the particular price of an air mixture.
/// </summary>
public double GetPrice(GasMixture mixture)
{
float basePrice = 0; // moles of gas * price/mole
float totalMoles = 0; // total number of moles in can
float maxComponent = 0; // moles of the dominant gas
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
{
basePrice += mixture.Moles[i] * GetGas(i).PricePerMole;
totalMoles += mixture.Moles[i];
maxComponent = Math.Max(maxComponent, mixture.Moles[i]);
}
// Pay more for gas canisters that are more pure
float purity = 1;
if (totalMoles > 0) {
purity = maxComponent / totalMoles;
}
return basePrice * purity;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InvalidateVisuals(EntityUid gridUid, Vector2i tile, GasTileOverlayComponent? comp = null)
{
_gasTileOverlaySystem.Invalidate(gridUid, tile, comp);
}
/// <summary>
/// Gets the volume in liters for a number of tiles, on a specific grid.
/// </summary>
/// <param name="mapGrid">The grid in question.</param>
/// <param name="tiles">The amount of tiles.</param>
/// <returns>The volume in liters that the tiles occupy.</returns>
private float GetVolumeForTiles(MapGridComponent mapGrid, int tiles = 1)
{
return Atmospherics.CellVolume * mapGrid.TileSize * tiles;
}
public readonly record struct AirtightData(AtmosDirection BlockedDirections, bool NoAirWhenBlocked,
bool FixVacuum);
private void UpdateAirtightData(EntityUid uid, GridAtmosphereComponent atmos, MapGridComponent grid, TileAtmosphere tile)
{
var oldBlocked = tile.AirtightData.BlockedDirections;
tile.AirtightData = tile.NoGridTile
? default
: GetAirtightData(uid, grid, tile.GridIndices);
if (tile.AirtightData.BlockedDirections != oldBlocked && tile.ExcitedGroup != null)
ExcitedGroupDispose(atmos, tile.ExcitedGroup);
}
private AirtightData GetAirtightData(EntityUid uid, MapGridComponent grid, Vector2i tile)
{
var blockedDirs = AtmosDirection.Invalid;
var noAirWhenBlocked = false;
var fixVacuum = false;
foreach (var ent in _map.GetAnchoredEntities(uid, grid, tile))
{
if (!_airtightQuery.TryGetComponent(ent, out var airtight))
continue;
fixVacuum |= airtight.FixVacuum;
if(!airtight.AirBlocked)
continue;
blockedDirs |= airtight.AirBlockedDirection;
noAirWhenBlocked |= airtight.NoAirWhenFullyAirBlocked;
if (blockedDirs == AtmosDirection.All && noAirWhenBlocked && fixVacuum)
break;
}
return new AirtightData(blockedDirs, noAirWhenBlocked, fixVacuum);
}
/// <summary>
/// Pries a tile in a grid.
/// </summary>
/// <param name="mapGrid">The grid in question.</param>
/// <param name="tile">The indices of the tile.</param>
private void PryTile(MapGridComponent mapGrid, Vector2i tile)
{
if (!mapGrid.TryGetTileRef(tile, out var tileRef))
return;
_tile.PryTile(tileRef);
}
}