コード例 #1
0
    private static void InstantiateRoomDoor(int x, int y, int floor, string block, Dungeon layout)
    {
        if (block != "X")
        {
            return;
        }
        var room = LevelGenRoomUtils.GetRoomFromCoords(x, y, floor, layout);

        if (room is CommonSpace)
        {
            return;
        }
        if (LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 3) && LevelGenGridUtils.IsCorridor(x - 1, y, floor, layout.grid))
        {
            MakeRoomDoor(x - 0.5f, y, 90);
        }
        if (LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 1) && LevelGenGridUtils.IsCorridor(x + 1, y, floor, layout.grid))
        {
            MakeRoomDoor(x + 0.5f, y, 270);
        }
        if (LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 0) && LevelGenGridUtils.IsCorridor(x, y - 1, floor, layout.grid))
        {
            MakeRoomDoor(x, y - 0.5f, 180);
        }
        if (LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 2) && LevelGenGridUtils.IsCorridor(x, y + 1, floor, layout.grid))
        {
            MakeRoomDoor(x, y + 0.5f, 0);
        }
    }
コード例 #2
0
    private void LayoutFloor(List <Room> floorRooms, int floor)
    {
        building.maxDimensions = LevelGenRoomUtils.CalculateMaxDimensions(floorRooms, building.numFloors);
        floorRooms             = LevelGenRoomUtils.RandomizeOrder(floorRooms);
        AddStartingCorridors(floor, building.maxDimensions, floorRooms.Count);
        Vector2 entranceLocation = new Vector2(0, 0);
        Vector2 exitLocation     = new Vector2(0, 0);

        entranceLocation = GetEntranceLocation(floor, building.rooms, building.grid);
        exitLocation     = GetExitLocation(floor, building.rooms, building.grid, entranceLocation);
        if (floor == 0)
        {
            building.grid[floor, (int)entranceLocation.x, (int)entranceLocation.y] = "E";
        }
        else
        {
            building.grid[floor, (int)entranceLocation.x, (int)entranceLocation.y] = "<";
        }
        if (floor < building.numFloors - 1)
        {
            building.grid[floor, (int)exitLocation.x, (int)exitLocation.y] = ">";
        }
        foreach (var room in floorRooms)
        {
            LevelGenRoomUtils.PackRoom(room, floor, building);
        }
        LevelGenConnectorUtils.ConnectRooms(floor, floorRooms, building);
    }
コード例 #3
0
    private static void ConnectRoomCrookedly(int floor, Room room, Dungeon building)
    {
        var corridors = LevelGenRoomUtils.FetchCorridorsForFloor(floor, building.rooms);
        int count     = 0;

        while (corridors.Count > 0 && count < 1000)
        {
            var corridor = LevelGenRoomUtils.FindClosestCorridor(room, corridors);
            foreach (var start in GetSurrounding(corridor))
            {
                foreach (var end in GetSurrounding(room))
                {
                    var _start = new Coordinates(start.x, start.y);
                    var _end   = new Coordinates(end.x, end.y);
                    var result = AddCrookedConnector(room, corridor, _start, _end, building);
                    if (result)
                    {
                        return;
                    }
                }
            }
            count++;
            corridors.Remove(corridor);
        }
    }
コード例 #4
0
    private static void ConnectRoomToOtherRooms(int floor, Room room, Dungeon building, List <Room> floorRooms)
    {
        var room2 = LevelGenRoomUtils.FindClosestRoom(room, floorRooms);

        if (LevelGenValidationUtils.IsStraightConnectingLine(room, room2, building.grid))
        {
            AddStraightConnectingLine(room, room2, building);
        }
    }
コード例 #5
0
    private List <Room> GetRoomsConnectedToPoint(int floor, Vector2 point)
    {
        var room  = LevelGenRoomUtils.GetRoomFromCoords((int)point.x, (int)point.y, floor, building);
        var rooms = new List <Room> {
            room
        };

        rooms = GetConnectedRoomsRecursively(room, rooms, building.rooms);
        return(rooms);
    }
