Exemple #1
0
        private static bool SmoothMap(Vector3Int centerPoint, int radiusToSmooth = int.MaxValue)
        {
            Dictionary <TerrainTile, TerrainType> changesToMake =
                new Dictionary <TerrainTile, TerrainType>();
            bool ringEmpty = false;
            int  i         = 0;

            while (i <= radiusToSmooth && !ringEmpty)
            {
                ringEmpty = true;
                List <Vector3Int> ring = HexTools.GetRing(centerPoint, i++);

                foreach (Vector3Int ringTile in ring)
                {
                    TerrainTile ttb = mapGen.GetTile(ringTile);
                    if (ttb == null)
                    {
                        continue;
                    }

                    ringEmpty = false;

                    int           wallCount        = 0;
                    TerrainTile[] surroundingTiles = mapGen.GetSurroundingTiles(ringTile);
                    foreach (TerrainTile tile in surroundingTiles)
                    {
                        if (tile == null || tile.terrainType == TerrainType.WaterGenerator)
                        {
                            ++wallCount;
                        }
                    }


                    if (wallCount > rules.minNeighboursToTurnToWater && ttb.terrainType != TerrainType.WaterGenerator)
                    {
                        changesToMake[ttb] = TerrainType.WaterGenerator;
                    }
                    else if (wallCount < rules.minNeighboursToTurnToWater && ttb.terrainType != TerrainType.LandGenerator)
                    {
                        changesToMake[ttb] = TerrainType.LandGenerator;
                    }
                }
            }

            foreach (var change in changesToMake)
            {
                mapGen.CreateAndSetTile(change.Key.coordinates, mapGen.GetTerrainData(change.Value).tile, change.Key);
            }

            return(changesToMake.Count > 0);
        }
Exemple #2
0
        private static void ProcessMap()
        {
            List <List <Vector3Int> > wallRegions = mapGen.GetRegions(TerrainType.DungeonWall);
            TerrainData wallData = mapGen.GetTerrainData(TerrainType.DungeonWall);

            foreach (List <Vector3Int> wallRegion in wallRegions)
            {
                if (wallRegion.Count < wallData.regionThresholdSize)
                {
                    foreach (Vector3Int coord in wallRegion)
                    {
                        mapGen.CreateAndSetTile(coord, rules.openTile, mapGen.GetTile(coord));
                    }
                }
            }

            List <List <Vector3Int> > roomRegions = mapGen.GetRegions(TerrainType.DungeonFloor);
            TerrainData roomData = mapGen.GetTerrainData(TerrainType.DungeonFloor);

            List <Region> survivingRegions = new List <Region>();

            foreach (List <Vector3Int> roomRegion in roomRegions)
            {
                if (roomRegion.Count < roomData.regionThresholdSize)
                {
                    foreach (Vector3Int coord in roomRegion)
                    {
                        mapGen.CreateAndSetTile(coord, rules.wallTile, mapGen.GetTile(coord));
                    }
                }
                else
                {
                    survivingRegions.Add(new Region(roomRegion));
                }
            }

            if (survivingRegions.Count == 0)
            {
                Debug.Log("Map contains no rooms!");
                return;
            }

            survivingRegions.Sort();
            survivingRegions[0].isMainRegion = true;
            survivingRegions[0].isAccessibleFromMainRegion = true;

            ConnectClosestRegions(survivingRegions);
        }