public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var burnedFuel = 0f;

            burnedFuel = Mathf.Max(0f, 0.00002f * (gasMix.Temperature - (0.00001f * Mathf.Pow(gasMix.Temperature, 2)))) * gasMix.GetMoles(Gas.NitrousOxide);
            gasMix.RemoveGas(Gas.NitrousOxide, burnedFuel);

            if (burnedFuel != 0)
            {
                var energyReleased = AtmosDefines.N2O_DECOMPOSITION_ENERGY_RELEASED * burnedFuel;

                gasMix.AddGas(Gas.Oxygen, burnedFuel / 2f);
                gasMix.AddGas(Gas.Nitrogen, burnedFuel);

                var newHeatCap = gasMix.WholeHeatCapacity;
                if (newHeatCap > 0.0003f)
                {
                    gasMix.SetTemperature((gasMix.Temperature + energyReleased) / newHeatCap);
                }
            }

            return(0f);
        }
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(
                gasMix.GetMoles(Gas.Nitrogen) + gasMix.GetMoles(Gas.Tritium) / 100,
                gasMix.GetMoles(Gas.Tritium) / 10,
                gasMix.GetMoles(Gas.Nitrogen) / 20);

            var energyUsed = reactionEfficiency * (AtmosDefines.NOBLIUM_FORMATION_ENERGY / Mathf.Max(gasMix.GetMoles(Gas.BZ), 1f));

            if (gasMix.GetMoles(Gas.Tritium) - 10 * reactionEfficiency < 0 || gasMix.GetMoles(Gas.Nitrogen) - 20 * reactionEfficiency < 0)
            {
                //No reaction
                return;
            }

            gasMix.RemoveGas(Gas.Tritium, 10 * reactionEfficiency);
            gasMix.RemoveGas(Gas.Nitrogen, 20 * reactionEfficiency);

            gasMix.AddGas(Gas.HyperNoblium, reactionEfficiency);

            gasMix.SetTemperature(
                Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity,
                          AtmosDefines.SPACE_TEMPERATURE));
        }
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var heatScale = Mathf.Min(gasMix.Temperature / AtmosDefines.STIMULUM_HEAT_SCALE,
                                      gasMix.GetMoles(Gas.Tritium), gasMix.GetMoles(Gas.Plasma), gasMix.GetMoles(Gas.Nitryl));

            var stimEnergyChange = heatScale + AtmosDefines.STIMULUM_FIRST_RISE * Mathf.Pow(heatScale, 2) -
                                   AtmosDefines.STIMULUM_FIRST_DROP * Mathf.Pow(heatScale, 3) +
                                   AtmosDefines.STIMULUM_SECOND_RISE * Mathf.Pow(heatScale, 4) -
                                   AtmosDefines.STIMULUM_ABSOLUTE_DROP * Mathf.Pow(heatScale, 5);

            if (gasMix.GetMoles(Gas.Tritium) - heatScale < 0 || gasMix.GetMoles(Gas.Nitryl) - heatScale < 0)
            {
                //No reaction
                return;
            }

            gasMix.AddGas(Gas.Stimulum, heatScale / 10f);

            gasMix.RemoveGas(Gas.Tritium, heatScale);
            gasMix.RemoveGas(Gas.Nitryl, heatScale);

            gasMix.SetTemperature(
                Mathf.Max((gasMix.Temperature * oldHeatCap + stimEnergyChange) / gasMix.WholeHeatCapacity,
                          AtmosDefines.SPACE_TEMPERATURE));
        }
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(gasMix.Temperature / 3731.5f, gasMix.GetMoles(Gas.Plasma), gasMix.GetMoles(Gas.CarbonDioxide), gasMix.GetMoles(Gas.BZ));

            var energyUsed = reactionEfficiency * 100;

            if (gasMix.GetMoles(Gas.Plasma) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.CarbonDioxide) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.BZ) - reactionEfficiency < 0)
            {
                //No reaction
                return;
            }

            gasMix.RemoveGas(Gas.Plasma, 5 * reactionEfficiency);
            gasMix.RemoveGas(Gas.CarbonDioxide, reactionEfficiency);
            gasMix.RemoveGas(Gas.BZ, 0.25f * reactionEfficiency);

            gasMix.AddGas(Gas.Freon, reactionEfficiency * 2);

            if (energyUsed > 0)
            {
                gasMix.SetTemperature(
                    Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity,
                              AtmosDefines.SPACE_TEMPERATURE));
            }
        }
