Exemplo n.º 1
0
        private string GetRainDesc(int rainAmt)
        {
            switch (WeatherUtilities.GetRainCategory(rainAmt))
            {
            case RainLevels.Sunshower:
                return(Translator.Get("weather-tv.rain.sunshowers"));

            case RainLevels.Light:
                return(Translator.Get("weather-tv.rain.light"));

            case RainLevels.Normal:
                return(Translator.Get("weather-tv.rain.normal"));

            case RainLevels.Moderate:
                return(Translator.Get("weather-tv.rain.moderate"));

            case RainLevels.Heavy:
                return(Translator.Get("weather-tv.rain.heavy"));

            case RainLevels.Severe:
                return(Translator.Get("weather-tv.rain.severe"));

            case RainLevels.Torrential:
                return(Translator.Get("weather-tv.rain.torrential"));

            case RainLevels.Typhoon:
                return(Translator.Get("weather-tv.rain.typhoon"));

            case RainLevels.NoahsFlood:
                return(Translator.Get("weather-tv.rain.noahsflood"));

            default:
                return(Translator.Get("weather-tv.rain.unknown"));
            }
        }
        private void SanityCheckConfigOptions()
        {
            if (WeatherOpt.MaxRainFall < 0)
            {
                WeatherOpt.MaxRainFall = 0;
            }

            if (WeatherOpt.MaxRainFall > WeatherUtilities.GetRainCategoryUpperBound(RainLevels.NoahsFlood))
            {
                WeatherOpt.MaxRainFall = WeatherUtilities.GetRainCategoryUpperBound(RainLevels.NoahsFlood);
            }
        }
Exemplo n.º 3
0
        internal static void CheckForStaticRainChanges(WeatherConditions curr, MersenneTwister Dice, double ChanceForNonNormalRain)
        {
            if (Game1.isLightning && Game1.isRaining)
            {
                curr.SetRainAmt(130);
            }
            double rainOdds, newRainOdds;

            rainOdds    = Dice.NextDouble();
            newRainOdds = Dice.NextDouble();

            //random chance to just set rain at a differnt number
            if (rainOdds < ChanceForNonNormalRain)
            {
                //yay use of probablity distribution
                ProbabilityDistribution <RainLevels> RainSpread = new ProbabilityDistribution <RainLevels>(RainLevels.Normal);
                RainSpread.AddNewCappedEndPoint(.12, RainLevels.Sunshower);
                RainSpread.AddNewCappedEndPoint(.28, RainLevels.Light);
                RainSpread.AddNewCappedEndPoint(.351, RainLevels.Normal);
                RainSpread.AddNewCappedEndPoint(.1362, RainLevels.Moderate);
                RainSpread.AddNewCappedEndPoint(.09563, RainLevels.Heavy);
                RainSpread.AddNewCappedEndPoint(.0382, RainLevels.Severe);
                RainSpread.AddNewCappedEndPoint(.0094, RainLevels.Torrential);
                RainSpread.AddNewCappedEndPoint(.0049, RainLevels.Typhoon);
                RainSpread.AddNewCappedEndPoint(.00287, RainLevels.NoahsFlood);

                if (!(RainSpread.GetEntryFromProb(newRainOdds, out RainLevels Result)))
                {
                    Result = RainLevels.Normal;
                    ClimatesOfFerngill.Logger.Log("The rain probablity spread has failed to find an rain level. Falling back to normal rain", LogLevel.Error);
                }

                curr.SetRainAmt(WeatherUtilities.ReturnRndRainAmtInLevel(Dice, Result));

                if (ClimatesOfFerngill.WeatherOpt.Verbose)
                {
                    ClimatesOfFerngill.Logger.Log($"We've set the rain to a non normal value - with roll {rainOdds} for setting non normal, and {newRainOdds} for category {Result}, resulting in new rain target {curr.AmtOfRainDrops} in category {WeatherUtilities.GetRainCategory(curr.AmtOfRainDrops)}");
                }
            }

            curr.TodayRain += curr.AmtOfRainDrops;
            curr.RefreshRainAmt();
        }
