コード例 #1
0
    /********************
    * Door creation
    ********************/
    // Create doors for a given room
    public void CreateDoors_Post(VirtualMap map, VirtualRoom r)
    {
        List <CellLocation> borderFloors = new List <CellLocation> ();

        // Examine borderFloors, create a list of border floors
        for (int i = 0; i < r.Width; i++)
        {
            for (int j = 0; j < r.Height; j++)
            {
                if (i == 0 || j == 0 || i == r.Width - 1 || j == r.Height - 1)
                {
                    CellLocation l = new CellLocation(r.leftCorner.x + 2 * i, r.leftCorner.y + 2 * j);
                    borderFloors.Add(l);
                }
            }
        }

        // Create doors close to the borders, where wall passages are
        CellLocation target_passage;

        foreach (CellLocation l in borderFloors)
        {
            foreach (VirtualMap.DirectionType dir in map.directions)
            {
                target_passage = map.GetNeighbourCellLocation(l, dir);
                if (map.GetCell(target_passage).IsWall())
                {
                    CheckDoorCreation(map, r, l, dir);
                }
            }
        }
    }
コード例 #2
0
    public void ConvertDoor(VirtualMap map, VirtualCell conversion_cell)
    {
        if (conversion_cell.IsDoor())
        {
            if (!behaviour.drawDoors)
            {
                conversion_cell.Type = VirtualCell.CellType.EmptyPassage;
            }
            else
            {
                CellLocation prev_loc = map.GetNeighbourCellLocation(conversion_cell.location, conversion_cell.Orientation);
                CellLocation next_loc = map.GetNeighbourCellLocation(conversion_cell.location, map.GetDirectionOpposite(conversion_cell.Orientation));
//				Debug.Log (prev_loc);
//				Debug.Log (next_loc);
//				Debug.Log (map.GetCell(prev_loc).IsRoomFloor());
//				Debug.Log (map.GetCell(next_loc).IsRoomFloor());
                if (map.GetCell(prev_loc).IsRoomFloor() && map.GetCell(next_loc).IsRoomFloor())
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomDoor;
                }
            }
        }
    }
コード例 #3
0
    // Various
    protected void ConvertWallOrientation(VirtualMap map, VirtualCell conversion_cell)
    {
        // Fix orientation of walls so that they follow the floors orientation
        conversion_cell.Orientation = VirtualMap.DirectionType.North;
        CellLocation neigh_loc = map.GetNeighbourCellLocation(conversion_cell.location, VirtualMap.DirectionType.North);

        if (!map.LocationIsOutsideBounds(neigh_loc))
        {
            VirtualCell neigh_cell = map.GetCell(neigh_loc);
            if (neigh_cell.IsNone())
            {
                conversion_cell.Orientation = VirtualMap.DirectionType.East;
            }
        }
    }
コード例 #4
0
    // Control if we can open a door in the given direction. Open it if possible
    private void CreateDoor(VirtualMap map, VirtualRoom r, RoomGenerator roomGenerator, CellLocation start_floor_loc, CellLocation end_floor_loc, VirtualMap.DirectionType direction)
    {
        CellLocation passage = map.GetNeighbourCellLocation(start_floor_loc, direction);

        // We check whether we are connecting to another room
        if (map.IsRoomFloor(end_floor_loc))
        {
            // Room-to-room door
            roomGenerator.OpenRoomDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
        }
        else
        {
            // Room-to-corridor door
            roomGenerator.OpenCorridorDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
        }
    }
