public void PumpToxins(GasMixture to) { if (!Owner.TryGetComponent(out MetabolismComponent metabolism)) { to.Merge(Air); Air.Clear(); return; } var toxins = metabolism.Clean(this); var toOld = to.Gases.ToArray(); to.Merge(toxins); for (var i = 0; i < toOld.Length; i++) { var newAmount = to.GetMoles(i); var oldAmount = toOld[i]; var delta = newAmount - oldAmount; toxins.AdjustMoles(i, -delta); } Air.Merge(toxins); }
public void Exhale(float frameTime, GasMixture to) { // TODO: Make the bloodstream separately pump toxins into the lungs, making the lungs' only job to empty. if (Body == null) { return; } if (!Body.Owner.TryGetComponent(out BloodstreamComponent? bloodstream)) { return; } bloodstream.PumpToxins(Air); var lungRemoved = Air.RemoveRatio(0.5f); var toOld = to.Gases.ToArray(); to.Merge(lungRemoved); for (var gas = 0; gas < Atmospherics.TotalNumberOfGases; gas++) { var newAmount = to.GetMoles(gas); var oldAmount = toOld[gas]; var delta = newAmount - oldAmount; lungRemoved.AdjustMoles(gas, -delta); } Air.Merge(lungRemoved); }
public async Task TestMerge() { var server = StartServerDummyTicker(); server.Assert(() => { var a = new GasMixture(10f); var b = new GasMixture(10f); a.AdjustMoles(Gas.Oxygen, 50); b.AdjustMoles(Gas.Nitrogen, 50); // a now has 50 moles of oxygen Assert.That(a.TotalMoles, Is.EqualTo(50)); Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(50)); // b now has 50 moles of nitrogen Assert.That(b.TotalMoles, Is.EqualTo(50)); Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(50)); b.Merge(a); // b now has its contents and the contents of a Assert.That(b.TotalMoles, Is.EqualTo(100)); Assert.That(b.GetMoles(Gas.Oxygen), Is.EqualTo(50)); Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(50)); // a should be the same, however. Assert.That(a.TotalMoles, Is.EqualTo(50)); Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(50)); }); await server.WaitIdleAsync(); }
private void OnBeforeUnanchored(EntityUid uid, AtmosUnsafeUnanchorComponent component, BeforeUnanchoredEvent args) { if (!component.Enabled || !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodes)) { return; } if (!component.Owner.Transform.Coordinates.TryGetTileAtmosphere(out var environment)) { environment = null; } var environmentPressure = environment?.Air?.Pressure ?? 0f; var environmentVolume = environment?.Air?.Volume ?? Atmospherics.CellVolume; var environmentTemperature = environment?.Air?.Volume ?? Atmospherics.TCMB; var lost = 0f; var timesLost = 0; foreach (var node in nodes.Nodes.Values) { if (node is not PipeNode pipe) { continue; } var difference = pipe.Air.Pressure - environmentPressure; lost += difference * environmentVolume / (environmentTemperature * Atmospherics.R); timesLost++; } var sharedLoss = lost / timesLost; var buffer = new GasMixture(); foreach (var node in nodes.Nodes.Values) { if (node is not PipeNode pipe) { continue; } buffer.Merge(pipe.Air.Remove(sharedLoss)); } environment?.AssumeAir(buffer); }
public void Transfer(GasMixture from, GasMixture to, float ratio) { var removed = from.RemoveRatio(ratio); var toOld = to.Gases.ToArray(); to.Merge(removed); for (var gas = 0; gas < Atmospherics.TotalNumberOfGases; gas++) { var newAmount = to.GetMoles(gas); var oldAmount = toOld[gas]; var delta = newAmount - oldAmount; removed.AdjustMoles(gas, -delta); } from.Merge(removed); }
public void Exhale(float frameTime, GasMixture to) { // TODO: Make the bloodstream separately pump toxins into the lungs, making the lungs' only job to empty. if (Body == null) { return; } if (!Body.Owner.TryGetComponent(out BloodstreamComponent? bloodstream)) { return; } bloodstream.PumpToxins(Air); var lungRemoved = Air.RemoveRatio(0.5f); to.Merge(lungRemoved); }
public void Transfer(GasMixture from, GasMixture to, float ratio) { to.Merge(from.RemoveRatio(ratio)); }
protected override void VentGas(GasMixture inletGas, GasMixture outletGas) { outletGas.Merge(inletGas); inletGas.Clear(); }