コード例 #1
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);
        }
コード例 #2
0
ファイル: StageTwo.cs プロジェクト: TheDizzler/BloodOfMaoo
        private static bool RunSimulation(List <TerrainTile> tiles)
        {
            Dictionary <TerrainTile, TerrainType> changesToMake =
                new Dictionary <TerrainTile, TerrainType>();

            foreach (TerrainTile tile in tiles)
            {
                Dictionary <TerrainType, int> neighbouringTerrainCount = new Dictionary <TerrainType, int>();
                TerrainTile[] neighbours = mapGen.GetSurroundingTiles(tile.coordinates);
                foreach (TerrainTile neighbour in neighbours)
                {
                    TerrainType terrainToCheck;
                    if (neighbour == null)
                    {
                        terrainToCheck = tile.terrainType;
                    }
                    else
                    {
                        terrainToCheck = neighbour.terrainType;
                    }
                    if (neighbouringTerrainCount.TryGetValue(terrainToCheck, out int count))
                    {
                        ++neighbouringTerrainCount[terrainToCheck];
                    }
                    else
                    {
                        neighbouringTerrainCount[terrainToCheck] = 1;
                    }
                }

                if (TileTransmogrifier(tile, neighbouringTerrainCount, out TerrainType newType))
                {
                    changesToMake[tile] = newType;
                }
            }

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

            return(changesToMake.Count > 0);
        }
コード例 #3
0
        private static Dictionary <TerrainType, List <Region> > ProcessMap()
        {
            Dictionary <TerrainType, List <Region> > regionDict = new Dictionary <TerrainType, List <Region> >();

            TerrainData waterData = mapGen.GetTerrainData(TerrainType.WaterGenerator);
            TerrainData landData  = mapGen.GetTerrainData(TerrainType.LandGenerator);
            List <List <Vector3Int> > waterRegions         = mapGen.GetRegions(TerrainType.WaterGenerator);
            List <Region>             survivinWaterRegions = new List <Region>();

            foreach (List <Vector3Int> waterRegion in waterRegions)
            {
                survivinWaterRegions.Add(new Region(waterRegion));
            }

            List <List <Vector3Int> > landRegions          = mapGen.GetRegions(TerrainType.LandGenerator);
            List <Region>             survivingLandRegions = new List <Region>();

            foreach (List <Vector3Int> landRegion in landRegions)
            {
                survivingLandRegions.Add(new Region(landRegion));
            }

            regionDict[TerrainType.WaterGenerator] = survivinWaterRegions;
            regionDict[TerrainType.LandGenerator]  = survivingLandRegions;

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

            //if (rules.allowConnectRegions)
            //{
            //	survivingLandRegions.Sort();
            //	survivingLandRegions[0].isMainRegion = true;
            //	survivingLandRegions[0].isAccessibleFromMainRegion = true;
            //	mapGen.ConnectClosestRegions(survivingLandRegions);
            //}

            return(regionDict);
        }