Exemplo n.º 1
0
        /// <summary>
        /// Generates a map based on the generator settings and area spreads
        /// </summary>
        /// <param name="settings">Generator settings to modify the generation process</param>
        /// <param name="area">Area that should be placed on the map</param>
        /// <returns>Returns the maps as a flatten byte array</returns>
        public Tile[] GenerateMap(GeneratorSettings settings, AreaSpread area)
        {
            if (settings.Seed >= 0)
            {
                random = new Random(settings.Seed);
            }
            else if (random == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            Tile[] map         = PopulateMap(settings);
            int    rowCount    = map.GetUpperBound(0);
            int    columnCount = map.GetUpperBound(1);

            CreateLayerOne(map, rowCount, columnCount, settings.TileSize, settings.MeterPerTile, area, settings.RadiusOfCylinder);

            return(map);
        }
Exemplo n.º 2
0
        private ObjectTile[] CreateObjectLayer(Tile[] map, AreaSpread area, int rowCount, int columnCount)
        {
            List <ObjectTile> tiles        = new List <ObjectTile>();
            float             tilesChanged = 0;
            float             tileCount    = rowCount * columnCount;

            while (tilesChanged / tileCount < area.Percentage)
            {
                int row        = random.Next(0, rowCount);
                int column     = random.Next(0, columnCount);
                int fieldIndex = TileMathHelper.ToIndex(row, column, columnCount);

                if (map[fieldIndex].Id == 0)
                {
                    ObjectTile tile = new ObjectTile(fieldIndex, area.Id);
                    tiles.Add(tile);
                    tilesChanged++;
                }
            }
            return(tiles.ToArray());
        }
Exemplo n.º 3
0
 private void CreateBiomeLayer(int mapIndex, Tile[][] maps, AreaSpread area)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Create the first (height) layer with circular areas
        /// </summary>
        /// <param name="map">The map where the area should be placed on</param>
        /// <param name="rowCount">Number of rows per grid</param>
        /// <param name="columnCount">Number of columns per grid</param>
        /// <param name="tileSize">Size of a tile in pixel</param>
        /// <param name="meterPerTile">Size of a tile in meter</param>
        /// <param name="area">Area that should be generated and placed on the given map</param>
        /// <param name="allowEdgeManipulation">Allows areas to overlap tiles from other maps</param>
        private void CreateLayerOne(Tile[] map, int rowCount, int columnCount, int tileSize, float meterPerTiles, AreaSpread area, bool allowEdgeManipulation)
        {
            float tilesChanged = 0;
            float tileCount    = rowCount * columnCount;

            while (tilesChanged / tileCount < area.Percentage)
            {
                int row        = random.Next(0, rowCount);
                int column     = random.Next(0, columnCount);
                int fieldIndex = TileMathHelper.ToIndex(row, column, columnCount);
                int minRadius  = random.Next(area.MinSizeInMeter, area.MaxSizeInMeter + 1);

                if (map[fieldIndex].Id == 0 || map[fieldIndex].Id == area.Id)
                {
                    if (area.SpreadType == SpreadOption.Circle)
                    {
                        tilesChanged += CreateCircleArea(map, row, column, rowCount, columnCount, minRadius, tileSize, meterPerTiles, area.Id, area.Flag, allowEdgeManipulation);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create the first (height) layer with circular areas
        /// </summary>
        /// <param name="mapIndex">Index of the map</param>
        /// <param name="maps">Current grids</param>
        /// <param name="edgeOverrides">Current edge override maps</param>
        /// <param name="rowCount">Number of rows per grid</param>
        /// <param name="columnCount">Number of columns per grid</param>
        /// <param name="tileSize">Size of a tile in pixel</param>
        /// <param name="meterPerTile">Size of a tile in meter</param>
        /// <param name="area">Area that should be generated and placed on the given map</param>
        /// <param name="allowEdgeOverflow">Allows areas to overlap tiles from other maps</param>
        private void CreateLayerOne(int mapIndex, Tile[][] maps, Tile[][] edgeOverrides, int rowCount, int columnCount, int tileSize, float meterPerTiles, AreaSpread area, bool allowEdgeOverflow)
        {
            int tilesChanged = 0;
            int tileCount    = rowCount * columnCount;

            while (((float)tilesChanged) / ((float)tileCount) < area.Percentage)
            {
                int row        = random.Next(0, rowCount);
                int column     = random.Next(0, columnCount);
                int fieldIndex = TileMathHelper.ToIndex(row, column, columnCount);
                int minRadius  = random.Next(area.MinSizeInMeter, area.MaxSizeInMeter + 1);

                if (maps[mapIndex][fieldIndex].Id == 0 || maps[mapIndex][fieldIndex].Id == area.Id)
                {
                    if (area.SpreadType == SpreadOption.Circle)
                    {
                        tilesChanged += CreateCircleArea(mapIndex, maps, edgeOverrides, row, column, rowCount, columnCount, minRadius, tileSize, meterPerTiles, area.Id, area.Flag, allowEdgeOverflow, area.UseEdgeNoise);
                    }
                }
            }
        }