コード例 #1
0
    private bool findBSPCAComboSpawns(LevelGenOutput output)
    {
        List <LevelGenMap.Coordinate> openTiles = new List <LevelGenMap.Coordinate>(output.OpenTiles);

        openTiles.Shuffle();
        EnemySelector enemySelector = new EnemySelector();

        int           difficulty      = ProgressData.GetCurrentDifficulty();
        IntegerVector enemyCountRange = output.Input.GetCurrentNumEnemiesRange();

        int[] guaranteedEnemiesPlaced = new int[output.Input.GuaranteedEnemiesByDifficulty.Length];
        this.NumEnemies = Random.Range(enemyCountRange.X, enemyCountRange.Y + 1);
        LevelGenCaveInfo caveInfo = output.MapInfo[LevelGenCaveInfo.KEY] as LevelGenCaveInfo;

        if (ProgressData.IsMiniBoss(ProgressData.MostRecentTile))
        {
            findMinibossSpawn(openTiles, (caveInfo.Data as List <List <LevelGenMap.Coordinate> >)[0]);
        }

        LevelGenRoomInfo roomInfo = output.MapInfo[LevelGenRoomInfo.KEY] as LevelGenRoomInfo;

        List <SimpleRect> availableRooms = new List <SimpleRect>(roomInfo.Data as List <SimpleRect>);

        availableRooms.Shuffle();

        // Player room
        SimpleRect playerRoom = availableRooms[availableRooms.Count - 1];

        availableRooms.RemoveAt(availableRooms.Count - 1);
        List <LevelGenMap.Coordinate> playerRoomCoords = coordinatesInRoom(playerRoom);

        openTiles.RemoveList(playerRoomCoords);
        playerRoomCoords.Shuffle();

        for (int p = 0; p < DynamicData.MAX_PLAYERS; ++p)
        {
            if (DynamicData.GetSessionPlayer(p).HasJoined)
            {
                _playerSpawns.Add(playerRoomCoords[playerRoomCoords.Count - 1].integerVector);
                playerRoomCoords.RemoveAt(playerRoomCoords.Count - 1);
            }
        }

        if (openTiles.Count <= (this.NumEnemies + DynamicData.MAX_PLAYERS) * output.Input.MinDistanceBetweenSpawns * 2 + 1)
        {
            Debug.Log("Regeneration necessary - CA");
            return(false);
        }
        else
        {
            spawnSimple(0, output, guaranteedEnemiesPlaced, enemySelector, difficulty, openTiles, false);
        }
        return(true);
    }
