Esempio n. 1
0
        public StellarBody.Params GetStellarBodyParams(
            string iconSpriteName,
            Vector3 position,
            float radius,
            int orbitalId,
            int colonyPlayerId,
            string type,
            float hazard,
            float maxHazard,
            string faction,
            float biosphere,
            double population,
            int?typeVariant,
            Kerberos.Sots.Strategy.InhabitedPlanet.ColonyStage colonyStage,
            SystemColonyType colonyType)
        {
            try
            {
                XmlElement[] hazardPointBrackets = this.GetHazardPointBrackets(type, typeVariant, hazard, orbitalId);
                float        num1       = float.Parse(hazardPointBrackets[1].GetAttribute("value"));
                float        num2       = float.Parse(hazardPointBrackets[0].GetAttribute("value"));
                XmlElement   atmo1      = this.GetAtmo(hazardPointBrackets[0].GetAttribute("atmo"));
                XmlElement   atmo2      = this.GetAtmo(hazardPointBrackets[1].GetAttribute("atmo"));
                XmlElement   heightGen1 = this.GetHeightGen(hazardPointBrackets[0].GetAttribute("heightgen"));
                XmlElement   heightGen2 = this.GetHeightGen(hazardPointBrackets[1].GetAttribute("heightgen"));
                XmlElement   faction1   = this.GetFaction(faction);
                Vector2      vector2    = faction1 != null?Vector2.Parse(faction1.GetAttribute("cityaltrange")) : Vector2.Zero;

                float t = 0.0f;
                if ((double)num1 - (double)num2 >= 1.40129846432482E-45)
                {
                    t = ((float)(((double)hazard - (double)num2) / ((double)num1 - (double)num2))).Saturate();
                }
                StellarBody.Params @params = new StellarBody.Params();
                @params.Civilians              = new StellarBody.PlanetCivilianData[0];
                @params.IconSpriteName         = iconSpriteName;
                @params.ColonyPlayerID         = colonyPlayerId;
                @params.AtmoThickness          = ScalarExtensions.Lerp(float.Parse(atmo1.GetAttribute("thick")), float.Parse(atmo2.GetAttribute("thick")), t);
                @params.AtmoKm                 = ScalarExtensions.Lerp(float.Parse(atmo1.GetAttribute("km")), float.Parse(atmo2.GetAttribute("km")), t);
                @params.AtmoKr                 = ScalarExtensions.Lerp(float.Parse(atmo1.GetAttribute("kr")), float.Parse(atmo2.GetAttribute("kr")), t);
                @params.AtmoScatterWaveLengths = Vector3.Lerp(Vector3.Parse(atmo1.GetAttribute("filter")), Vector3.Parse(atmo2.GetAttribute("filter")), t);
                @params.AtmoScaleDepth         = ScalarExtensions.Lerp(float.Parse(atmo1.GetAttribute("scaledepth")), float.Parse(atmo2.GetAttribute("scaledepth")), t);
                @params.CloudDiffuseTexture    = atmo1.GetAttribute("clouddiffuse");
                @params.CloudSpecularTexture   = atmo1.GetAttribute("cloudspecular");
                @params.CloudOpacity           = ScalarExtensions.Lerp(float.Parse(atmo1.GetAttribute("cloudcover")), float.Parse(atmo2.GetAttribute("cloudcover")), t);
                @params.CloudDiffuseColor      = Vector3.Lerp(Vector3.Parse(atmo1.GetAttribute("clouddiffusecolor")), Vector3.Parse(atmo2.GetAttribute("clouddiffusecolor")), t);
                @params.CloudSpecularColor     = Vector3.Lerp(Vector3.Parse(atmo1.GetAttribute("cloudspecularcolor")), Vector3.Parse(atmo2.GetAttribute("cloudspecularcolor")), t);
                @params.CityEmissiveTexture    = faction1.GetAttribute("cityemissive");
                @params.CitySprawl             = (float)(population / 1000000000.0);
                @params.HeightGradient1Texture = hazardPointBrackets[0].GetAttribute("heightgrad");
                @params.HeightGradient2Texture = hazardPointBrackets[1].GetAttribute("heightgrad");
                @params.HeightGradient2Blend   = t;
                @params.HeightGradient3Texture = faction1.GetAttribute("idealgrad");
                @params.HeightGradient3Blend   = 1f - (hazard / maxHazard).Saturate();
                @params.MaxCityAltitude        = vector2.Y;
                @params.MinCityAltitude        = vector2.X;
                @params.WaterSpecularColor     = Vector3.Lerp(Vector3.Parse(hazardPointBrackets[0].GetAttribute("waterspec")), Vector3.Parse(hazardPointBrackets[1].GetAttribute("waterspec")), t);
                @params.MaxLandHeight          = ScalarExtensions.Lerp(float.Parse(hazardPointBrackets[0].GetAttribute("maxlandalt")), float.Parse(hazardPointBrackets[1].GetAttribute("maxlandalt")), t);
                @params.MaxWaterDepth          = ScalarExtensions.Lerp(float.Parse(hazardPointBrackets[0].GetAttribute("maxseadepth")), float.Parse(hazardPointBrackets[1].GetAttribute("maxseadepth")), t);
                @params.WaterLevel             = ScalarExtensions.Lerp(float.Parse(hazardPointBrackets[0].GetAttribute("sealevel")), float.Parse(hazardPointBrackets[1].GetAttribute("sealevel")), t);
                float num3 = ScalarExtensions.Lerp(float.Parse(hazardPointBrackets[0].GetAttribute("bumpiness")), float.Parse(hazardPointBrackets[1].GetAttribute("bumpiness")), t);
                @params.Position     = position;
                @params.Radius       = radius;
                @params.RandomSeed   = orbitalId;
                @params.UseHeightMap = true;
                @params.TextureSize  = 512;
                @params.BodyType     = type;
                @params.ColonyStage  = colonyStage;
                @params.ColonyType   = colonyType;
                string attribute1 = heightGen1.GetAttribute(nameof(type));
                string attribute2 = heightGen2.GetAttribute(nameof(type));
                if (attribute1 == "planecuts")
                {
                    StellarBody.HGPlaneCutsParams hgPlaneCutsParams = new StellarBody.HGPlaneCutsParams();
                    hgPlaneCutsParams.Bumpiness = num3;
                    if (attribute2 == attribute1)
                    {
                        hgPlaneCutsParams.BaseHeight = ScalarExtensions.Lerp(float.Parse(heightGen1.GetAttribute("baseheight")), float.Parse(heightGen2.GetAttribute("baseheight")), t);
                        hgPlaneCutsParams.Iterations = (int)ScalarExtensions.Lerp((float)int.Parse(heightGen1.GetAttribute("iterations")), (float)int.Parse(heightGen2.GetAttribute("iterations")), t);
                        hgPlaneCutsParams.Shift      = ScalarExtensions.Lerp(float.Parse(heightGen1.GetAttribute("shift")), float.Parse(heightGen2.GetAttribute("shift")), t);
                    }
                    else
                    {
                        hgPlaneCutsParams.BaseHeight = float.Parse(heightGen1.GetAttribute("baseheight"));
                        hgPlaneCutsParams.Iterations = int.Parse(heightGen1.GetAttribute("iterations"));
                        hgPlaneCutsParams.Shift      = float.Parse(heightGen1.GetAttribute("shift"));
                    }
                    @params.HeightGen = (StellarBody.HeightGenParams)hgPlaneCutsParams;
                }
                else if (attribute1 == "blend")
                {
                    StellarBody.HGBlendParams hgBlendParams = new StellarBody.HGBlendParams();
                    hgBlendParams.Bumpiness     = num3;
                    hgBlendParams.Layer1Texture = heightGen1.GetAttribute("base");
                    if (attribute2 == attribute1)
                    {
                        hgBlendParams.Layer2Texture = heightGen2.GetAttribute("base");
                        hgBlendParams.Layer2Amount  = t;
                    }
                    else
                    {
                        hgBlendParams.Layer2Texture = hgBlendParams.Layer1Texture;
                        hgBlendParams.Layer2Amount  = 0.0f;
                    }
                    @params.HeightGen = (StellarBody.HeightGenParams)hgBlendParams;
                }
                return(@params);
            }
            catch (Exception ex)
            {
                App.Log.Warn(string.Format("Parse error resolving planet display rules (type={0}, will use defaults instead):\n" + ex.ToString(), (object)(type ?? "null")), "data");
                return(StellarBody.Params.Default);
            }
        }