コード例 #6
0
    private static void ConnectRoom(int floor, Room room, Dungeon building)
    {
        var corridors = LevelGenRoomUtils.FetchCorridorsForFloor(floor, building.rooms);
        var corridor  = LevelGenRoomUtils.FindClosestCorridor(room, corridors);

        if (LevelGenValidationUtils.IsStraightConnectingLine(room, corridor, building.grid))
        {
            AddStraightConnectingLine(room, corridor, building);
        }
    }
コード例 #7
0
    public override void LayoutRooms()
    {
        LevelGenGridUtils.FillGrid(building.grid, building.numFloors, 120, 120);
        var roomsBySize = LevelGenRoomUtils.SortRoomsBySize(building.rooms);

        building.numFloors = Random.Range(1, 6);
        var roomsByFloor = ChunkRoomsByFloors(roomsBySize);

        for (int i = 0; i < building.numFloors; i++)
        {
            LayoutFloor(roomsByFloor[i], i);
        }
    }
コード例 #8
0
    public bool SetupVault()
    {
        LevelGenGridUtils.FillGrid(building.grid, building.numFloors, 120, 120);
        var success = true;
        var rooms   = new List <Room>();

        foreach (var room in building.rooms)
        {
            rooms.Add(room);
        }
        success = LevelGenRoomUtils.PackPreConnectedRooms(building, rooms);
        return(success);
    }
コード例 #9
0
    public static void ConnectRooms(int floor, List <Room> floorRooms, Dungeon building)
    {
        foreach (var room in floorRooms)
        {
            ConnectRoom(floor, room, building);
        }
        var unconnected = LevelGenRoomUtils.GetUnconnectedRooms(floorRooms, floor);

        foreach (var room in unconnected)
        {
            ConnectRoomCrookedly(floor, room, building);
        }
    }
コード例 #10
0
    private static void AddCommonSpaceSideFurnishing(CommonSpace room, string[,,] grid)
    {
        var population = room.inhabitants.Count;
        var size       = Mathf.Sqrt(DesignedBuilding.monsterRoomSizes[room.inhabitants[0].generalType]);
        int bedType    = ActiveCastleLivingQuartersGen.GetBedType(room);

        if (bedType == 1)
        {
            population /= 2;
        }
        bool fancy = (bedType >= 6);

        population /= 2;
        Dictionary <string, GameObject> furniture;
        Dictionary <string, float>      furnitureProbs;

        if (fancy)
        {
            furniture      = prefabs["castle"]["commonSpaceSideFurnitureFancy"];
            furnitureProbs = prefabProbability["castle"]["commonSpaceSideFurnitureFancy"];
        }
        else
        {
            furniture      = prefabs["castle"]["commonSpaceSideFurniture"];
            furnitureProbs = prefabProbability["castle"]["commonSpaceSideFurniture"];
        }
        var potentialSpots = LevelGenRoomUtils.GetPotentialSideDressingSpots(room, grid);

        foreach (var spot in potentialSpots)
        {
            var roll = Random.Range(0, 100);
            if (roll < 100 * population / (float)potentialSpots.Count)
            {
                var xFudge        = Random.Range(-0.05f, 0.05f);
                var yFudge        = Random.Range(-0.05f, 0.05f);
                var rotationFudge = Random.Range(-2.5f, 2.5f);
                var wallRotation  = LevelGenGridUtils.GetWallRotation((int)spot.x, (int)spot.y, room.floor, grid);
                var xAdjust       = LevelGenGridUtils.GetXSideDressingAdjustment((int)spot.x, (int)spot.y, room.floor, grid);
                var yAdjust       = LevelGenGridUtils.GetYSideDressingAdjustment((int)spot.x, (int)spot.y, room.floor, grid);
                var obj           = LevelGenInstantiationUtils.InstantiateBlockObject(furniture, furnitureProbs, xAdjust + xFudge + spot.x, yAdjust + yFudge + spot.y);
                room.dressingLocations.Add(spot);
                obj.transform.localScale = new Vector3(size, size, size);
                obj.transform.Rotate(0, rotationFudge + wallRotation, 0);
            }
        }
    }
