// Directional floors public void ConvertDirectionalFloor(VirtualMap map, VirtualCell conversion_cell, bool mayBeDirectional) { if (!mayBeDirectional) { return; } if (conversion_cell.IsCorridorFloor()) { ConvertDirectionalCorridorFloor(map, conversion_cell); } else if (conversion_cell.IsRoomFloor()) { ConvertDirectionalRoomFloor(map, conversion_cell); } }
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; } } } }