Example #1
0
        public static void LoadConfigNodes()
        {
            idOrganizedListOfGasSpecies    = new Dictionary <string, AtmosphericGasSpecies>();
            bodyOrganizedListOfAtmospheres = new Dictionary <CelestialBody, AtmosphereComposition>();
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("RH_ATM_GAS_SPECIES"))
            {
                foreach (ConfigNode gasSpeciesNode in node.GetNodes("GAS_SPECIES"))
                {
                    string id = gasSpeciesNode.GetValue("name");
                    AtmosphericGasSpecies newSpecies = new AtmosphericGasSpecies(id);

                    idOrganizedListOfGasSpecies.Add(id, newSpecies);
                }
            }
            foreach (KeyValuePair <string, AtmosphericGasSpecies> pair in idOrganizedListOfGasSpecies)
            {
                pair.Value.Initialize();
            }

            AtmosphereComposition defaultOxygenatedRocky   = new AtmosphereComposition(),
                                  defaultUnoxygenatedRocky = new AtmosphereComposition(),
                                  defaultGasGiant          = new AtmosphereComposition();

            float gasGiantRadius = 3000;

            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("RH_ATM_COMPOSITIONS"))
            {
                foreach (ConfigNode atmNode in node.GetNodes("ATM_COMPOSITION"))
                {
                    AtmosphereComposition newComposition = new AtmosphereComposition();

                    newComposition.gasSpeciesAndMassFractions = new Dictionary <AtmosphericGasSpecies, float>();

                    foreach (ConfigNode gasSpeciesNode in atmNode.GetNodes("GAS_SPECIES"))
                    {
                        AtmosphericGasSpecies decompositionSpecies = AtmDataOrganizer.idOrganizedListOfGasSpecies[gasSpeciesNode.GetValue("name")];

                        float massFraction = float.Parse(gasSpeciesNode.GetValue("massFraction"));
                        newComposition.gasSpeciesAndMassFractions.Add(decompositionSpecies, massFraction);
                    }

                    newComposition.referenceTemperature = float.Parse(atmNode.GetValue("referenceTemperature"));
                    newComposition.maxSimVelocity       = float.Parse(atmNode.GetValue("maxSimVelocity"));

                    string bodyName = atmNode.GetValue("name");

                    for (int idx = 0; idx < FlightGlobals.Bodies.Count; idx++)
                    {
                        CelestialBody body = FlightGlobals.Bodies[idx];
                        if (body.name == bodyName)
                        {
                            newComposition.specHeatRatio = (float)body.atmosphereAdiabaticIndex;
                            newComposition.gasConstant   = (float)((double)(AtmosphericGasSpecies.UniversalGasConstant) / (body.atmosphereMolarMass * 1000d));
                            bodyOrganizedListOfAtmospheres.Add(body, newComposition);
                            break;
                        }
                    }

                    if (bodyName == "defaultOxygenatedRocky")
                    {
                        defaultOxygenatedRocky = newComposition;
                    }
                    else if (bodyName == "defaultUnoxygenatedRocky")
                    {
                        defaultUnoxygenatedRocky = newComposition;
                    }
                    else if (bodyName == "defaultGasGiant")
                    {
                        defaultGasGiant = newComposition;
                    }
                }
                gasGiantRadius = float.Parse(node.GetValue("gasGiantRadius"));
            }

            foreach (CelestialBody body in FlightGlobals.Bodies)
            {
                if (!bodyOrganizedListOfAtmospheres.ContainsKey(body))
                {
                    if (body.Radius > gasGiantRadius)
                    {
                        bodyOrganizedListOfAtmospheres.Add(body, defaultGasGiant);
                    }
                    else if (body.atmosphereContainsOxygen)
                    {
                        bodyOrganizedListOfAtmospheres.Add(body, defaultOxygenatedRocky);
                    }
                    else
                    {
                        bodyOrganizedListOfAtmospheres.Add(body, defaultUnoxygenatedRocky);
                    }
                }
            }
        }