コード例 #11
0
    public static void ConnectSingleBlock(int x, int y, int floor, Dungeon building)
    {
        var corridors = LevelGenRoomUtils.FetchCorridorsForFloor(floor, building.rooms);
        int count     = 0;

        while (corridors.Count > 0 && count < 1000)
        {
            var corridor = LevelGenRoomUtils.FindClosestCorridorToBlock(x, y, floor, building, corridors);
            foreach (var start in GetSurrounding(corridor))
            {
                var _start = new Coordinates(start.x, start.y);
                var _end   = new Coordinates(x, y);
                var result = AddCrookedConnectorToBlock(corridor, _start, _end, building);
                if (result)
                {
                    return;
                }
            }
            count++;
            corridors.Remove(corridor);
        }
    }
コード例 #12
0
    public static void ConnectRoomsToOneAnother(int floor, List <Room> floorRooms, Dungeon building)
    {
        var connectedRooms   = new List <Room>();
        var unconnectedRooms = floorRooms;

        connectedRooms.Add(unconnectedRooms[0]);
        unconnectedRooms.RemoveAt(0);
        var attempts = 0;

        while (unconnectedRooms.Count > 0 && attempts < 10)
        {
            foreach (var room in unconnectedRooms)
            {
                ConnectRoomToOtherRooms(floor, room, building, connectedRooms);
                if (!LevelGenRoomUtils.RoomUnconnected(building.rooms, room, floor))
                {
                    connectedRooms.Add(room);
                    unconnectedRooms.Remove(room);
                    break;
                }
            }
            attempts++;
        }
        attempts = 0;
        while (unconnectedRooms.Count > 0 && attempts < 10)
        {
            foreach (var room in unconnectedRooms)
            {
                ConnectRoomToRoomsCrookedly(floor, room, building, connectedRooms);
                if (!LevelGenRoomUtils.RoomUnconnected(building.rooms, room, floor))
                {
                    connectedRooms.Add(room);
                    unconnectedRooms.Remove(room);
                    break;
                }
            }
            attempts++;
        }
    }
コード例 #13
0
 private static void InstantiateRoomWall(int x, int y, int floor, string block, Dungeon layout)
 {
     if (block != "X")
     {
         return;
     }
     if (!LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 3) && LevelGenGridUtils.IsCorridor(x - 1, y, floor, layout.grid))
     {
         MakeRoomWall(x - 0.5f, y, 0);
     }
     if (!LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 1) && LevelGenGridUtils.IsCorridor(x + 1, y, floor, layout.grid))
     {
         MakeRoomWall(x + 0.5f, y, 180);
     }
     if (!LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 0) && LevelGenGridUtils.IsCorridor(x, y - 1, floor, layout.grid))
     {
         MakeRoomWall(x, y - 0.5f, 90);
     }
     if (!LevelGenRoomUtils.IsRoomEntrance(x, y, floor, layout, 2) && LevelGenGridUtils.IsCorridor(x, y + 1, floor, layout.grid))
     {
         MakeRoomWall(x, y + 0.5f, 270);
     }
 }
コード例 #14
0
    private static void ConnectRoomToRoomsCrookedly(int floor, Room room, Dungeon building, List <Room> rooms)
    {
        int count = 0;

        while (rooms.Count > 0 && count < 1000)
        {
            var room2 = LevelGenRoomUtils.FindClosestRoom(room, rooms);
            foreach (var start in GetSurrounding(room2))
            {
                foreach (var end in GetSurrounding(room))
                {
                    var _start = new Coordinates(start.x, start.y);
                    var _end   = new Coordinates(end.x, end.y);
                    var result = AddCrookedConnector(room, room2, _start, _end, building);
                    if (result)
                    {
                        return;
                    }
                }
            }
            count++;
            rooms.Remove(room2);
        }
    }