Example #1
0
        /// <summary>
        /// Calculate the average Gas tile if you averaged all the adjacent ones and itself
        /// </summary>
        /// <returns>The mean gas mix.</returns>
        private void CalcMeanGasMix()
        {
            meanGasMix.Clear();

            var targetCount = 0;

            for (var i = 0; i < nodes.Count; i++)
            {
                MetaDataNode node = nodes[i];

                if (node == null)
                {
                    continue;
                }

                //If node is not occupied then we want to add it to the total
                if (node.IsOccupied == false && node.IsIsolatedNode == false)
                {
                    meanGasMix.Volume += node.GasMix.Volume;
                    GasMix.TransferGas(meanGasMix, node.GasMix, node.GasMix.Moles, true);
                    targetCount++;
                }
                else if (node.IsIsolatedNode == false)
                {
                    //Remove all overlays for occupied tiles
                    RemovalAllGasOverlays(node);

                    //We trap the gas in the walls to stop instances where you remove a wall and theres a vacuum there
                }
            }

            // Sometimes, we calculate the meanGasMix of a tile surrounded by IsOccupied tiles (no atmos, ie: walls)
            if (targetCount == 0)
            {
                return;
            }

            meanGasMix.Volume /= targetCount;             //Note: this assumes the volume of all tiles are the same


            lock (meanGasMix.GasesArray)             //no Double lock
            {
                for (int i = meanGasMix.GasesArray.Count - 1; i >= 0; i--)
                {
                    var gasData = meanGasMix.GasesArray[i];
                    meanGasMix.GasData.SetMoles(gasData.GasSO, meanGasMix.GasData.GetGasMoles(gasData.GasSO) / targetCount);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Calculate the average Gas tile if you averaged all the adjacent ones and itself
        /// </summary>
        /// <returns>The mean gas mix.</returns>
        private void CalcMeanGasMix()
        {
            meanGasMix.Copy(GasMixes.Empty);

            var targetCount = 0;

            for (var i = 0; i < nodes.Count; i++)
            {
                MetaDataNode node = nodes[i];

                if (node == null)
                {
                    continue;
                }

                meanGasMix.Volume += node.GasMix.Volume;
                GasMix.TransferGas(meanGasMix, node.GasMix, node.GasMix.Moles);

                if (!node.IsOccupied)
                {
                    targetCount++;
                }
                else
                {
                    //Decay if occupied
                    node.GasMix.SetToEmpty();
                }
            }

            // Sometimes, we calculate the meanGasMix of a tile surrounded by IsOccupied tiles (no atmos, ie: walls)
            if (targetCount == 0)
            {
                return;
            }

            meanGasMix.Volume /= targetCount;             //Note: this assumes the volume of all tiles are the same
            for (var i = 0; i < Gas.Count; i++)
            {
                meanGasMix.Gases[i] = meanGasMix.Gases[i] / targetCount;
            }
        }