Пример #1
0
        public static void ApplyBiomeSettings()
        {
            Log.Message("[Map Designer] Applying settings");
            MapDesignerSettings settings = MapDesignerMod.mod.settings;

            // densities
            Dictionary <string, BiomeDefault> biomeDefaults = settings.biomeDefaults;

            float densityPlant  = settings.densityPlant;
            float densityAnimal = settings.densityAnimal;

            foreach (BiomeDef biome in DefDatabase <BiomeDef> .AllDefs)
            {
                try
                {
                    biome.animalDensity = biomeDefaults[biome.defName].animalDensity * densityAnimal;
                    biome.plantDensity  = biomeDefaults[biome.defName].plantDensity * densityPlant;

                    if (biome.plantDensity > 1f)
                    {
                        biome.wildPlantRegrowDays = biomeDefaults[biome.defName].wildPlantRegrowDays / biome.plantDensity;
                        biome.plantDensity        = 1f;
                    }
                }
                catch
                {
                    Log.Message("[Map Designer] ERROR applying plant and animal settings to " + biome.defName);
                }
            }

            Dictionary <string, FloatRange> densityDefaults = settings.densityDefaults;

            // ruins
            try
            {
                float densityRuins = settings.densityRuins;
                if (densityRuins > 1)
                {
                    densityRuins = (float)Math.Pow(densityRuins, 3);
                }
                (DefDatabase <GenStepDef> .GetNamed("ScatterRuinsSimple").genStep as GenStep_Scatterer).countPer10kCellsRange.min = densityDefaults["ScatterRuinsSimple"].min * densityRuins;
                (DefDatabase <GenStepDef> .GetNamed("ScatterRuinsSimple").genStep as GenStep_Scatterer).countPer10kCellsRange.max = densityDefaults["ScatterRuinsSimple"].max * densityRuins;
            }
            catch
            {
                Log.Message("[Map Designer] ERROR with settings: ruins");
            }

            // ancient dangers
            try
            {
                float densityDanger = settings.densityDanger;
                if (densityDanger > 1)
                {
                    densityDanger = (float)Math.Pow(densityDanger, 4);
                }
                (DefDatabase <GenStepDef> .GetNamed("ScatterShrines").genStep as GenStep_Scatterer).countPer10kCellsRange.min = densityDefaults["ScatterShrines"].min * densityDanger;
                (DefDatabase <GenStepDef> .GetNamed("ScatterShrines").genStep as GenStep_Scatterer).countPer10kCellsRange.max = densityDefaults["ScatterShrines"].max * densityDanger;
            }
            catch
            {
                Log.Message("[Map Designer] ERROR with settings: ancient dangers");
            }

            // geysers
            try
            {
                float densityGeyser = settings.densityGeyser;
                if (densityGeyser > 1)
                {
                    densityGeyser = (float)Math.Pow(densityGeyser, 2);
                }
                (DefDatabase <GenStepDef> .GetNamed("SteamGeysers").genStep as GenStep_Scatterer).countPer10kCellsRange.min = densityDefaults["SteamGeysers"].min * densityGeyser;
                (DefDatabase <GenStepDef> .GetNamed("SteamGeysers").genStep as GenStep_Scatterer).countPer10kCellsRange.max = densityDefaults["SteamGeysers"].max * densityGeyser;
            }
            catch
            {
                Log.Message("[Map Designer] ERROR with settings: geysers");
            }

            // rivers
            float widthOnMap = 6f;

            foreach (RiverDef river in DefDatabase <RiverDef> .AllDefs)
            {
                try
                {
                    river.widthOnMap *= settings.sizeRiver;
                    river.widthOnMap  = Math.Min(175, river.widthOnMap);
                }
                catch
                {
                    Log.Message("[Map Designer] ERROR with settings: river width : " + river.defName);
                }
            }

            // terrain
            if (Math.Abs(settings.terrainFert - 1f) > 0.05 || Math.Abs(settings.terrainWater - 1f) > 0.05)
            {
                Log.Message(String.Format("[Map Designer] Terrain settings: fertility: {0} | Water {1}", Math.Round(100 * settings.terrainFert), Math.Round(100 * settings.terrainWater)));
                foreach (BiomeDef biome in DefDatabase <BiomeDef> .AllDefs)
                {
                    if (!biome.terrainsByFertility.NullOrEmpty())
                    {
                        //Log.Message("Doing adjustments for " + biome.defName);
                        try
                        {
                            TerrainDefault newTerrain;
                            float          minFertBound = -0.2f;
                            float          maxFertBound = 1.2f;

                            if (ModsConfig.IsActive("BiomesTeam.BiomesCore"))
                            {
                                maxFertBound = HelperMethods.GetMaxFertByBiome(biome);
                            }
                            newTerrain = TerrainUtility.StretchTerrainFertility(biomeDefaults[biome.defName].terrain, minFertBound, maxFertBound);


                            biome.terrainsByFertility = newTerrain.terrainsByFertility;
                            biome.terrainPatchMakers  = newTerrain.terrainPatchMakers;
                        }

                        catch (Exception e)
                        {
                            Log.Message("[Map Designer] ERROR with settings: terrain : " + biome.defName);
                            Log.Message(e.Message);

                            TerrainDefault dictEntry = settings.biomeDefaults[biome.defName].terrain;
                            Log.Message("--terrainsByFertility");
                            foreach (TerrainThreshold t in dictEntry.terrainsByFertility)
                            {
                                Log.Message(String.Format("- {0} .... {1} | {2}", t.terrain.defName, Math.Round(t.min, 2), Math.Round(t.max, 2)));
                            }
                            Log.Message("--terrainPatchMakers");
                            for (int i = 0; i < dictEntry.terrainPatchMakers.Count(); i++)
                            {
                                TerrainPatchMaker p = dictEntry.terrainPatchMakers[i];
                                Log.Message(String.Format("Patchmaker #{0} | min {1} | max {2}", i, p.minFertility, p.maxFertility));
                                foreach (TerrainThreshold t in p.thresholds)
                                {
                                    Log.Message(String.Format("--- {0} | {1} | {2}", t.terrain.defName, Math.Round(t.min, 2), Math.Round(t.max, 2)));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Log.Message("[Map Designer] Terrain settings: Default");
                foreach (BiomeDef biome in DefDatabase <BiomeDef> .AllDefs)
                {
                    biome.terrainsByFertility = biomeDefaults[biome.defName].terrain.terrainsByFertility;
                    biome.terrainPatchMakers  = biomeDefaults[biome.defName].terrain.terrainPatchMakers;
                }
            }
        }
Пример #2
0
        public static TerrainDefault StretchTerrainFertility(TerrainDefault old, float min, float max)
        {
            oldTerrain = old;
            minMapFert = min;
            maxMapFert = max;

            newTerrain = new TerrainDefault();
            newTerrain.terrainsByFertility = new List <TerrainThreshold>(oldTerrain.terrainsByFertility);

            newTerrain.terrainPatchMakers = new List <TerrainPatchMaker>();
            for (int i = 0; i < oldTerrain.terrainPatchMakers.Count(); i++)
            {
                TerrainPatchMaker p = new TerrainPatchMaker();
                p.maxFertility      = oldTerrain.terrainPatchMakers[i].maxFertility;
                p.minFertility      = oldTerrain.terrainPatchMakers[i].minFertility;
                p.perlinFrequency   = oldTerrain.terrainPatchMakers[i].perlinFrequency;
                p.perlinLacunarity  = oldTerrain.terrainPatchMakers[i].perlinLacunarity;
                p.perlinOctaves     = oldTerrain.terrainPatchMakers[i].perlinOctaves;
                p.perlinPersistence = oldTerrain.terrainPatchMakers[i].perlinPersistence;
                p.thresholds        = new List <TerrainThreshold>(oldTerrain.terrainPatchMakers[i].thresholds);

                newTerrain.terrainPatchMakers.Add(p);
            }


            List <TerrainThreshold> oldTerrainsByFertility = oldTerrain.terrainsByFertility;

            List <TBF> listTbf = new List <TBF>();

            // convert to TBFs
            for (int i = 0; i < oldTerrainsByFertility.Count(); i++)
            {
                TBF item = new TBF()
                {
                    thresh = oldTerrainsByFertility[i],
                    size   = Math.Min(oldTerrainsByFertility[i].max, maxMapFert) - Math.Max(oldTerrainsByFertility[i].min, minMapFert)
                };
                listTbf.Add(item);
            }

            // the actual adjustments
            if (listTbf.Count() >= 1)
            {
                FertChangeTbf(listTbf);
            }

            // TerrainPatchMaker adjustments
            List <TerrainDef> patchTerrains = new List <TerrainDef>();

            foreach (TerrainPatchMaker p in newTerrain.terrainPatchMakers)
            {
                foreach (TerrainThreshold t in p.thresholds)
                {
                    patchTerrains.Add(t.terrain);
                }
            }

            // check that there are terrains
            if (patchTerrains.Count() >= 1)
            {
                FertChangePatchMakers(patchTerrains);
            }

            return(newTerrain);
        }