Beispiel #5
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(gasMix.Temperature / 37315, gasMix.GetMoles(Gas.Oxygen), gasMix.GetMoles(Gas.Nitrogen));

            var energyUsed = reactionEfficiency * AtmosDefines.NITRYL_FORMATION_ENERGY;

            if (gasMix.GetMoles(Gas.Oxygen) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.Nitrogen) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.BZ) - reactionEfficiency < 0)
            {
                //No reaction
                return(0f);
            }

            gasMix.RemoveGas(Gas.Oxygen, 2 * reactionEfficiency);
            gasMix.RemoveGas(Gas.Nitrogen, reactionEfficiency);
            gasMix.RemoveGas(Gas.BZ, 0.05f * reactionEfficiency);

            gasMix.AddGas(Gas.Nitryl, reactionEfficiency);

            if (energyUsed > 0)
            {
                gasMix.SetTemperature(Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity, 2.7f));
            }

            return(0f);
        }
Beispiel #6
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(gasMix.GetMoles(Gas.Oxygen), gasMix.GetMoles(Gas.Nitrogen));

            var energyUsed = reactionEfficiency * AtmosDefines.NITROUS_FORMATION_ENERGY;

            if (gasMix.GetMoles(Gas.Oxygen) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.Nitrogen) - reactionEfficiency < 0)
            {
                //No reaction
                return;
            }

            if (gasMix.Temperature > 250f)
            {
                //No reaction
                return;
            }

            gasMix.RemoveGas(Gas.Oxygen, reactionEfficiency);
            gasMix.RemoveGas(Gas.Nitrogen, 2 * reactionEfficiency);

            gasMix.AddGas(Gas.NitrousOxide, reactionEfficiency);

            if (energyUsed > 0)
            {
                gasMix.SetTemperature(Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity, 2.7f));
            }
        }
Beispiel #7
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(
                //More efficient at less than 10 Kpa
                (float)(1 / ((gasMix.Pressure / (0.1 * 101.325))))
                * (Mathf.Max(gasMix.GetMoles(Gas.Plasma) * gasMix.GetMoles(Gas.NitrousOxide), 1f)),

                gasMix.GetMoles(Gas.NitrousOxide),
                gasMix.GetMoles(Gas.Plasma) / 2);

            var energyReleased = 2 * reactionEfficiency * AtmosDefines.FIRE_CARBON_ENERGY_RELEASED;

            if (gasMix.GetMoles(Gas.NitrousOxide) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.Plasma) - 2 * reactionEfficiency < 0 || energyReleased <= 0)
            {
                //No reaction
                return;
            }

            gasMix.AddGas(Gas.BZ, reactionEfficiency);

            gasMix.RemoveGas(Gas.NitrousOxide, reactionEfficiency);
            gasMix.RemoveGas(Gas.Plasma, 2 * reactionEfficiency);

            gasMix.SetTemperature(Mathf.Max((gasMix.Temperature * oldHeatCap + energyReleased) / gasMix.WholeHeatCapacity, 2.7f));
        }
