public void ConvertDirectionalRoomFloor(VirtualMap map, VirtualCell conversion_cell) { CellLocation l = conversion_cell.location; if (behaviour.useDirectionalFloors) { if (conversion_cell.IsRoomFloor()) { CellLocation[] border_neighs; CellLocation[] floor_neighs; bool considerDoorsAsWalls = true; // Count how many border neighbours are non-walls int countFloorNeighs = 0; bool[] validIndices = new bool[4]; if (conversion_cell.IsTile()) { // This was a tile, check neigh walls border_neighs = map.GetAllNeighbours(l); for (int i = 0; i < border_neighs.Length; i++) { CellLocation other_l = border_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && !(map.GetCell(other_l).IsWall()) && !(considerDoorsAsWalls && map.GetCell(other_l).IsDoor()) ) { countFloorNeighs++; validIndices[i] = true; } } } else { // This was a border, check neigh floors instead floor_neighs = map.GetAllNeighbours(l); // Debug.Log ("From " + l);None for (int i = 0; i < floor_neighs.Length; i++) { CellLocation other_l = floor_neighs[i]; // Debug.Log ("At " + other_l + " is " + map.GetCell(other_l).Type); bool insideRoomTile = CheckInsideRoomTile(map, other_l); // We need this to be checked now, or we cannot know if a tile is inside a room reliably if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && (map.GetCell(other_l).IsFloor() || //|| map.GetCell(other_l).IsNone() map.GetCell(other_l).IsInsideRoomColumn() || // Treat inside room columns as floors here insideRoomTile // || map.GetCell(other_l).IsNone() )) { countFloorNeighs++; validIndices[i] = true; } } } // Define the adbvanced floors // Debug.Log (countFloorNeighs); if (countFloorNeighs == 2) { bool adjacentFloors = false; // This is a room corner for (int i = 0; i < 4; i++) { if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; adjacentFloors = true; break; } } if (adjacentFloors) { conversion_cell.Type = VirtualCell.CellType.RoomFloorCorner; } else { conversion_cell.Type = VirtualCell.CellType.RoomFloorInside; } } else if (countFloorNeighs == 3) { conversion_cell.Type = VirtualCell.CellType.RoomFloorBorder; for (int i = 0; i < 4; i++) { if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 2, 4)]; break; } } } else if (countFloorNeighs == 4) { conversion_cell.Type = VirtualCell.CellType.RoomFloorInside; } else { // Wrong number of floor neighs, may happen if we have too small rooms. We always use the INSIDE one, then. conversion_cell.Type = VirtualCell.CellType.RoomFloorInside; } } } }
public void ConvertDirectionalCorridorFloor(VirtualMap map, VirtualCell conversion_cell) { CellLocation l = conversion_cell.location; if (behaviour.useDirectionalFloors) { if (conversion_cell.IsCorridorFloor()) { // Count how many border neighbours are non-walls int countFloorNeighs = 0; bool[] validIndices = new bool[4]; if (conversion_cell.IsTile()) { // This was a tile, check neigh walls CellLocation[] border_neighs = map.GetAllNeighbours(l); for (int i = 0; i < border_neighs.Length; i++) { CellLocation other_l = border_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && !(map.GetCell(other_l).IsWall())) // TODO: Maybe isValid is not needed! { countFloorNeighs++; validIndices[i] = true; } } } else { // This was a border, check neigh floors instead CellLocation[] floor_neighs = map.GetAllNeighbours(l); for (int i = 0; i < floor_neighs.Length; i++) { CellLocation other_l = floor_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && map.GetCell(other_l).IsFloor()) // TODO: Maybe isValid is not needed! { countFloorNeighs++; validIndices[i] = true; } } } // Define the adbvanced floors if (countFloorNeighs == 1) { conversion_cell.Type = VirtualCell.CellType.CorridorFloorU; for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; break; } } } else if (countFloorNeighs == 2) { // Corridor I conversion_cell.Type = VirtualCell.CellType.CorridorFloorI; for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } // Corridor L for (int i = 0; i < 4; i++) { if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This and the next are valid: left turn (we consider all of them to be left turns( conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; conversion_cell.Type = VirtualCell.CellType.CorridorFloorL; break; } } } else if (countFloorNeighs == 3) { conversion_cell.Type = VirtualCell.CellType.CorridorFloorT; for (int i = 0; i < 4; i++) { if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This, the one before and the next are valid: T cross (with this being the middle road) conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } } else if (countFloorNeighs == 4) { conversion_cell.Type = VirtualCell.CellType.CorridorFloorX; } } } }