public void generateNewTempForecast() { forecastTemp = new QueueDirectAccess <float>(); forecastTemp.resize(daysToForecast); int daysInSeasons = climate.getDaysPerSeason(); int seasonsInClimate = climate.getSeasonsInClimate(); int dayInForecast = currentDay; int seasonInForecast = currentSeason; for (int i = 0; i < daysToForecast; i++) { if (dayInForecast == daysInSeasons) { dayInForecast = 0; seasonInForecast++; if (seasonInForecast == seasonsInClimate) { seasonInForecast = 0; } } float temperature = climate.getTempFromSeasonAndDay(seasonInForecast, dayInForecast); forecastTemp.enqueue(temperature); dayInForecast++; } }
public void generateNewWeatherForecast() { forecastWeather = new QueueDirectAccess <Weather.weatherTypes>(); forecastWeather.resize(daysToForecast); if (forecastTemp == null) { Debug.LogError("Error: Can't generate a weather forecast before temperature."); return; } else if (forecastTemp.getSize() != daysToForecast) { Debug.LogError("Error: Size mismatch. Generate new temperature forecast before weather."); return; } for (int i = 0; i < daysToForecast; i++) { forecastWeather.enqueue(weather.getWeather(forecastTemp[i])); } }
public weatherTypes getWeather(float temp) { int weightedChanceSum = 0; QueueDirectAccess <weatherTypes> allowedWeather = new QueueDirectAccess <weatherTypes>(); allowedWeather.resize(weatherTypesCount); allowedWeather.enqueue(weatherTypes.PERFECT_WEATHER); weightedChanceSum += chances[weatherTypes.PERFECT_WEATHER]; allowedWeather.enqueue(weatherTypes.SUNNY); weightedChanceSum += chances[weatherTypes.SUNNY]; allowedWeather.enqueue(weatherTypes.CLOUDY); weightedChanceSum += chances[weatherTypes.CLOUDY]; allowedWeather.enqueue(weatherTypes.SCARY_LIGHTNING); weightedChanceSum += chances[weatherTypes.SCARY_LIGHTNING]; allowedWeather.enqueue(weatherTypes.HELLFIRE); weightedChanceSum += chances[weatherTypes.HELLFIRE]; if (temp >= 20) { allowedWeather.enqueue(weatherTypes.SUPER_HOT); weightedChanceSum += chances[weatherTypes.SUPER_HOT]; } if (temp > 0) { allowedWeather.enqueue(weatherTypes.RAIN); weightedChanceSum += chances[weatherTypes.RAIN]; allowedWeather.enqueue(weatherTypes.ACID_RAIN); weightedChanceSum += chances[weatherTypes.ACID_RAIN]; } else { allowedWeather.enqueue(weatherTypes.SNOW); weightedChanceSum += chances[weatherTypes.SNOW]; } if (temp <= -20) { allowedWeather.enqueue(weatherTypes.BLIZZARD); weightedChanceSum += chances[weatherTypes.BLIZZARD]; } int weatherPick = UnityEngine.Random.Range(0, weightedChanceSum); weatherTypes weather = allowedWeather[0]; while (!allowedWeather.isEmpty() && weatherPick > chances[allowedWeather[0]]) { weather = allowedWeather.dequeue(); weatherPick -= chances[weather]; } if (!allowedWeather.isEmpty()) { weather = allowedWeather.dequeue(); } return(weather); }