Пример #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 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;
            }
        }
    }
Пример #3
0
    public void ConvertDirectionalCorridorColumn(VirtualMap map, VirtualCell conversion_cell)
    {
        CellLocation l = conversion_cell.location;

        if (behaviour.useDirectionalFloors)
        {
            // Count how many border neighbours are walls
            int    countWallNeighs = 0;
            bool[] validIndices    = new bool[4];

            // 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()
                    )                                     // TODO: Maybe isValid is not needed!
                {
                    VirtualCell other_cell = map.GetCell(other_l);
                    if (other_cell.IsWall() && !map.IsPassageRemovable(other_cell.location))
                    {
                        countWallNeighs++;
                        validIndices[i] = true;
                    }
                }
            }

            // Define the advanced tile to use
            // TODO: merge this with the one for directional floors somehow!
            if (countWallNeighs == 0)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallO;
            }
            else if (countWallNeighs == 1)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallU;
                for (int i = 0; i < 4; i++)
                {
                    if (validIndices[i])
                    {
                        conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)];
                        break;
                    }
                }
            }
            else if (countWallNeighs == 2)
            {
                // Corridor I
                conversion_cell.Type = VirtualCell.CellType.CorridorWallI;
                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.CorridorWallL;
                        break;
                    }
                }
            }
            else if (countWallNeighs == 3)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallT;
                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 (countWallNeighs == 4)
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorWallX;
            }
        }
    }