public List <int> GetEdgeData() { if (!edgesValid) { ResetEdges(); for (int x = -Info.Map.Size + 2; x <= Info.Map.Size - 2; x++) { for (int y = -Info.Map.Size + 2; y <= Info.Map.Size - 2; y++) { Data.Cell currentCell = GetCell(x, y); if (currentCell.Solid) { continue; } foreach (KeyValuePair <Type.Direction, int2> keyValuePair in MapSystem.Directions) { Type.Direction neighborDirection = keyValuePair.Key; int2 neighborOffset = keyValuePair.Value; int2 neighborPosition = currentCell.Position + neighborOffset; if (Util.Map.OnMap(neighborPosition)) { Data.Cell neighborCell = GetCell(neighborPosition); if (neighborCell.Solid) { continue; } if (ValidEdge(neighborCell, neighborDirection)) { int currentCellIndex = Util.Map.PositionToIndex(currentCell.Position); int neighborCellIndex = Util.Map.PositionToIndex(neighborCell.Position); edges[currentCellIndex + Info.Map.Area * neighborCellIndex] = 1; edges[neighborCellIndex + Info.Map.Area * currentCellIndex] = 1; } } } } } edgesValid = true; } return(edges); }
private bool ValidEdge(Data.Cell neighborCell, Type.Direction neighborDirection) { int2 northPosition = neighborCell.Position + MapSystem.Directions[Type.Direction.NN]; int2 eastPosition = neighborCell.Position + MapSystem.Directions[Type.Direction.EE]; int2 southPosition = neighborCell.Position + MapSystem.Directions[Type.Direction.SS]; int2 westPosition = neighborCell.Position + MapSystem.Directions[Type.Direction.WW]; bool northSolid = !Util.Map.OnMap(northPosition) || cells[Util.Map.PositionToIndex(northPosition)].Solid; bool eastSolid = !Util.Map.OnMap(eastPosition) || cells[Util.Map.PositionToIndex(eastPosition)].Solid; bool southSolid = !Util.Map.OnMap(southPosition) || cells[Util.Map.PositionToIndex(southPosition)].Solid; bool westSolid = !Util.Map.OnMap(westPosition) || cells[Util.Map.PositionToIndex(westPosition)].Solid; if (neighborDirection == Type.Direction.NE) { if (northSolid || eastSolid) { return(false); } } if (neighborDirection == Type.Direction.SE) { if (southSolid || eastSolid) { return(false); } } if (neighborDirection == Type.Direction.NW) { if (northSolid || westSolid) { return(false); } } if (neighborDirection == Type.Direction.SW) { if (southSolid || westSolid) { return(false); } } return(true); }
private static Data.Room ExpandRoom(Data.Room room, List <Data.Room> rooms, List <RectInt> placeholders) { bool expanded = false; Data.Room expandedRoom = room; List <Type.Direction> directions = new List <Type.Direction> { Type.Direction.SS, Type.Direction.NN, Type.Direction.WW, Type.Direction.EE }; while (!expanded && directions.Count > 0) { int index = Random.Range(0, directions.Count - 1); Type.Direction direction = directions[index]; directions.RemoveAt(index); switch (direction) { case Type.Direction.SS: expandedRoom.Bounds.xMin -= 1; break; case Type.Direction.WW: expandedRoom.Bounds.xMax += 1; break; case Type.Direction.NN: expandedRoom.Bounds.yMin -= 1; break; case Type.Direction.EE: expandedRoom.Bounds.yMax += 1; break; } bool roomCollision = false; if (Util.Map.OnMap(expandedRoom.Bounds) == false) { roomCollision = true; } else { foreach (Data.Room testRoom in rooms) { if (testRoom.Equals(room)) { continue; } if (testRoom.Bounds.Overlaps(expandedRoom.Bounds)) { roomCollision = true; } } foreach (RectInt bounds in placeholders) { if (bounds.Overlaps(expandedRoom.Bounds)) { roomCollision = true; } } } if (!roomCollision) { expanded = true; } } return(expanded ? expandedRoom : room); }