示例#1
0
    public int AttemptToSpawnSquares(Job.JobArea mapType, int percentChange, int remainingSquaresToSpawn, int verticalModifer, int chanceToSpawnEnemy)
    {
        int newSquareCount = 0;

        foreach (MapSquare square in activeSquares)
        {
            List <MapSquare> adjacentSquares = square.GetAdjacentSquares();
            foreach (MapSquare adjacentSquare in adjacentSquares)
            {
                if (newSquareCount < remainingSquaresToSpawn)
                {
                    int modifier = 0;
                    if (square.GetUpSquare() == adjacentSquare)
                    {
                        modifier += verticalModifer;
                    }

                    if (!adjacentSquare.IsActive() && Random.Range(0, 100) < percentChange + modifier)
                    {
                        adjacentSquare.InitializeSquare(mapSquareImageHolder.GetSquareImage(mapType), mapSquareImageHolder.GetLocationImage(mapType), false);
                        newSquareCount++;
                        if (Random.Range(0, 100) < chanceToSpawnEnemy)
                        {
                            MapData mapData = FindObjectOfType <MapData>();
                            adjacentSquare.SpawnEnemy(mapType, mapData.GetSecurityLevel(), mapData.GetJob());
                        }
                    }
                }
            }
        }
        mapGrid.ConsolidateNewActiveSquaresInAllRows();
        return(newSquareCount);
    }
    private void SetupMap(Job.JobArea mapType, int mapSize, int mapSquareChanceForVerticalModifier, int percentEnemySpawn)
    {
        // initialize starting square in first row
        int activeSquares = 1;

        activeRows.Add(rows[startingRow]);
        MapSquare firstSquare = rows[startingRow].InitializeFirstSquare(startingSquare, mapSquareImageHolder.GetSquareImage(mapType));

        // then start spawning the rest
        int currentRow = startingRow;

        ConsolidateNewActiveSquaresInAllRows();
        while (activeSquares < mapSize)
        {
            // go through active rows and spawn squares around each active square
            for (int i = activeRows.Count - 1; i >= 0; i--)
            {
                int amountOfNewSquares = activeRows[i].AttemptToSpawnSquares(mapType, percentChanceForSpawn, mapSize - activeSquares, mapSquareChanceForVerticalModifier, percentEnemySpawn);
                activeSquares += amountOfNewSquares;
            }

            ConsolidateNewActiveSquaresInAllRows();

            // then look for active rows and add them to the active rows list, setting them up for spawns as well
            foreach (MapSquareRow row in rows)
            {
                if (row.ContainsActiveSquares() && !activeRows.Contains(row))
                {
                    activeRows.Add(row);
                }
            }
        }
        int activeSquareAccurateCount = 0;

        foreach (MapSquareRow row in rows)
        {
            activeSquareAccurateCount += row.CountActiveSquares();
        }

        // This is just for debug purposes
        //CheckNumberOfTransportationHacks();

        SpawnGoal(firstSquare);
    }