using System.Runtime.CompilerServices; using Content.Server.Atmos.Components; using Content.Shared.Atmos; using Content.Shared.Maps; using Robust.Shared.Map; namespace Content.Server.Atmos.EntitySystems; public partial class AtmosphereSystem { /// /// Gets the particular price of an air mixture. /// 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) { _gasTileOverlaySystem.Invalidate(gridUid, tile); } public bool NeedsVacuumFixing(IMapGrid mapGrid, Vector2i indices) { var value = false; var enumerator = GetObstructingComponentsEnumerator(mapGrid, indices); while (enumerator.MoveNext(out var airtight)) { value |= airtight.FixVacuum; } return value; } /// /// Gets the volume in liters for a number of tiles, on a specific grid. /// /// The grid in question. /// The amount of tiles. /// The volume in liters that the tiles occupy. private float GetVolumeForTiles(IMapGrid mapGrid, int tiles = 1) { return Atmospherics.CellVolume * mapGrid.TileSize * tiles; } /// /// Gets all obstructing instances in a specific tile. /// /// The grid where to get the tile. /// The indices of the tile. /// The enumerator for the airtight components. public AtmosObstructionEnumerator GetObstructingComponentsEnumerator(IMapGrid mapGrid, Vector2i tile) { var ancEnumerator = mapGrid.GetAnchoredEntitiesEnumerator(tile); var airQuery = GetEntityQuery(); var enumerator = new AtmosObstructionEnumerator(ancEnumerator, airQuery); return enumerator; } private AtmosDirection GetBlockedDirections(IMapGrid mapGrid, Vector2i indices) { var value = AtmosDirection.Invalid; var enumerator = GetObstructingComponentsEnumerator(mapGrid, indices); while (enumerator.MoveNext(out var airtight)) { if(airtight.AirBlocked) value |= airtight.AirBlockedDirection; } return value; } /// /// Pries a tile in a grid. /// /// The grid in question. /// The indices of the tile. private void PryTile(IMapGrid mapGrid, Vector2i tile) { if (!mapGrid.TryGetTileRef(tile, out var tileRef)) return; tileRef.PryTile(_mapManager, _tileDefinitionManager, EntityManager, _robustRandom); } }