Esempio n. 1
0
        private TerrainDef TerrainFrom(IntVec3 c, Map map, float elevation, float fertility, RiverMaker river, bool preferSolid)
        {
            TerrainDef terrainDef = null;

            if (river != null)
            {
                terrainDef = river.TerrainAt(c, recordForValidation: true);
            }
            if (terrainDef == null && preferSolid)
            {
                return(GenStep_RocksFromGrid.RockDefAt(c).building.naturalTerrain);
            }
            TerrainDef terrainDef2 = BeachMaker.BeachTerrainAt(c, map.Biome);

            if (terrainDef2 == TerrainDefOf.WaterOceanDeep)
            {
                return(terrainDef2);
            }
            if (terrainDef != null && terrainDef.IsRiver)
            {
                return(terrainDef);
            }
            if (terrainDef2 != null)
            {
                return(terrainDef2);
            }
            if (terrainDef != null)
            {
                return(terrainDef);
            }
            for (int i = 0; i < map.Biome.terrainPatchMakers.Count; i++)
            {
                terrainDef2 = map.Biome.terrainPatchMakers[i].TerrainAt(c, map, fertility);
                if (terrainDef2 != null)
                {
                    return(terrainDef2);
                }
            }
            if (elevation > 0.55f && elevation < 0.61f)
            {
                return(TerrainDefOf.Gravel);
            }
            if (elevation >= 0.61f)
            {
                return(GenStep_RocksFromGrid.RockDefAt(c).building.naturalTerrain);
            }
            terrainDef2 = TerrainThreshold.TerrainAtValue(map.Biome.terrainsByFertility, fertility);
            if (terrainDef2 != null)
            {
                return(terrainDef2);
            }
            if (!debug_WarnedMissingTerrain)
            {
                Log.Error("No terrain found in biome " + map.Biome.defName + " for elevation=" + elevation + ", fertility=" + fertility);
                debug_WarnedMissingTerrain = true;
            }
            return(TerrainDefOf.Sand);
        }
Esempio n. 2
0
        public override void Generate(Map map)
        {
            if (!map.TileInfo.WaterCovered)
            {
                map.regionAndRoomUpdater.Enabled = false;
                float num = 0.7f;
                List <RoofThreshold> list          = new List <RoofThreshold>();
                RoofThreshold        roofThreshold = new RoofThreshold();
                roofThreshold.roofDef    = RoofDefOf.RoofRockThick;
                roofThreshold.minGridVal = (float)(num * 1.1399999856948853);
                list.Add(roofThreshold);
                RoofThreshold roofThreshold2 = new RoofThreshold();
                roofThreshold2.roofDef    = RoofDefOf.RoofRockThin;
                roofThreshold2.minGridVal = (float)(num * 1.0399999618530273);
                list.Add(roofThreshold2);
                MapGenFloatGrid elevation = MapGenerator.Elevation;
                MapGenFloatGrid caves     = MapGenerator.Caves;
                foreach (IntVec3 allCell in map.AllCells)
                {
                    float num2 = elevation[allCell];
                    if (num2 > num)
                    {
                        if (caves[allCell] <= 0.0)
                        {
                            ThingDef def = GenStep_RocksFromGrid.RockDefAt(allCell);
                            GenSpawn.Spawn(def, allCell, map);
                        }
                        int num3 = 0;
                        while (num3 < list.Count)
                        {
                            if (!(num2 > list[num3].minGridVal))
                            {
                                num3++;
                                continue;
                            }
                            map.roofGrid.SetRoof(allCell, list[num3].roofDef);
                            break;
                        }
                    }
                }
                BoolGrid       visited  = new BoolGrid(map);
                List <IntVec3> toRemove = new List <IntVec3>();
                foreach (IntVec3 allCell2 in map.AllCells)
                {
                    if (!visited[allCell2] && this.IsNaturalRoofAt(allCell2, map))
                    {
                        toRemove.Clear();
                        map.floodFiller.FloodFill(allCell2, (IntVec3 x) => this.IsNaturalRoofAt(x, map), delegate(IntVec3 x)
                        {
                            visited[x] = true;
                            toRemove.Add(x);
                        }, 2147483647, false, null);
                        if (toRemove.Count < 20)
                        {
                            for (int i = 0; i < toRemove.Count; i++)
                            {
                                map.roofGrid.SetRoof(toRemove[i], null);
                            }
                        }
                    }
                }
                GenStep_ScatterLumpsMineable genStep_ScatterLumpsMineable = new GenStep_ScatterLumpsMineable();
                float num4 = 10f;
                switch (Find.WorldGrid[map.Tile].hilliness)
                {
                case Hilliness.Flat:
                    num4 = 4f;
                    break;

                case Hilliness.SmallHills:
                    num4 = 8f;
                    break;

                case Hilliness.LargeHills:
                    num4 = 11f;
                    break;

                case Hilliness.Mountainous:
                    num4 = 15f;
                    break;

                case Hilliness.Impassable:
                    num4 = 16f;
                    break;
                }
                genStep_ScatterLumpsMineable.countPer10kCellsRange = new FloatRange(num4, num4);
                genStep_ScatterLumpsMineable.Generate(map);
                map.regionAndRoomUpdater.Enabled = true;
            }
        }
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!map.TileInfo.WaterCovered)
            {
                map.regionAndRoomUpdater.Enabled = false;
                float num = 0.7f;
                List <GenStep_RocksFromGrid.RoofThreshold> list = new List <GenStep_RocksFromGrid.RoofThreshold>();
                list.Add(new GenStep_RocksFromGrid.RoofThreshold
                {
                    roofDef    = RoofDefOf.RoofRockThick,
                    minGridVal = num * 1.14f
                });
                list.Add(new GenStep_RocksFromGrid.RoofThreshold
                {
                    roofDef    = RoofDefOf.RoofRockThin,
                    minGridVal = num * 1.04f
                });
                MapGenFloatGrid elevation = MapGenerator.Elevation;
                MapGenFloatGrid caves     = MapGenerator.Caves;
                foreach (IntVec3 intVec in map.AllCells)
                {
                    float num2 = elevation[intVec];
                    if (num2 > num)
                    {
                        if (caves[intVec] <= 0f)
                        {
                            ThingDef def = GenStep_RocksFromGrid.RockDefAt(intVec);
                            GenSpawn.Spawn(def, intVec, map, WipeMode.Vanish);
                        }
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (num2 > list[i].minGridVal)
                            {
                                map.roofGrid.SetRoof(intVec, list[i].roofDef);
                                break;
                            }
                        }
                    }
                }
                BoolGrid       visited  = new BoolGrid(map);
                List <IntVec3> toRemove = new List <IntVec3>();
                foreach (IntVec3 intVec2 in map.AllCells)
                {
                    if (!visited[intVec2])
                    {
                        if (this.IsNaturalRoofAt(intVec2, map))
                        {
                            toRemove.Clear();
                            map.floodFiller.FloodFill(intVec2, (IntVec3 x) => this.IsNaturalRoofAt(x, map), delegate(IntVec3 x)
                            {
                                visited[x] = true;
                                toRemove.Add(x);
                            }, int.MaxValue, false, null);
                            if (toRemove.Count < 20)
                            {
                                for (int j = 0; j < toRemove.Count; j++)
                                {
                                    map.roofGrid.SetRoof(toRemove[j], null);
                                }
                            }
                        }
                    }
                }
                GenStep_ScatterLumpsMineable genStep_ScatterLumpsMineable = new GenStep_ScatterLumpsMineable();
                genStep_ScatterLumpsMineable.maxValue = this.maxMineableValue;
                float num3 = 10f;
                switch (Find.WorldGrid[map.Tile].hilliness)
                {
                case Hilliness.Flat:
                    num3 = 4f;
                    break;

                case Hilliness.SmallHills:
                    num3 = 8f;
                    break;

                case Hilliness.LargeHills:
                    num3 = 11f;
                    break;

                case Hilliness.Mountainous:
                    num3 = 15f;
                    break;

                case Hilliness.Impassable:
                    num3 = 16f;
                    break;
                }
                genStep_ScatterLumpsMineable.countPer10kCellsRange = new FloatRange(num3, num3);
                genStep_ScatterLumpsMineable.Generate(map, parms);
                map.regionAndRoomUpdater.Enabled = true;
            }
        }
