Esempio n. 1
0
        public static void GenerateTranslatedMaps(int amountToGenerate, int seedStart)
        {
            var sw = new Stopwatch();

            for (var i = seedStart; i < seedStart + amountToGenerate; i++)
            {
                sw.Restart();
                var random123 = new Random(i);
                var ca        = new CellularAutomata(64, 64, Enums.Half.Top, maxRangeToGroupPoint: 7, r: random123);
                ca.RunGenerations();
                ca.CreateImpassableTerrain(maxLength: 25, maxPathNoiseDisplacement: 1, maxWidth: 2);

                var map = new MapPhenotype(ca.Map, new Enums.Item[64, 64]);
                map.SmoothTerrain();

                var newMap = MapHelper.IncreaseSizeOfMap(map, 2);
                newMap.SmoothTerrain(random: random123);
                newMap.PlaceCliffs();

                newMap.SmoothCliffs();
                newMap.UpdateCliffPositions(Enums.Half.Top);
                newMap.SaveMapToPngFile(string.Format("map {0}_4_translated_post_smooth_cliffs", i), itemMap: false);
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            Console.ReadKey();
        }
Esempio n. 2
0
        /// <summary>
        /// Creates base maps using a cellular automaton with the given settings.
        /// </summary>
        /// <param name="mapSize"> The height and width of the base maps. </param>
        /// <param name="oddsOfHeight"> The chance of height1 happening. </param>
        /// <param name="oddsOfHeight2"> The chance of height2 happening.</param>
        /// <param name="maxRangeToGroupPoints"> The max range to the group points. </param>
        /// <param name="groupPoints"> The number of points where terrain should be grouped during the initial seeding. </param>
        /// <param name="generateHeight2"> Determines if the cellular automata should generate height2 or not. </param>
        /// <param name="caRandomSeeds"> The random seeds to use for the CA's random generator. </param>
        /// <param name="caRuleset"> The ruleset to use by the CA. If left as null, the default ruleset is used. </param>
        /// <param name="sections"> The number of impassable terrain sections. </param>
        /// <param name="maxLength"> The max length of impassable terrain sections. </param>
        /// <param name="placementIntervals"> The interval at which areas are placed in the impassable terrain section. </param>
        /// <param name="maxPathNoiseDisplacement"> The max displacement for an area in the impassable terrain.</param>
        /// <param name="maxWidth"> The max width of a point. </param>
        /// <param name="caGenerations"> The number of generations run by the CA. </param>
        /// <param name="generateHeight2ThroughRules"> Determines if height2 should be generated through rules or not.</param>
        /// <param name="smoothingNormalNeighbourhood"> If the number of neighbours in the normal Moore neighbourhood is less than or equal to this number, smoothing happens. </param>
        /// <param name="smoothingExtNeighbourhood"> If the number of neighbours in the extended Moore neighbourhood is less than or equal to this number, smoothing happens. </param>
        /// <param name="smoothingGenerations"> The number of smoothing generations run. </param>
        /// <param name="smoothingRuleSet"> The ruleset used for smoothing. If left as null, the default smoothing ruleset will be used. </param>
        /// <param name="fileToWriteTo"> The file to write the timings to. </param>
        /// <param name="baseMapFolder"> The folder to print the base maps to in "Images/Finished Maps". </param>
        /// <returns> A list of base maps. </returns>
        public static List <MapPhenotype> GetBaseMaps(
            int mapSize                      = 128,
            double oddsOfHeight              = 0.4,
            double oddsOfHeight2             = 0.2,
            int maxRangeToGroupPoints        = 15,
            int groupPoints                  = 3,
            bool generateHeight2             = true,
            List <int> caRandomSeeds         = null,
            List <Rule> caRuleset            = null,
            int sections                     = 4,
            int maxLength                    = 50,
            double placementIntervals        = 0.1,
            int maxPathNoiseDisplacement     = 3,
            int maxWidth                     = 4,
            int caGenerations                = 10,
            bool generateHeight2ThroughRules = true,
            int smoothingNormalNeighbourhood = 2,
            int smoothingExtNeighbourhood    = 6,
            int smoothingGenerations         = 10,
            List <Rule> smoothingRuleSet     = null,
            string fileToWriteTo             = "BaseMapGeneration.txt",
            string baseMapFolder             = "BaseMaps")
        {
            var stringToWrite = new StringBuilder();

            var baseMaps = new List <MapPhenotype>();

            CellularAutomata ca;
            var sw = new Stopwatch();

            sw.Start();

            if (caRandomSeeds == null || caRandomSeeds.Count == 0)
            {
                ca = new CellularAutomata(mapSize, mapSize, Enums.Half.Top, oddsOfHeight, oddsOfHeight2, maxRangeToGroupPoints, groupPoints, generateHeight2);
                if (caRuleset != null)
                {
                    ca.SetRuleset(caRuleset);
                }

                ca.CreateImpassableTerrain(sections, maxLength, placementIntervals, maxPathNoiseDisplacement, maxWidth);

                ca.RunGenerations(caGenerations, generateHeight2ThroughRules);
                var map = new MapPhenotype(ca.Map, new Enums.Item[mapSize, mapSize]);
                map.SmoothTerrain(smoothingNormalNeighbourhood, smoothingExtNeighbourhood, smoothingGenerations, smoothingRuleSet);
                map.PlaceCliffs();
                map.SmoothCliffs();
                map.UpdateCliffPositions(Enums.Half.Top);
                baseMaps.Add(map);

                stringToWrite.AppendLine(string.Format("It took {0} ms to generate the base map.", sw.ElapsedMilliseconds));
            }
            else
            {
                var i = 0;
                foreach (var seed in caRandomSeeds)
                {
                    sw.Restart();

                    var random = new Random(seed);
                    ca = new CellularAutomata(mapSize, mapSize, Enums.Half.Top, oddsOfHeight, oddsOfHeight2, maxRangeToGroupPoints, groupPoints, generateHeight2, random);
                    if (caRuleset != null)
                    {
                        ca.SetRuleset(caRuleset);
                    }

                    ca.CreateImpassableTerrain(sections, maxLength, placementIntervals, maxPathNoiseDisplacement, maxWidth);

                    ca.RunGenerations(caGenerations, generateHeight2ThroughRules);

                    var map = new MapPhenotype(ca.Map, new Enums.Item[mapSize, mapSize]);
                    map.SmoothTerrain(smoothingNormalNeighbourhood, smoothingExtNeighbourhood, smoothingGenerations, smoothingRuleSet, random);
                    map.PlaceCliffs();
                    map.SmoothCliffs();
                    map.UpdateCliffPositions(Enums.Half.Top);
                    baseMaps.Add(map);

                    stringToWrite.AppendLine(string.Format("It took {0} ms to generate base map number {1}.", sw.ElapsedMilliseconds, i));
                    i++;
                }
            }

            WriteToTextFile(stringToWrite.ToString(), fileToWriteTo, baseMapFolder);

            return(baseMaps);
        }