예제 #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);
        }
        public override void Generate(Map map)
        {
            BeachMaker.Init(map);
            RiverMaker      riverMaker  = this.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;
                if (edifice != null && edifice.def.Fillage == FillCategory.Full)
                {
                    goto IL_0083;
                }
                if (caves[allCell] > 0.0)
                {
                    goto IL_0083;
                }
                terrainDef = this.TerrainFrom(allCell, map, elevation[allCell], fertility[allCell], riverMaker, false);
                goto IL_00c2;
IL_0083:
                terrainDef = this.TerrainFrom(allCell, map, elevation[allCell], fertility[allCell], riverMaker, true);
                goto IL_00c2;
IL_00c2:
                if ((terrainDef == TerrainDefOf.WaterMovingShallow || terrainDef == TerrainDefOf.WaterMovingDeep) && edifice != null)
                {
                    list.Add(edifice.Position);
                    edifice.Destroy(DestroyMode.Vanish);
                }
                terrainGrid.SetTerrain(allCell, terrainDef);
            }
            if (riverMaker != null)
            {
                riverMaker.ValidatePassage(map);
            }
            RoofCollapseCellsFinder.RemoveBulkCollapsingRoofs(list, map);
            BeachMaker.Cleanup();
            foreach (TerrainPatchMaker terrainPatchMaker in map.Biome.terrainPatchMakers)
            {
                terrainPatchMaker.Cleanup();
            }
        }
예제 #3
0
        public override void Generate(Map map, GenStepParams parms)
        {
            BeachMaker.Init(map);
            RiverMaker      riverMaker  = this.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 c in map.AllCells)
            {
                Building   edifice = c.GetEdifice(map);
                TerrainDef terrainDef;
                if ((edifice != null && edifice.def.Fillage == FillCategory.Full) || caves[c] > 0f)
                {
                    terrainDef = this.TerrainFrom(c, map, elevation[c], fertility[c], riverMaker, true);
                }
                else
                {
                    terrainDef = this.TerrainFrom(c, map, elevation[c], fertility[c], riverMaker, false);
                }
                if (terrainDef.IsRiver)
                {
                    if (edifice != null)
                    {
                        list.Add(edifice.Position);
                        edifice.Destroy(DestroyMode.Vanish);
                    }
                }
                terrainGrid.SetTerrain(c, terrainDef);
            }
            if (riverMaker != null)
            {
                riverMaker.ValidatePassage(map);
            }
            RoofCollapseCellsFinder.RemoveBulkCollapsingRoofs(list, map);
            BeachMaker.Cleanup();
            foreach (TerrainPatchMaker terrainPatchMaker in map.Biome.terrainPatchMakers)
            {
                terrainPatchMaker.Cleanup();
            }
        }
예제 #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);
        }