コード例 #5
0
    // Control if we can open a door in the given direction. Open it if possible
    private bool CheckDoorCreation(VirtualMap map, VirtualRoom r, CellLocation start_floor_loc, VirtualMap.DirectionType direction)
    {
        bool         result        = false;
        CellLocation end_floor_loc = map.GetTargetLocation(start_floor_loc, direction);
        CellLocation passage       = map.GetNeighbourCellLocation(start_floor_loc, direction);

        // We get the ending floor and check its validity
        if (end_floor_loc.isValid() && !map.GetCell(end_floor_loc).IsRock())
        {
            // We check whether we are connecting to another room
            if (map.roomCells.Contains(end_floor_loc))
            {
                // Check if we skip creating the door
                if (DungeonGenerator.Random.Instance.Next(0, 100) > doorsDensityModifier && // We do not skip if we request more doors than needed
                    r.IsAlreadyConnectedToARoomAt(end_floor_loc, map))       // We skip if we are already connected
                {
                    return(result);
                }

                OpenRoomDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
            }
            else
            {
                // We need one door for each corridor segment that has been separated out by this room
                //		To do that, we also create a door if the ending floor is a dead end, effectively getting rid of the dead end
                //		Also, we create if the ending floor is a rock (i.e. 4 walls), which can happen if this room blocks out single floor cells!

                // We check if we need to skip
                if (CheckSkipDoorToCorridor(map, r, end_floor_loc))
                {
                    return(result);
                }

                // Debug.Log("Room " + r + " CREATING TO " + passage);

                OpenCorridorDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
            }

            result = true;
        }
        return(result);
    }
コード例 #6
0
    protected void ConvertFake3DEffect(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation below_loc = map.GetNeighbourCellLocation(conversion_cell.location, VirtualMap.DirectionType.South);

        if ((conversion_cell.IsColumn() || conversion_cell.IsWall()))
        {
            // If we have a wall below and this is a wall, we transform this to a special wall
            bool        isAbove    = false;
            VirtualCell below_cell = null;
            if (!map.LocationIsOutsideBounds(below_loc))
            {
                below_cell = map.GetCell(below_loc);
                if (below_cell.IsColumn() || below_cell.IsWall() || below_cell.IsRock())
                {
                    isAbove = true;
                }
                else
                {
                    isAbove = false;
                }
            }
            else
            {
                isAbove = true;
            }

            if (isAbove)
            {
                if (conversion_cell.IsRoom())
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Room_WallAbove;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Corridor_WallAbove;
                }
            }
            else
            {
                if (conversion_cell.IsRoom())
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Room_WallFront;

//					// Also, we add this to make sure the doors work correctly
//					if (below_cell.IsDoor()){
//						conversion_cell.AddCellInstance(VirtualCell.CellType.DoorHorizontalTop,below_cell.Orientation);
//					}
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.Fake3D_Corridor_WallFront;
                }
            }

            conversion_cell.Orientation = VirtualMap.DirectionType.West;             // Force orientation
        }
        else if (conversion_cell.IsDoor())
        {
            if (conversion_cell.IsHorizontal())
            {
                conversion_cell.Type = VirtualCell.CellType.DoorHorizontalBottom;
            }
            else
            {
                conversion_cell.Type = VirtualCell.CellType.DoorVertical;
            }
        }
    }
コード例 #7
0
    /********************
    * Door creation
    ********************/
    public void CreateDoors(VirtualMap map, VirtualRoom r, RoomGenerator roomGenerator)
    {
        // Create a list of border floors (close to the borders of the room)
        List <CellLocation> borderFloors = new List <CellLocation>();

        for (int i = 0; i < r.Width; i++)
        {
            for (int j = 0; j < r.Height; j++)
            {
                if (i == 0 || j == 0 || i == r.Width - 1 || j == r.Height - 1)
                {
                    CellLocation l = new CellLocation(r.leftCorner.x + 2 * i, r.leftCorner.y + 2 * j);
                    borderFloors.Add(l);
                }
            }
        }

        // For each border floor, check if we are connecting to something on the other side
        List <CellLocation>             outsideBorderFloors = new List <CellLocation>();
        List <CellLocation>             insideBorderFloors  = new List <CellLocation>();
        List <VirtualMap.DirectionType> borderDirections    = new List <VirtualMap.DirectionType>();

        CellLocation target_passage;
        CellLocation target_floor;

        foreach (CellLocation l in borderFloors)
        {
            foreach (VirtualMap.DirectionType dir in map.directions)
            {
                target_passage = map.GetNeighbourCellLocation(l, dir);
                target_floor   = map.GetTargetLocation(l, dir);
                if (!map.LocationIsOutsideBounds(target_floor) &&
                    map.GetCell(target_passage).IsWall() &&
                    !map.IsSurroundedByWalls(target_floor))
                {
                    outsideBorderFloors.Add(target_floor);
                    insideBorderFloors.Add(l);
                    borderDirections.Add(dir);
                }
            }
        }

        // We now create a door for each outside border floor, making sure to avoid re-creating doors if the floors are already connected
        List <CellLocation> unremovedFloors = new List <CellLocation>(outsideBorderFloors);

        for (int i = 0; i < outsideBorderFloors.Count; i++)
        {
            CellLocation l = outsideBorderFloors[i];
            // If not already removed (but we may not skip if we request more doors than needed)
            if (unremovedFloors.Contains(l) || DungeonGenerator.Random.Instance.Next(0, 100) < doorsDensityModifier)
            {
                CreateDoor(map, r, roomGenerator, insideBorderFloors[i], l, borderDirections[i]);
                unremovedFloors.Remove(l);

                // We also remove the other connected cells
                for (int j = unremovedFloors.Count - 1; j >= 0; j--)
                {
                    CellLocation other_l    = unremovedFloors[j];
                    bool         existsPath = map.ExistsPathBetweenLocations(l, other_l);
                    if (existsPath)
                    {
                        unremovedFloors.Remove(other_l);
                    }
                }
            }
        }
    }
