Exemplo n.º 1
0
        }                                    // in hours

        #endregion

        #region Public Static Methods

        public static List <WeatherData> GenerateFog(DateTime dateTime, List <WeatherData> weatherData)
        {
            WeatherData weather   = weatherData[0];
            int         monthIdx  = dateTime.Month - 1;
            double      fogChance = PrecipVariation.PRECIP_CHANCE_MONTH[(monthIdx - 1).Mod(PrecipVariation.PRECIP_CHANCE_MONTH.Length)].Lerp(PrecipVariation.PRECIP_CHANCE_MONTH[monthIdx.Mod(PrecipVariation.PRECIP_CHANCE_MONTH.Length)], dateTime.Day / DateTime.DaysInMonth(dateTime.Year, dateTime.Month)) * 50;

            int chanceRoll = TimedChance.D100.Roll();

            if (chanceRoll <= fogChance)
            {
                int fogRoll   = TimedChance.D100.Roll();
                int fogChange = 0;
                int dayTotal  = 1;
                int duration  = 1;

                foreach (FogVariation variation in FogVariation.FOG_VARIATION_TABLE)
                {
                    if (variation.IsWithinRange(fogRoll))
                    {
                        fogChange = variation.Fog;
                        if (variation.DurationUnit == DurationUnits.Days)
                        {
                            dayTotal = variation.Duration;
                        }
                        else
                        {
                            duration = variation.Duration;
                        }

                        break;
                    }
                }

                weather.MorningFog.Level = (FogLevel)Math.Min((int)weather.MorningFog.Level + fogChange, (int)FogLevel.Heavy);
                if (dayTotal == 1)
                {
                    weather.MorningFog.Duration = duration;
                }
                else
                {
                    weather.MorningFog.Duration = 24;
                }

                //WeatherData[] weatherData = new WeatherData[dayTotal];
                weatherData[0] = weather;

                for (int i = 1; i < dayTotal; i++)
                {
                    if (i >= weatherData.Count)
                    {
                        weatherData.Add(new WeatherData());
                    }
                    weatherData[i].MorningFog.Level    = (FogLevel)Math.Min((int)weather.MorningFog.Level + fogChange, (int)FogLevel.Heavy);
                    weatherData[i].MorningFog.Duration = 24;
                }

                //MessageBox.Show(tempChange + " for " + duration + " days");
            }

            chanceRoll = TimedChance.D100.Roll();

            if (chanceRoll <= fogChance)
            {
                int fogRoll   = TimedChance.D100.Roll();
                int fogChange = 0;
                int dayTotal  = 1;
                int duration  = 1;

                foreach (FogVariation variation in FogVariation.FOG_VARIATION_TABLE)
                {
                    if (variation.IsWithinRange(fogRoll))
                    {
                        fogChange = variation.Fog;
                        if (variation.DurationUnit == DurationUnits.Days)
                        {
                            dayTotal = variation.Duration;
                        }
                        else
                        {
                            duration = variation.Duration;
                        }

                        break;
                    }
                }

                weather.EveningFog.Level = (FogLevel)Math.Min((int)weather.EveningFog.Level + fogChange, (int)FogLevel.Heavy);
                if (dayTotal == 1)
                {
                    weather.EveningFog.Duration = duration;
                }
                else
                {
                    weather.EveningFog.Duration = 24;
                }

                for (int i = 1; i < dayTotal; i++)
                {
                    if (i >= weatherData.Count)
                    {
                        weatherData.Add(new WeatherData());
                    }
                    weatherData[i].EveningFog.Level    = (FogLevel)Math.Min((int)weather.EveningFog.Level + fogChange, (int)FogLevel.Heavy);
                    weatherData[i].EveningFog.Duration = 24;
                }

                //MessageBox.Show(tempChange + " for " + duration + " days");
            }

            return(weatherData);
        }
Exemplo n.º 2
0
 public DayData(DateTime equivalentDateTime, string notes, WeatherData weather = null)
 {
     Date    = equivalentDateTime;
     Notes   = notes;
     Weather = weather;
 }
