コード例 #1
0
        /**
         * <summary>
         * Layered expansion method. Basically just repeats an expansion using
         * the given HexExpander for the given number of passes. On each pass,
         * the number of hexes that will be modified is reduced by a random
         * amount between the two proportion bounds of this class.
         * </summary>
         * <param name="passes">Number of expansion passes.</param>
         */
        public void Expand(int passes)
        {
            int hexesToModify = ValidCoords.Count;

            for (int i = 0; i < passes; i++)
            {
                double proportionThisRound = _rand.GenerateDouble();
                proportionThisRound *= (UpperProportionBound - LowerProportionBound);
                proportionThisRound += LowerProportionBound;

                hexesToModify = (int)(hexesToModify * proportionThisRound);
                Expander.Expand(ValidCoords, hexesToModify);
            }
        }
コード例 #2
0
        /** <summary>
         * Generates a modifier to add onto the base roll, used to determine the number of sides
         * to expand out to from a starting hex.
         * </summary>
         * <remarks>
         * This modifier is random, but will likely be higher when there are more hexes that
         * have not yet been expanded to. This is done to favour a more blob-shaped core with
         * branches/peninsulae as generation goes on.
         * </remarks>
         * <returns>A modifier not exceeding Hex.SIDES, likely higher when there are more hexes
         * that have not yet been placed.</returns>
         */
        protected virtual int RollModifier()
        {
            double ratio = _remainingHexes / _totalHexes;
            int    mod   = 0;

            while ((mod < Hex.SIDES) &&
                   (ratio > 0))
            {
                double comp = _rand.GenerateDouble();
                if (comp <= ratio)
                {
                    mod++;
                    ratio /= 2;
                }
                else
                {
                    break;
                }
            }
            return(mod);
        }
コード例 #3
0
ファイル: WorldGen.cs プロジェクト: mdmooney/WorldGen
        private void FillLandmass(Landmass mass)
        {
            // Elevation
            // Pick a number of passes; a range of the total number of
            // elements in the enum works best
            int              passes   = _rand.GenerateInt(1, 5);
            List <Coords>    eleHexes = new List <Coords>(mass.Hexes);
            HeightExpander   hEx      = new HeightExpander(_rand, _world.Map);
            LayeredExpansion layered  = new LayeredExpansion(_rand, hEx, eleHexes, 0.6, 0.8);

            layered.Expand(passes);

            // Rivers
            int totalRiverHexes = mass.TotalHexes / 20;
            int remainingHexes  = totalRiverHexes;

            while (remainingHexes > 0)
            {
                if (remainingHexes == 1)
                {
                    break;
                }
                int      riverLength = _rand.GenerateInt(2, remainingHexes);
                RiverGen rgen        = new RiverGen(_rand, _world, mass, riverLength);
                int      genLength   = rgen.Generate();
                if (genLength > 1)
                {
                    remainingHexes -= genLength;
                    rgen.Commit();
                    _world.Rivers.Add(rgen.GenRiver);
                }
            }


            // Temperature
            SetTemperatures();

            // Humidity
            passes = _rand.GenerateInt(1, 5);
            List <Coords>    humiHexes = new List <Coords>(mass.Hexes);
            HumidityExpander humEx     = new HumidityExpander(_rand, _world.Map);

            layered = new LayeredExpansion(_rand, humEx, humiHexes, 0.6, 0.8);
            layered.Expand(passes);

            // Biomes
            BiomeExpander bioEx;
            List <Coords> bioHexes   = new List <Coords>(mass.Hexes);
            int           tenPercent = mass.TotalHexes / 10;

            while (bioHexes.Count > 0)
            {
                int expandThisRound = bioHexes.Count;
                if (expandThisRound > tenPercent)
                {
                    double fraction = _rand.GenerateDouble() / 2.0;
                    expandThisRound = (int)(expandThisRound * fraction);
                }

                bioEx = new BiomeExpander(_rand, _world.Map, _world.Biomes);
                var placedCoords = bioEx.Expand(bioHexes, expandThisRound);
                bioHexes.RemoveAll(x => placedCoords.Contains(x));
            }
        }