コード例 #8
0
    // This will convert 'None' cells to columns where necessary.
    protected bool ConvertColumn(VirtualMap map, VirtualCell conversion_cell, bool mayBeDirectional = true)
    {
        CellLocation l = conversion_cell.location;
        //Debug.Log(l);
        bool isRoomColumn     = false;
        bool isCorridorColumn = false;
        bool isPassageColumn  = false;
        bool createColumn     = true;

        if (map.IsColumnRemovable(l, behaviour.drawWallCorners, behaviour.createColumnsInRooms))
        {
            //Debug.Log(conversion_cell.location + " Is removable!");
            createColumn = false;
        }
        else
        {
            //Debug.Log(conversion_cell.location + " Is not removable!");

            // We check all neighs to determine what type of column this is
            foreach (VirtualMap.DirectionType dir in map.directions)
            {
                CellLocation neigh_loc = map.GetNeighbourCellLocation(l, dir);
                if (!map.LocationIsOutsideBounds(neigh_loc))
                {
                    VirtualCell neigh_cell = map.GetCell(neigh_loc);

                    //Debug.Log("CHECK " + neigh_cell.location + " TYPE " + neigh_cell.Type);

                    if (neigh_cell.IsDoor())
                    {
                        conversion_cell.Type = VirtualCell.CellType.PassageColumn;
                        isPassageColumn      = true;
                        break;
                    }
                    else if (!isRoomColumn && neigh_cell.IsCorridorWall())
                    {
                        conversion_cell.Type = VirtualCell.CellType.CorridorColumn;
                        isCorridorColumn     = true;
                        // Do not break, as we need to check all the other walls to be sure
                    }
                    else if (neigh_cell.IsRoomWall())
                    {
                        conversion_cell.Type = VirtualCell.CellType.RoomColumn;
                        isRoomColumn         = true;
                        // Do not break, as we need to check all the other walls to be sure
                    }
                }
            }
        }

        // This may be surrounded by floors!
        if (createColumn &&
            (!isRoomColumn && !isCorridorColumn && !isPassageColumn))
        {
            if (map.IsInRoom(l))
            {
                if (behaviour.createColumnsInRooms)
                {
                    conversion_cell.Type = VirtualCell.CellType.InsideRoomColumn;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloorInside;
                }
            }
            else
            {
                // NOT IN ROOM: THIS IS EITHER SURROUNDED BY ROCKS OR BY CORRIDORS!!
                // We check all neighbours to make sure

                /*foreach(VirtualMap.DirectionType dir in map.directions){
                 *      CellLocation neigh_loc = map.GetNeighbourCellLocationOfSameType(l,dir);
                 *      if (!map.LocationIsOutsideBounds(neigh_loc)){
                 *              VirtualCell neigh_cell = map.GetCell(neigh_loc);
                 * }*/
                conversion_cell.Type = VirtualCell.CellType.CorridorColumn;
            }
            //Debug.Log("ROOM COL? " + conversion_cell.Type);
        }


        // Directional column
        if (createColumn)
        {
            ConvertDirectionalColumn(map, conversion_cell, mayBeDirectional);
        }

        // If the column is not created, we disable it
        if (!createColumn)
        {
            conversion_cell.Type = VirtualCell.CellType.None;
        }

        return(createColumn);
    }