Beispiel #8
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var ballShotAngle = 180 * Mathf.Cos(gasMix.GetMoles(Gas.WaterVapor) * gasMix.GetMoles(Gas.Nitryl)) + 180;

            var stimUsed = Mathf.Min(AtmosDefines.STIM_BALL_GAS_AMOUNT * gasMix.GetMoles(Gas.Plasma), gasMix.GetMoles(Gas.Stimulum));

            var pluoxUsed = Mathf.Min(AtmosDefines.STIM_BALL_GAS_AMOUNT * gasMix.GetMoles(Gas.Plasma), gasMix.GetMoles(Gas.Pluoxium));

            var energyReleased = stimUsed * AtmosDefines.STIMULUM_HEAT_SCALE;

            //TODO shoot stim projectile using the angle

            gasMix.AddGas(Gas.CarbonDioxide, 4 * pluoxUsed);
            gasMix.AddGas(Gas.Nitrogen, 8 * stimUsed);

            gasMix.SetGas(Gas.Plasma, gasMix.GetMoles(Gas.Plasma) * 0.5f);

            gasMix.RemoveGas(Gas.Pluoxium, 10 * pluoxUsed);
            gasMix.RemoveGas(Gas.Stimulum, 20 * stimUsed);

            gasMix.SetTemperature(Mathf.Clamp((gasMix.Temperature * oldHeatCap + energyReleased) / gasMix.WholeHeatCapacity, 2.7f, Single.PositiveInfinity));

            return(0f);
        }
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(gasMix.Temperature / 37315, gasMix.GetMoles(Gas.Oxygen), gasMix.GetMoles(Gas.Nitrogen));

            var energyUsed = reactionEfficiency * AtmosDefines.NITRYL_FORMATION_ENERGY;

            if (gasMix.GetMoles(Gas.Oxygen) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.Nitrogen) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.BZ) - reactionEfficiency < 0)
            {
                //No reaction
                return;
            }

            gasMix.RemoveGas(Gas.Oxygen, 2 * reactionEfficiency);
            gasMix.RemoveGas(Gas.Nitrogen, reactionEfficiency);
            gasMix.RemoveGas(Gas.BZ, 0.05f * reactionEfficiency);

            gasMix.AddGas(Gas.Nitryl, reactionEfficiency);

            if (energyUsed > 0)
            {
                gasMix.SetTemperature(
                    Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity,
                              AtmosDefines.SPACE_TEMPERATURE));
            }
        }
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var heatScale = Mathf.Min(gasMix.Temperature / AtmosDefines.STIMULUM_HEAT_SCALE, gasMix.GetMoles(Gas.Tritium), gasMix.GetMoles(Gas.Plasma), gasMix.GetMoles(Gas.Nitryl));

            var stimEnergyChange = heatScale + AtmosDefines.STIMULUM_FIRST_RISE * Mathf.Pow(heatScale, 2) -
                                   AtmosDefines.STIMULUM_FIRST_DROP * Mathf.Pow(heatScale, 3) +
                                   AtmosDefines.STIMULUM_SECOND_RISE * Mathf.Pow(heatScale, 4) -
                                   AtmosDefines.STIMULUM_ABSOLUTE_DROP * Mathf.Pow(heatScale, 5);

            if (gasMix.GetMoles(Gas.Tritium) - heatScale < 0 || gasMix.GetMoles(Gas.Plasma) - heatScale < 0 || gasMix.GetMoles(Gas.Nitryl) - heatScale < 0)
            {
                //No reaction
                return(0f);
            }

            gasMix.AddGas(Gas.Stimulum, heatScale / 10f);

            gasMix.RemoveGas(Gas.Tritium, heatScale);
            gasMix.RemoveGas(Gas.Plasma, heatScale);
            gasMix.RemoveGas(Gas.Nitryl, heatScale);

            gasMix.SetTemperature(Mathf.Max((gasMix.Temperature * oldHeatCap + stimEnergyChange) / gasMix.WholeHeatCapacity, 2.7f));

            return(0f);
        }
Beispiel #11
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(gasMix.Temperature / 3731.5f, gasMix.GetMoles(Gas.Plasma), gasMix.GetMoles(Gas.CarbonDioxide), gasMix.GetMoles(Gas.BZ));

            var energyUsed = reactionEfficiency * 100;

            if (gasMix.GetMoles(Gas.Plasma) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.CarbonDioxide) - reactionEfficiency < 0 || gasMix.GetMoles(Gas.BZ) - reactionEfficiency < 0)
            {
                //No reaction
                return(0f);
            }

            gasMix.RemoveGas(Gas.Plasma, 5 * reactionEfficiency);
            gasMix.RemoveGas(Gas.CarbonDioxide, reactionEfficiency);
            gasMix.RemoveGas(Gas.BZ, 0.25f * reactionEfficiency);

            gasMix.AddGas(Gas.Freon, reactionEfficiency * 2);

            if (energyUsed > 0)
            {
                gasMix.SetTemperature(Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity, 2.7f));
            }

            return(0f);
        }
