// Rain
 void setRainIntensity(weatherGet weather, float rainIntensity)
 {
     if (weather.getRainDuration() > 0)
     {
         weather.setRainIntensity(rainIntensity);
     }
 }
    void chooseWeather()
    {
        switch (weatherTypeArray[Random.Range(0, 2)])
        {
        /*
         * NOTE that simulated weather values are different from real time weather values because of the following factors:
         *       1. Location (location in Earth, nearness to the body of water, nearness to the equator / poles)
         *       2. Geography (altitude, landforms)
         *       3. Time (morning, evening)
         *       4. Global warming (including greenhouse gas emmisions, pollution and pollutants)
         */

        // Sunny
        case "sunny":

            // Weather type definition
            weatherType = "sunny";

            // Sun - MOST DOMINANT
            sunIntensity = Random.Range(5.00f, 10.00f);

            // Rain
            // Chances of raining during sunny days is 5%
            // Rain can only last up to 4 hours in the game
            // Because of factors like the sun's heat and temperature, water evaporates more easily and amount of water falling from the sky will be less
            rainChance      = 5;
            rainDurationMin = 0;
            rainDurationMax = 4;
            rainIntensity   = Random.Range(0.00f, 0.40f);

            // Temperature - HOT
            tempMin = 25;
            tempMax = 40;

            wEasy.setRainDuration(Random.Range(rainDurationMin, rainDurationMax));
            wMedium.setRainDuration(Random.Range(rainDurationMin, rainDurationMax));
            wHard.setRainDuration(Random.Range(rainDurationMin, rainDurationMax));
            setRainIntensity(wEasy, rainIntensity);
            setRainIntensity(wMedium, rainIntensity);
            setRainIntensity(wHard, rainIntensity);
            setSunIntensity(wEasy, sunIntensity);
            setSunIntensity(wMedium, sunIntensity + 2);
            setSunIntensity(wHard, sunIntensity + 5);

            wEasy.setTemperatureMin(tempMin);
            wMedium.setTemperatureMin(tempMin + 2);
            wHard.setTemperatureMin(tempMin + 5);

            wEasy.setTemperatureMax(tempMax - 10);
            wMedium.setTemperatureMax(tempMax - 5);
            wHard.setTemperatureMax(tempMax);

            break;

        // Rainy
        case "rainy":

            // Weather type definition
            weatherType = "rainy";

            // Sun
            // Variable is weakened by the amount of water and clouds
            sunIntensity = Random.Range(0.00f, 4.5f);

            // Rain - MOST DOMINANT
            // Chances of raining during rainy days is 80%
            // Rain can last 1 whole day in the game
            rainChance      = 80;
            rainDurationMin = 4;
            rainDurationMax = 24;
            rainIntensity   = Random.Range(0.40f, 0.70f);


            // Temperature - MILD
            tempMin = 20;
            tempMax = 29;

            //set weather
            wEasy.setRainDuration(Random.Range(rainDurationMin, rainDurationMax));
            wMedium.setRainDuration(Random.Range(rainDurationMin + 2, rainDurationMax));
            wHard.setRainDuration(Random.Range(rainDurationMin + 5, rainDurationMax));

            setRainIntensity(wEasy, rainIntensity);
            setRainIntensity(wMedium, rainIntensity + 0.10f);
            setRainIntensity(wHard, rainIntensity + 0.20f);

            setSunIntensity(wEasy, sunIntensity);
            setSunIntensity(wMedium, sunIntensity);
            setSunIntensity(wHard, sunIntensity);

            wEasy.setTemperatureMin(tempMin);
            wMedium.setTemperatureMin(tempMin - 1);
            wHard.setTemperatureMin(tempMin - 2);

            wEasy.setTemperatureMax(tempMax - 5);
            wMedium.setTemperatureMax(tempMax - 2);
            wHard.setTemperatureMax(tempMax);

            break;

        // Cold
        case "cold":

            // Weather type definition
            weatherType = "cold";

            // Sun
            sunIntensity = Random.Range(1.50f, 6.00f);

            // Rain
            // Chances of raining during cold days is 50%
            // Rain may last 1 whole day
            rainChance      = 50;
            rainDurationMin = 0;
            rainDurationMax = 12;
            rainIntensity   = Random.Range(0f, 0.20f);

            // Temperature - COLD
            tempMin = 18;
            tempMax = 22;

            wEasy.setRainDuration(Random.Range(rainDurationMin, rainDurationMax));
            wMedium.setRainDuration(Random.Range(rainDurationMin + 2, rainDurationMax + 3));
            wHard.setRainDuration(Random.Range(rainDurationMin + 5, rainDurationMax + 8));

            setRainIntensity(wEasy, rainIntensity);
            setRainIntensity(wMedium, rainIntensity + 0.10f);
            setRainIntensity(wHard, rainIntensity + 0.20f);

            setSunIntensity(wEasy, sunIntensity);
            setSunIntensity(wMedium, sunIntensity);
            setSunIntensity(wHard, sunIntensity);

            wEasy.setTemperatureMin(tempMin);
            wMedium.setTemperatureMin(tempMin - 2);
            wHard.setTemperatureMin(tempMin - 5);

            wEasy.setTemperatureMax(tempMax);
            wMedium.setTemperatureMax(tempMax - 2);
            wHard.setTemperatureMax(tempMax - 5);
            break;

        // Undefined
        default:
            break;
        }

        //set sun duration
        wEasy.setSunDuration(23 - wEasy.getRainDuration());
        wMedium.setSunDuration(23 - wMedium.getRainDuration());
        wHard.setSunDuration(23 - wHard.getRainDuration());

        ////set rain chance percentage
        wEasy.setRainChancePercentage(rainChance);
        wMedium.setRainChancePercentage(rainChance);
        wHard.setRainChancePercentage(rainChance);

        ////set weather type
        wEasy.setWeatherType(weatherType);
        wMedium.setWeatherType(weatherType);
        wHard.setWeatherType(weatherType);
    }
