Esempio n. 1
0
    // A dead end cell has one and only one direction free for walking (i.e. there is no wall there -> empty)
    public bool IsDeadEnd(CellLocation l, bool alsoConsiderDoors = false)
    {
        int emptyCount = 0;

        CellLocation[] locs = GetAllNeighbours(l);
        foreach (CellLocation n_l in locs)
        {
            VirtualCell.CellType type = this.GetCell(n_l.x, n_l.y).Type;
            if (type == VirtualCell.CellType.EmptyPassage ||
                (alsoConsiderDoors && VirtualCell.IsDoor(type)))
            {
                emptyCount++;
                //Debug.Log("For loc " + l + " neigh " + n_l + " is empty!");
            }
        }

        return(emptyCount == 1);
    }
Esempio n. 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;
                }
            }
        }
    }
    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;
            }
        }
    }
    protected void AddFillingFloors(VirtualMap map, VirtualCell conversion_cell)
    {
        if (conversion_cell.Type == VirtualCell.CellType.None)
        {
            return;
        }

        // Fill with floors
        VirtualCell.CellType     initial_type = conversion_cell.Type;
        VirtualMap.DirectionType initial_dir  = conversion_cell.Orientation;
        bool addedFloor = false;

        if (behaviour.fillWithFloors)
        {
            bool mayBeDirectional = false;
            if (CheckRoom(map, conversion_cell.location))
            {
                if (conversion_cell.IsDoor() || conversion_cell.IsEmpty())
                {
                    AddToCorrectRoom(map, conversion_cell.location);
                    conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                    ConvertDirectionalRoomFloor(map, conversion_cell);
                    mayBeDirectional = true;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                }
            }
            else
            {
                if (conversion_cell.IsDoor() || conversion_cell.IsEmpty())
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                    ConvertDirectionalCorridorFloor(map, conversion_cell);
                    mayBeDirectional = true;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                }
            }
            ConvertFloor(map, conversion_cell, mayBeDirectional);
            addedFloor = true;
        }
        else
        {
            // Special case: when not filling with floors AND we do not draw doors, we still need to place a floor underneath the empty passage representing the doors!
            if (conversion_cell.IsEmpty())                      // Decomment this if you want floors underneath doors ALWAYS: // || input_cell.IsDoor()){
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                ConvertDirectionalCorridorFloor(map, conversion_cell);
                ConvertFloor(map, conversion_cell);
                addedFloor = true;
            }
        }

        if (addedFloor)
        {
            // The initial type is switched in, the floor becomes a subtype
            VirtualCell.CellType     new_subtype = conversion_cell.Type;
            VirtualMap.DirectionType new_dir     = conversion_cell.Orientation;
            conversion_cell.Type        = initial_type;
            conversion_cell.Orientation = initial_dir;
            conversion_cell.AddCellInstance(new_subtype, new_dir);
        }
    }
Esempio n. 5
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);
    }