Пример #1
0
    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
                        }
                    }
                }
            }
        }
    }