Beispiel #12
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            var energyReleased = 0f;
            var oldHeatCap     = gasMix.WholeHeatCapacity;

            var temperatureScale = 1f;

            if (gasMix.Temperature < AtmosDefines.FREON_LOWER_TEMPERATURE)
            {
                temperatureScale = 0;
            }
            else
            {
                temperatureScale = (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - gasMix.Temperature) / (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - AtmosDefines.FREON_LOWER_TEMPERATURE);
            }

            if (temperatureScale >= 0)
            {
                var oxygenBurnRate = AtmosDefines.OXYGEN_BURN_RATE_BASE - temperatureScale;

                var freonBurnRate = 0f;

                if (gasMix.GetMoles(Gas.Oxygen) > gasMix.GetMoles(Gas.Freon) * AtmosDefines.FREON_OXYGEN_FULLBURN)
                {
                    freonBurnRate = gasMix.GetMoles(Gas.Freon) * temperatureScale /
                                    AtmosDefines.FREON_BURN_RATE_DELTA;
                }
                else
                {
                    freonBurnRate = (temperatureScale * (gasMix.GetMoles(Gas.Oxygen) / AtmosDefines.FREON_OXYGEN_FULLBURN) / AtmosDefines.FREON_BURN_RATE_DELTA);
                }

                if (freonBurnRate > 0.0001f)
                {
                    freonBurnRate = Mathf.Min(freonBurnRate, gasMix.GetMoles(Gas.Freon), gasMix.GetMoles(Gas.Oxygen));

                    gasMix.RemoveGas(Gas.Freon, freonBurnRate);
                    gasMix.RemoveGas(Gas.Oxygen, freonBurnRate * oxygenBurnRate);

                    gasMix.AddGas(Gas.CarbonDioxide, freonBurnRate);

                    if (gasMix.Temperature < 160 && gasMix.Temperature > 120 && rnd.Next(0, 2) == 0)
                    {
                        SpawnSafeThread.SpawnPrefab(tilePos, AtmosManager.Instance.hotIce);
                    }

                    energyReleased += AtmosDefines.FIRE_FREON_ENERGY_RELEASED * freonBurnRate;
                }
            }

            if (energyReleased < 0)
            {
                var newHeatCap = gasMix.WholeHeatCapacity;
                if (newHeatCap > 0.0003f)
                {
                    gasMix.SetTemperature((gasMix.Temperature * oldHeatCap + energyReleased) / newHeatCap);
                }
            }
        }
