Exemplo n.º 1
0
        public override void Generate(Map map, GenStepParams parms)
        {
            BeachMaker.Init(map);
            RiverMaker      riverMaker  = GenerateRiver(map);
            List <IntVec3>  list        = new List <IntVec3>();
            MapGenFloatGrid elevation   = MapGenerator.Elevation;
            MapGenFloatGrid fertility   = MapGenerator.Fertility;
            MapGenFloatGrid caves       = MapGenerator.Caves;
            TerrainGrid     terrainGrid = map.terrainGrid;

            foreach (IntVec3 allCell in map.AllCells)
            {
                Building   edifice    = allCell.GetEdifice(map);
                TerrainDef terrainDef = null;
                terrainDef = (((edifice == null || edifice.def.Fillage != FillCategory.Full) && !(caves[allCell] > 0f)) ? TerrainFrom(allCell, map, elevation[allCell], fertility[allCell], riverMaker, preferSolid: false) : TerrainFrom(allCell, map, elevation[allCell], fertility[allCell], riverMaker, preferSolid: true));
                if (terrainDef.IsRiver && edifice != null)
                {
                    list.Add(edifice.Position);
                    edifice.Destroy();
                }
                terrainGrid.SetTerrain(allCell, terrainDef);
            }
            riverMaker?.ValidatePassage(map);
            RemoveIslands(map);
            RoofCollapseCellsFinder.RemoveBulkCollapsingRoofs(list, map);
            BeachMaker.Cleanup();
            foreach (TerrainPatchMaker terrainPatchMaker in map.Biome.terrainPatchMakers)
            {
                terrainPatchMaker.Cleanup();
            }
        }
Exemplo n.º 2
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (map.TileInfo.WaterCovered)
            {
                return;
            }
            ModExt_Biome_FeatureControl extFtControl = map.Biome.GetModExtension <ModExt_Biome_FeatureControl>();

            if (extFtControl == null || extFtControl.overwriteRockChunks != RockChunksOverwriteType.AddToCaves)
            {
                return;
            }
            freqFactorNoise = new Perlin(0.014999999664723873, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
            freqFactorNoise = new ScaleBias(1.0, 1.0, freqFactorNoise);
            NoiseDebugUI.StoreNoiseRender(freqFactorNoise, "cave_rock_chunks_freq_factor");
            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 cell in map.AllCells)
            {
                float probVal = PlaceProbabilityPerCell * freqFactorNoise.GetValue(cell);
                if (elevation[cell] >= ThreshLooseRock && Rand.Value < probVal)
                {
                    GrowLowRockFormationFrom(cell, map);
                }
            }
            freqFactorNoise = null;
        }
Exemplo n.º 3
0
        public override void Generate(Map map, GenStepParams parms)
        {
            ModuleBase chambers = new Perlin(0.010, 1.7, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);

            ModuleBase columns = new Perlin(0.150, 0.5, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);

            columns = new ScaleBias(0.5, 0.5, columns);

            // push columns to the centers of chambers
            ModuleBase columnsNoise = new Invert(chambers);

            columnsNoise = new ScaleBias(3f, -2f, columnsNoise);
            columnsNoise = new Min(new Const(0.0), columnsNoise);
            columns      = new Add(columns, columnsNoise);

            // broken tunnel network
            ModuleBase tunnels      = new Perlin(0.01, 1.7, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);
            ModuleBase tunnelsNoise = new Perlin(0.005, 0.0, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.Medium);

            tunnels = new Abs(tunnels);
            tunnels = new Add(new Const(0.5), tunnels);
            tunnels = new Add(tunnels, new Clamp(0, 0.5, tunnelsNoise));

            chambers = new Min(new Add(chambers, new Const(0.75)), tunnels);

            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 cell in map.AllCells)
            {
                elevation[cell] = Math.Max(columns.GetValue(cell), chambers.GetValue(cell));
            }
        }
