Пример #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 GasMix CalcMeanGasMix()
        {
            meanGasMix.Copy(GasMixes.Empty);

            int targetCount = 0;

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

                if (node == null)
                {
                    continue;
                }

                for (int j = 0; j < Gas.Count; j++)
                {
                    meanGasMix.Gases[j] += node.GasMix.Gases[j];
                }

                meanGasMix.SetPressure(meanGasMix.Pressure + node.GasMix.Pressure);

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

            // Sometime, we calculate the meanGasMix of a tile surrounded by IsOccupied tiles (no atmos)
            // This condition is to avoid a divide by zero error (or 0 / 0 that gives NaN)
            if (targetCount != 0)
            {
                for (int j = 0; j < Gas.Count; j++)
                {
                    meanGasMix.Gases[j] /= targetCount;
                }

                meanGasMix.SetPressure(meanGasMix.Pressure / targetCount);
            }

            return(meanGasMix);
        }
Пример #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;
            }
        }