public ChunkCellData(CellSettings settings, CaveChunkManager chunkManager, Vector3Int chunkCoordinate) { _chunkManager = chunkManager; Settings = settings; ChunkCoordinate = chunkCoordinate; //ChunkSeed = Settings.GenerateSeed(Settings.Seed, chunkCoordinate); _noiseGenerator = new Noise(Settings.Seed); }
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); int secondY = Mathf.Max(firstPoint.y, secondPoint.y); int firstZ = Mathf.Min(firstPoint.z, secondPoint.z); int secondZ = Mathf.Max(firstPoint.z, secondPoint.z); firstX = Mathf.Max(firstX - settings.TunnelRadius, 0); secondX = Mathf.Min(secondX + settings.TunnelRadius, settings.ChunkCubicSize.x - 1); firstY = Mathf.Max(firstY - settings.TunnelRadius, 0); secondY = Mathf.Min(secondY + settings.TunnelRadius, settings.ChunkCubicSize.y - 1); firstZ = Mathf.Max(firstZ - settings.TunnelRadius, 0); secondZ = Mathf.Min(secondZ + settings.TunnelRadius, settings.ChunkCubicSize.z - 1); List <Vector3Int> tunnelCells = new List <Vector3Int>(); for (int x = firstX; x <= secondX; x++) { for (int y = firstY; y <= secondY; y++) { for (int z = firstZ; z < secondZ; z++) { float distance = DistanceFromPointToLine(new Vector3Int(x, y, z), firstPoint, secondPoint); if (distance > settings.TunnelRadius) { continue; } cells[x, y, z] = CellType.Hollow; tunnelCells.Add(new Vector3Int(x, y, z)); } } } return(tunnelCells); }
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); if (EmergencyShutdown.Instance.CheckForShutdownTimer()) { return(tunnels); } if (secondHollow == null) { continue; } 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); }