Exemplo n.º 4
0
        internal string GenerateTVForecast(WeatherConditions Current, MersenneTwister Dice, double fogOdds, string MoonPhase = "", bool IsMoonUp = false)
        {
            string ret = "";

            //opening string
            ret += Translator.Get("weather-tv.opening", new
            {
                location       = Translator.Get("fern-loc." + Dice.Next(12)),
                playerLocation = Translator.Get("weather-location.player." + Dice.Next(4))
            });

            //hazard warning
            if (MoonPhase == "Blood Moon" && IsMoonUp)
            {
                ret += Translator.Get("weather-tv.bloodmoon");
            }

            if (Current.WeatherIsHazardous())
            {
                string hazard = "", rainfallW = "", hazardT = "", hazardF;

                if (Current.HasWeather(CurrentWeather.Heatwave))
                {
                    hazardT = Translator.Get("weather-tv.hazard.hw");
                }
                if (Current.HasWeather(CurrentWeather.Frost))
                {
                    hazardT = Translator.Get("weather-tv.hazard.frost");
                }

                if (Current.HasWeather(CurrentWeather.Blizzard))
                {
                    hazard = Translator.Get("weather-tv.hazard.blizzard");
                }
                if (Current.HasWeather(CurrentWeather.WhiteOut))
                {
                    hazard = Translator.Get("weather-tv.hazard.whiteout");
                }
                if (Current.HasWeather(CurrentWeather.ThunderFrenzy))
                {
                    hazard = Translator.Get("weather-tv.hazard.thunderfrenzy");
                }
                if (Current.HasWeather(CurrentWeather.Sandstorm))
                {
                    hazard = Translator.Get("weather-tv.hazard.sandstorm");
                }
                if (WeatherUtilities.IsSevereRainFall(Current.AmtOfRainDrops))
                {
                    switch (WeatherUtilities.GetRainCategory(Current.AmtOfRainDrops))
                    {
                    case RainLevels.Severe:
                        hazard = Translator.Get("weather-tv.hazard.rainfall.severe");
                        break;

                    case RainLevels.Torrential:
                        hazard = Translator.Get("weather-tv.hazard.rainfall.torrential");
                        break;

                    case RainLevels.Typhoon:
                        hazard = Translator.Get("weather-tv.hazard.rainfall.typhoon");
                        break;

                    case RainLevels.NoahsFlood:
                        hazard = Translator.Get("weather-tv.hazard.rainfall.noahsflood");
                        break;

                    default:
                        hazard = Translator.Get("weather-tv.hazard.rainfall.severe");
                        break;
                    }

                    rainfallW = Translator.Get("weather-tv.hazard.rainfallW");
                }

                if (!String.IsNullOrEmpty(hazard) && !String.IsNullOrEmpty(hazardT))
                {
                    hazardF = Translator.Get("weather-tv.twoHazardString", new { hazardOne = hazard, hazardTwo = hazardT });
                }
                else if (!String.IsNullOrEmpty(hazard))
                {
                    hazardF = hazard;
                }
                else
                {
                    hazardF = hazardT;
                }

                ret += Translator.Get("weather-tv.hazard", new {
                    hazard          = hazardF,
                    repLocation     = Translator.Get("weather-location.reporter." + Dice.Next(4)),
                    rainfallWarning = rainfallW
                });
            }

            //current conditions
            string time;

            switch (SDVTime.CurrentTimePeriod)
            {
            case SDVTimePeriods.Morning:
                time = Translator.Get("weather-tv.time.morning");
                break;

            case SDVTimePeriods.Noon:
            case SDVTimePeriods.Afternoon:
                time = Translator.Get("weather-tv.time.afternoon");
                break;

            case SDVTimePeriods.Evening:
                time = Translator.Get("weather-tv.time.evening");
                break;

            case SDVTimePeriods.Night:
                time = Translator.Get("weather-tv.time.night");
                break;

            case SDVTimePeriods.Midnight:
            case SDVTimePeriods.LateNight:
                time = Translator.Get("weather-tv.time.latenight");
                break;

            default:
                time = Translator.Get("weather-tv.time.generic");
                break;
            }

            string abText = "";

            if (Current.IsAbnormalHeat)
            {
                abText = Translator.Get("weather-tv.abnormalHeat");
            }

            if (Current.IsAbnormalChill)
            {
                abText = Translator.Get("weather-tv.abnormalChill");
            }

            string sysText = "";

            if (Current.trackerModel.WeatherSystemDays > 0)
            {
                if (Current.trackerModel.IsWeatherSystem)
                {
                    sysText = Translator.Get("weather-tv.systemMaint");
                }
            }

            //the first monster, describing the weather.
            string dWeather = "";

            if (!String.IsNullOrEmpty(SDVUtilities.GetFestivalName(SDate.Now())))
            {
                dWeather = Translator.Get("weather-tv.weat.festival", new { festivalName = SDVUtilities.GetFestivalName(SDate.Now()) });
            }

            if (Current.HasWeather(CurrentWeather.Wedding))
            {
                dWeather = Translator.Get("weather-tv.weat.wedding");
            }

            if (Current.HasWeather(CurrentWeather.Sunny))
            {
                dWeather = Translator.Get("weather-tv.weat.sunny");
            }

            if (Current.HasWeather(CurrentWeather.Rain) && !Current.HasWeather(CurrentWeather.Lightning))
            {
                dWeather = (Current.IsVariableRain ? Translator.Get("weather-tv.weat.rain.variable", new { rainDesc = GetRainDesc(Current.AmtOfRainDrops).Trim() })
                                                   : Translator.Get("weather-tv.weat.rain", new { rainDesc = GetRainDesc(Current.AmtOfRainDrops).Trim() }));
            }

            if (Current.HasWeather(CurrentWeather.Rain) && Current.HasWeather(CurrentWeather.Lightning) && !Current.HasWeather(CurrentWeather.ThunderFrenzy))
            {
                dWeather = Translator.Get("weather-tv.weat.thunderstorm");
            }

            if (Current.HasWeather(CurrentWeather.ThunderFrenzy))
            {
                dWeather = Translator.Get("weather-tv.weat.thunderfrenzy");
            }

            if (!Current.HasWeather(CurrentWeather.Rain) && Current.HasWeather(CurrentWeather.Lightning))
            {
                dWeather = Translator.Get("weather-tv.weat.drylightning");
            }

            if (Current.HasWeather(CurrentWeather.Blizzard) && !Current.HasWeather(CurrentWeather.WhiteOut))
            {
                dWeather = Translator.Get("weather-tv.weat.blizzard");
            }

            if (Current.HasWeather(CurrentWeather.WhiteOut))
            {
                dWeather = Translator.Get("weather-tv.weat.whiteout");
            }

            if (Current.HasWeather(CurrentWeather.Snow) && !Current.HasWeather(CurrentWeather.Blizzard) && !Current.HasWeather(CurrentWeather.WhiteOut) && !Current.HasWeather(CurrentWeather.Lightning))
            {
                dWeather = Translator.Get("weather-tv.weat.snowy");
            }

            if (Current.HasWeather(CurrentWeather.Snow) && !Current.HasWeather(CurrentWeather.Blizzard) && !Current.HasWeather(CurrentWeather.WhiteOut) && Current.HasWeather(CurrentWeather.Lightning))
            {
                dWeather = Translator.Get("weather-tv.weat.thundersnow");
            }

            if (Current.HasWeather(CurrentWeather.Sandstorm))
            {
                dWeather = Translator.Get("weather-tv.weat.sandstorms");
            }

            if (Current.HasWeather(CurrentWeather.Wind))
            {
                if (Game1.currentSeason == "winter")
                {
                    dWeather = Translator.Get("weather-tv.weat.windy.winter");
                }
                else
                {
                    dWeather = Translator.Get("weather-tv.weat.windy");
                }
            }

            string fog = "";

            if (Current.HasWeather(CurrentWeather.Fog))
            {
                if (!Current.HasWeather(CurrentWeather.Wedding))
                {
                    fog = Translator.Get("weather-tv.weat.fog", new { time = Current.GetFogTime() });
                }
                else
                {
                    fog = Translator.Get("weather-tv.weat.fogWed", new { time = Current.GetFogTime() });
                }
            }

            //ending up the current conditions.
            string tHazard = "";

            if (Current.HasWeather(CurrentWeather.Heatwave))
            {
                tHazard = Translator.Get("weather-tv.tempHazard.heat");
            }

            if (Current.HasWeather(CurrentWeather.Frost))
            {
                tHazard = Translator.Get("weather-tv.tempHazard.cold",
                                         new { time = (Game1.currentSeason == "spring"
                          ? Translator.Get("weather-tv.tempHazard.cold.spring") :
                                                       Translator.Get("weather-tv.tempHazard.cold.fall")) });
            }

            string rRate = "";

            if (Current.HasWeather(CurrentWeather.Rain))
            {
                rRate = Translator.Get("weather-tv.rainfallRate", new { rate = WeatherUtilities.GetRainfallAmt(Current.AmtOfRainDrops).ToString("N2") });
            }

            var transParams = new Dictionary <string, string> {
                { "time", time },
                { "currentTemp", GetTemperatureString(Current.GetCurrentTemperature(Game1.timeOfDay)) },
                { "abnormalText", abText },
                { "systemText", sysText },
                { "descWeather", dWeather },
                { "fogText", fog },
                { "tempHazard", tHazard },
                { "rainfallRate", rRate }
            };

            ret += Translator.Get("weather-tv.currentCond", transParams);
            transParams.Clear();

            //now, tomorrow!! :D

            sysText = "";
            if (Current.trackerModel.WeatherSystemDays > 0)
            {
                if (Current.trackerModel.IsWeatherSystem)
                {
                    sysText = Translator.Get("weather-tv.tmrw.systemMaint",
                                             new { desc = Translator.Get("weather-location.system.desc." + Dice.Next(6)) });
                }
                if (!Current.trackerModel.IsWeatherSystem && (Game1.weatherForTomorrow != WeatherUtilities.GetWeatherCode()))
                {
                    sysText = Translator.Get("weather-tv.tmrw.systemEnding",
                                             new { desc = Translator.Get("weather-location.system.desc." + Dice.Next(6)), direction = Translator.Get("weather-location.system.move." + Dice.Next(4)) });
                }
            }
            else
            {
                sysText = Translator.Get("weather-tv.tmrw.systemNone");
            }

            //now weather
            switch (Game1.weatherForTomorrow)
            {
            case Game1.weather_rain:
                dWeather = Translator.Get("weather-tv.rain." + Dice.Next(2));
                break;

            case Game1.weather_festival:
                dWeather = Translator.Get("weather-tv.festival", new { festName = SDVUtilities.GetFestivalName(SDate.Now().AddDays(1)) });
                break;

            case Game1.weather_debris:
                dWeather = Translator.Get("weather-tv.debris." + Dice.Next(2));
                break;

            case Game1.weather_snow:
                dWeather = Translator.Get("weather-tv.snowy." + Dice.Next(2));
                break;

            case Game1.weather_wedding:
                dWeather = Translator.Get("weather-tv.wedding");
                break;

            case Game1.weather_lightning:
                dWeather = Translator.Get("weather-tv.tstorm." + Dice.Next(2));
                break;

            case Game1.weather_sunny:
            default:
                dWeather = Translator.Get("weather-tv.sunny." + Dice.Next(2));
                break;
            }

            //overrides for festival and wedding (just in case, my paranoia is spiking. :|)
            if (!String.IsNullOrEmpty(SDVUtilities.GetFestivalName(SDate.Now().AddDays(1))))
            {
                dWeather = Translator.Get("weather-tv.festival", new { festName = SDVUtilities.GetFestivalName(SDate.Now().AddDays(1)) });
            }
            if (Game1.player.spouse != null && Game1.player.isEngaged() && Game1.player.friendshipData[Game1.player.spouse].CountdownToWedding == 1)
            {
                dWeather = Translator.Get("weather-tv.wedding");
            }

            fog = "";
            //now, the fog string
            if (fogOdds >= .6)
            {
                fog = Translator.Get("weather-tv.fogChance");
            }

            //tHazard string

            if (Current.TomorrowHigh > (Current.TodayHigh + 1.5))
            {
                tHazard = Translator.Get("weather-tv.tmrw.warmer", new
                {
                    high = GetTemperatureString(Current.TomorrowHigh),
                    low  = GetTemperatureString(Current.TomorrowLow),
                });
            }
            else if ((Current.TomorrowHigh < (Current.TodayHigh - 1.5)))
            {
                tHazard = Translator.Get("weather-tv.tmrw.cooler", new
                {
                    high = GetTemperatureString(Current.TomorrowHigh),
                    low  = GetTemperatureString(Current.TomorrowLow),
                });
            }
            else
            {
                tHazard = Translator.Get("weather-tv.tmrw.effsame", new
                {
                    high = GetTemperatureString(Current.TomorrowHigh),
                    low  = GetTemperatureString(Current.TomorrowLow),
                });
            }


            transParams.Add("sysText", sysText);
            transParams.Add("weather", dWeather);
            transParams.Add("fogChance", fog);
            transParams.Add("tempString", tHazard);

            ret += Translator.Get("weather-tv.tomorrowForecast", transParams);
            return(ret);
        }
