Exemplo n.º 1
0
        public World(Random Random, MapGeneratorSettings Settings)
        {
            _Settings      = Settings;
            _Noise         = new LatticeNoiseGenerator(Random, Settings.Terrain);
            _MoistureNoise = new LatticeNoiseGenerator(Random, Settings.Moisture);
            _WaterLevel    = Settings.WaterLevel;

            _MicroRegions = new MicroRegion[Settings.Width, Settings.Height];
            _HeightMap    = new float[Settings.Width, Settings.Height];
            _MoistureMap  = new float[Settings.Width, Settings.Height];
            for (int i = 0; i < Settings.Width; ++i)
            {
                for (int j = 0; j < Settings.Height; ++j)
                {
                    float n = (float)_Noise.Generate(i, j);
                    float h = n > _WaterLevel ? (n - _WaterLevel) / (1 - _WaterLevel) : n / _WaterLevel - 1;
                    float m = (float)_MoistureNoise.Generate(i, j);
                    _HeightMap[i, j]   = h;
                    _MoistureMap[i, j] = m;
                    Biome B = Settings.BiomeMap.Closest(HeightAt(i, j), TemperatureAt(i, j), Moisture(i, j));
                    _MicroRegions[i, j] = new MicroRegion(i, j, B, this, h <= 0);
                }
            }
            _Shade = new FloatingImage(_HeightMap, Channel.RED)
                     .Filter(new Cence.Filters.Emboss()).GetChannel(Channel.RED);

            CreateRegions(Random, Settings.Regions, Settings.Language);
            CreateResources(Random, Settings.Population, Settings.Resource, Settings.Resources);
            InitializeEconomy();
        }
Exemplo n.º 2
0
        private static Bitmap GenerateHeightMap()
        {
            //Instatiate a new LatticeNoiseGenerator passing the type of WaveGenerator to be applied to the lattice.
            LatticeNoiseGenerator generator = new LatticeNoiseGenerator(typeof(SineWave));

            //Create a random starting x and y point, this is to ensure that we get a random height map everytime we call GenerateHeightMap.
            Random random  = new Random((int)DateTime.Now.Ticks);
            int    xOffset = random.Next();
            int    yOffset = random.Next();

            //Create a byte array to store all of the generated heights.
            byte[] heightMap = new byte[SIZE * SIZE];
            for (int x = 0; x < SIZE; x++)
            {
                for (int y = 0; y < SIZE; y++)
                {
                    //Populate each of the points in the array one at a time, all we need is a point in coordenant space and some input variables.
                    //I have set the hypothetical size to be the same as the bitmap image we are creating, if you are generating maps without a size constraint, you can really put anything in here.
                    //The density has been set to 0.25, this means that the hypotetical size is divided into 10 lattice points each of size 10, and wave forms are attached to these points, and increased density will also increase noisyness.
                    //The frequency has been set to 0.2, this gives a nice smooth heightmap, if you want it to be noisy, try increasing to 1 or 2. If you want an even smoother map, lower it some more.
                    heightMap[x + y * SIZE] = (byte)generator.Observe(x + xOffset, y + yOffset, SIZE, 255, 0.25, 0.2);
                }
            }

            //Return a new bitmap, can't return the raw bitmap, as the converter must be disposed correctly before we can write to file.
            using (Bitmap raw = BitmapConverter.Convert(heightMap))
                return(new Bitmap(raw));
        }
Exemplo n.º 3
0
 public CultureMap(Random Random, LatticeNoiseSettings Settings)
 {
     _Individualism        = new LatticeNoiseGenerator(Random, Settings);
     _Indulgence           = new LatticeNoiseGenerator(Random, Settings);
     _LongTermOrientation  = new LatticeNoiseGenerator(Random, Settings);
     _PowerDistance        = new LatticeNoiseGenerator(Random, Settings);
     _Toughness            = new LatticeNoiseGenerator(Random, Settings);
     _UncertaintyAvoidance = new LatticeNoiseGenerator(Random, Settings);
 }
Exemplo n.º 4
0
        void CreateResources(Random Random, LatticeNoiseSettings Population, LatticeNoiseSettings Resource, NaturalResource[] Resources)
        {
            Console.WriteLine("POPULATING");
            LatticeNoiseGenerator PopulationNoise = new LatticeNoiseGenerator(Random, Population);

            for (int i = 0; i < _Regions.Length; ++i)
            {
                float f = _Regions[i].Center.Biome.RegionSlow;
                _Regions[i].AddPopulation(this, (float)((PopulationNoise.Generate(_Regions[i].Center.X, _Regions[i].Center.Y)) * Math.Sqrt(f)) + .5f);
            }

            foreach (NaturalResource R in Resources)
            {
                Console.WriteLine("{0} {1}", R.Name, R.Noisy);
                LatticeNoiseGenerator Noise = R.Noisy ? new LatticeNoiseGenerator(Random, Resource) : null;
                foreach (Region Region in _Regions)
                {
                    float amount = (float)R.Distribute(
                        R.Noisy ? (float)Noise.Generate(Region.Center.X, Region.Center.Y) : 0, Region.Center);
                    Region.AddResource(R, amount);
                }
            }
        }