Exemplo n.º 3
0
        public static List <WeatherData> GeneratePrecipitation(DateTime dateTime, List <WeatherData> weatherData)
        {
            int monthIdx = dateTime.Month - 1;
            //double precipChance = PrecipVariation.PRECIP_CHANCE_MONTH[(monthIdx - 1).Mod(PrecipVariation.PRECIP_CHANCE_MONTH.Length)].Lerp(PrecipVariation.PRECIP_CHANCE_MONTH[monthIdx.Mod(PrecipVariation.PRECIP_CHANCE_MONTH.Length)], dateTime.Day / DateTime.DaysInMonth(dateTime.Year, dateTime.Month)) * 100;
            double precipChance = PrecipVariation.PRECIP_CHANCE_MONTH.LerpOver(monthIdx, dateTime.Day / DateTime.DaysInMonth(dateTime.Year, dateTime.Month)) * 100;

            int chanceRoll = TimedChance.D100.Roll();

            if (chanceRoll <= precipChance)
            {
                int precipRoll   = TimedChance.D100.Roll();
                int precipChange = 0;
                int dayTotal     = 1;
                int duration     = 1;

                foreach (PrecipVariation variation in PrecipVariation.PRECIP_VARIATION_TABLE)
                {
                    if (variation.IsWithinRange(precipRoll))
                    {
                        precipChange = variation.Precipitiation;
                        if (variation.DurationUnit == DurationUnits.Days)
                        {
                            dayTotal = variation.Duration;
                        }
                        else
                        {
                            duration = variation.Duration;
                        }

                        break;
                    }
                }

                WeatherData weather = weatherData[0];
                if (weather.Precipitation.Level > 0)
                {
                    precipChange = 1;
                }

                weather.Precipitation.Level      = (PrecipitationLevel)Math.Min((int)weather.Precipitation.Level + precipChange, (int)PrecipitationLevel.Heavy);
                weather.Precipitation.CloudCover = OvercastLevel.Heavy;
                if (dayTotal == 1)
                {
                    weather.Precipitation.Duration = duration;
                }
                else
                {
                    weather.Precipitation.Duration = 24;
                }

                if (DescriptionData.CheckPrecipitationType(weather.Temperature) == PrecipitationType.Snow)
                {
                    weather.Precipitation.SnowAccumulation = PrecipVariation.SNOW_ACCUMULATION[(int)weather.Precipitation.Level].Roll((int)weather.Precipitation.Duration);
                }
                else if (DescriptionData.CheckPrecipitationType(weather.Temperature) == PrecipitationType.Sleet)
                {
                    weather.Precipitation.SnowAccumulation = PrecipVariation.SNOW_ACCUMULATION[(int)weather.Precipitation.Level].Roll((int)weather.Precipitation.Duration) * 0.5;
                }

                if (weather.Wind.Level >= WindLevel.Strong && weather.Precipitation.Level >= PrecipitationLevel.Heavy)
                {
                    if (DescriptionData.CheckPrecipitationType(weather.Temperature) == PrecipitationType.Snow && weather.Wind.Level >= WindLevel.Severe)
                    {
                        weather.Precipitation.Level = PrecipitationLevel.Storm;
                    }
                    else if (DescriptionData.CheckPrecipitationType(weather.Temperature) != PrecipitationType.Snow)
                    {
                        weather.Precipitation.Level = PrecipitationLevel.Storm;
                    }
                }

                for (int i = 1; i < dayTotal; i++)
                {
                    if (i >= weatherData.Count)
                    {
                        weatherData.Add(new WeatherData());
                    }
                    weatherData[i].Precipitation.Level      = (PrecipitationLevel)Math.Min(Math.Max((int)weather.Precipitation.Level + precipChange - i, 0), (int)PrecipitationLevel.Heavy);
                    weatherData[i].Precipitation.CloudCover = OvercastLevel.Heavy;
                    weatherData[i].Precipitation.Duration   = 24;
                }


                return(weatherData);
            }
            else
            {
                int         cloudRoll = TimedChance.D100.Roll();
                WeatherData weather   = weatherData[0];

                foreach (PrecipVariation variation in PrecipVariation.OVERCAST_VARIATION_TABLE)
                {
                    if (variation.IsWithinRange(cloudRoll))
                    {
                        weather.Precipitation.CloudCover = (OvercastLevel)variation.Precipitiation;

                        break;
                    }
                }

                double overcastTempChange = TemperatureVariation.OVERCAST_TEMP_CHANGE_MONTH.LerpOver(monthIdx, dateTime.Day / DateTime.DaysInMonth(dateTime.Year, dateTime.Month));
                if (weather.Precipitation.CloudCover > OvercastLevel.None)
                {
                    weather.Temperature += overcastTempChange * ((int)weather.Precipitation.CloudCover / (int)OvercastLevel.Heavy);
                }
                else if (weather.Precipitation.CloudCover == OvercastLevel.None)
                {
                    weather.Temperature -= overcastTempChange;
                }
            }

            return(weatherData);
        }