Exemplo n.º 4
0
 public override void Generate(Map map, GenStepParams parms)
 {
     if (Find.World.HasCaves(map.Tile))
     {
         directionNoise = new Perlin(0.0020500000100582838, 2.0, 0.5, 4, Rand.Int, QualityMode.Medium);
         MapGenFloatGrid elevation = MapGenerator.Elevation;
         BoolGrid        visited   = new BoolGrid(map);
         List <IntVec3>  group     = new List <IntVec3>();
         foreach (IntVec3 allCell in map.AllCells)
         {
             if (!visited[allCell] && IsRock(allCell, elevation, map))
             {
                 group.Clear();
                 map.floodFiller.FloodFill(allCell, (IntVec3 x) => IsRock(x, elevation, map), delegate(IntVec3 x)
                 {
                     visited[x] = true;
                     group.Add(x);
                 });
                 Trim(group, map);
                 RemoveSmallDisconnectedSubGroups(group, map);
                 if (group.Count >= 300)
                 {
                     DoOpenTunnels(group, map);
                     DoClosedTunnels(group, map);
                 }
             }
         }
     }
 }
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!Find.World.HasCaves(map.Tile))
            {
                return;
            }
            Perlin          perlin  = new Perlin(0.079999998211860657, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
            Perlin          perlin2 = new Perlin(0.15999999642372131, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
            MapGenFloatGrid caves   = MapGenerator.Caves;

            foreach (IntVec3 current in map.AllCells)
            {
                if (caves[current] > 0f)
                {
                    TerrainDef terrain = current.GetTerrain(map);
                    if (!terrain.IsRiver)
                    {
                        float num  = (float)perlin.GetValue((double)current.x, 0.0, (double)current.z);
                        float num2 = (float)perlin2.GetValue((double)current.x, 0.0, (double)current.z);
                        if (num > 0.93f)
                        {
                            map.terrainGrid.SetTerrain(current, TerrainDefOf.WaterShallow);
                        }
                        else if (num2 > 0.55f)
                        {
                            map.terrainGrid.SetTerrain(current, TerrainDefOf.Gravel);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
 public override void Generate(Map map, GenStepParams parms)
 {
     if (Find.World.HasCaves(map.Tile))
     {
         Perlin          perlin  = new Perlin(0.079999998211860657, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
         Perlin          perlin2 = new Perlin(0.15999999642372131, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
         MapGenFloatGrid caves   = MapGenerator.Caves;
         foreach (IntVec3 allCell in map.AllCells)
         {
             if (!(caves[allCell] <= 0f) && !allCell.GetTerrain(map).IsRiver)
             {
                 float num  = (float)perlin.GetValue(allCell.x, 0.0, allCell.z);
                 float num2 = (float)perlin2.GetValue(allCell.x, 0.0, allCell.z);
                 if (num > 0.93f)
                 {
                     map.terrainGrid.SetTerrain(allCell, TerrainDefOf.WaterShallow);
                 }
                 else if (num2 > 0.55f)
                 {
                     map.terrainGrid.SetTerrain(allCell, TerrainDefOf.Gravel);
                 }
             }
         }
     }
 }
 public override void Generate(Map map)
 {
     if (Find.World.HasCaves(map.Tile))
     {
         Perlin          perlin  = new Perlin(0.079999998211860657, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
         Perlin          perlin2 = new Perlin(0.15999999642372131, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium);
         MapGenFloatGrid caves   = MapGenerator.Caves;
         foreach (IntVec3 allCell in map.AllCells)
         {
             IntVec3 current = allCell;
             if (!(caves[current] <= 0.0))
             {
                 TerrainDef terrain = current.GetTerrain(map);
                 if (terrain != TerrainDefOf.WaterMovingShallow && terrain != TerrainDefOf.WaterMovingDeep)
                 {
                     float num  = (float)perlin.GetValue((double)current.x, 0.0, (double)current.z);
                     float num2 = (float)perlin2.GetValue((double)current.x, 0.0, (double)current.z);
                     if (num > 0.93000000715255737)
                     {
                         map.terrainGrid.SetTerrain(current, TerrainDefOf.WaterShallow);
                     }
                     else if (num2 > 0.550000011920929)
                     {
                         map.terrainGrid.SetTerrain(current, TerrainDefOf.Gravel);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
        public override void Generate(Map map, GenStepParams parms)
        {
            var mapParent = map.Parent as MapParent_ZLevel;

            if (mapParent.hasCaves)
            {
                directionNoise = new Perlin(DirectionNoiseFrequency, 2.0, 0.5, 4, Rand.Int, QualityMode.Medium);
                MapGenFloatGrid elevation = MapGenerator.Elevation;
                BoolGrid        visited   = new BoolGrid(map);
                List <IntVec3>  group     = new List <IntVec3>();
                foreach (IntVec3 allCell in map.AllCells)
                {
                    if (!visited[allCell] && IsRock(allCell, elevation, map))
                    {
                        group.Clear();
                        map.floodFiller.FloodFill(allCell, (IntVec3 x) => IsRock(x, elevation, map), delegate(IntVec3 x)
                        {
                            visited[x] = true;
                            group.Add(x);
                        });
                        Trim(group, map);
                        RemoveSmallDisconnectedSubGroups(group, map);
                        if (group.Count >= MinRocksToGenerateAnyTunnel)
                        {
                            DoOpenTunnels(group, map);
                            DoClosedTunnels(group, map);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
 public MapGridSet(MapGenFloatGrid elevationGrid, MapGenFloatGrid fertilityGrid, MapGenFloatGrid cavesGrid, Map map)
 {
     ElevationGrid = elevationGrid;
     FertilityGrid = fertilityGrid;
     CavesGrid     = cavesGrid;
     Map           = map;
 }
Exemplo n.º 10
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (map.Biome != Util_CaveBiome.CaveBiomeDef)
            {
                // Nothing to do in other biomes.
                return;
            }

            // Generate basic map elevation.
            NoiseRenderer.renderSize = new IntVec2(map.Size.x, map.Size.z);
            ModuleBase perlinMap = new Perlin(ElevationFreq, 1.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);

            perlinMap = new ScaleBias(0.5, 0.5, perlinMap);
            NoiseDebugUI.StoreNoiseRender(perlinMap, "Cave: elev base");
            perlinMap = new Multiply(perlinMap, new Const(ElevationFactorCave));
            NoiseDebugUI.StoreNoiseRender(perlinMap, "Cave: elev cave-factored");

            // Override base elevation grid so the GenStep_Terrain.Generate function uses this one.
            MapGenFloatGrid mapGenFloatGrid = MapGenerator.FloatGridNamed("Elevation");

            foreach (IntVec3 current in map.AllCells)
            {
                mapGenFloatGrid[current] = perlinMap.GetValue(current);
            }
        }
Exemplo n.º 11
0
        public override void Generate(Map map)
        {
            //if (!Find.World.HasCaves(map.Tile))
            //{
            //    return;
            //}
            this.directionNoise = new Perlin(0.0020500000100582838, 2.0, 0.5, 4, Rand.Int, QualityMode.Medium);
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            BoolGrid        visited   = new BoolGrid(map);
            List <IntVec3>  group     = new List <IntVec3>();

            foreach (IntVec3 current in map.AllCells)
            {
                if (!visited[current] && this.IsRock(current, elevation, map))
                {
                    group.Clear();
                    map.floodFiller.FloodFill(current, (IntVec3 x) => this.IsRock(x, elevation, map), delegate(IntVec3 x)
                    {
                        visited[x] = true;
                        group.Add(x);
                    }, 2147483647, false, null);
                    this.Trim(group, map);
                    //this.RemoveSmallDisconnectedSubGroups(group, map);
                    if (group.Count >= 50)
                    {
                        this.DoOpenTunnels(group, map);
                        this.DoClosedTunnels(group, map);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!Find.World.HasCaves(map.Tile))
            {
                return;
            }
            this.directionNoise = new Perlin(0.0020500000100582838, 2.0, 0.5, 4, Rand.Int, QualityMode.Medium);
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            BoolGrid        visited   = new BoolGrid(map);
            List <IntVec3>  group     = new List <IntVec3>();

            foreach (IntVec3 intVec in map.AllCells)
            {
                if (!visited[intVec] && this.IsRock(intVec, elevation, map))
                {
                    group.Clear();
                    map.floodFiller.FloodFill(intVec, (IntVec3 x) => this.IsRock(x, elevation, map), delegate(IntVec3 x)
                    {
                        visited[x] = true;
                        group.Add(x);
                    }, int.MaxValue, false, null);
                    this.Trim(group, map);
                    this.RemoveSmallDisconnectedSubGroups(group, map);
                    if (group.Count >= 300)
                    {
                        this.DoOpenTunnels(group, map);
                        this.DoClosedTunnels(group, map);
                    }
                }
            }
        }
Exemplo n.º 13
0
 private void spawnPlant(IntVec3 place, MapGenFloatGrid caves, float desiredTotalDensity, ThingDef plantDef)
 {
     if (place.GetEdifice(map) == null && place.GetCover(map) == null && caves[place] <= 0f)
     {
         float num2 = map.fertilityGrid.FertilityAt(place);
         float num3 = num2 * desiredTotalDensity;
         if (Rand.Value < num3)
         {
             for (int j = 0; j < plantDef.plant.wildClusterSizeRange.RandomInRange; j++)
             {
                 IntVec3 c2;
                 if (j == 0)
                 {
                     c2 = place;
                 }
                 else if (!GenPlantReproduction.TryFindReproductionDestination(place, plantDef, SeedTargFindMode.MapGenCluster, map, out c2))
                 {
                     break;
                 }
                 Plant plant = (Plant)ThingMaker.MakeThing(plantDef, null);
                 plant.Growth = Rand.Range(0.07f, 1f);
                 if (plant.def.plant.LimitedLifespan)
                 {
                     plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0));
                 }
                 GenSpawn.Spawn(plant, c2, map);
             }
         }
     }
 }
        private IntVec3 FindRandomEdgeCellForTunnel(List <IntVec3> group, Map map)
        {
            MapGenFloatGrid caves = MapGenerator.Caves;

            IntVec3[] cardinalDirections = GenAdj.CardinalDirections;
            tmpCells.Clear();
            tmpGroupSet.Clear();
            tmpGroupSet.AddRange(group);
            for (int i = 0; i < group.Count; i++)
            {
                if (group[i].DistanceToEdge(map) < 3 || caves[group[i]] > 0f)
                {
                    continue;
                }
                for (int j = 0; j < 4; j++)
                {
                    IntVec3 item = group[i] + cardinalDirections[j];
                    if (!tmpGroupSet.Contains(item))
                    {
                        tmpCells.Add(group[i]);
                        break;
                    }
                }
            }
            if (!tmpCells.Any())
            {
                Log.Warning("Could not find any valid edge cell.");
                return(group.RandomElement());
            }
            return(tmpCells.RandomElement());
        }
Exemplo n.º 15
0
        public static void WorkOnMapGenerator(Map map)
        {
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            MapGenFloatGrid fertility = MapGenerator.Fertility;

            foreach (IntVec3 cell in map.AllCells)
            {
                // Set elevation
                if (extIslands.calcElevationType == GenStepCalculationType.Set)
                {
                    elevation[cell] = GetValueAt(cell, noiseElevation) * extIslands.elevationPostScale + extIslands.elevationPostOffset;
                }
                else if (extIslands.calcElevationType == GenStepCalculationType.Add)
                {
                    elevation[cell] += GetValueAt(cell, noiseElevation) * extIslands.elevationPostScale + extIslands.elevationPostOffset;
                }
                // Set fertility
                if (extIslands.calcFertilityType == GenStepCalculationType.Set)
                {
                    fertility[cell] = GetValueAt(cell, noiseFertility) * extIslands.fertilityPostScale + extIslands.fertilityPostOffset;
                }
                else if (extIslands.calcFertilityType == GenStepCalculationType.Add)
                {
                    fertility[cell] += GetValueAt(cell, noiseFertility) * extIslands.fertilityPostScale + extIslands.fertilityPostOffset;
                }
            }
        }
Exemplo n.º 16
0
        public override void Generate(Map map, GenStepParams parms)
        {
            ModuleBase tunnels = new Perlin(0.024, 2.2, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);

            tunnels = new ScaleBias(0.5, 0.5, tunnels);

            ModuleBase noise = new Perlin(0.02, 1.5, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.Medium);



            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 cell in map.AllCells)
            {
                elevation[cell] = 0.53f + 2f * Math.Abs(tunnels.GetValue(cell) - 0.5f) + 0.10f * noise.GetValue(cell);
            }


            IntVec3 roomLoc = map.Center;

            roomLoc.x = (int)(Rand.Range(0.3f, 1.7f) * roomLoc.x);
            roomLoc.z = (int)(Rand.Range(0.3f, 1.7f) * roomLoc.z);

            ModuleBase roomNoise = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);
            float      sizeAdj   = Rand.Range(8f, 10f);

            foreach (IntVec3 cell in map.AllCells)
            {
                float distance = (float)Math.Sqrt(Math.Pow(cell.x - roomLoc.x, 2) + Math.Pow(cell.z - roomLoc.z, 2));

                float addition = 25 * (1f - (sizeAdj * distance / map.Size.x)) + 15f * roomNoise.GetValue(cell);

                elevation[cell] -= Math.Max(0, addition);
            }
        }
Exemplo n.º 17
0
        private void SmoothGenerated(Map map)
        {
            MapGenFloatGrid caves     = MapGenerator.Caves;
            List <IntVec3>  caveCells = new List <IntVec3>();

            foreach (IntVec3 cell in map.AllCells)
            {
                if (caves[cell] > 0f)
                {
                    caveCells.Add(cell);
                }
            }
            GenMorphology.Close(caveCells, 3, map);
            foreach (IntVec3 cell in map.AllCells)
            {
                if (cell.CloseToEdge(map, 3)) // Skip changing caves near the edge
                {
                    continue;
                }
                if (caveCells.Contains(cell)) // Cave spot on cell (cave should be there)
                {
                    if (caves[cell] <= 0f)    // No existing cave
                    {
                        caves[cell] = 1f;     // Add new cave spot
                    }
                }
                else // No cave spot on cell (cave should not be there)
                {
                    if (caves[cell] > 0f) // Old existing cave
                    {
                        caves[cell] = 0f; // Remove cave spot
                    }
                }
            }
        }
        private IntVec3 FindRandomEdgeCellForTunnel(List <IntVec3> group, Map map)
        {
            MapGenFloatGrid caves = MapGenerator.Caves;

            IntVec3[] cardinalDirections = GenAdj.CardinalDirections;
            GenStep_ElevateEvelationForUnderground.tmpCells.Clear();
            GenStep_ElevateEvelationForUnderground.tmpGroupSet.Clear();
            GenStep_ElevateEvelationForUnderground.tmpGroupSet.AddRange(group);
            for (int i = 0; i < group.Count; i++)
            {
                if (group[i].DistanceToEdge(map) >= 3 && caves[group[i]] <= 0f)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        IntVec3 item = group[i] + cardinalDirections[j];
                        if (!GenStep_ElevateEvelationForUnderground.tmpGroupSet.Contains(item))
                        {
                            GenStep_ElevateEvelationForUnderground.tmpCells.Add(group[i]);
                            break;
                        }
                    }
                }
            }
            if (!GenStep_ElevateEvelationForUnderground.tmpCells.Any <IntVec3>())
            {
                Log.Warning("Could not find any valid edge cell.", false);
                return(group.RandomElement <IntVec3>());
            }
            return(GenStep_ElevateEvelationForUnderground.tmpCells.RandomElement <IntVec3>());
        }
Exemplo n.º 19
0
        /// <summary>
        /// This is a heavily simplified version of the vanilla GenStep_Terrain
        /// Most of the original isn't needed, and there are several changes to the parts that are left
        /// </summary>
        /// <param name="map"></param>
        /// <param name="parms"></param>
        public override void Generate(Map map, GenStepParams parms)
        {
            //check if it's our biome. If not, skip
            if (map.Biome.defName != "RockMoonBiome")
            {
                return;
            }

            mapRadiusSize = map.Size.x / 2;

            List <IntVec3>  list        = new List <IntVec3>();
            MapGenFloatGrid elevation   = MapGenerator.Elevation;
            MapGenFloatGrid fertility   = MapGenerator.Fertility;
            MapGenFloatGrid caves       = MapGenerator.Caves;
            TerrainGrid     terrainGrid = map.terrainGrid;

            foreach (IntVec3 current in map.AllCells)
            {
                Building   edifice = current.GetEdifice(map);
                TerrainDef terrainDef;
                terrainDef = this.TerrainFrom(current, fertility[current]);

                terrainGrid.SetTerrain(current, terrainDef);
            }
            RoofCollapseCellsFinder.RemoveBulkCollapsingRoofs(list, map);
            BeachMaker.Cleanup();
            foreach (TerrainPatchMaker current2 in map.Biome.terrainPatchMakers)
            {
                current2.Cleanup();
            }
        }
Exemplo n.º 20
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!map.Biome.HasModExtension <BiomesMap>())
            {
                return;
            }
            if (!map.Biome.GetModExtension <BiomesMap>().isIsland)
            {
                return;
            }


            this.freqFactorNoise = new Perlin(0.014999999664723873, 2.0, 0.5, 6, Rand.Range(0, 999999), QualityMode.Medium);
            this.freqFactorNoise = new ScaleBias(1.0, 1.0, this.freqFactorNoise);
            NoiseDebugUI.StoreNoiseRender(this.freqFactorNoise, "rock_chunks_freq_factor");
            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 current in map.AllCells)
            {
                float num = 0.006f * this.freqFactorNoise.GetValue(current);
                if (elevation[current] < 0.55f && Rand.Value < num)
                {
                    this.GrowLowRockFormationFrom(current, map);
                }
            }
            this.freqFactorNoise = null;
        }
Exemplo n.º 21
0
        private float GetDistToCave(IntVec3 cell, List <IntVec3> group, Map map, float maxDist, bool treatOpenSpaceAsCave)
        {
            MapGenFloatGrid caves = MapGenerator.Caves;

            GenStep_Caves.tmpGroupSet.Clear();
            GenStep_Caves.tmpGroupSet.AddRange(group);
            int num = GenRadial.NumCellsInRadius(maxDist);

            IntVec3[] radialPattern = GenRadial.RadialPattern;
            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = cell + radialPattern[i];
                if (treatOpenSpaceAsCave && !GenStep_Caves.tmpGroupSet.Contains(intVec))
                {
                    goto IL_007b;
                }
                if (intVec.InBounds(map) && caves[intVec] > 0.0)
                {
                    goto IL_007b;
                }
                continue;
IL_007b:
                return(cell.DistanceTo(intVec));
            }
            return(maxDist);
        }
Exemplo n.º 22
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!Find.Storyteller.difficulty.allowCaveHives)
            {
                return;
            }
            if (BetterInfestationsMod.settings == null)
            {
                return;
            }
            if (!BetterInfestationsMod.settings.allowHiveMapGen)
            {
                return;
            }
            MapGenFloatGrid caves     = MapGenerator.Caves;
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            float           num       = 0.7f;
            int             num2      = 0;

            rockCells.Clear();
            foreach (IntVec3 current in map.AllCells)
            {
                if (elevation[current] > num)
                {
                    rockCells.Add(current);
                }
                if (caves[current] > 0f)
                {
                    num2++;
                }
            }
            List <IntVec3> list = (from c in map.AllCells
                                   where map.thingGrid.ThingsAt(c).Any((Thing thing) => thing.Faction != null)
                                   select c).ToList();

            GenMorphology.Dilate(list, 50, map, null);
            HashSet <IntVec3> hashSet = new HashSet <IntVec3>(list);
            int num3 = GenMath.RoundRandom(num2 / 1000f);

            if (num3 > BetterInfestationsMod.settings.maxMapGenHives)
            {
                num3 = BetterInfestationsMod.settings.maxMapGenHives;
            }
            GenMorphology.Erode(rockCells, 10, map, null);
            possibleSpawnCells.Clear();
            for (int i = 0; i < rockCells.Count; i++)
            {
                if (caves[rockCells[i]] > 0f && !hashSet.Contains(rockCells[i]))
                {
                    possibleSpawnCells.Add(rockCells[i]);
                }
            }
            spawnedQueens.Clear();
            for (int j = 0; j < num3; j++)
            {
                TrySpawnHive(map);
            }
            spawnedQueens.Clear();
        }
Exemplo n.º 23
0
        public override void Generate(Map map)
        {
            if (map.Biome != Util_CaveBiome.CaveBiomeDef)
            {
                // Nothing to do in other biomes.
                return;
            }
            // Compute number of cave wells (5 for standard map 250x250, around 13 for bigest map 400x400).
            caveWellsNumber = Mathf.CeilToInt((map.Size.x * map.Size.z) / 12500);

            MapGenFloatGrid elevationGrid = MapGenerator.Elevation;

            foreach (IntVec3 cell in map.AllCells)
            {
                Thing thing = map.edificeGrid.InnerArray[map.cellIndices.CellToIndex(cell)];
                if (thing != null && thing.def.holdsRoof)
                {
                    map.roofGrid.SetRoof(cell, RoofDefOf.RoofRockThick);
                }
                else
                {
                    // Spawn cave roof holder.
                    GenSpawn.Spawn(Util_CaveBiome.CaveRoofDef, cell, map);
                }
            }

            // Update regions and rooms to be able to use the CanReachMapEdge function to find good cave well spots.
            map.regionAndRoomUpdater.Enabled = true;
            map.regionAndRoomUpdater.RebuildAllRegionsAndRooms();

            // Get cave wells position.
            caveWellsPosition = GetCaveWellsPosition(map);

            // Spawn cave wells.
            // First cave well is always dry (to avoid starting thing scattering errors).
            SpawnDryCaveWellWithAnimalCorpsesAt(map, caveWellsPosition[0]);
            for (int caveWellIndex = 1; caveWellIndex < caveWellsNumber; caveWellIndex++)
            {
                if (Rand.Value < 0.5f)
                {
                    // Spawn aqueous cave well.
                    SpawnAqueousCaveWellAt(map, caveWellsPosition[caveWellIndex]);
                }
                else if (Rand.Value < 0.9f)
                {
                    // Spawn dry cave well + fallen animal corpses.
                    SpawnDryCaveWellWithAnimalCorpsesAt(map, caveWellsPosition[caveWellIndex]);
                }
                else
                {
                    // Spawn dry cave well + sacrificial stone.
                    SpawnDryCaveWellWithRitualStoneAt(map, caveWellsPosition[caveWellIndex]);
                }
            }

            // TODO: should correct null region error? May be due to artificial buildings. River should avoid this.
            // Update regions and rooms now that cave wells are spawned.
            map.regionAndRoomUpdater.RebuildAllRegionsAndRooms();
        }
 private bool IsRock(IntVec3 c, MapGenFloatGrid elevation, Map map)
 {
     if (c.InBounds(map))
     {
         return(elevation[c] > 0.7f);
     }
     return(false);
 }
Exemplo n.º 25
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!(map.Biome.defName == "BiomesPreview_Atoll"))
            {
                return;
            }

            MapGenFloatGrid fertility = MapGenerator.Fertility;

            // make ellipse centered on the map's center. Smaller maps get smaller ellipses
            IntRange NoiseRange = new IntRange(-50, 50);

            NoiseRange.min = (int)(0 - 0.15 * map.Size.x);
            NoiseRange.max = (int)(0.15 * map.Size.x);

            IntVec3 mapCenter = map.Center;
            int     x         = NoiseRange.RandomInRange;
            int     z         = NoiseRange.RandomInRange;

            IntVec3 focus1 = mapCenter;

            focus1.x += x;
            focus1.z += z;

            IntVec3 focus2 = mapCenter;

            focus2.x -= x;
            focus2.z -= z;

            List <IntVec3> shape = MakeEllipse(focus1, focus2, map);

            // generate random circles and cut them out of the ellipse, so that the final shape is squigglier
            // some circles won't overlap with the main shape, so maps can end up either really squiggly or almost perfectly elliptical. Variety!
            List <IntVec3> originalShape = shape;
            IntRange       cutoutSizes   = new IntRange(Math.Min(totalRange.min / 8, 56), Math.Min(totalRange.max / 3, 56));

            int numCutouts = 6;

            for (int i = 0; i < numCutouts; i++)
            {
                IntVec3 tempCenter = map.AllCells.RandomElement();

                if (!originalShape.Contains(tempCenter) && shape.Count >= 0.75 * originalShape.Count)
                {
                    shape = shape.Except(GenRadial.RadialCellsAround(tempCenter, cutoutSizes.RandomInRange, true)).ToList();
                }
            }

            Makelandmass(shape, ref fertility, map);
            SetNewTerrains(map);

            GenStep_OceanRockChunks genStep = new GenStep_OceanRockChunks();

            genStep.Generate(map, parms);
            GenStep_OceanDeepResources deepLumps = new GenStep_OceanDeepResources();

            deepLumps.Generate(map, parms);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Makes the landmass shape on the map's fertility grid.
        /// Generates randomly-sized circles on each tile in the main shape and increments fertility in each circle.
        /// The circles "pile" up, resulting in a bumpy, irregular landmass with the same overall shape as the initial landCells list
        /// </summary>
        private void Makelandmass(List <IntVec3> landCells, ref MapGenFloatGrid fertility, Map map)
        {
            // smaller shapes get higher increments. For atolls, this lets smaller "hills" get tall enough to actually spawn water at the peak
            float fertIncrement = 0.06f;

            if (totalDist < 90)
            {
                fertIncrement = 0.09f;
            }
            if (totalDist < 70)
            {
                fertIncrement = 0.13f;
            }
            if (totalDist < 55)
            {
                fertIncrement = 0.2f;
            }
            if (totalDist < 30)
            {
                fertIncrement = 0.3f;
            }

            foreach (IntVec3 a in landCells)
            {
                if (Rand.Bool)
                {
                    IntVec3 ne = a;

                    List <IntVec3> island = new List <IntVec3>();

                    // Small chance of bigger circles. Helps the overall shape to look more natural.
                    // For atolls, this helps to flatten/ spread out the sand and shallow water around the island.
                    if (Rand.Chance(0.3f))
                    {
                        if (Rand.Chance(0.2f))
                        {
                            island = GenRadial.RadialCellsAround(ne, Math.Min(56, 3.5f * SizeRange.RandomInRange), true).ToList();
                        }
                        else
                        {
                            island = GenRadial.RadialCellsAround(ne, Math.Min(56, 2.0f * SizeRange.RandomInRange), true).ToList();
                        }
                    }
                    else
                    {
                        island = GenRadial.RadialCellsAround(ne, Math.Min(56, SizeRange.RandomInRange), true).ToList();
                    }

                    foreach (IntVec3 groundTile in island)
                    {
                        if (groundTile.InBounds(map))
                        {
                            fertility[groundTile] += fertIncrement;
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
        public override void Generate(Map map, GenStepParams parms)
        {
            MapDesignerSettings settings = MapDesignerMod.mod.settings;

            lakeSize      = settings.lakeSize * map.Size.x / 2;
            lakeRoundness = settings.lakeRoundness;
            lakeBeachSize = settings.lakeBeachSize;
            if (map.Biome.defName.Contains("BiomesIsland"))
            {
                lakeSize *= 0.5f;
            }

            MapGenFloatGrid lakeGrid   = MapGenerator.FloatGridNamed("ZMD_Lake");
            IntVec3         mapCenter  = map.Center;
            ModuleBase      moduleBase = new Perlin(0.020999999716877937, 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);

            foreach (IntVec3 current in map.AllCells)
            {
                float distance = HelperMethods.DistanceBetweenPoints(current, mapCenter);
                lakeGrid[current] = 0f + lakeRoundness * moduleBase.GetValue(current) + 0.1f * (lakeSize - distance);
            }

            float           deepBelow    = lakeGrid[mapCenter] * (1 - settings.lakeDepth);
            MapGenFloatGrid elevation    = MapGenerator.Elevation;
            MapGenFloatGrid fertility    = MapGenerator.Fertility;
            float           deepWater    = -2005;
            float           shallowWater = -1025;

            if (settings.flagLakeSalty)
            {
                deepWater    = -2015;
                shallowWater = -1035;
            }
            float beachValue = Feature_TerrainFrom.ValueFromTerrain(settings.lakeShore);

            foreach (IntVec3 current in map.AllCells)
            {
                if (elevation[current] < 0.65f)         // leaves mountains & most surrounding gravel untouched
                {
                    if (lakeGrid[current] > deepBelow)
                    {
                        fertility[current] = deepWater;
                    }
                    else
                    {
                        if (lakeGrid[current] > 0f)
                        {
                            fertility[current] = shallowWater;
                        }
                        else if (lakeGrid[current] > 0f - 0.1f * lakeBeachSize)
                        {
                            fertility[current] = beachValue;
                        }
                    }
                }
            }
        }
        private void GrowLowRockFormationFrom(IntVec3 root, Map map)
        {
            ThingDef        filth_RubbleRock = ThingDefOf.Filth_RubbleRock;
            ThingDef        mineableThing    = Find.World.NaturalRockTypesIn(map.Tile).RandomElement <ThingDef>().building.mineableThing;
            Rot4            random           = Rot4.Random;
            MapGenFloatGrid elevation        = MapGenerator.Elevation;
            IntVec3         intVec           = root;

            while (true)
            {
                Rot4 random2 = Rot4.Random;
                if (!(random2 == random))
                {
                    intVec += random2.FacingCell;
                    if (!intVec.InBounds(map) || intVec.GetEdifice(map) != null || intVec.GetFirstItem(map) != null)
                    {
                        break;
                    }
                    if (elevation[intVec] > 0.55f)
                    {
                        return;
                    }
                    if (!map.terrainGrid.TerrainAt(intVec).affordances.Contains(TerrainAffordanceDefOf.Heavy))
                    {
                        return;
                    }
                    GenSpawn.Spawn(mineableThing, intVec, map, WipeMode.Vanish);
                    IntVec3[] adjacentCellsAndInside = GenAdj.AdjacentCellsAndInside;
                    for (int i = 0; i < adjacentCellsAndInside.Length; i++)
                    {
                        IntVec3 b = adjacentCellsAndInside[i];
                        if (Rand.Value < 0.5f)
                        {
                            IntVec3 c = intVec + b;
                            if (c.InBounds(map))
                            {
                                bool         flag      = false;
                                List <Thing> thingList = c.GetThingList(map);
                                for (int j = 0; j < thingList.Count; j++)
                                {
                                    Thing thing = thingList[j];
                                    if (thing.def.category != ThingCategory.Plant && thing.def.category != ThingCategory.Item && thing.def.category != ThingCategory.Pawn)
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                                if (!flag)
                                {
                                    FilthMaker.MakeFilth(c, map, filth_RubbleRock, 1);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 29
0
        public override void Generate(Map map)
        {
            map.regionAndRoomUpdater.Enabled = false;
            List <ThingDef> list = map.Biome.AllWildPlants.ToList();

            for (int i = 0; i < list.Count; i++)
            {
                GenStep_Plants.numExtant.Add(list[i], 0);
            }
            GenStep_Plants.desiredProportions = GenPlant.CalculateDesiredPlantProportions(map.Biome);
            MapGenFloatGrid caves = MapGenerator.Caves;
            float           num   = map.Biome.plantDensity * map.gameConditionManager.AggregatePlantDensityFactor();

            foreach (IntVec3 item in map.AllCells.InRandomOrder(null))
            {
                if (item.GetEdifice(map) == null && item.GetCover(map) == null && !(caves[item] > 0.0))
                {
                    float num2 = map.fertilityGrid.FertilityAt(item);
                    float num3 = num2 * num;
                    if (!(Rand.Value >= num3))
                    {
                        IEnumerable <ThingDef> source = from def in list
                                                        where def.CanEverPlantAt(item, map)
                                                        select def;
                        if (source.Any())
                        {
                            ThingDef thingDef      = source.RandomElementByWeight((ThingDef x) => GenStep_Plants.PlantChoiceWeight(x, map));
                            int      randomInRange = thingDef.plant.wildClusterSizeRange.RandomInRange;
                            for (int j = 0; j < randomInRange; j++)
                            {
                                IntVec3 loc = default(IntVec3);
                                if (j == 0)
                                {
                                    loc = item;
                                }
                                else if (!GenPlantReproduction.TryFindReproductionDestination(item, thingDef, SeedTargFindMode.MapGenCluster, map, out loc))
                                {
                                    break;
                                }
                                Plant plant = (Plant)ThingMaker.MakeThing(thingDef, null);
                                plant.Growth = Rand.Range(0.07f, 1f);
                                if (plant.def.plant.LimitedLifespan)
                                {
                                    plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0));
                                }
                                GenSpawn.Spawn(plant, loc, map);
                                GenStep_Plants.RecordAdded(thingDef);
                            }
                        }
                    }
                }
            }
            GenStep_Plants.numExtant.Clear();
            GenStep_Plants.desiredProportions.Clear();
            GenStep_Plants.totalExtant       = 0;
            map.regionAndRoomUpdater.Enabled = true;
        }
        public static bool GenerateCavePlant_PreFix(Map map)
        {
            map.regionAndRoomUpdater.Enabled = false;
            MapGenFloatGrid caves  = MapGenerator.Caves;
            List <ThingDef> source = (from x in DefDatabase <ThingDef> .AllDefsListForReading
                                      where x.category == ThingCategory.Plant && x.plant.cavePlant
                                      select x).ToList <ThingDef>();

            foreach (IntVec3 c in map.AllCells.InRandomOrder(null))
            {
                if (c.GetEdifice(map) == null && c.GetCover(map) == null && (caves[c] > 0f || map.Biome.defName == "RWBCavern") && c.Roofed(map) && map.fertilityGrid.FertilityAt(c) > 0f)
                {
                    IEnumerable <ThingDef> source2 = from def in source
                                                     where def.CanEverPlantAt(c, map)
                                                     select def;
                    if (source2.Any <ThingDef>())
                    {
                        ThingDef thingDef      = source2.RandomElement <ThingDef>();
                        int      randomInRange = thingDef.plant.wildClusterSizeRange.RandomInRange;
                        float    chance;
                        if (Math.Abs(map.Biome.CommonalityOfPlant(thingDef)) > Double.Epsilon)
                        {
                            chance = map.Biome.CommonalityOfPlant(thingDef);
                        }
                        else
                        {
                            chance = 0.18f;
                        }
                        if (Rand.Chance(chance))
                        {
                            for (int i = 0; i < randomInRange; i++)
                            {
                                IntVec3 c2;
                                if (i == 0)
                                {
                                    c2 = c;
                                }
                                else if (!GenPlantReproduction.TryFindReproductionDestination(c, thingDef, SeedTargFindMode.MapGenCluster, map, out c2))
                                {
                                    break;
                                }
                                Plant plant = (Plant)ThingMaker.MakeThing(thingDef, null);
                                plant.Growth = Rand.Range(0.07f, 1f);
                                if (plant.def.plant.LimitedLifespan)
                                {
                                    plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0));
                                }
                                GenSpawn.Spawn(plant, c2, map);
                            }
                        }
                    }
                }
            }
            map.regionAndRoomUpdater.Enabled = true;
            return(false);
        }