Exemplo n.º 1
0
    // Returns true if this passage cell can be removed from the map (i.e. not shown)
    public bool IsPassageRemovable(CellLocation l)
    {
        VirtualCell cell = this.GetCell(l);

        if (cell.IsWall() || cell.IsEmpty())
        {
            // We count how many valid neighs are floors, and how many are nones
            int validNeigh = 0;
            int floorCount = 0;
            int noneCount  = 0;

            CellLocation n;
            foreach (DirectionType dir in directions)
            {
                n = GetNeighbourCellLocation(l, dir);
                if (!LocationIsOutsideBounds(n))
                {
                    validNeigh++;
                    VirtualCell neigh_cell = GetCell(n);
                    if (neigh_cell.IsFloor())
                    {
                        floorCount++;
                    }
                    else if (neigh_cell.IsNone() || neigh_cell.IsRock())
                    {
                        noneCount++;
                    }
                }
            }
            //Debug.Log(l + " Valid neighs: " + validNeigh + " floorCount: " + floorCount + " noneCount: " + noneCount);
            return(floorCount == 0);
        }
        return(false);
    }
 protected void ConvertTileIntersections(VirtualMap map, VirtualCell conversion_cell)
 {
     if (conversion_cell.IsEmpty())
     {
         // Empty passages should be filled with floors, unless removable (and thus become rock)
         if (map.IsPassageRemovable(conversion_cell.location))
         {
             conversion_cell.Type = VirtualCell.CellType.Rock;
         }
         else
         {
             if (CheckRoom(map, conversion_cell.location))
             {
                 AddToCorrectRoom(map, conversion_cell.location);
                 conversion_cell.Type = VirtualCell.CellType.RoomFloor;
             }
             else
             {
                 conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
             }
         }
     }
     else
     {
         // 'None' cells will remain as such, since they will be converted to columns later (or to floors), if needed.
     }
 }
 protected void ConvertTileIntersections(VirtualMap map, VirtualCell conversion_cell)
 {
     if (conversion_cell.IsEmpty())
     {
         // Empty passages should be filled with floors
         conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
     }
     else
     {
         // 'None' cells will remain as such, since they will be converted to rocks later
     }
 }
    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);
        }
    }
Exemplo n.º 5
0
    // Returns true if this 'none' (i.e. column) cell can be removed from the map (i.e. not shown)
    public bool IsColumnRemovable(CellLocation l, bool drawCorners = true, bool createColumnsInRooms = false)
    {
        VirtualCell cell = this.GetCell(l);

        if (cell.IsNone())  // Should be performed only on a NONE
        {
            int validNeigh = 0;
            int wallCount  = 0;
            int emptyCount = 0;

            CellLocation n;
            foreach (DirectionType dir in directions)
            {
                n = GetNeighbourCellLocation(l, dir);
                if (!LocationIsOutsideBounds(n))
                {
                    validNeigh++;
                    VirtualCell neigh_cell = GetCell(n);
                    //Debug.Log(neigh_cell.Type);
                    if (neigh_cell.IsEmpty() || neigh_cell.IsRock())
                    {
                        emptyCount++;
                    }
                    else
                    {
                        wallCount++;

                        // HACK: we need to do this or the columns won't know if the walls have been made removable during this step!
                        if (IsPassageRemovable(n))
                        {
                            wallCount--;
                            emptyCount++;
                        }
                    }
                    //Debug.Log("Neigh " + n + " is " + GetCell(n).Type);
                }
            }

            //Debug.Log("Cell " + l + " W " + wallCount + " ,  E " + emptyCount + " ,  V " + validNeigh);
            if (!drawCorners)
            {
                // We do not draw corners of rooms (corner = two walls and adjacent)
                if (wallCount == 2)
                {
                    // We check whether the two walls are adjacent (also doors)
                    // At least one neigh wall need not be removable as well for this to be a corner (and not an isolated None cell)
                    bool lastWasWall = false;
                    foreach (DirectionType dir in directions)
                    {
                        n = GetNeighbourCellLocation(l, dir);
                        //Debug.Log(n);
                        if (!LocationIsOutsideBounds(n) && (GetCell(n).IsWall() || GetCell(n).IsDoor()))
                        {
                            //Debug.Log("WALL!");
                            if (lastWasWall)
                            {
                                return(true);               // Adjacent!
                            }
                            lastWasWall = true;
                        }
                        else
                        {
                            lastWasWall = false;
                        }
                    }
                }
            }


            // HACK: check if we are in a room (as in the standardmap a roomcolumn is in fact surrounded by empties!)
            if (IsInRoom(l) && createColumnsInRooms)
            {
                return(false);
            }

            return(wallCount == 0);
        }
        return(false);
    }