// 3D protected void ConvertCeiling(VirtualMap map, VirtualCell conversion_cell) { // Checking if we need to add a ceiling VirtualCell.CellType cell_type = conversion_cell.Type; //Debug.Log(conversion_cell); if (conversion_cell.IsFloor()) { VirtualCell.CellType ceiling_type = VirtualCell.CellType.None; if (VirtualCell.IsRoomFloor(cell_type)) { if (behaviour.addCeilingToRooms) { ceiling_type = VirtualCell.CellType.RoomCeiling; } } else { if (behaviour.addCeilingToCorridors) { ceiling_type = VirtualCell.CellType.CorridorCeiling; } } if (ceiling_type != VirtualCell.CellType.None) { conversion_cell.AddCellInstance(ceiling_type, conversion_cell.Orientation); } } }
// 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); } }
protected void AddStairsToRooms(VirtualMap currentMap, VirtualMap[] maps, int storey) { if (storey == 0) { return; // Do not add at the first one! We'll add stairs from top to bottom. } bool allowStairsCloseToDoors = false; // Debug.Log ("CHECKING STAIRS FOR STOREY " + storey); // Stairs are added if we have two consecutive floors both at storey i and i+1 foreach (CellLocation l in currentMap.roomCells) { VirtualCell cell_here = currentMap.GetCell(l); if (cell_here.location == currentMap.end || cell_here.location == currentMap.start) { continue; // Not on the start/end cells } foreach (VirtualMap.DirectionType direction in currentMap.directions) { CellLocation next_l = currentMap.GetNeighbourCellLocationAtStep(l, direction, this.TileSeparationSteps); if (currentMap.LocationIsOutsideBounds(next_l)) { continue; } if (next_l == currentMap.end || next_l == currentMap.start) { continue; // Not on the start/end cells } VirtualCell cell_next = currentMap.GetCell(next_l); // Debug.Log ("Cell here: " + cell_here.starting_location + " is " + cell_here.Type + " and next: " + cell_next.starting_location + " is " + cell_next.Type); if (VirtualCell.IsRoomFloor(cell_here.Type) && VirtualCell.IsRoomFloor(cell_next.Type)) { if (!currentMap.CellsAreInTheSameRoom(cell_here.location, cell_next.location)) { continue; } // Two consecutive floors! Check the below map as well // Debug.Log ("DOUBLE FLOORS! " + storey); if (!allowStairsCloseToDoors && (currentMap.HasAdjacentDoor(cell_here.location) || currentMap.HasAdjacentDoor(cell_next.location))) { continue; } VirtualMap belowMap = maps[storey - 1]; if (belowMap.GetCell(l).IsRoomFloor() && belowMap.GetCell(next_l).IsRoomFloor()) { if (l == belowMap.end || l == belowMap.start) { continue; // Not on the start/end cells } if (next_l == belowMap.end || next_l == belowMap.start) { continue; // Not on the start/end cells } if (!belowMap.CellsAreInTheSameRoom(cell_here.location, cell_next.location)) { continue; } // Also below! This is a two-tile stair! Update the map! if (!allowStairsCloseToDoors && (currentMap.HasAdjacentDoor(cell_here.location) || currentMap.HasAdjacentDoor(cell_next.location))) { continue; } // We place the stair below belowMap.GetCell(l).AddCellInstance(VirtualCell.CellType.Ladder2, direction); // We remove any ceiling below belowMap.GetCell(l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Ceilings); belowMap.GetCell(next_l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Ceilings); // We override the current map by removing its floors currentMap.GetCell(l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Floors); currentMap.GetCell(next_l).RemoveCellInstancesOfTypesInSelection(SelectionObjectType.Floors); nStairs++; if (nStairs > 0) { return; // At most one stair } } } } } }
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; } } } }