Пример #1
0
    private void CheckForMinimumMapSize()
    {
        //check that our map has atleast a certain minimum of playable space if not regenerate the map
        float percentageOfOpenTiles = CalculatePlayingArea();

        if (percentageOfOpenTiles < mapSettings.minimumPercentageOfOpenTiles)
        {
            if (numberOfMapsGenerated < maxMapsToGenerate)
            {
                numberOfMapsGenerated++;
                // if this reaches MaxMapsToGenerate then we have tried to generate too many maps with the minimumPercentageOfOpenTiles,
                //at this point to prevent a crash we need to ignore minimumPercentageOfOpenTiles
                DeleteEntireMap();
                initMap();
                if (!EnsureSpawnPointAndExitCanExist())
                {
                    RespawnMap();
                }
                //rerun the already called MapCleanUp functions
                RemoveBlockedOpenTiles();
                FixEdges(mapSettings.wallSprite);
                RemoveFloatingWalls();
                DungeonBoardWaterGeneration waterGeneration = ScriptableObject.CreateInstance <DungeonBoardWaterGeneration>();
                waterGeneration.GenerateLiquid(this, ref container, mapSettings.waterSprite);
                RemoveDisconnectedCaves();
                CheckForMinimumMapSize();
                return;
            }
            else
            {
                Debug.Log("Map generation failed too many times based off of minimum percentage of open tiles allowed, therefore a map was generated without a minimum number of open tiles, consider the settings your using!");
                mapSettings.minimumPercentageOfOpenTiles = 0.0f;
                numberOfMapsGenerated = 0;
                DeleteEntireMap();
                initMap();
                if (!EnsureSpawnPointAndExitCanExist())
                {
                    RespawnMap();
                }
                //rerun the already called MapCleanUp functions
                RemoveBlockedOpenTiles();
                FixEdges(mapSettings.wallSprite);
                RemoveFloatingWalls();
                DungeonBoardWaterGeneration waterGeneration = ScriptableObject.CreateInstance <DungeonBoardWaterGeneration>();
                waterGeneration.GenerateLiquid(this, ref container, mapSettings.waterSprite);
                RemoveDisconnectedCaves();
                return;
            }
        }
    }
Пример #2
0
    //public
    public void init(DungeonBoardSettings Settings)
    {
        //if the settings call for rows or cols under the minimum amount then scale the value up to the minimum
        Settings.rows = (Settings.rows < minNumberOfRows) ? minNumberOfRows : Settings.rows;
        Settings.cols = (Settings.cols < minNumberOfCols) ? minNumberOfCols : Settings.cols;
        Settings.minimumPercentageOfOpenTiles = (Settings.rows == minNumberOfRows && Settings.cols == minNumberOfCols) ? 0.25f : Settings.minimumPercentageOfOpenTiles;
        //

        //basic board info setup
        base.init(Settings.rows, Settings.cols, Settings.tileObject, "DungeonGrid");
        mapSettings = Settings;
        //

        //map generation
        initMap();         //create the static grid that we use to play the game of life on
        MapSimulation();   //play the game of life on the grid a number of times equal to mapSettings.numberOfSimulations
        //

        //map cleanup
        if (!EnsureSpawnPointAndExitCanExist())           //ensure that we can create a spawn and exit, if not restart map generation
        {
            RespawnMap();
        }
        RemoveBlockedOpenTiles();         // if any floor tiles are completely blocked in, remove them from the game
        FixEdges(mapSettings.wallSprite); //if any floor tiles are touching the edge of the gird change them to walls
        RemoveFloatingWalls();            //remove any walls that are just freefloating next to destoryed tiles
        //

        //water generation
        DungeonBoardWaterGeneration waterGeneration = ScriptableObject.CreateInstance <DungeonBoardWaterGeneration>();

        waterGeneration.GenerateLiquid(this, ref container, mapSettings.waterSprite);         //generate water in natural holes in the map
        //

        //grass generation
        DungeonBoardGrassGeneration grassGeneration = ScriptableObject.CreateInstance <DungeonBoardGrassGeneration>();

        grassGeneration.GenerateGrass(this, ref container, mapSettings.grassSprites);
        //

        //fix caves
        if (mapSettings.allowDisconnectedCaves)           //if we allow caves to spawn disconnected then place teleporters to connect them
        {
            ConnectDisconnectedCaves();
        }
        else             //otherwise remove the disconnected caves and make sure we retain a certain percentage of play space
        {
            RemoveDisconnectedCaves();
            CheckForMinimumMapSize();
        }
        if (mapSettings.runEdgeSmoothing)           //if we enable smoothing out map edges
        {
            SmoothMapEdges();
        }
        SetDestroyed();           //Set the destroyed status for all tiles
        ChangeInnerWallSprites(); //set walls that the player cannot see the "bottom" side of to a different sprite
        //

        //Final data setup
        SetAllOriginalSpritesAndColors(); //set the sprite and color values for each tile for use in later logic
        SpawnPlayerAndExitPoint();        //spawn the player and the exit point for the map
        SetUpEdges();                     //setup all tiles with edge information
        CalculateTileNeighbours();        //setup all tiles with neighbour information
        //
    }