Beispiel #13
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            float consumed = 0;

            float temperature = gasMix.Temperature;

            float BurnRate = GetOxygenContact(gasMix);

            //Logger.Log(BurnRate.ToString() + "BurnRate");
            if (BurnRate > 0)
            {
                var superSaturated = false;

                float MolesPlasmaBurnt = gasMix.GetMoles(Gas.Plasma) * Reactions.BurningDelta * BurnRate;
                if (MolesPlasmaBurnt * 2 > gasMix.GetMoles(Gas.Oxygen))
                {
                    MolesPlasmaBurnt = (gasMix.GetMoles(Gas.Oxygen) * Reactions.BurningDelta * BurnRate) / 2;
                }

                if (MolesPlasmaBurnt < 0)
                {
                    return(0);
                }

                if (gasMix.GetMoles(Gas.Oxygen) / gasMix.GetMoles(Gas.Plasma) > AtmosDefines.SUPER_SATURATION_THRESHOLD)
                {
                    superSaturated = true;
                }

                gasMix.RemoveGas(Gas.Plasma, MolesPlasmaBurnt);
                if (gasMix.Gases[Gas.Plasma] < 0)
                {
                    gasMix.Gases[Gas.Plasma] = 0;
                }

                gasMix.RemoveGas(Gas.Oxygen, MolesPlasmaBurnt * 2);
                if (gasMix.Gases[Gas.Oxygen] < 0)
                {
                    gasMix.Gases[Gas.Oxygen] = 0;
                }
                var TotalmolestoCO2 = MolesPlasmaBurnt + (MolesPlasmaBurnt * 2);

                if (superSaturated)
                {
                    gasMix.AddGas(Gas.Tritium, TotalmolestoCO2 / 3);
                }
                else
                {
                    gasMix.AddGas(Gas.CarbonDioxide, TotalmolestoCO2 / 3);
                }

                float heatCapacity = gasMix.WholeHeatCapacity;
                gasMix.SetTemperature((temperature * heatCapacity + (Reactions.EnergyPerMole * TotalmolestoCO2)) / gasMix.WholeHeatCapacity);
                consumed = TotalmolestoCO2;
            }
            return(consumed);
        }
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var energyReleased = 0f;
            var oldHeatCap     = gasMix.WholeHeatCapacity;
            var burnedFuel     = 0f;

            if (gasMix.GetMoles(Gas.Oxygen) < gasMix.GetMoles(Gas.Tritium) || AtmosDefines.MINIMUM_TRIT_OXYBURN_ENERGY > gasMix.InternalEnergy)
            {
                burnedFuel = gasMix.GetMoles(Gas.Oxygen) / AtmosDefines.TRITIUM_BURN_OXY_FACTOR;

                gasMix.RemoveGas(Gas.Tritium, burnedFuel);
                gasMix.AddGas(Gas.WaterVapor, burnedFuel / AtmosDefines.TRITIUM_BURN_OXY_FACTOR);

                energyReleased += AtmosDefines.FIRE_HYDROGEN_ENERGY_WEAK * burnedFuel;
            }
            else
            {
                burnedFuel = gasMix.GetMoles(Gas.Tritium);

                gasMix.RemoveGas(Gas.Tritium, burnedFuel / AtmosDefines.TRITIUM_BURN_TRIT_FACTOR);
                gasMix.RemoveGas(Gas.Oxygen, burnedFuel);

                gasMix.AddGas(Gas.WaterVapor, burnedFuel / AtmosDefines.TRITIUM_BURN_TRIT_FACTOR);

                energyReleased += AtmosDefines.FIRE_HYDROGEN_ENERGY_RELEASED * burnedFuel;
            }

            if (burnedFuel != 0)
            {
                if (rnd.Next(0, 10) == 0 && burnedFuel > AtmosDefines.TRITIUM_MINIMUM_RADIATION_ENERGY)
                {
                    RadiationManager.Instance.RequestPulse(node.Position.ToWorld(node.PositionMatrix).RoundToInt(),
                                                           energyReleased / AtmosDefines.TRITIUM_BURN_RADIOACTIVITY_FACTOR,
                                                           rnd.Next(Int32.MinValue, Int32.MaxValue));
                }
            }

            if (energyReleased > 0)
            {
                var newHeatCap = gasMix.WholeHeatCapacity;
                if (newHeatCap > 0.0003f)
                {
                    gasMix.SetTemperature((gasMix.Temperature * oldHeatCap + energyReleased) / newHeatCap);
                }
            }

            //Create fire if possible
            if (gasMix.Temperature > AtmosDefines.FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
            {
                //Dont do expose as we are off the main thread
                node.ReactionManager.ExposeHotspot(node.Position, doExposure: false);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Transfers heat between an Open tile and a Solid tile
        /// Uses data from MetaDataNode for SolidNode and GasMix values for Open node
        /// </summary>
        private void ConductFromOpenToSolid(MetaDataNode solidNode, GasMix meanGasMix)
        {
            var tempDelta = solidNode.ConductivityTemperature - meanGasMix.Temperature;

            if (Mathf.Abs(tempDelta) <= AtmosDefines.MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER)
            {
                return;
            }

            if (meanGasMix.WholeHeatCapacity <= AtmosConstants.MINIMUM_HEAT_CAPACITY)
            {
                return;
            }

            if (solidNode.HeatCapacity <= AtmosConstants.MINIMUM_HEAT_CAPACITY)
            {
                return;
            }

            //The larger the combined capacity the less is shared
            var heat = solidNode.ThermalConductivity * tempDelta *
                       (solidNode.HeatCapacity * meanGasMix.WholeHeatCapacity /
                        (solidNode.HeatCapacity + meanGasMix.WholeHeatCapacity));

            solidNode.ConductivityTemperature = Mathf.Max(
                solidNode.ConductivityTemperature - (heat / solidNode.HeatCapacity),
                AtmosDefines.SPACE_TEMPERATURE);

            meanGasMix.SetTemperature(Mathf.Max(
                                          meanGasMix.Temperature + (heat / meanGasMix.WholeHeatCapacity),
                                          AtmosDefines.SPACE_TEMPERATURE));

            //Do atmos update for the Solid node if temperature is allowed so it can do conduction
            //This is checking for the start temperature as this is how the cycle will begin
            if (solidNode.ConductivityTemperature < AtmosDefines.MINIMUM_TEMPERATURE_START_SUPERCONDUCTION)
            {
                return;
            }

            if (solidNode.AllowedToSuperConduct == false)
            {
                solidNode.AllowedToSuperConduct = true;

                //Allow this node to trigger other tiles super conduction
                solidNode.StartingSuperConduct = true;
            }

            AtmosManager.Update(solidNode);
        }
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            if (gasMix.GetMoles(Gas.WaterVapor) != 0 && gasMix.GetMoles(Gas.WaterVapor) / gasMix.Moles > 0.1)
            {
                //No reaction
                return;
            }

            var cleanedAir = Mathf.Min(gasMix.GetMoles(Gas.Miasma), 20 + (gasMix.Temperature - 373.15f - 70) / 20);

            gasMix.RemoveGas(Gas.Miasma, cleanedAir);

            gasMix.AddGas(Gas.Oxygen, cleanedAir);

            gasMix.SetTemperature(gasMix.Temperature + cleanedAir * 0.002f);
        }
Beispiel #17
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var energyReleased = 0f;
            var oldHeatCap     = gasMix.WholeHeatCapacity;

            var burnedFuel = 0f;

            if (gasMix.GetMoles(Gas.Oxygen) < gasMix.GetMoles(Gas.Tritium) || AtmosDefines.MINIMUM_TRIT_OXYBURN_ENERGY > gasMix.InternalEnergy)
            {
                burnedFuel = gasMix.GetMoles(Gas.Oxygen) / AtmosDefines.TRITIUM_BURN_OXY_FACTOR;
                gasMix.RemoveGas(Gas.Tritium, burnedFuel);
            }
            else
            {
                burnedFuel = gasMix.GetMoles(Gas.Tritium) * AtmosDefines.TRITIUM_BURN_TRIT_FACTOR;
                gasMix.RemoveGas(Gas.Tritium, gasMix.GetMoles(Gas.Tritium) / AtmosDefines.TRITIUM_BURN_TRIT_FACTOR);
                gasMix.RemoveGas(Gas.Oxygen, gasMix.GetMoles(Gas.Tritium));
            }

            if (burnedFuel != 0)
            {
                energyReleased += AtmosDefines.FIRE_HYDROGEN_ENERGY_RELEASED * burnedFuel;

                if (Random.Range(0, 10) == 0 && burnedFuel > AtmosDefines.TRITIUM_MINIMUM_RADIATION_ENERGY)
                {
                    RadiationManager.Instance.RequestPulse(MatrixManager.AtPoint(tilePos.RoundToInt(), true).Matrix, tilePos.RoundToInt(), energyReleased / AtmosDefines.TRITIUM_BURN_RADIOACTIVITY_FACTOR, Random.Range(Int32.MinValue, Int32.MaxValue));
                }

                gasMix.AddGas(Gas.WaterVapor, burnedFuel / AtmosDefines.TRITIUM_BURN_OXY_FACTOR);
            }

            if (energyReleased > 0)
            {
                var newHeatCap = gasMix.WholeHeatCapacity;
                if (newHeatCap > 0.0003f)
                {
                    gasMix.SetTemperature((gasMix.Temperature * oldHeatCap + energyReleased) / newHeatCap);
                }
            }

            return(0f);
        }