Example #2
0
        public void Initialize()
        {
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("RH_ATM_GAS_SPECIES"))
            {
                foreach (ConfigNode gasSpeciesNode in node.GetNodes("GAS_SPECIES"))
                {
                    if (gasSpeciesNode.GetValue("name") == this.id)
                    {
                        Debug.Log("Loading '" + id + "' data");
                        ConfigNode thisNode = gasSpeciesNode;

                        degFreedomLowTemp  = int.Parse(thisNode.GetValue("degFreedomLowTemp"));
                        degFreedomHighTemp = int.Parse(thisNode.GetValue("degFreedomHighTemp"));

                        tempLowDegFreedom  = float.Parse(thisNode.GetValue("tempLowDegFreedom"));
                        tempHighDegFreedom = float.Parse(thisNode.GetValue("tempHighDegFreedom"));


                        tempBeginDecomposition = float.Parse(thisNode.GetValue("tempBeginDecomposition"));
                        tempEndDecomposition   = float.Parse(thisNode.GetValue("tempEndDecomposition"));

                        float molecularMass = float.Parse(thisNode.GetValue("molecularMass"));
                        specificGasConstant = UniversalGasConstant / molecularMass;

                        heatOfFormation = float.Parse(thisNode.GetValue("heatOfFormation")) / molecularMass * 1000000;

                        decompositionSpeciesWithFraction = new Dictionary <AtmosphericGasSpecies, float>();
                        foreach (ConfigNode decompositionGasSpeciesNode in thisNode.GetNodes("DECOMPOSITION_SPECIES"))
                        {
                            AtmosphericGasSpecies decompositionSpecies = AtmDataOrganizer.idOrganizedListOfGasSpecies[decompositionGasSpeciesNode.GetValue("name")];
                            float massFraction = float.Parse(decompositionGasSpeciesNode.GetValue("massFraction"));

                            decompositionSpeciesWithFraction.Add(decompositionSpecies, massFraction);
                        }

                        break;
                    }
                }
            }

            CpLowTemp  = ((float)degFreedomLowTemp * 0.5f + 1f) * specificGasConstant;
            CpHighTemp = ((float)degFreedomHighTemp * 0.5f + 1f) * specificGasConstant;

            float tmp = tempLowDegFreedom - tempHighDegFreedom;

            tmp = tmp * tmp * tmp;
            tmp = 1 / tmp;

            tmp *= (CpHighTemp - CpLowTemp);

            constantsCpCurve[0] = 2f * tmp;
            constantsCpCurve[1] = -3f * (tempLowDegFreedom + tempHighDegFreedom) * tmp;
            constantsCpCurve[2] = 6f * tempLowDegFreedom * tempHighDegFreedom * tmp;
            constantsCpCurve[3] = tempLowDegFreedom * tempLowDegFreedom * (tempLowDegFreedom - 3f * tempHighDegFreedom) * tmp + CpLowTemp;


            tmp = tempBeginDecomposition - tempEndDecomposition;
            tmp = tmp * tmp * tmp;
            tmp = 1 / tmp;

            constantsDecompositionCurve[0] = -2f * tmp;
            constantsDecompositionCurve[1] = 3f * (tempBeginDecomposition + tempEndDecomposition) * tmp;
            constantsDecompositionCurve[2] = -6f * tempBeginDecomposition * tempEndDecomposition * tmp;
            constantsDecompositionCurve[3] = -tempBeginDecomposition * tempBeginDecomposition * (tempBeginDecomposition - 3f * tempEndDecomposition) * tmp + 1f;


            //Debug.Log("Initialized Gas Species '" + id + "'\n\r");
        }
Example #3
0
        public static void LoadConfigNodes()
        {
            idOrganizedListOfGasSpecies = new Dictionary<string, AtmosphericGasSpecies>();
            bodyOrganizedListOfAtmospheres = new Dictionary<CelestialBody, AtmosphereComposition>();
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("RH_ATM_GAS_SPECIES"))
            {
                foreach (ConfigNode gasSpeciesNode in node.GetNodes("GAS_SPECIES"))
                {
                    string id = gasSpeciesNode.GetValue("name");
                    AtmosphericGasSpecies newSpecies = new AtmosphericGasSpecies(id);

                    idOrganizedListOfGasSpecies.Add(id, newSpecies);
                }
            }
            foreach (KeyValuePair<string, AtmosphericGasSpecies> pair in idOrganizedListOfGasSpecies)
                pair.Value.Initialize();

            AtmosphereComposition defaultOxygenatedRocky = new AtmosphereComposition(),
                defaultUnoxygenatedRocky = new AtmosphereComposition(),
                defaultGasGiant = new AtmosphereComposition();

            float gasGiantRadius = 3000;

            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("RH_ATM_COMPOSITIONS"))
            {
                foreach (ConfigNode atmNode in node.GetNodes("ATM_COMPOSITION"))
                {
                    AtmosphereComposition newComposition = new AtmosphereComposition();

                    newComposition.gasSpeciesAndMassFractions = new Dictionary<AtmosphericGasSpecies, float>();

                    foreach (ConfigNode gasSpeciesNode in atmNode.GetNodes("GAS_SPECIES"))
                    {
                        AtmosphericGasSpecies decompositionSpecies = AtmDataOrganizer.idOrganizedListOfGasSpecies[gasSpeciesNode.GetValue("name")];

                        float massFraction = float.Parse(gasSpeciesNode.GetValue("massFraction"));
                        newComposition.gasSpeciesAndMassFractions.Add(decompositionSpecies, massFraction);
                    }

                    newComposition.referenceTemperature = float.Parse(atmNode.GetValue("referenceTemperature"));
                    newComposition.maxSimVelocity = float.Parse(atmNode.GetValue("maxSimVelocity"));

                    string bodyName = atmNode.GetValue("name");

                    for(int idx = 0; idx < FlightGlobals.Bodies.Count; idx++)
                    {
                        CelestialBody body = FlightGlobals.Bodies[idx];
                        if(body.name == bodyName)
                        {
                            newComposition.specHeatRatio = (float)body.atmosphereAdiabaticIndex;
                            newComposition.gasConstant = (float)((double)(AtmosphericGasSpecies.UniversalGasConstant) / (body.atmosphereMolarMass * 1000d));
                            bodyOrganizedListOfAtmospheres.Add(body, newComposition);
                            break;
                        }
                    }

                    if (bodyName == "defaultOxygenatedRocky")
                        defaultOxygenatedRocky = newComposition;
                    else if (bodyName == "defaultUnoxygenatedRocky")
                        defaultUnoxygenatedRocky = newComposition;
                    else if (bodyName == "defaultGasGiant")
                        defaultGasGiant = newComposition;
                }
                gasGiantRadius = float.Parse(node.GetValue("gasGiantRadius"));
            }

            foreach(CelestialBody body in FlightGlobals.Bodies)
            {
                if(!bodyOrganizedListOfAtmospheres.ContainsKey(body))
                {
                    if (body.Radius > gasGiantRadius)
                        bodyOrganizedListOfAtmospheres.Add(body, defaultGasGiant);
                    else if(body.atmosphereContainsOxygen)
                        bodyOrganizedListOfAtmospheres.Add(body, defaultOxygenatedRocky);
                    else
                        bodyOrganizedListOfAtmospheres.Add(body, defaultUnoxygenatedRocky);
                }
            }
        }