Esempio n. 1
0
        /// <summary>
        /// Takes the existing map of the planet and creates a climate
        /// map for the planet.
        /// </summary>
        public void GenerateClimate()
        {
            // Watt / m^2 average
            // TODO make dynamic based on star(s) and distance of planet.
            var fullSun = 1000;
            // TODO, parameterize this to make it available.
            var airZones = 6;

            // Use the Planet seed, but offset by 1 to get a different map.
            var noise    = new FastNoise(Seed + 1);
            var secNoise = new FastNoise(Seed + 2);

            // setup SolarMap for heat application. TODO, add back in later.
            #region SolarMapAndPrevailingWind

            /*
             * for (int row = 0; row < Height; ++row)
             * {
             *  // The amount that hits is relative to the height with equator
             *  // getting full and poles getting almost none.
             *  var correctedSun = (int)(Math.Sin(row / Height * Math.PI) * fullSun);
             *  // just in case, ensure only G and B is effected.
             *  correctedSun = correctedSun & 0x0000FFFF;
             *
             *  // we can also generate prevailing winds this way.
             *  // we default to 6 cells the 2 at the center point equator wise and NE to SW
             *  // TODO parameterize this.
             *  var zone = (int)(row / Height * airZones);
             *  int prevailingWind = 0;
             *
             *  // 0 NW, 2 W, 4 SW, 6 SE, 8 E, 10 NE
             *  if (zone < airZones / 2)
             *  { // north hemisphere.
             *      if (zone % 2 == 1) // if odd
             *      {// 2 hex/day SW
             *          prevailingWind = GetDirection("SW", false) + ToSpeed(2);
             *      }
             *      else
             *      {// 2 hex/day NE
             *          prevailingWind = GetDirection("NE", false) + ToSpeed(2);
             *      }
             *  }
             *  else // if above half
             *  {// Southern Hemisphere
             *      if (zone % 2 == 1)
             *      {// 2 hex/day NW
             *          prevailingWind = GetDirection("NW", false) + ToSpeed(2);
             *      }
             *      else
             *      {// 2 hex/day SE
             *          prevailingWind = GetDirection("SE", false) + ToSpeed(2);
             *      }
             *  }
             *
             *  for (int col = 0; col < Width; ++col)
             *  {
             *      // add existing albedo to corrected sun, then set.
             *      var val = SolarMap.GetHexValue(col, row) + correctedSun;
             *      SolarMap.SetPixelArgb(col, row, val);
             *      // also add prevailing winds to the green channel.
             *
             *      ClimateEx.SetHexGreen(col, row, prevailingWind);
             *  }
             * }*/
            #endregion SolarMapAndPrevailingWind

            int scale = 1;
            // TODO create real calculation for environment
            // For a shortcut, just make a selection of high and low tempurature selections.
            foreach (var pixel in Terrain)
            {
                // select random value between 0 and 255 for the tempurature
                // restricted further to 128 +/- 64
                var tempurature = (int)(255 * (1 + CylinderSample(pixel.Coord.x, pixel.Coord.y, noise) / 4));
                Climate.SetHexBlue(pixel.Coord, tempurature);

                // set humidity between 0 and 255.
                var hum = (int)(255 * (1 + CylinderSample(pixel.Coord.x, pixel.Coord.y, secNoise)) / 2);
                Climate.SetHexGreen(pixel.Coord, hum);

                // set rainfall equal to humidity for now
                Climate.SetHexRed(pixel.Coord, hum);
            }
        }