コード例 #1
0
        public void Step()
        {
            if (filterActive)
            {
                PipeObject input          = atmosNeighbours[0];
                PipeObject outputFiltered = atmosNeighbours[3];
                PipeObject outputOther    = atmosNeighbours[1];

                // Return when there is no gas
                if (input == null || input.GetTotalMoles() <= 1f || outputFiltered == null || outputOther == null)
                {
                    return;
                }

                AtmosContainer inputContainer = input.GetAtmosContainer();

                // Both outputs must not be blocked
                if (outputFiltered.GetPressure() <= _targetPressure && outputOther.GetPressure() <= _targetPressure)
                {
                    // Use the pipe with the highest pressure as reference
                    PipeObject nearestOutput = (outputFiltered.GetPressure() > outputOther.GetPressure()) ? outputFiltered : outputOther;

                    // Calculate necessary moles to transfer using PV=nRT
                    float pressureDifference = _targetPressure - nearestOutput.GetPressure();
                    float transferMoles      = pressureDifference * 1000 * nearestOutput.volume / (nearestOutput.GetAtmosContainer().GetTemperature() * Gas.gasConstant);

                    // We can not transfer more moles than the machinery allows
                    transferMoles = Mathf.Min(Gas.maxMoleTransfer, transferMoles);

                    // We can't transfer more moles than there are in the input
                    if (transferMoles > input.GetTotalMoles())
                    {
                        transferMoles = input.GetTotalMoles();
                    }

                    // for (int i = 0; i < Gas.numOfGases; i++)
                    foreach (AtmosGasses gas in Enum.GetValues(typeof(AtmosGasses)))
                    {
                        // Divide the moles according to their percentage
                        float molePerGas = (inputContainer.GetGas(gas) / input.GetTotalMoles()) * transferMoles;
                        if (inputContainer.GetGas(gas) > 0f)
                        {
                            input.RemoveGas(gas, molePerGas);

                            // Determine output based on filtering setting
                            if (IsFiltered(gas))
                            {
                                outputFiltered.AddGas(gas, molePerGas);
                            }
                            else
                            {
                                outputOther.AddGas(gas, molePerGas);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: PumpObject.cs プロジェクト: Ryan089/SS3D
        public void Step()
        {
            // If both sides of the pump are connected
            if (pumpActive && atmosNeighbours[0] && atmosNeighbours[1])
            {
                PipeObject input  = atmosNeighbours[0];
                PipeObject output = atmosNeighbours[1];

                if (input.GetTotalMoles() == 0)
                {
                    return;
                }

                AtmosContainer inputContainer = input.GetAtmosContainer();

                // And the output pressure is acceptable
                if (pumpType == PumpType.Pressure)
                {
                    if (output.GetPressure() <= TargetPressure - 0.1f)
                    {
                        float totalMoles = input.GetTotalMoles();

                        // Calculate necessary moles to transfer using PV=nRT
                        float pressureDifference = TargetPressure - output.GetPressure();
                        float transferMoles      = pressureDifference * 1000 * output.volume / (output.GetAtmosContainer().GetTemperature() * Gas.gasConstant);

                        // We can not transfer more moles than the machinery allows
                        transferMoles = Mathf.Min(Gas.maxMoleTransfer, transferMoles);

                        // We can't transfer more moles than there are
                        if (transferMoles > totalMoles)
                        {
                            transferMoles = totalMoles;
                        }

                        for (int i = 0; i < Gas.numOfGases; i++)
                        {
                            // Divide the moles according to their percentage
                            float molePerGas = (inputContainer.GetGas(i) / totalMoles) * transferMoles;
                            if (inputContainer.GetGas(i) > 0f)
                            {
                                input.RemoveGas(i, molePerGas);
                                output.AddGas(i, molePerGas);
                            }
                        }
                    }
                }
                // TODO: different pump speeds between volume/pressure pumps
                else if (pumpType == PumpType.Volume)
                {
                    // At 200 L/s
                    float inputVolume   = input.volume * 1000 / CurrentVolumeSetting;
                    float transferMoles = input.GetPressure() * 1000 * inputVolume / (input.GetAtmosContainer().GetTemperature() * Gas.gasConstant);
                    float totalMoles    = input.GetTotalMoles();

                    // We can not transfer more moles than the machinery allows
                    transferMoles = Mathf.Min(molesPerStep, transferMoles);

                    for (int i = 0; i < Gas.numOfGases; i++)
                    {
                        // We can't transfer more moles than there are
                        if (transferMoles > totalMoles)
                        {
                            transferMoles = totalMoles;
                        }

                        // Divide the moles according to their percentage
                        float molePerGas = (inputContainer.GetGas(i) / totalMoles) * transferMoles;

                        if (inputContainer.GetGas(i) >= molePerGas)
                        {
                            input.RemoveGas(i, molePerGas);
                            output.AddGas(i, molePerGas);
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: VentObject.cs プロジェクト: xTheLifex/SS3D
        public void Step()
        {
            bool ventActive = false;

            if (deviceActive)
            {
                PipeObject  input  = connectedPipe;
                AtmosObject output = GetComponentInParent <TileObject>().atmos;

                if (input != null || input.GetTotalMoles() > 0)
                {
                    AtmosContainer inputContainer = input.GetAtmosContainer();


                    if (mode == OperatingMode.External)
                    {
                        // If the output pressure is acceptable
                        if (output.GetPressure() <= TargetPressure - 1f)
                        {
                            ventActive = true;
                            float totalMoles = input.GetTotalMoles();

                            // Calculate necessary moles to transfer using PV=nRT
                            float pressureDifference = TargetPressure - output.GetPressure();
                            float transferMoles      = pressureDifference * 1000 * output.GetAtmosContainer().Volume / (output.GetAtmosContainer().GetTemperature() * Gas.gasConstant);

                            // We can not transfer more moles than the machinery allows
                            transferMoles = Mathf.Min(Gas.maxMoleTransfer, transferMoles);

                            // We can't transfer more moles than there are
                            if (transferMoles > totalMoles)
                            {
                                transferMoles = totalMoles;
                            }

                            for (int i = 0; i < Gas.numOfGases; i++)
                            {
                                // Divide the moles according to their percentage
                                float molePerGas = (inputContainer.GetGas(i) / totalMoles) * transferMoles;
                                if (inputContainer.GetGas(i) > 0f)
                                {
                                    input.RemoveGas(i, molePerGas);
                                    output.AddGas(i, molePerGas);
                                }
                            }
                        }
                    }

                    else if (mode == OperatingMode.Internal)
                    {
                        // If the output pressure is acceptable
                        if (input.GetPressure() >= TargetPressure + 1f)
                        {
                            ventActive = true;
                            float totalMoles = input.GetTotalMoles();

                            // Calculate necessary moles to transfer using PV=nRT
                            float pressureDifference = input.GetPressure() - TargetPressure;
                            float transferMoles      = pressureDifference * 1000 * input.GetAtmosContainer().Volume / (input.GetAtmosContainer().GetTemperature() * Gas.gasConstant);

                            // We can not transfer more moles than the machinery allows
                            transferMoles = Mathf.Min(Gas.maxMoleTransfer, transferMoles);

                            // We can't transfer more moles than there are in the input
                            if (transferMoles > totalMoles)
                            {
                                transferMoles = totalMoles;
                            }

                            for (int i = 0; i < Gas.numOfGases; i++)
                            {
                                // Divide the moles according to their percentage
                                float molePerGas = (inputContainer.GetGas(i) / totalMoles) * transferMoles;
                                if (inputContainer.GetGas(i) > 0f)
                                {
                                    input.RemoveGas(i, molePerGas);
                                    output.AddGas(i, molePerGas);
                                }
                            }
                        }
                    }
                }
            }

            // Update the animator
            anim.SetBool("ventActive", ventActive);
            anim.SetBool("deviceActive", deviceActive);
        }
コード例 #4
0
ファイル: ScrubberObject.cs プロジェクト: xTheLifex/SS3D
        public void Step()
        {
            int  numOfTiles  = 0;
            bool scrubActive = false;

            switch (range)
            {
            case Range.Normal:
                numOfTiles = 1;
                break;

            case Range.Extended:
                numOfTiles = 5;
                break;
            }
            if (deviceActive)
            {
                // We loop 1 or 5 times based on the range setting
                for (int i = 0; i < numOfTiles; i++)
                {
                    if (i == 0)
                    {
                        if (input == null)
                        {
                            input = GetComponentInParent <TileObject>().atmos;
                        }
                    }
                    else
                    {
                        input = atmosNeighbours[i - 1];
                    }

                    PipeObject output = connectedPipe;

                    if (input == null || input.GetTotalMoles() == 0 || output == null || mode == OperatingMode.Off)
                    {
                        return;
                    }

                    AtmosContainer inputContainer  = input.GetAtmosContainer();
                    AtmosContainer outputContainer = output.GetAtmosContainer();



                    // If the output pressure is acceptable
                    if (output.GetPressure() <= TargetPressure - 1f)
                    {
                        float totalMoles = input.GetTotalMoles();

                        // Calculate necessary moles to transfer using PV=nRT
                        float pressureDifference = _targetPressure - output.GetPressure();
                        float transferMoles      = pressureDifference * 1000 * output.volume / (output.GetAtmosContainer().GetTemperature() * Gas.gasConstant);

                        // We can not transfer more moles than the machinery allows
                        transferMoles = Mathf.Min(Gas.maxMoleTransfer, transferMoles);

                        // We don't transfer tiny amounts
                        transferMoles = Mathf.Max(transferMoles, Gas.minMoleTransfer);

                        // We can't transfer more moles than there are in the input
                        if (transferMoles > totalMoles)
                        {
                            transferMoles = totalMoles;
                        }

                        for (int j = 0; j < atmosGasses.Length; j++)
                        {
                            if (mode == OperatingMode.Siphoning)
                            {
                                scrubActive = true;

                                // Divide the moles according to their percentage
                                float molePerGas = (inputContainer.GetGas(atmosGasses[j]) / input.GetTotalMoles()) * transferMoles;
                                if (inputContainer.GetGas(atmosGasses[j]) > 0f)
                                {
                                    input.RemoveGas(atmosGasses[j], molePerGas);
                                    output.AddGas(atmosGasses[j], molePerGas);
                                }
                            }

                            // If scrubbing, remove only filtered gas
                            if (mode == OperatingMode.Scrubbing && IsFiltered(atmosGasses[j]))
                            {
                                if (inputContainer.GetGas(atmosGasses[j]) > 0f)
                                {
                                    scrubActive = true;

                                    // To avoid leaving a small amount of a certain gas, we apply the min threshold again
                                    float molePerGas = Mathf.Min(transferMoles, inputContainer.GetGas(atmosGasses[j]));

                                    input.RemoveGas(atmosGasses[j], molePerGas);
                                    output.AddGas(atmosGasses[j], molePerGas);
                                }
                            }
                        }
                    }
                }
            }

            // Update the animator
            anim.SetBool("scrubActive", scrubActive);
            anim.SetBool("deviceActive", deviceActive);
        }