예제 #1
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();
            }
        }
예제 #2
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);
        }