Beispiel #18
0
 /// <summary>
 /// Exposes the hotspot, igniting gases on the tile
 /// </summary>
 private void Expose()
 {
     if ((Volume / node.GasMix.Volume) > 0.95f)
     {
         GasMix gasMix   = node.GasMix;
         float  consumed = Reactions.React(ref gasMix);
         node.GasMix = gasMix;
         Volume      = consumed * 40;
         Temperature = node.GasMix.Temperature;
     }
     else
     {
         GasMix removed = node.GasMix.RemoveVolume(Volume);
         removed.SetTemperature(Temperature);
         float consumed = Reactions.React(ref removed);
         Volume       = consumed * 40;
         Temperature  = removed.Temperature;
         node.GasMix -= removed;
     }
 }
Beispiel #19
0
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var waterMoles = gasMix.GetMoles(Gas.WaterVapor);

            if (waterMoles != 0 && waterMoles / gasMix.Moles > 0.1)
            {
                //No reaction
                return;
            }

            var cleanedAir =
                Mathf.Min(
                    gasMix.GetMoles(Gas.Miasma),
                    20 + (gasMix.Temperature - AtmosDefines.FIRE_MINIMUM_TEMPERATURE_TO_EXIST - 70) / 20);

            gasMix.RemoveGas(Gas.Miasma, cleanedAir);

            gasMix.AddGas(Gas.Oxygen, cleanedAir);

            gasMix.SetTemperature(gasMix.Temperature + cleanedAir * 0.002f);
        }
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEfficiency = Mathf.Min(gasMix.GetMoles(Gas.Nitrogen) + gasMix.GetMoles(Gas.Tritium) / 100, gasMix.GetMoles(Gas.Tritium) / 10, gasMix.GetMoles(Gas.Nitrogen) / 20);

            var energyUsed = reactionEfficiency * (AtmosDefines.NOBLIUM_FORMATION_ENERGY / Mathf.Max(gasMix.GetMoles(Gas.BZ), 1f));

            if (gasMix.GetMoles(Gas.Tritium) - 10 * reactionEfficiency < 0 || gasMix.GetMoles(Gas.Nitrogen) - 20 * reactionEfficiency < 0)
            {
                //No reaction
                return(0f);
            }

            gasMix.RemoveGas(Gas.Tritium, 10 * reactionEfficiency);
            gasMix.RemoveGas(Gas.Nitrogen, 20 * reactionEfficiency);

            gasMix.AddGas(Gas.HyperNoblium, reactionEfficiency);

            gasMix.SetTemperature(Mathf.Max((gasMix.Temperature * oldHeatCap - energyUsed) / gasMix.WholeHeatCapacity, 2.7f));

            return(0f);
        }