Esempio n. 2
0
        public static StellarBody Create(App game, StellarBody.Params p)
        {
            Player        player     = game.GetPlayer(p.ColonyPlayerID);
            List <object> objectList = new List <object>();

            objectList.AddRange((IEnumerable <object>) new object[38]
            {
                (object)(player != null ? player.ObjectID : 0),
                (object)p.OrbitalID,
                (object)p.IconSpriteName,
                (object)(p.SurfaceMaterial ?? "planet_earth2"),
                (object)p.Position,
                (object)p.Radius,
                (object)p.IsInCombat,
                (object)game.AssetDatabase.DefaultPlanetSensorRange,
                (object)p.AtmoThickness,
                (object)p.AtmoScatterWaveLengths,
                (object)p.AtmoKm,
                (object)p.AtmoKr,
                (object)p.AtmoScaleDepth,
                (object)p.UseHeightMap,
                (object)p.RandomSeed,
                (object)p.TextureSize,
                (object)p.HeightGradient1Texture,
                (object)p.HeightGradient2Texture,
                (object)p.HeightGradient3Texture,
                (object)p.HeightGradient2Blend,
                (object)p.HeightGradient3Blend,
                (object)p.CityEmissiveTexture,
                (object)p.MinCityAltitude,
                (object)p.MaxCityAltitude,
                (object)p.CitySprawl,
                (double)p.CloudOpacity != 0.0 ? (object)p.CloudDiffuseTexture : (object)string.Empty,
                (double)p.CloudOpacity != 0.0 ? (object)p.CloudSpecularTexture : (object)string.Empty,
                (object)p.CloudOpacity,
                (object)p.CloudDiffuseColor,
                (object)p.CloudSpecularColor,
                (object)p.WaterLevel,
                (object)p.WaterSpecularColor,
                (object)p.MaxWaterDepth,
                (object)p.MaxLandHeight,
                (object)p.BodyType,
                (object)(p.BodyName ?? string.Empty),
                (object)(int)p.ColonyStage,
                (object)(int)p.ColonyType
            });
            if (p.HeightGen != null)
            {
                if (p.HeightGen is StellarBody.HGBlendParams)
                {
                    StellarBody.HGBlendParams heightGen = p.HeightGen as StellarBody.HGBlendParams;
                    objectList.AddRange((IEnumerable <object>) new object[5]
                    {
                        (object)"blend",
                        (object)heightGen.Bumpiness,
                        (object)heightGen.Layer1Texture,
                        (object)heightGen.Layer2Texture,
                        (object)heightGen.Layer2Amount
                    });
                }
                else if (p.HeightGen is StellarBody.HGPlaneCutsParams)
                {
                    StellarBody.HGPlaneCutsParams heightGen = p.HeightGen as StellarBody.HGPlaneCutsParams;
                    objectList.AddRange((IEnumerable <object>) new object[5]
                    {
                        (object)"planecuts",
                        (object)heightGen.Bumpiness,
                        (object)heightGen.BaseHeight,
                        (object)heightGen.Iterations,
                        (object)heightGen.Shift
                    });
                }
                else
                {
                    objectList.Add((object)"none");
                }
            }
            else
            {
                objectList.Add((object)"none");
            }
            objectList.Add((object)p.Civilians.Length);
            foreach (StellarBody.PlanetCivilianData civilian in p.Civilians)
            {
                objectList.Add((object)civilian.Faction);
                objectList.Add((object)civilian.Population);
            }
            objectList.Add((object)p.ImperialPopulation);
            objectList.Add((object)p.Infrastructure);
            objectList.Add((object)p.Suitability);
            objectList.Add((object)Constants.MinSuitability);
            objectList.Add((object)Constants.MaxSuitability);
            StellarBody stellarBody = game.AddObject <StellarBody>(objectList.ToArray());

            stellarBody.Parameters = p;
            return(stellarBody);
        }