Пример #1
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            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(0f);
            }

            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));

            return(0f);
        }
Пример #2
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            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(0f);
            }

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

            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));
            }

            return(0f);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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 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);
        }
Пример #8
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            if (gasMix.GetMoles(Gas.WaterVapor) != 0 && gasMix.GetMoles(Gas.WaterVapor) / gasMix.Moles > 0.1)
            {
                //No reaction
                return(0f);
            }

            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);

            return(0f);
        }
        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);
        }
Пример #10
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;
     }
 }
        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);
        }
Пример #12
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);
        }
Пример #13
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            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(0f);
            }

            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(MatrixManager.AtPoint(tilePos.RoundToInt(), true).Matrix, tilePos.RoundToInt(), Mathf.Max((AtmosDefines.FUSION_RAD_COEFFICIENT / instability) + AtmosDefines.FUSION_RAD_MAX, 0), UnityEngine.Random.Range(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));
                }
            }

            return(0f);
        }
Пример #14
0
        public float React(ref GasMix gasMix, Vector3 tilePos)
        {
            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 && UnityEngine.Random.Range(0, 2) == 0)
                    {
                        Spawn.ServerPrefab(AtmosManager.Instance.hotIce, tilePos, MatrixManager.GetDefaultParent(tilePos, true));
                    }

                    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);
                }
            }

            return(0f);
        }