/// <summary> /// Inhales directly from a given mixture. /// </summary> public void TakeGasFrom(EntityUid uid, float frameTime, GasMixture from, LungComponent?lung = null, MechanismComponent?mech = null) { if (!Resolve(uid, ref lung, ref mech)) { return; } var ratio = (Atmospherics.BreathVolume / from.Volume) * frameTime; _atmosSys.Merge(lung.Air, from.RemoveRatio(ratio)); // Push to bloodstream if (mech.Body == null) { return; } if (!EntityManager.TryGetComponent((mech.Body).Owner, out BloodstreamComponent? bloodstream)) { return; } var to = bloodstream.Air; _atmosSys.Merge(to, lung.Air); lung.Air.Clear(); }
public async Task RemoveRatio(float ratio) { var server = StartServer(); server.Assert(() => { var a = new GasMixture(10f); a.AdjustMoles(Gas.Oxygen, 100); a.AdjustMoles(Gas.Nitrogen, 100); var origTotal = a.TotalMoles; // we remove moles from the mixture with a ratio. var b = a.RemoveRatio(ratio); // check that the amount of moles in the original and the new mixture are correct. Assert.That(b.TotalMoles, Is.EqualTo(origTotal * ratio)); Assert.That(a.TotalMoles, Is.EqualTo(origTotal - b.TotalMoles)); Assert.That(b.GetMoles(Gas.Oxygen), Is.EqualTo(100 * ratio)); Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(100 * ratio)); Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(100 - b.GetMoles(Gas.Oxygen))); Assert.That(a.GetMoles(Gas.Nitrogen), Is.EqualTo(100 - b.GetMoles(Gas.Nitrogen))); }); await server.WaitIdleAsync(); }
public async Task RemoveRatio(float ratio) { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; await server.WaitAssertion(() => { var a = new GasMixture(10f); a.AdjustMoles(Gas.Oxygen, 100); a.AdjustMoles(Gas.Nitrogen, 100); var origTotal = a.TotalMoles; // we remove moles from the mixture with a ratio. var b = a.RemoveRatio(ratio); // check that the amount of moles in the original and the new mixture are correct. Assert.That(b.TotalMoles, Is.EqualTo(origTotal *ratio)); Assert.That(a.TotalMoles, Is.EqualTo(origTotal - b.TotalMoles)); Assert.That(b.GetMoles(Gas.Oxygen), Is.EqualTo(100 * ratio)); Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(100 * ratio)); Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(100 - b.GetMoles(Gas.Oxygen))); Assert.That(a.GetMoles(Gas.Nitrogen), Is.EqualTo(100 - b.GetMoles(Gas.Nitrogen))); }); await pairTracker.CleanReturnAsync(); }
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 Transfer(GasMixture from, GasMixture to, float ratio) { to.Merge(from.RemoveRatio(ratio)); }