Exemplo n.º 5
0
 public string DescRainfallAmt(int rainFall)
 {
     return(WeatherUtilities.GetRainfallAmt(rainFall).ToString("N2"));
 }
Exemplo n.º 6
0
        internal string GenerateMenuPopup(WeatherConditions Current, string MoonPhase = "", string NightTime = "")
        {
            string text;

            if (SDate.Now().Season == "spring" && SDate.Now().Day == 1)
            {
                text = Translator.Get("weather-menu.openingS1D1", new { descDay = Translator.Get($"date{UpperSeason(SDate.Now().Season)}{SDate.Now().Day}") }) + Environment.NewLine + Environment.NewLine;
            }
            else if (SDate.Now().Season == "winter" && SDate.Now().Day == 28)
            {
                text = Translator.Get("weather-menu.openingS4D28", new { descDay = Translator.Get($"date{UpperSeason(SDate.Now().Season)}{SDate.Now().Day}") }) + Environment.NewLine + Environment.NewLine;
            }
            else
            {
                text = Translator.Get("weather-menu.opening", new { descDay = Translator.Get($"date{UpperSeason(SDate.Now().Season)}{SDate.Now().Day}") }) + Environment.NewLine + Environment.NewLine;
            }

            if (Current.ContainsCondition(CurrentWeather.Sandstorm))
            {
                text += Translator.Get("weather-menu.condition.sandstorm") + Environment.NewLine;
            }

            if (Current.ContainsCondition(CurrentWeather.Heatwave))
            {
                text += Translator.Get("weather-menu.condition.heatwave") + Environment.NewLine;
            }

            if (Current.ContainsCondition(CurrentWeather.Frost))
            {
                text += Translator.Get("weather-menu.condition.frost") + Environment.NewLine;
            }

            if (Current.ContainsCondition(CurrentWeather.WhiteOut))
            {
                text += Translator.Get("weather-menu.condition.whiteOut") + Environment.NewLine;
            }

            if (Current.ContainsCondition(CurrentWeather.ThunderFrenzy))
            {
                text += Translator.Get("weather-menu.condition.thunderFrenzy") + Environment.NewLine;
            }

            if (Current.IsVariableRain)
            {
                switch (WeatherUtilities.GetRainCategory(Current.AmtOfRainDrops))
                {
                case RainLevels.Severe:
                    text += Translator.Get("weather-condition.vrain.severe_sw") + Environment.NewLine;
                    break;

                case RainLevels.Torrential:
                    text += Translator.Get("weather-condition.vrain.torrential_sw") + Environment.NewLine;
                    break;

                case RainLevels.Typhoon:
                    text += Translator.Get("weather-condition.vrain.typhoon_sw") + Environment.NewLine;
                    break;

                case RainLevels.NoahsFlood:
                    text += Translator.Get("weather-condition.vrain.godswrath_sw") + Environment.NewLine;
                    break;

                default:
                    break;
                }
            }

            if (MoonPhase == "Blood Moon")
            {
                text += Translator.Get("weather-menu.condition.bloodmoon") + Environment.NewLine;
            }

            if (ClimatesOfFerngill.UseLunarDisturbancesApi && ClimatesOfFerngill.MoonAPI.IsSolarEclipse())
            {
                text += Translator.Get("weather-menu.condition.solareclipse") + Environment.NewLine;
            }

            ISDVWeather CurrentFog = Current.GetWeatherMatchingType("Fog").First();
            string      fogString  = "";

            //  If the fog is visible, we don't need to display fog information. However, if it's in the morning,
            //    and we know evening fog is likely, we should display the message it's expected
            // That said, if it's not, we need to pull the fog information down, assuming it's been reset. This checks that the fog end
            //    time is *before* now. To avoid nested trinary statements..
            if (SDVTime.CurrentTime < CurrentFog.WeatherExpirationTime && Current.GenerateEveningFog && CurrentFog.WeatherBeginTime < new SDVTime(1200))
            {
                fogString = Translator.Get("weather-menu.expectedFog");
            }
            if (CurrentFog.WeatherBeginTime > SDVTime.CurrentTime && Current.GenerateEveningFog)
            {
                fogString = Translator.Get("weather-menu.fogFuture",
                                           new
                {
                    fogTime = CurrentFog.WeatherBeginTime.ToString(),
                    endFog  = CurrentFog.WeatherExpirationTime.ToString()
                });
            }

            //Current Conditions.
            string currentMenu;

            if (Current.HasWeather(CurrentWeather.Rain) && Current.IsVariableRain)
            {
                currentMenu = "weather-menu.currentRainfall";
            }
            else
            {
                currentMenu = "weather-menu.current";
            }

            text += Translator.Get(currentMenu, new
            {
                todayCondition = Current.HasWeather(CurrentWeather.Fog)
                                        ? Translator.Get("weather-menu.fog", new { condition = GetBasicWeather(Current), fogTime = CurrentFog.IsWeatherVisible
                                                ? CurrentFog.WeatherExpirationTime.ToString()
                                                : "" })
                                        : GetBasicWeather(Current),
                tempString      = GetTemperatureString(Current.GetCurrentTemperature(Game1.timeOfDay)),
                todayHigh       = GetTemperatureString(Current.TodayHigh),
                todayLow        = GetTemperatureString(Current.TodayLow),
                currentRainfall = WeatherUtilities.GetRainfallAmt(Current.AmtOfRainDrops).ToString("N2"),
                fogString
            }) + Environment.NewLine;

            //Tomorrow weather
            text += Translator.Get("weather-menu.tomorrow",
                                   new {
                tomorrowCondition = GetBasicWeather(Game1.weatherForTomorrow),
                tomorrowLow       = GetTemperatureString(Current.TomorrowLow),
                tomorrowHigh      = GetTemperatureString(Current.TomorrowHigh)
            }) + Environment.NewLine;

            //now, night time
            if (!String.IsNullOrEmpty(NightTime))
            {
                text += NightTime + Environment.NewLine;
            }

            if (ClimatesOfFerngill.UseLunarDisturbancesApi)
            {
                if (ClimatesOfFerngill.MoonAPI.IsMoonUp(Game1.timeOfDay))
                {
                    text += Translator.Get("weather-menu.desc-moonNotUp", new { moonPhase = ClimatesOfFerngill.MoonAPI.GetCurrentMoonPhase(), moonRise = ClimatesOfFerngill.MoonAPI.GetMoonRise(), moonSet = ClimatesOfFerngill.MoonAPI.GetMoonSet() });
                }
                else
                {
                    text += Translator.Get("weather-menu.desc-moonUp", new { moonPhase = ClimatesOfFerngill.MoonAPI.GetCurrentMoonPhase(), moonSet = ClimatesOfFerngill.MoonAPI.GetMoonSet() });
                }
            }

            //new line replacer
            text.Replace("[NLK]", Environment.NewLine);

            return(text);
        }
