Exemplo n.º 1
0
        internal static void SetWeatherNonSystemForTomorrow(MersenneTwister Dice, FerngillClimate GameClimate, double rainDays, double stormDays, double windyDays, RangePair TmrwTemps)
        {
            ProbabilityDistribution <string> WeatherDist = new ProbabilityDistribution <string>("sunny");

            WeatherDist.AddNewEndPoint(rainDays, "rain");
            if (ClimatesOfFerngill.WeatherOpt.DisableHighRainWind)
            {
                WeatherDist.AddNewCappedEndPoint(windyDays, "debris");
            }

            double distOdd = Dice.NextDoublePositive();

            if (ClimatesOfFerngill.WeatherOpt.Verbose)
            {
                ClimatesOfFerngill.Logger.Log(WeatherDist.ToString());
                ClimatesOfFerngill.Logger.Log($"Distribution odds is {distOdd}");
            }

            if (!(WeatherDist.GetEntryFromProb(distOdd, out string Result)))
            {
                Result = "sunny";
                ClimatesOfFerngill.Logger.Log("The weather has failed to process in some manner. Falling back to [sunny]", LogLevel.Info);
            }

            if (ClimatesOfFerngill.WeatherOpt.Verbose)
            {
                ClimatesOfFerngill.Logger.Log($"Weather result is {Result}");
            }

            SetWeatherTomorrow(Result, Dice, GameClimate, stormDays, TmrwTemps);
        }
Exemplo n.º 2
0
        private void SetTommorowWeather()
        {
            //if tomorrow is a festival or wedding, we need to set the weather and leave.
            if (Utility.isFestivalDay(Game1.dayOfMonth + 1, Game1.currentSeason))
            {
                Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_festival;
                if (WeatherOpt.Verbose)
                {
                    Monitor.Log($"Festival tomorrow. Aborting processing.", LogLevel.Trace);
                }

                //if (WeatherOpt.Verbose) Monitor.Log(DebugOutput.ToString());
                return;
            }

            if (Game1.player.spouse != null && Game1.player.isEngaged() && Game1.player.friendshipData[Game1.player.spouse].CountdownToWedding == 1)
            {
                Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_wedding;
                if (WeatherOpt.Verbose)
                {
                    Monitor.Log($"Wedding tomorrow. Aborting processing.", LogLevel.Trace);
                }

                return;
            }

            if (ForceDays.CheckForForceDay(DescriptionEngine, SDate.Now().AddDays(1), Monitor, WeatherOpt.Verbose))
            {
                if (WeatherOpt.Verbose)
                {
                    Monitor.Log($"The game will force tomorrow. Aborting processing.", LogLevel.Trace);
                }
                return;
            }

            if (WeatherOpt.Verbose)
            {
                Monitor.Log("Setting weather for tomorrow");
            }

            //now set tomorrow's weather
            var OddsForTheDay = GameClimate.GetClimateForDate(SDate.Now().AddDays(1));

            double rainDays  = OddsForTheDay.RetrieveOdds(Dice, "rain", SDate.Now().AddDays(1).Day);
            double windyDays = OddsForTheDay.RetrieveOdds(Dice, "debris", SDate.Now().AddDays(1).Day);
            double stormDays = OddsForTheDay.RetrieveOdds(Dice, "storm", SDate.Now().AddDays(1).Day);

            if (WeatherOpt.Verbose)
            {
                Monitor.Log($"Odds are Rain: {rainDays.ToString("N3")}, Windy: {windyDays.ToString("N3")}, and Storm {stormDays.ToString("N3")}");
            }

            ProbabilityDistribution <string> WeatherDist = new ProbabilityDistribution <string>("sunny");

            WeatherDist.AddNewEndPoint(rainDays, "rain");

            if (WeatherOpt.DisableHighRainWind)
            {
                WeatherDist.AddNewCappedEndPoint(windyDays, "debris");
            }

            double distOdd = Dice.NextDoublePositive();

            if (WeatherOpt.Verbose)
            {
                Monitor.Log(WeatherDist.ToString());
                Monitor.Log($"Distribution odds is {distOdd}");
            }

            if (!(WeatherDist.GetEntryFromProb(distOdd, out string Result)))
            {
                Result = "sunny";
                Monitor.Log("The weather has failed to process in some manner. Falling back to [sunny]", LogLevel.Info);
            }

            if (WeatherOpt.Verbose)
            {
                Monitor.Log($"Weather result is {Result}");
            }

            if (!Conditions.IsTodayTempSet)
            {
                throw new NullReferenceException("Today's temperatures have not been set!");
            }

            //now parse the result.
            if (Result == "rain")
            {
                //snow applies first
                double MidPointTemp = Conditions.TodayHigh -
                                      ((Conditions.TodayHigh - Conditions.TodayLow) / 2);

                if ((Conditions.TodayHigh <= 2 || MidPointTemp <= 0) && Game1.currentSeason != "spring")
                {
                    if (WeatherOpt.Verbose)
                    {
                        Monitor.Log($"Snow is enabled, with the High for the day being: {Conditions.TodayHigh}" +
                                    $" and the calculated midpoint temperature being {MidPointTemp}");
                    }

                    Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_snow;
                }
                else
                {
                    Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_rain;
                }

                if (!GameClimate.AllowRainInWinter && Game1.currentSeason == "winter" && Game1.weatherForTomorrow == Game1.weather_rain)
                {
                    Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_snow;
                }

                //apply lightning logic.
                if (Dice.NextDoublePositive() >= stormDays && Game1.weatherForTomorrow == Game1.weather_rain)
                {
                    Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_lightning;
                    if (SDate.Now().Year == 1 && SDate.Now().Season == "spring" && !WeatherOpt.AllowStormsSpringYear1)
                    {
                        Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_rain;
                    }
                }

                //tracking time! - Snow fall on Fall 28, if the flag is set.
                if (Game1.dayOfMonth == 28 && Game1.currentSeason == "fall" && WeatherOpt.SnowOnFall28)
                {
                    Conditions.ForceTodayTemps(2, -1);
                    Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_snow;
                }
            }

            if (Result == "debris")
            {
                Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_debris;
            }

            if (Result == "sunny")
            {
                Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_sunny;
            }

            if (WeatherOpt.Verbose)
            {
                Monitor.Log($"We've set the weather for Tomorrow. It is: {DescriptionEngine.DescribeInGameWeather(Game1.weatherForTomorrow)}");
            }
        }