public GasMix RemoveGasReturn(Gas gas, float moles) { Gases[gas] -= moles; Recalculate(); return(this); }
private static bool GasMoving(Tuple <int, int> Tile) { List <List <int> > AdjacentTilesAndItself = Globals.DictionaryOfAdjacents[Tile]; var TileList = new List <int> { Tile.Item1, Tile.Item2 }; var MixCalculationDictionary = new Dictionary <Gas, float>(); var JMCalculationDictionary = new Dictionary <Gas, float>(); var RemoveTile = false; var TileWorkingOn = new List <List <int> >(); var keyToDelete = new List <Gas>(); var Decay = true; var IsSpace = false; var MolesAll = 0f; var Temperature = 0f; var Count = 0; //float Pressure; for (var d = 0; d < AdjacentTilesAndItself.Count; d++) { if (Globals.TileData[AdjacentTilesAndItself[d][0], AdjacentTilesAndItself[d][1]].Space) { IsSpace = true; break; } if (Globals.TileData[AdjacentTilesAndItself[d][0], AdjacentTilesAndItself[d][1]].Obstructed == false) { Tuple <int, int> TileInWorkTuple = Tuple.Create(AdjacentTilesAndItself[d][0], AdjacentTilesAndItself[d][1]); //for (var j = 0; j < tiles.GetLength(1); j++) foreach (KeyValuePair <Gas, float> KeyValue in Globals.AirMixes[TileInWorkTuple]) { if (MixCalculationDictionary.TryGetValue(KeyValue.Key, out float MixCalculationDictionarykey)) { } else { MixCalculationDictionarykey = 0; } if (JMCalculationDictionary.TryGetValue(KeyValue.Key, out float JMCalculationDictionarykey)) { } else { JMCalculationDictionarykey = 0; } MixCalculationDictionary[KeyValue.Key] = KeyValue.Value + MixCalculationDictionarykey; //*************** JMCalculationDictionary[KeyValue.Key] = Globals.TileData[AdjacentTilesAndItself[d][0], AdjacentTilesAndItself[d][1]].Temperature * KeyValue.Value * KeyValue.Key.HeatCapacity + JMCalculationDictionarykey; //*************** if (KeyValue.Value < 0.000000000000001) { keyToDelete.Add(KeyValue.Key); } } if (0.01f < Math.Abs(Globals.TileData[TileList[0], TileList[1]].Pressure - Globals.TileData[AdjacentTilesAndItself[d][0], AdjacentTilesAndItself[d][1]].Pressure)) { Decay = false; } Count += 1; TileWorkingOn.Add(AdjacentTilesAndItself[d]); } } if (IsSpace == false) { foreach (KeyValuePair <Gas, float> KeyValue in MixCalculationDictionary) { float KeyMixWorkedOut = MixCalculationDictionary[KeyValue.Key] / Count; MolesAll += KeyMixWorkedOut; JMCalculationDictionary[KeyValue.Key] = JMCalculationDictionary[KeyValue.Key] / KeyValue.Key.HeatCapacity / KeyMixWorkedOut / JMCalculationDictionary.Count; Globals.AirMixes[Tile][KeyValue.Key] = KeyMixWorkedOut; Temperature += JMCalculationDictionary[KeyValue.Key] / Count; if (KeyValue.Key == Gas.Plasma) { if (KeyValue.Value > 0.0f) // This needs tweaking to find what the minimum amount of plasma is needed For a reaction is { Globals.TilesWithPlasmaSet.Add(Tile); } //Globals.TilesWithPlasmaSet.Add(Tile) } } //Pressure = (((MolesAll * Globals.GasConstant * Temperature) / 2) / 1000); for (var i = 0; i < keyToDelete.Count; i++) { Gas Key = keyToDelete[i]; try { Globals.AirMixes[Tile].Remove(Key); } catch (KeyNotFoundException) { } } for (var j = 0; j < TileWorkingOn.Count(); j++) { if (Globals.TileData[TileWorkingOn[j][0], TileWorkingOn[j][1]].Space == false) { Tuple <int, int> TileApplyingTuple = Tuple.Create(TileWorkingOn[j][0], TileWorkingOn[j][1]); Globals.AirMixes[TileApplyingTuple] = new Dictionary <Gas, float>(Globals.AirMixes[Tile]); Globals.TileData[TileWorkingOn[j][0], TileWorkingOn[j][1]].Temperature = Temperature; Globals.TileData[TileWorkingOn[j][0], TileWorkingOn[j][1]].Moles = MolesAll; //Globals.TileData[AdjacentTilesAndItself[j][0],AdjacentTilesAndItself[j][1]].Pressure = Pressure; } } } else { for (var j = 0; j < AdjacentTilesAndItself.Count(); j++) { Tuple <int, int> TileApplyingTuple = Tuple.Create(AdjacentTilesAndItself[j][0], AdjacentTilesAndItself[j][1]); Globals.AirMixes[TileApplyingTuple] = new Dictionary <Gas, float>(Globals.SpaceMix); Globals.TileData[AdjacentTilesAndItself[j][0], AdjacentTilesAndItself[j][1]].Temperature = 2.7f; Globals.TileData[AdjacentTilesAndItself[j][0], AdjacentTilesAndItself[j][1]].Moles = 0.000000000000281f; //Globals.TileData[AdjacentTilesAndItself[j][0], AdjacentTilesAndItself[j][1]].Pressure = 0.000000316f; } } if (Decay) { //Console.WriteLine(Tile); if (Globals.CheckCountDictionaryMoving[Tile] >= 3) { RemoveTile = true; Globals.CheckCountDictionaryMoving[Tile] = 0; } else { Globals.CheckCountDictionaryMoving[Tile] += 1; } } return(RemoveTile); }
public GasMix AddGasReturn(Gas gas, float moles) { Gases[gas] += moles; Recalculate(); return(this); }
public void AddGas(Gas gas, float moles) { Gases[gas] += moles; Recalculate(); }
/// <summary> /// Set the moles value of a gas inside of a GasMix. /// </summary> /// <param name="gas">The gas you want to set.</param> /// <param name="moles">The amount to set the gas.</param> public void SetGas(Gas gas, float moles) { Gases[gas] = moles; Recalculate(); }
public float GetMoles(Gas gas) { return(Gases[gas]); }
public float GetPressure(Gas gas) { return(Moles > 0 ? Pressure * Gases[gas] / Moles : 0); }