Exemplo n.º 7
0
        internal static void DynamicRainOnNewDay(WeatherConditions curr, MersenneTwister Dice)
        {
            if (!curr.HasWeather(CurrentWeather.Rain))
            {
                return;
            }

            curr.SetRainAmt(70);
            //Rain chances. This will also affect storms (in that storms still can have variable rain) .
            //only roll this if it's actually raining. :|
            double roll = Dice.NextDouble();

            if (roll <= ClimatesOfFerngill.WeatherOpt.VariableRainChance && Game1.isRaining)
            {
                ClimatesOfFerngill.Logger.Log($"With {roll}, we are setting for variable rain against {ClimatesOfFerngill.WeatherOpt.VariableRainChance}");
                curr.SetVariableRain(true);

                //check for overcast chance first.
                if (Dice.NextDouble() < ClimatesOfFerngill.WeatherOpt.OvercastChance && !Game1.isLightning)
                {
                    WeatherUtilities.SetWeatherOvercast(true);
                    SDVUtilities.AlterWaterStatusOfCrops(water: false);
                    SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_overcast"), 0);
                }

                //now that we've done that base check, we need to change the rainfall...
                //... after we calc rainfall to see if it's watered. Essentially, every time this is called,
                //... it'll check to see if it should flip the tiles.

                //Variable Rain may set the starting rain at 0300 to be something else than normal, and as such, StartingRain should
                // only be checked if IsVariableRain is true.

                // Odds are fixed: Normal (default) is 72%, Light is 16%, Heavy is 6%, Sunshower is 5%, Severe is 1%
                double startingRainRoll = Dice.NextDouble();
                if (startingRainRoll <= .72)
                {
                    curr.StartingRain = RainLevels.Normal;
                }
                else if (startingRainRoll > .72 && startingRainRoll <= .88)
                {
                    curr.StartingRain = RainLevels.Light;
                }
                else if (startingRainRoll > .88 && startingRainRoll <= .94)
                {
                    curr.StartingRain = RainLevels.Heavy;
                }
                else if (startingRainRoll > .94 && startingRainRoll <= .99)
                {
                    curr.StartingRain = RainLevels.Sunshower;
                }
                else if (startingRainRoll > .99)
                {
                    curr.StartingRain = RainLevels.Severe;
                }

                if (Game1.isLightning && !(curr.StartingRain == RainLevels.Light || curr.StartingRain == RainLevels.Sunshower || curr.StartingRain == RainLevels.Normal))
                {
                    curr.StartingRain = RainLevels.Heavy;
                }

                curr.SetRainAmt(WeatherUtilities.GetRainCategoryMidPoint(curr.StartingRain));
                curr.TodayRain = curr.AmtOfRainDrops;

                //now run this for 0300 to 0600.
                for (int i = 0; i < 17; i++)
                {
                    curr.SetRainAmt(GetNewRainAmount(curr.AmtOfRainDrops, ClimatesOfFerngill.Translator));
                    curr.TodayRain += curr.AmtOfRainDrops;
                }

                //set starting amount at 6am
                curr.RefreshRainAmt();
            }
        }