コード例 #2
0
    private bool findBSPSpawns(LevelGenOutput output)
    {
        List <LevelGenMap.Coordinate> openTiles = new List <LevelGenMap.Coordinate>(output.OpenTiles);

        openTiles.Shuffle();

        LevelGenRoomInfo roomInfo        = output.MapInfo[LevelGenRoomInfo.KEY] as LevelGenRoomInfo;
        EnemySelector    enemySelector   = new EnemySelector();
        IntegerVector    enemyCountRange = output.Input.GetCurrentNumEnemiesRange();

        this.NumEnemies = Random.Range(enemyCountRange.X, enemyCountRange.Y + 1);

        if (ProgressData.IsMiniBoss(ProgressData.MostRecentTile))
        {
            findMinibossSpawn(openTiles, openTiles);
        }

        int difficulty = ProgressData.GetCurrentDifficulty();

        int[] guaranteedEnemiesPlaced = new int[output.Input.GuaranteedEnemiesByDifficulty.Length];
        int   totalGuarantees         = 0;

        for (int i = 0; i < guaranteedEnemiesPlaced.Length; ++i)
        {
            totalGuarantees += output.Input.GuaranteedEnemiesByDifficulty[i];
        }

        if (openTiles.Count <= (this.NumEnemies + DynamicData.MAX_PLAYERS) * output.Input.MinDistanceBetweenSpawns * 2 + 1 ||
            roomInfo == null || roomInfo.Data.Count < 4 + difficulty)
        {
            Debug.Log("Regeneration necessary - BSP 1");
            return(false);
        }
        else
        {
            List <SimpleRect> availableRooms = new List <SimpleRect>(roomInfo.Data as List <SimpleRect>);
            availableRooms.Shuffle();

            // Player room
            SimpleRect playerRoom = availableRooms[availableRooms.Count - 1];
            availableRooms.RemoveAt(availableRooms.Count - 1);
            List <LevelGenMap.Coordinate> playerRoomCoords = coordinatesInRoom(playerRoom);
            openTiles.RemoveList(playerRoomCoords);
            playerRoomCoords.Shuffle();

            for (int p = 0; p < DynamicData.MAX_PLAYERS; ++p)
            {
                if (DynamicData.GetSessionPlayer(p).HasJoined)
                {
                    _playerSpawns.Add(playerRoomCoords[playerRoomCoords.Count - 1].integerVector);
                    playerRoomCoords.RemoveAt(playerRoomCoords.Count - 1);
                }
            }

            if (openTiles.Count <= this.NumEnemies * output.Input.MinDistanceBetweenSpawns * 2 + 1)
            {
                Debug.Log("Regeneration necessary - BSP 2");
                return(false);
            }
            else
            {
                int  enemiesSpawned          = 0;
                int  guaranteesSpawned       = 0;
                bool haveUnitedAllRoomsSoFar = true;

                // Enemy rooms
                for (int r = 0; r < availableRooms.Count; ++r)
                {
                    SimpleRect room = availableRooms[r];
                    if (this.NumEnemies - enemiesSpawned < 4 || (r == availableRooms.Count - 1 && haveUnitedAllRoomsSoFar && guaranteesSpawned < totalGuarantees))
                    {
                        break;
                    }
                    if (Random.value > 0.65f)
                    {
                        haveUnitedAllRoomsSoFar = false;
                        continue;
                    }

                    List <EnemySpawn> roomSpawns = new List <EnemySpawn>();

                    EnemySelector.WeightSet roomWeightSet = new EnemySelector.WeightSet();
                    enemySelector.AddWeightSet(roomWeightSet);

                    // United-spawn room
                    int favoredEnemyId = pickMaybeGuaranteedEnemy(guaranteesSpawned, totalGuarantees, enemiesSpawned, difficulty, guaranteedEnemiesPlaced, output, enemySelector);

                    roomWeightSet.WeightsByEnemyId[favoredEnemyId] = 100;

                    List <IntegerVector> roomCorners = new List <IntegerVector>();
                    roomCorners.Add(new IntegerVector(room.X, room.Y));
                    roomCorners.Add(new IntegerVector(room.X + room.Width, room.Y));
                    roomCorners.Add(new IntegerVector(room.X, room.Y + room.Height));
                    roomCorners.Add(new IntegerVector(room.X + room.Width, room.Y + room.Height));
                    roomCorners.Shuffle();

                    IntegerVector firstPosition = roomCorners[roomCorners.Count - 1];
                    ++enemiesSpawned;
                    roomSpawns.Add(new EnemySpawn(firstPosition, favoredEnemyId));
                    roomCorners.RemoveAt(roomCorners.Count - 1);
                    int enemyDifficulty = StaticData.EnemyData.EnemyTypes[favoredEnemyId].Difficulty;
                    if (guaranteedEnemiesPlaced[enemyDifficulty] < output.Input.GuaranteedEnemiesByDifficulty[enemyDifficulty])
                    {
                        guaranteedEnemiesPlaced[enemyDifficulty] += 1;
                        ++guaranteesSpawned;
                    }

                    foreach (IntegerVector position in roomCorners)
                    {
                        ++enemiesSpawned;
                        int enemyId = enemySelector.ChooseEnemy(difficulty);
                        roomSpawns.Add(new EnemySpawn(position, enemyId));
                        enemyDifficulty = StaticData.EnemyData.EnemyTypes[enemyId].Difficulty;
                        if (guaranteedEnemiesPlaced[enemyDifficulty] < output.Input.GuaranteedEnemiesByDifficulty[enemyDifficulty])
                        {
                            guaranteedEnemiesPlaced[enemyDifficulty] += 1;
                            ++guaranteesSpawned;
                        }
                    }

                    bool extraTwo = false;
                    if (this.NumEnemies - enemiesSpawned > 2 && Random.value < CHANCE_FOR_EXTRA_TWO_IN_BSP_ROOM)
                    {
                        // Let's add 2 along the walls of the longest room dimension
                        extraTwo       = true;
                        favoredEnemyId = pickMaybeGuaranteedEnemy(guaranteesSpawned, totalGuarantees, enemiesSpawned, difficulty, guaranteedEnemiesPlaced, output, enemySelector);
                        roomWeightSet.WeightsByEnemyId[favoredEnemyId] = 100;

                        IntegerVector position1;
                        IntegerVector position2;
                        if (room.Width > room.Height)
                        {
                            position1 = new IntegerVector(room.X + room.Width / 2, room.Y);
                            position2 = new IntegerVector(room.X + room.Width / 2, room.Y + room.Height);
                        }
                        else
                        {
                            position1 = new IntegerVector(room.X, room.Y + room.Height / 2);
                            position2 = new IntegerVector(room.X + room.Width, room.Y + room.Height / 2);
                        }

                        enemiesSpawned += 2;
                        roomSpawns.Add(new EnemySpawn(position1, favoredEnemyId));
                        enemyDifficulty = StaticData.EnemyData.EnemyTypes[favoredEnemyId].Difficulty;
                        if (guaranteedEnemiesPlaced[enemyDifficulty] < output.Input.GuaranteedEnemiesByDifficulty[enemyDifficulty])
                        {
                            guaranteedEnemiesPlaced[enemyDifficulty] += 1;
                            ++guaranteesSpawned;
                        }

                        int enemyId = enemySelector.ChooseEnemy(difficulty);
                        roomSpawns.Add(new EnemySpawn(position2, enemyId));
                        enemyDifficulty = StaticData.EnemyData.EnemyTypes[enemyId].Difficulty;
                        if (guaranteedEnemiesPlaced[enemyDifficulty] < output.Input.GuaranteedEnemiesByDifficulty[enemyDifficulty])
                        {
                            guaranteedEnemiesPlaced[enemyDifficulty] += 1;
                            ++guaranteesSpawned;
                        }
                    }

                    _enemySpawns.Add(new EnemySpawnGroup(new IntegerVector(room.X + room.Width / 2, room.Y + room.Height / 2), roomSpawns, ((Mathf.Max(room.Width, room.Height) + 2.6f) / 2.0f) * _tileRenderer.TileRenderSize));

                    if (!enemySelector.RemoveWeightSet(roomWeightSet))
                    {
                        Debug.Log("hrrmmmm");
                    }

                    if (extraTwo || Random.value < CHANCE_FOR_REMOVE_SPAWN_ROOM_FOR_FUTURE_BSP)
                    {
                        openTiles.RemoveList(coordinatesInRoom(room));
                    }
                }

                // Non united-room spawns
                spawnSimple(enemiesSpawned, output, guaranteedEnemiesPlaced, enemySelector, difficulty, openTiles, false);
            }
        }

        return(true);
    }