public void SetValues( GUI_AcuThresholdsPage thresholdsPage, int index, ThresholdType type, string thresholdName, float[] values, GasSO gas = default) { this.thresholdsPage = thresholdsPage; Index = index; Type = type; Name = thresholdName; Values = values; Gas = gas; if (type == ThresholdType.Linebreak) { label.SetValueServer(string.Empty); return; } StringBuilder sb = new StringBuilder($"{thresholdName, -14} | ", 55); foreach (float value in values) { // Use a '?' to represent a gas for which the ACU thresholds does not have values for. // Allows a technician to set appropriate values for this discovered gas. sb.Append($"{(float.IsNaN(value) ? "?" : value.ToString()), -7} | "); } label.SetValueServer(sb.Remove(sb.Length - 3, 3).ToString()); }
/// <summary> /// Gets a specific gas from the gas array, returns null if gas isn't in mix /// </summary> public static GasValues GetGasType(this GasData data, GasSO gasType) { if (data.GasesDict.TryGetValue(gasType, out var value)) { return(value); } return(null); }
public void Pool() { GasSO = null; Moles = 0; lock (AtmosUtils.PooledGasValues) { AtmosUtils.PooledGasValues.Add(this); } }
public void SetFilteredGasValue(GasSO GasIndex) { foreach (var INFilter in Filter.CapableFiltering) { if (INFilter.Value == GasIndex) //Checks what button has been pressed And sets the correct position appropriate { ((NetUIElement <string>) this[INFilter.Key]).SetValueServer("1"); } } }
public override void OnSpawnServer(SpawnInfo info) { GasIndex = CapableFiltering[initalFilterValue.ToString()]; if (IsOn) { spriteHandlerOverlay.PushTexture(); } else { spriteHandlerOverlay.PushClear(); } base.OnSpawnServer(info); }
private static void InternalSetMoles(GasData data, GasSO gasType, float moles, bool isChange) { lock (data.GasesArray) //Because it gets the gas and it could be added in between this { //Try to get gas value if already inside mix GetGasType(data, gasType, out var gas); if (gas != null) { if (isChange) { gas.Moles += moles; } else { gas.Moles = moles; } //Remove gas from mix if less than threshold if (gas.Moles <= AtmosConstants.MinPressureDifference) { data.RemoveGasType(gasType); } return; } //Gas isn't inside mix so we'll add it //Dont add new data for negative moles if (Math.Sign(moles) == -1) { return; } //Dont add if approx 0 or below threshold if (moles.Approx(0) || moles <= AtmosConstants.MinPressureDifference) { return; } var newValues = GetGasValues(); newValues.Moles = moles; newValues.GasSO = gasType; data.GasesArray.Add(newValues); data.GasesDict.Add(gasType, newValues); } }
public void BtnToggleGasFilter(int gasIndex) { SetSetting(() => { GasSO gas = Gas.Gases[gasIndex]; if (scrubber.FilteredGases.Contains(gas)) { scrubber.FilteredGases.Remove(gas); } else { scrubber.FilteredGases.Add(gas); } }); }
/// <summary> /// Removes a specific gas type /// </summary> public static void RemoveGasType(this GasData data, GasSO gasType) { lock (data.GasesArray) //no Double lock { for (int i = data.GasesArray.Count - 1; i >= 0; i--) { if (data.GasesArray[i].GasSO == gasType) { data.GasesDict.Remove(gasType); data.GasesArray[i].Pool(); data.GasesArray.RemoveAt(i); return; } } } }
private void ModeScrub() { // Scrub out a portion of each specified gas. // If all these gases exceed transfer amount, reduce each gas scrub mole count proportionally. float scrubbableMolesAvailable = 0; lock (metaNode.GasMix.GasesArray) //no Double lock { foreach (GasValues gas in metaNode.GasMix.GasesArray) //doesn't appear to modify list while iterating { if (FilteredGases.Contains(gas.GasSO)) { scrubbingGasMoles[gas.GasSO] = gas.Moles * (IsExpandedRange ? 0.05f : 0.20f) * Effectiveness; scrubbableMolesAvailable += scrubbingGasMoles[gas.GasSO]; } } } if (scrubbableMolesAvailable.Approx(0)) { return; // No viable gases found } float molesToTransfer = scrubbableMolesAvailable.Clamp(0, nominalMolesTransferCap * Effectiveness); float ratio = molesToTransfer / scrubbableMolesAvailable; ratio = ratio.Clamp(0, 1); // actual scrubbing for (int i = 0; i < Gas.Gases.Count; i++) { GasSO gas = Gas.Gases[i]; float transferAmount = scrubbingGasMoles[i] * ratio; if (transferAmount.Approx(0)) { continue; } metaNode.GasMix.RemoveGas(gas, transferAmount); if (selfSufficient == false) { pipeMix.AddGas(gas, transferAmount); } } Array.Clear(scrubbingGasMoles, 0, scrubbingGasMoles.Length); }
/// <summary> /// Removes a specific gas type /// </summary> public static void RemoveGasType(this GasData data, GasSO gasType) { var newData = new GasValues[data.GasesArray.Length - 1]; var count = 0; foreach (var gas in data.GasesArray) { if (gas.GasSO == gasType) { continue; } newData[count] = gas; count++; } data.GasesArray = newData; data.GasesDict.Remove(gasType); }
public override void OnPeriodicUpdate() { modeLabel.SetValueServer($"Mode: {Acu.DesiredMode}"); UpdateLabels(); var gasesToDisplay = new List <GasValues>(Acu.AtmosphericAverage.GetGases()); gasesToDisplay.Sort((gasA, gasB) => gasB.Moles.CompareTo(gasA.Moles)); if (metricsContainer.Entries.Length != gasesToDisplay.Count) { metricsContainer.SetItems(gasesToDisplay.Count); } for (int i = 0; i < metricsContainer.Entries.Length; i++) { GasSO gas = gasesToDisplay[i].GasSO; float ratio = Acu.AtmosphericAverage.GetGasRatio(gas); float moles = Acu.AtmosphericAverage.GetGasMoles(gas); UpdateGasEntry(i, gas.Name, ratio, moles, Acu.GasLevelStatus[gas]); } }
public void RemoveGasOverlay(GasSO gas) { gasOverlayData.Remove(gas); }
public void AddGasOverlay(GasSO gas) { gasOverlayData.Add(gas); }
/// <summary> /// Gets a specific gas from the gas array, returns null if gas isn't in mix /// </summary> public static void GetGasType(this GasData data, GasSO gasType, out GasValues gasData) { gasData = GetGasType(data, gasType); }
public float GetGasMoles(GasSO gas) { return(SampleSize == 0 ? 0 : gasMolesSum[gas] / SampleSize); }
/// <summary> /// Sets moles for a specific gas to a specific value in the gas data /// </summary> public static void SetMoles(this GasData data, GasSO gasType, float moles) { InternalSetMoles(data, gasType, moles, false); }
/// <summary> /// Adds/Removes moles for a specific gas in the gas data /// </summary> public static void ChangeMoles(this GasData data, GasSO gasType, float moles) { InternalSetMoles(data, gasType, moles, true); }
/// <summary> /// Gets moles of a specific gas from the gas array, returns 0 if gas isn't in mix /// </summary> public static float GetGasMoles(this GasData data, GasSO gasType) { return(GetGasType(data, gasType)?.Moles ?? 0); }
/// <summary> /// Checks to see if the gas mix contains a specific gas /// </summary> public static bool HasGasType(this GasData data, GasSO gasType) { return(data.GasesDict.ContainsKey(gasType)); }
public Reagent GetGasToReagent(GasSO InGas) { CheckState(); return(GasToReagent[InGas]); }
public bool HasGas(GasSO gas) { return(gasMolesSum.ContainsKey(gas)); }
/// <summary> /// Gets moles of a specific gas from the gas array, returns 0 if gas isn't in mix /// </summary> public static void GetGasMoles(this GasData data, GasSO gasType, out float gasMoles) { gasMoles = GetGasMoles(data, gasType); }
/// <summary> /// Gets the ratio, as a decimal, of the moles for the given gas in the atmospheric average. /// </summary> /// <returns>(decimal) moles ratio</returns> public float GetGasRatio(GasSO gas) { var sum = gasMolesSum.Sum(kvp => kvp.Value); return(sum == 0 ? 0 : gasMolesSum[gas] / sum); }
private static void InternalSetMoles(GasData data, GasSO gasType, float moles, bool isChange) { //Try to get gas value if already inside mix GetGasType(data, gasType, out var gas); if (gas != null) { if (isChange) { gas.Moles += moles; } else { gas.Moles = moles; } //Remove gas from mix if less than threshold if (gas.Moles <= AtmosConstants.MinPressureDifference) { data.RemoveGasType(gasType); } return; } //Gas isn't inside mix so we'll add it //Dont add new data for negative moles if (Math.Sign(moles) == -1) { return; } //Dont add if approx 0 or below threshold if (moles.Approx(0) || moles <= AtmosConstants.MinPressureDifference) { return; } //Create new array and add old gas values and new gas var newValues = new GasValues { Moles = moles, GasSO = gasType }; var newArray = new GasValues[data.GasesArray.Length + 1]; for (int i = 0; i < newArray.Length; i++) { if (data.GasesArray.Length == i) { newArray[i] = newValues; //Should only happen on last index since we are adding only one thing so can break break; } newArray[i] = data.GasesArray[i]; } data.GasesArray = newArray; data.GasesDict.Add(gasType, newValues); }