Exemplo n.º 8
0
        internal static int GetNewRainAmount(int prevRain, ITranslationHelper Translation, bool showRain = true)
        {
            int    currRain           = prevRain;
            double ChanceOfRainChange = ClimatesOfFerngill.WeatherOpt.VRChangeChance;
            bool   massiveChange      = false;

            //do some rain chance pre pumping
            if (currRain == 0)
            {
                ChanceOfRainChange += .20;
            }
            if (currRain > WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Torrential))
            {
                ChanceOfRainChange += .10;
            }
            if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood)
            {
                ChanceOfRainChange += .15;
            }

            double FlipChance = .5;

            //so, lower: decrease, higher: increase
            if (WeatherUtilities.IsSevereRainFall(currRain))
            {
                FlipChance += .2;
            }
            if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.Torrential || WeatherUtilities.GetRainCategory(currRain) == RainLevels.Typhoon || WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood)
            {
                FlipChance += .15; //15% chance remaining of increasing.
            }
            if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.Typhoon || WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood)
            {
                FlipChance += .1456; //.44% chance remaning of increasing.
            }
            if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood)
            {
                FlipChance += .0018; //.26% chance remaning of increasing.
            }
            if (currRain == ClimatesOfFerngill.WeatherOpt.MaxRainFall)
            {
                FlipChance = 1;         //you must go ddown.
            }
            if (currRain <= WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Light))
            {
                FlipChance -= .2; //70% chance of increasing
            }
            if (currRain <= WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Sunshower))
            {
                FlipChance -= .1; //80% chance of increasing
            }
            if (currRain == 0)
            {
                FlipChance -= .15;         //95% chance of increasing
            }
            if (ClimatesOfFerngill.WeatherOpt.Verbose)
            {
                ClimatesOfFerngill.Logger.Log($"Rain is {prevRain}, current chance for rain change is {ChanceOfRainChange}.");
                ClimatesOfFerngill.Logger.Log($"Calculated chance for rain decreasing: {WeatherUtilities.GetStepChance(currRain, increase: false).ToString("N3")}, rain increasing: {WeatherUtilities.GetStepChance(currRain, increase: true).ToString("N3")}. Flip chance is {FlipChance.ToString("N3")} ");
            }

            // I just spent nine minutes typing out an invalid explanation for this. :|
            // So, i'm renaming the variables.

            // And redoing this entirely. It's a lot of duplicated effort.
            //Greater than flip chance is increase, lesser is decrease

            if (ClimatesOfFerngill.Dice.NextDouble() < ChanceOfRainChange)
            {
                // Handle rain changes.
                // first check for a massive change 145% to 245%
                double stepRoll = ClimatesOfFerngill.Dice.NextDouble();
                if (ClimatesOfFerngill.Dice.NextDouble() > FlipChance)
                {
                    if (ClimatesOfFerngill.WeatherOpt.Verbose)
                    {
                        ClimatesOfFerngill.Logger.Log("Increasing rain!");
                    }

                    if (stepRoll <= WeatherUtilities.GetStepChance(currRain, increase: true))
                    {
                        //get the multiplier.  This should be between 145% and 245%

                        int mult = Math.Max(1, (int)(Math.Floor(ClimatesOfFerngill.Dice.NextDouble() + .68)));

                        if (currRain == 0)
                        {
                            currRain = 15 * mult;
                        }
                        else
                        {
                            currRain = (int)(Math.Floor(currRain * mult * 1.0));
                        }

                        massiveChange = true;
                    }
                }
                else
                {
                    if (stepRoll <= WeatherUtilities.GetStepChance(currRain, increase: false))
                    {
                        ClimatesOfFerngill.Logger.Log("Increasing rain!");
                        currRain      = (int)(Math.Floor(currRain / (ClimatesOfFerngill.Dice.NextDouble() + 1.45)));
                        massiveChange = true;
                    }
                }

                if (!massiveChange)
                {
                    double mult = (1 + (ClimatesOfFerngill.Dice.NextDouble() * 1.3) - .55);
                    if (currRain == 0)
                    {
                        currRain = 4;
                    }

                    if (currRain < WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Light))
                    {
                        mult += 4.5;
                    }

                    currRain = (int)(Math.Floor(currRain * mult));
                }
            }



            if (!ClimatesOfFerngill.WeatherOpt.HazardousWeather)
            {
                if (ClimatesOfFerngill.WeatherOpt.Verbose)
                {
                    ClimatesOfFerngill.Logger.Log("Triggering Hazardous Weather Failsafe");
                }

                currRain = WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Severe);
            }

            if (WeatherConditions.PreventGoingOutside(currRain))
            {
                if (Game1.timeOfDay >= 2300)
                {
                    //drop the rain to at least allow the person to return home if they aren't.
                    currRain = WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Severe);
                }
            }

            if (currRain > ClimatesOfFerngill.WeatherOpt.MaxRainFall)
            {
                currRain = ClimatesOfFerngill.WeatherOpt.MaxRainFall;
            }

            if (currRain < 0)
            {
                currRain = 0;
            }

            if (currRain != prevRain && Game1.timeOfDay != 600 && showRain && !(Game1.currentLocation is Desert))
            {
                if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.None)
                {
                    Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.NearlyNoRain")));
                    return(currRain);
                }

                else if (currRain > prevRain)
                {
                    if (WeatherUtilities.GetRainCategory(currRain) != WeatherUtilities.GetRainCategory(prevRain))
                    {
                        Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.CateIncrease", new { currRain, category = WeatherUtilities.DescRainCategory(currRain) })));
                        return(currRain);
                    }
                    else if (Math.Abs(currRain / prevRain) >= ClimatesOfFerngill.WeatherOpt.VRainNotifThreshold || ClimatesOfFerngill.WeatherOpt.Verbose)
                    {
                        Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.Increase", new { currRain })));
                        return(currRain);
                    }
                }
                else
                {
                    if (WeatherUtilities.GetRainCategory(currRain) != WeatherUtilities.GetRainCategory(prevRain))
                    {
                        Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.CateDecrease", new { currRain, category = WeatherUtilities.DescRainCategory(currRain) })));
                        return(currRain);
                    }
                    else if (Math.Abs(currRain / prevRain) >= ClimatesOfFerngill.WeatherOpt.VRainNotifThreshold || ClimatesOfFerngill.WeatherOpt.Verbose)
                    {
                        Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.Decrease", new { currRain })));
                        return(currRain);
                    }
                }
            }

            return(currRain);
        }
