public void ComputeStartAndEnd(VirtualMap map, VirtualMap vmapBelow)
    {
        List <CellLocation> iterable_locations;
        bool foundStart = false;

        if (forceStartAndEndInRooms)
        {
            iterable_locations = new List <CellLocation>(map.RoomWalkableLocations);
        }
        else
        {
            iterable_locations = new List <CellLocation>(map.WalkableLocations);
        }

        // Makes sure it is in some dead end, or in a room, if possible
        List <CellLocation> possible_start_locations = new List <CellLocation>();

        foreach (CellLocation l in iterable_locations)
        {
            if (map.IsDeadEnd(l) || map.IsInRoom(l))
            {
                possible_start_locations.Add(l);
            }
        }

        // If not possible, consider all locations equally
        if (possible_start_locations.Count == 0)
        {
            possible_start_locations = iterable_locations;
        }
        //		Debug.Log ("Possible start locations: " + possible_start_locations.Count);

        // TODO: Make an option for the start to be on the perimeter
//		foreach (CellLocation l in possible_start_locations) {
//			if (map.IsOnPerimeter(l) possible_start_locations
//		}


        // NOTE: we here find a start, but the algorithm already could have one! maybe use that?
        if (vmapBelow == null)
        {
            // Choose a random walkable cell as the starting point
            int index;
            index = DungeonGenerator.Random.Instance.Next(0, possible_start_locations.Count - 1);
            if (index != -1 && possible_start_locations.Count != 0)
            {
                map.start  = new CellLocation(possible_start_locations[index].x, possible_start_locations[index].y);
                foundStart = true;
            }
        }
        else
        {
            // Choose the cell above the below map's end as the starting point
            map.start  = vmapBelow.end;
            foundStart = true;
        }

        if (foundStart)
        {
            //Debug.Log ("CHOSEN START: " + map.start);
            // For this to work, we must compute the distance of all cells from the starting cell
            map.ComputeCellDistances(startCellLocation: map.start);

            // Choose a cell at a certain distance from the starting point as the ending point
            map.end = map.GetCellLocationInLimits(iterable_locations, minimumDistanceBetweenStartAndEnd / 100.0f * map.GetMaximumDistance(), maximumDistanceBetweenStartAndEnd / 100.0f * map.GetMaximumDistance());
        }

        //Debug.Log("START : " + map.start);
        //Debug.Log("END : " + map.end);
        //Debug.Log(map.GetWalkDistance(map.start,map.end));

        if (!foundStart)
        {
            Debug.LogError("Cannot find a suitable entrance!");
        }
        //DebugUtils.Assert(foundStart, "Cannot find a suitable entrance!");
    }
Пример #2
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);
    }