Beispiel #21
0
        /// <summary>
        /// Ensures that both containers have the same pressure
        /// </summary>
        /// <param name="otherGas"></param>
        public GasMix MergeGasMix(GasMix otherGas)
        {
            float totalInternalEnergy    = InternalEnergy + otherGas.InternalEnergy;
            float totalWholeHeatCapacity = WholeHeatCapacity + otherGas.WholeHeatCapacity;
            float Newtemperature         = totalInternalEnergy / totalWholeHeatCapacity;
            float totalVolume            = Volume + otherGas.Volume;

            for (int i = 0; i < Gas.Count; i++)
            {
                if (Gases[i] < 0)
                {
                    Debug.Log("OH GOFD!!");
                }

                float gas = (Gases[i] + otherGas.Gases[i]) / totalVolume;
                Gases[i]          = gas * Volume;
                otherGas.Gases[i] = gas * otherGas.Volume;
            }

            SetTemperature(Newtemperature);
            otherGas.SetTemperature(Newtemperature);
            return(otherGas);
        }
        public void React(GasMix gasMix, MetaDataNode node)
        {
            var energyReleased  = 0f;
            var temperature     = gasMix.Temperature;
            var oldHeatCapacity = gasMix.WholeHeatCapacity;

            //More plasma released at higher temperatures
            float temperatureScale;

            if (temperature > AtmosDefines.PLASMA_UPPER_TEMPERATURE)
            {
                temperatureScale = 1;
            }
            else
            {
                //Will be decimal until PLASMA_UPPER_TEMPERATURE is reached
                temperatureScale = (temperature - AtmosDefines.PLASMA_MINIMUM_BURN_TEMPERATURE) /
                                   (AtmosDefines.PLASMA_UPPER_TEMPERATURE - AtmosDefines.PLASMA_MINIMUM_BURN_TEMPERATURE);
            }

            if (temperatureScale > 0)
            {
                //Handle plasma burning
                var oxygenMoles = gasMix.GetMoles(Gas.Oxygen);
                var plasmaMoles = gasMix.GetMoles(Gas.Plasma);

                float plasmaBurnRate;
                var   oxygenBurnRate = AtmosDefines.OXYGEN_BURN_RATE_BASE - temperatureScale;

                var superSaturation = oxygenMoles / plasmaMoles > AtmosDefines.SUPER_SATURATION_THRESHOLD;

                if (oxygenMoles > plasmaMoles * AtmosDefines.PLASMA_OXYGEN_FULLBURN)
                {
                    plasmaBurnRate = (plasmaMoles * temperatureScale) / AtmosDefines.PLASMA_BURN_RATE_DELTA;
                }
                else
                {
                    plasmaBurnRate = (temperatureScale * (oxygenMoles / AtmosDefines.PLASMA_OXYGEN_FULLBURN)) / AtmosDefines.PLASMA_BURN_RATE_DELTA;
                }

                if (plasmaBurnRate > AtmosConstants.MINIMUM_HEAT_CAPACITY)
                {
                    //Ensures matter is conserved properly
                    plasmaBurnRate = Mathf.Min(plasmaBurnRate, plasmaMoles, oxygenMoles / oxygenBurnRate);

                    gasMix.SetGas(Gas.Plasma, plasmaMoles - plasmaBurnRate);
                    gasMix.SetGas(Gas.Oxygen, oxygenMoles - (plasmaBurnRate * oxygenBurnRate));

                    if (superSaturation)
                    {
                        gasMix.AddGas(Gas.Tritium, plasmaBurnRate);
                    }
                    else
                    {
                        gasMix.AddGas(Gas.CarbonDioxide, plasmaBurnRate * 0.75f);
                        gasMix.AddGas(Gas.WaterVapor, plasmaBurnRate * 0.25f);
                    }

                    energyReleased += AtmosDefines.FIRE_PLASMA_ENERGY_RELEASED * plasmaBurnRate;
                }
            }

            if (energyReleased > 0)
            {
                var newHeatCapacity = gasMix.WholeHeatCapacity;
                if (newHeatCapacity > AtmosConstants.MINIMUM_HEAT_CAPACITY)
                {
                    gasMix.SetTemperature((gasMix.Temperature * oldHeatCapacity + energyReleased) / newHeatCapacity);
                }
            }

            //Create fire if possible
            if (gasMix.Temperature > AtmosDefines.FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
            {
                //Dont do expose as we are off the main thread
                node.ReactionManager.ExposeHotspot(node.Position, doExposure: false);
            }
        }
Beispiel #23
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            var oldHeatCap = gasMix.WholeHeatCapacity;

            var reactionEnergy = 0f;

            var initialPlasma = gasMix.GetMoles(Gas.Plasma);

            var initialCarbon = gasMix.GetMoles(Gas.CarbonDioxide);

            var scaleFactor = gasMix.Volume / Mathf.PI;

            var toroidalSize = (2 * Mathf.PI) + ((Mathf.PI / 180) *
                                                 Mathf.Atan((gasMix.Volume - AtmosDefines.TOROID_VOLUME_BREAKEVEN) /
                                                            AtmosDefines.TOROID_VOLUME_BREAKEVEN));

            var gasPower = 0f;


            foreach (var gas in Gas.All)
            {
                gasPower += gas.FusionPower * gasMix.GetMoles(gas);
            }

            var instability = Mathf.Pow(gasPower * AtmosDefines.INSTABILITY_GAS_POWER_FACTOR, 2) % toroidalSize;

            var plasma = (initialPlasma - AtmosDefines.FUSION_MOLE_THRESHOLD) / scaleFactor;

            var carbon = (initialCarbon - AtmosDefines.FUSION_MOLE_THRESHOLD) / scaleFactor;

            plasma = (plasma - instability * Mathf.Sin(carbon)) % toroidalSize;

            carbon = (carbon - plasma) % toroidalSize;

            gasMix.SetGas(Gas.Plasma, plasma * scaleFactor + AtmosDefines.FUSION_MOLE_THRESHOLD);
            gasMix.SetGas(Gas.CarbonDioxide, carbon * scaleFactor + AtmosDefines.FUSION_MOLE_THRESHOLD);

            var deltaPlasma = initialPlasma - gasMix.GetMoles(Gas.Plasma);

            reactionEnergy += deltaPlasma * AtmosDefines.PLASMA_BINDING_ENERGY;

            if (instability < AtmosDefines.FUSION_INSTABILITY_ENDOTHERMALITY)
            {
                reactionEnergy = Mathf.Max(reactionEnergy, 0);
            }
            else if (reactionEnergy < 0)
            {
                reactionEnergy *= Mathf.Pow(instability - AtmosDefines.FUSION_INSTABILITY_ENDOTHERMALITY, 5);
            }

            if (gasMix.InternalEnergy + reactionEnergy < 0)
            {
                gasMix.SetGas(Gas.Plasma, initialPlasma);
                gasMix.SetGas(Gas.CarbonDioxide, initialCarbon);
                return;
            }

            gasMix.RemoveGas(Gas.Tritium, AtmosDefines.FUSION_TRITIUM_MOLES_USED);

            if (reactionEnergy > 0)
            {
                gasMix.AddGas(Gas.Oxygen, AtmosDefines.FUSION_TRITIUM_MOLES_USED * (reactionEnergy * AtmosDefines.FUSION_TRITIUM_CONVERSION_COEFFICIENT));
                gasMix.AddGas(Gas.NitrousOxide, AtmosDefines.FUSION_TRITIUM_MOLES_USED * (reactionEnergy * AtmosDefines.FUSION_TRITIUM_CONVERSION_COEFFICIENT));
            }

            if (reactionEnergy != 0)
            {
                RadiationManager.Instance.RequestPulse(matrix, tilePos.RoundToInt(), Mathf.Max((AtmosDefines.FUSION_RAD_COEFFICIENT / instability) + AtmosDefines.FUSION_RAD_MAX, 0), rnd.Next(Int32.MinValue, Int32.MaxValue));

                var newHeatCap = gasMix.WholeHeatCapacity;
                if (newHeatCap > 0.0003f && (gasMix.Temperature <= AtmosDefines.FUSION_MAXIMUM_TEMPERATURE || reactionEnergy <= 0))
                {
                    gasMix.SetTemperature(Mathf.Clamp(((gasMix.Temperature * oldHeatCap + reactionEnergy) / newHeatCap), 2.7f, Single.PositiveInfinity));
                }
            }
        }