Exemplo n.º 9
0
 internal static string GetUnitAmt(int val)
 {
     return(WeatherUtilities.GetRainfallAmt(val) + " mm/hr");
 }
Exemplo n.º 10
0
#pragma warning disable IDE0060 // Remove unused parameter
        /// <summary>
        /// This function changes the weather (Console Command)
        /// </summary>
        /// <param name="arg1">The command used</param>
        /// <param name="arg2">The console command parameters</param>
        public static void WeatherChangeFromConsole(string arg1, string[] arg2)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            if (arg2.Length < 1)
            {
                return;
            }

            string ChosenWeather = arg2[0];

            switch (ChosenWeather)
            {
            case "rain":
                WeatherUtilities.SetWeatherRain();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_rain"), LogLevel.Info);
                break;

            case "testing":
                WeatherUtilities.SetWeatherTesting();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log("HERE BE KRAKENS!", LogLevel.Info);
                break;

            case "testing2":
                WeatherUtilities.SetWeatherTesting2();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log("HERE BE KRAKENS, MATEY! FIRE PORT!", LogLevel.Info);
                break;

            case "testing3":
                WeatherUtilities.SetWeatherTesting3();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log("[The Skull Moon Hates You]", LogLevel.Info);
                break;

            case "sandstorm":
                WeatherUtilities.SetWeatherSandstorm();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log("Doo doo doo doo doo doo doo doo", LogLevel.Info);
                break;

            case "vrain":
                WeatherUtilities.SetWeatherRain();
                ClimatesOfFerngill.ForceVariableRain();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_rain"), LogLevel.Info);
                break;

            case "storm":
                WeatherUtilities.SetWeatherStorm();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_storm"), LogLevel.Info);
                break;

            case "thunderfrenzy":
                WeatherUtilities.SetWeatherStorm();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("ThunderFrenzy").First().CreateWeather();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_snow"), LogLevel.Info);
                break;

            case "snow":
                WeatherUtilities.SetWeatherSnow();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_snow"), LogLevel.Info);
                break;

            case "debris":
                WeatherUtilities.SetWeatherDebris();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_debris", LogLevel.Info));
                break;

            case "sunny":
                WeatherUtilities.SetWeatherSunny();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_sun", LogLevel.Info));
                break;

            case "overcast":
                WeatherUtilities.SetWeatherOvercast();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_overcast", LogLevel.Info));
                break;

            case "blizzard":
                WeatherUtilities.SetWeatherSnow();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().CreateWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("WhiteOut").First().EndWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().SetWeatherBeginTime(new SDVTime(0600));
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().SetWeatherExpirationTime(new SDVTime(2800));
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_snow"), LogLevel.Info);
                break;

            case "fog":
                WeatherUtilities.SetWeatherSunny();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().EndWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("WhiteOut").First().EndWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Fog").First().CreateWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Fog").First().SetWeatherBeginTime(new SDVTime(0600));
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Fog").First().SetWeatherBeginTime(new SDVTime(2800));
                break;

            case "whiteout":
                WeatherUtilities.SetWeatherSnow();
                Game1.updateWeatherIcon();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().CreateWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("WhiteOut").First().CreateWeather();
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().SetWeatherBeginTime(new SDVTime(0600));
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("WhiteOut").First().SetWeatherBeginTime(new SDVTime(0600));
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("Blizzard").First().SetWeatherExpirationTime(new SDVTime(2800));
                ClimatesOfFerngill.Conditions.GetWeatherMatchingType("WhiteOut").First().SetWeatherExpirationTime(new SDVTime(2800));
                ClimatesOfFerngill.Logger.Log(ClimatesOfFerngill.Translator.Get("console-text.weatherset_snow"), LogLevel.Info);
                break;
            }

            Game1.updateWeatherIcon();
            ClimatesOfFerngill.Conditions.SetTodayWeather();
            ClimatesOfFerngill.Conditions.GenerateWeatherSync();
        }
        private void SetTomorrowWeather()
        {
            //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;
                Conditions.HaltWeatherSystem();

                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;
                Conditions.HaltWeatherSystem();

                if (WeatherOpt.Verbose)
                {
                    Monitor.Log($"Wedding tomorrow. Aborting processing.", LogLevel.Trace);
                }

                return;
            }

            if (WeatherUtilities.CheckForForceDay(DescriptionEngine, SDate.Now().AddDays(1), Monitor, WeatherOpt.Verbose))
            {
                Conditions.HaltWeatherSystem();
                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));

            //get system odds
            double rainSystem = OddsForTheDay.RetrieveSystemOdds("rain");
            double windSystem = OddsForTheDay.RetrieveSystemOdds("debris");
            double sunSystem  = OddsForTheDay.RetrieveSystemOdds("sunny");

            if (!Game1.player.mailReceived.Contains("ccDoorUnlock"))
            {
                rainSystem = Math.Max(rainSystem - .1, 0);
                windSystem = Math.Max(windSystem - .1, 0);
                sunSystem  = Math.Min(sunSystem + .2, 1);
            }


            //get loose odds
            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 (!Game1.player.mailReceived.Contains("ccDoorUnlock"))
            {
                rainDays  = Math.Max(rainDays - .1, 0);
                windyDays = Math.Max(windyDays - .1, 0);
            }

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

            //set tomorrow's weather
            if (Conditions.trackerModel.IsWeatherSystem)
            {
                double SystemContinuesOdds = WeatherProcessing.GetWeatherSystemOddsForNewDay(Conditions);
                if (WeatherOpt.Verbose)
                {
                    Monitor.Log($"Rolling system odds against {SystemContinuesOdds:N3}");
                }

                if (Dice.NextDouble() < SystemContinuesOdds)
                {
                    if (WeatherOpt.Verbose)
                    {
                        Monitor.Log($"Continuing system odds - now for {Conditions.trackerModel.WeatherSystemDays + 1} for weather {Conditions.trackerModel.WeatherSystemType}");
                    }
                    Conditions.trackerModel.WeatherSystemDays++;
                    WeatherProcessing.SetWeatherTomorrow(Conditions.trackerModel.WeatherSystemType, Dice, GameClimate, stormDays, Conditions.GetTomorrowTemps());
                }

                else
                {
                    if (WeatherOpt.Verbose)
                    {
                        Monitor.Log($"Ending system, new weather type.");
                    }
                    Conditions.trackerModel.IsWeatherSystem = false;
                    WeatherProcessing.SetWeatherNonSystemForTomorrow(Dice, GameClimate, rainDays, stormDays, windyDays, Conditions.GetTomorrowTemps());
                }
            }
            else
            {
                if (Dice.NextDouble() < WeatherOpt.WeatherSystemChance)
                {
                    if (WeatherOpt.Verbose)
                    {
                        Monitor.Log($"Rolling system odds against {WeatherOpt.WeatherSystemChance:N3}, created system.");
                    }

                    ProbabilityDistribution <string> SystemDist = new ProbabilityDistribution <string>();

                    SystemDist.AddNewCappedEndPoint(rainSystem, "rain");
                    SystemDist.AddNewCappedEndPoint(windSystem, "debris");
                    SystemDist.AddNewCappedEndPoint(sunSystem, "sunny");

                    double distOdd = Dice.NextDouble();

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

                    Conditions.SetNewWeatherSystem(Result, 1);
                    WeatherProcessing.SetWeatherTomorrow(Result, Dice, GameClimate, stormDays, Conditions.GetTomorrowTemps());
                }
                else
                {
                    WeatherProcessing.SetWeatherNonSystemForTomorrow(Dice, GameClimate, rainDays, stormDays, windyDays, Conditions.GetTomorrowTemps());
                }
            }
        }