Esempio n. 4
0
        private TerrainDef TerrainFrom(IntVec3 c, Map map, float elevation, float fertility, RiverMaker river, bool preferSolid)
        {
            TerrainDef terrainDef = null;

            if (river != null)
            {
                terrainDef = river.TerrainAt(c, true);
            }
            TerrainDef result;

            if (terrainDef == null && preferSolid)
            {
                result = GenStep_RocksFromGrid.RockDefAt(c).building.naturalTerrain;
            }
            else
            {
                TerrainDef terrainDef2 = BeachMaker.BeachTerrainAt(c, map.Biome);
                if (terrainDef2 == TerrainDefOf.WaterOceanDeep)
                {
                    result = terrainDef2;
                }
                else if (terrainDef != null && terrainDef.IsRiver)
                {
                    result = terrainDef;
                }
                else if (terrainDef2 != null)
                {
                    result = terrainDef2;
                }
                else if (terrainDef != null)
                {
                    result = terrainDef;
                }
                else
                {
                    for (int i = 0; i < map.Biome.terrainPatchMakers.Count; i++)
                    {
                        terrainDef2 = map.Biome.terrainPatchMakers[i].TerrainAt(c, map, fertility);
                        if (terrainDef2 != null)
                        {
                            return(terrainDef2);
                        }
                    }
                    if (elevation > 0.55f && elevation < 0.61f)
                    {
                        result = TerrainDefOf.Gravel;
                    }
                    else if (elevation >= 0.61f)
                    {
                        result = GenStep_RocksFromGrid.RockDefAt(c).building.naturalTerrain;
                    }
                    else
                    {
                        terrainDef2 = TerrainThreshold.TerrainAtValue(map.Biome.terrainsByFertility, fertility);
                        if (terrainDef2 != null)
                        {
                            result = terrainDef2;
                        }
                        else
                        {
                            if (!GenStep_Terrain.debug_WarnedMissingTerrain)
                            {
                                Log.Error(string.Concat(new object[]
                                {
                                    "No terrain found in biome ",
                                    map.Biome.defName,
                                    " for elevation=",
                                    elevation,
                                    ", fertility=",
                                    fertility
                                }), false);
                                GenStep_Terrain.debug_WarnedMissingTerrain = true;
                            }
                            result = TerrainDefOf.Sand;
                        }
                    }
                }
            }
            return(result);
        }