//private void AddRoomsMidpointsToConnectionLines() //{ // foreach (Delaunay.Geo.LineSegment line in spanningTree) // { // DelaunayMSTRoom roomStart = GetRoomByPoint(line.p0.Value.x, line.p0.Value.y); // if (roomStart != null) // { // line.cellStart = roomStart; // } // else // { // Debug.LogError("Could not find cell start for " + line.p0.Value); // } // DelaunayMSTRoom roomEnd = GetRoomByPoint(line.p1.Value.x, line.p1.Value.y); // if (roomEnd != null) // { // line.cellEnd = roomEnd; // } // else // { // Debug.LogError("Could not find cell end for " + line.p1.Value); // } // } //} private void FindConnectedRoomsAndPathsBetweenThem() { foreach (var line in spanningTree) { DelaunayMSTRoom roomStart = GetRoomByPoint(line.p0.Value.x, line.p0.Value.y); if (roomStart == null) { Debug.LogError("Could not find cell start for " + line.p0.Value); } DelaunayMSTRoom roomEnd = GetRoomByPoint(line.p1.Value.x, line.p1.Value.y); if (roomEnd == null) { Debug.LogError("Could not find cell end for " + line.p1.Value); } Vector2Int start = new Vector2Int((int)line.p0.Value.x, (int)line.p0.Value.y); Vector2Int end = new Vector2Int((int)line.p1.Value.x, (int)line.p1.Value.y); //Vector2 start = line.p0.Value; //Vector2 end = line.p1.Value; Line firstHallway = new Line { start = start, //blockPath.end = new Vector2(end.x, start.y); end = new Vector2Int(end.x, start.y) }; Line secondHallway = new Line { start = firstHallway.end, end = end }; RoomsConnection path = new RoomsConnection { from = roomStart, to = roomEnd }; path.path.Add(firstHallway); path.path.Add(secondHallway); paths.Add(path); } spanningTree.Clear(); }
public void FillCellMap(ref Cell[,] map, CellType wallCell = CellType.Empty, CellType floorCell = CellType.Empty) { if (wallCell == CellType.Empty && floorCell == CellType.Empty) { Debug.LogError("Both cell types are CellType.Empty."); return; } // Spawn rooms for (int i = 0; i < rooms.Count; i++) { DelaunayMSTRoom room = rooms[i]; for (int x = room.x; x < room.x + room.width; x++) { map[x, room.y] = Cell.CreateCell(wallCell); map[x, room.y + room.height - 1] = Cell.CreateCell(wallCell); } for (int z = room.y; z < room.y + room.height; z++) { map[room.x, z] = Cell.CreateCell(wallCell); map[room.x + room.width - 1, z] = Cell.CreateCell(wallCell); } for (int z = room.y + 1; z < room.y + room.height - 1; z++) { for (int x = room.x + 1; x < room.x + room.width - 1; x++) { map[x, z] = Cell.CreateCell(floorCell); } } } // Spawn hallways for (int i = 0; i < paths.Count; i++) { RoomsConnection connection = paths[i]; for (int j = 0; j < connection.path.Count; j++) { Line hallway = connection.path[j]; int fromX = Mathf.Min(hallway.start.x, hallway.end.x); int toX = Mathf.Max(hallway.start.x, hallway.end.x); int fromZ = Mathf.Min(hallway.start.y, hallway.end.y); int toZ = Mathf.Max(hallway.start.y, hallway.end.y); for (int x = fromX; x <= toX; x++) { for (int z = fromZ; z <= toZ; z++) { map[x, z] = Cell.CreateCell(floorCell); AddPathWalls(x, z, ref map, wallCell, floorCell); } } } } }