Example #1
0
        protected ChunkCellData(CellSettings settings, CaveChunkManager chunkManager, Vector3Int chunkCoordinate)
        {
            Debug.Log($"Created chunk {GetType()}");

            _chunkManager = chunkManager;

            Settings        = settings;
            ChunkCoordinate = chunkCoordinate;
            ChunkSeed       = Settings.GenerateSeed(Settings.Seed, chunkCoordinate);
        }
 public GeneratedChunkCellData(CellSettings settings, CaveChunkManager chunkManager, Vector3Int chunkCoordinate) : base(settings, chunkManager, chunkCoordinate)
 {
 }
Example #3
0
        private static List <Vector3Int> GetTunnelCellsAndConnectCaves(ref CellType[,,] cells, CellSettings settings, Vector3Int firstPoint, Vector3Int secondPoint)
        {
            int firstX  = Mathf.Min(firstPoint.x, secondPoint.x);
            int secondX = Mathf.Max(firstPoint.x, secondPoint.x);
            int firstY  = Mathf.Min(firstPoint.y, secondPoint.y);            //TODO test, may not work
            int secondY = Mathf.Max(firstPoint.y, secondPoint.y);

            firstX  = Mathf.Max(firstX - settings.TunnelWidth, 0);
            secondX = Mathf.Min(secondX + settings.TunnelWidth, settings.TerrainCubicSize.x - 1);
            firstY  = Mathf.Max(firstY - settings.TunnelWidth, 0);
            secondY = Mathf.Min(secondY + settings.TunnelWidth, settings.TerrainCubicSize.y - 1);

            List <Vector3Int> tunnelCells = new List <Vector3Int>();

            for (int x = firstX; x <= secondX; x++)
            {
                for (int y = firstY; y <= secondY; y++)
                {
                    float distance = DistanceFromPointToLine(firstPoint, secondPoint, x, y);

                    if (distance > settings.TunnelWidth)
                    {
                        continue;
                    }

                    int maxHeight = Mathf.Min(settings.TunnelHeight, settings.TerrainCubicSize.z);

                    for (int z = 0; z < maxHeight; z++)
                    {
                        cells[x, y, z] = CellType.Hollow;

                        tunnelCells.Add(new Vector3Int(x, y, z));
                    }
                }
            }

            return(tunnelCells);
        }
Example #4
0
        public static List <Tunnel> CreateTunnelsAndConnectCaves(ref CellType[,,] cells, List <HollowGroup> hollows, CellSettings settings)
        {
            List <HollowGroup> alreadyConnectedCaves = new List <HollowGroup>();
            List <Tunnel>      tunnels = new List <Tunnel>();

            foreach (HollowGroup firstHollow in hollows)
            {
                (HollowGroup secondHollow, Vector3Int firstPoint, Vector3Int secondPoint) = ClosestNotConnectedHollow(firstHollow, hollows, alreadyConnectedCaves);

                List <Vector3Int> tunnelCells = GetTunnelCellsAndConnectCaves(ref cells, settings, firstPoint, secondPoint);

                Tunnel tunnel = new Tunnel(tunnelCells, firstHollow, secondHollow, firstPoint, secondPoint);
                tunnels.Add(tunnel);

                alreadyConnectedCaves.Add(firstHollow);
            }

            return(tunnels);
        }