Пример #3
0
    private void Update()
    {
        changeTempTimer += Time.deltaTime;

        if (hour == 23)
        {
            hour = timekeeper.hour_military;
        }

        if (newWeather == true)
        {
            //Debug.Log("New Weather");
            newWeather     = false;
            currentWeather = weather[Random.Range(0, 2)];
            //Debug.Log(currentWeather + " " + currentWeather.getWeatherType());
            triggerRain = Random.Range(0, currentWeather.getSunDuration() - 1);
            //Debug.Log("Brand new TriggerRain " + triggerRain);
            rainChancePicker();
        }

        if (currentWeather.getSunny() == true)
        {
            if (timekeeper.hour_military == hour + 1)
            {
                currentWeather.setSunDuration(currentWeather.getSunDuration() - 1);
                hour = timekeeper.hour_military;
            }
            if (currentWeather.getSunDuration() <= 0 || currentWeather.getSunDuration() == triggerRain)
            {
                if (currentWeather.getSunDuration() == triggerRain)
                {
                    triggerRain = 0;
                }
                currentWeather.setRaining(true);
                currentWeather.setSunny(false);
            }
        }
        else if (currentWeather.getRaining() == true)
        {
            if (timekeeper.hour_military == hour + 1)
            {
                currentWeather.setRainDuration(currentWeather.getRainDuration() - 1);
                hour = timekeeper.hour_military;
            }
            if (currentWeather.getRainDuration() <= 0 /*||currentWeather.getRainDuration() == triggerSun*/)
            {
                currentWeather.setRaining(false);
                currentWeather.setSunny(true);
            }
        }
        if (currentWeather.getSunDuration() <= 0 && currentWeather.getRainDuration() <= 0)
        {
            weatherSimulator.makeWeather = true;
            //Debug.Log("Simulating new weather");
        }
        if (RainScript == null)
        {
            return;
        }
        else if (currentWeather.getRaining())
        {
            RainScript.RainIntensity = currentWeather.getRainIntensity();

            RainScript.EnableWind = true;
        }
        else if (currentWeather.getSunny())
        {
            RainScript.RainIntensity = 0f;
            RainScript.EnableWind    = false;
        }

        if (changeTempTimer >= 5)
        {
            //Debug.Log("Changing Temp");
            int newTemp = Random.Range(currentWeather.getTemperatureMin(), currentWeather.getTemperatureMax());

            if (hour >= 18)
            {
                newTemp -= 10;
            }

            labelTemperature.text = newTemp.ToString() + "°C";

            changeTempTimer = 0;
        }
    }