void Start() { maxIntensityValue = biome.GetMaxIntensityValue(); //obtener estado inicial como el valor mas probable de cada estado a menos que hayan inconsistencias ( mas lluvia que nubes, lluvia y nieve a la vez....) GetInitialSeason(clock.getCurrentDate()); currentState = GetInitialState(); visualizeState(); lastUpdate = clock.getCurrentTime().Clone(); //calcular matrices acumulativas updateAcumulativeValues(currentSeason.GetIndex()); }
void Update() { if (lastUpdate.SecondsBetween(clock.getCurrentTime()) >= update_frequency * 60) { if (debug) { Debug.Log("It is time to calculate a new weather state"); Debug.Break(); } if (!(clock.GetSeason().GetIndex() == currentSeasonIndex)) { currentSeasonIndex = clock.GetSeason().GetIndex(); updateAcumulativeValues(currentSeasonIndex); } currentState = getNextState(currentState); lastUpdate = clock.getCurrentTime().Clone(); visualizeState(); } }
// accumulative values are asumed to be not null and correct for the season private WeatherState getNextState(WeatherState currentState) { int clouds, rain, snow, lightning; clouds = rain = snow = lightning = 0; //CLOUD VALUE: float random = UnityEngine.Random.value; for (int i = 0; i <= maxIntensityValue; i++) { if (random < cloudAcumulativeValues[currentState.GetClouds(), i]) { clouds = i; break; } } if (debug) { Debug.Log("CALCULATING CLOUD VALUE: "); Debug.Log("Acumulative values: " + matrixToString(cloudAcumulativeValues)); Debug.Log("Random value: " + random + ", \t Selected value:" + clouds); } //RAIN VALUE random = UnityEngine.Random.value; for (int i = 0; i <= maxIntensityValue; i++) { if (random < rainAcumulativeValues[currentState.GetClouds(), i]) { rain = i; break; } } //SNOW VALUE random = UnityEngine.Random.value; for (int i = 0; i <= maxIntensityValue; i++) { if (random < snowAcumulativeValues[currentState.GetClouds(), i]) { snow = i; break; } } //LIGHTNING VALUE random = UnityEngine.Random.value; for (int i = 0; i <= maxIntensityValue; i++) { if (random < lightningAcumulativeValues[currentState.GetClouds(), i]) { lightning = i; break; } } //COHERENCY TEST if (rain > 0 && snow > 0) { if (biome.GetCloudProbability(rain, currentSeasonIndex) > biome.GetCloudProbability(snow, currentSeasonIndex)) { snow = 0; if (debug) { Debug.Log("WEATHERCONTROLLER: rain found to be more likely than snow, therefore snow has been set to 0 "); Debug.Break(); } } else { rain = 0; if (debug) { Debug.Log("WEATHERCONTROLLER: snow found to be more likely than rain, therefore rain has been set to 0 "); Debug.Break(); } } } if (snow > clouds) { snow = clouds; if (debug) { Debug.Log("WEATHERCONTROLLER: snow value was greater then the cloud intensity. The snow value has been changed to: " + snow); Debug.Break(); } } if (rain > clouds) { rain = clouds; if (debug) { Debug.Log("WEATHERCONTROLLER: rain value was greater then the cloud intensity. The rain value has been changed to: " + rain); Debug.Break(); } } if (lightning >= clouds) { lightning = clouds; if (debug) { Debug.Log("WEATHERCONTROLLER: lightning value was greater then the cloud and rain intensities. The lighning value has been changed to: " + lightning); Debug.Break(); } } return(new WeatherState(clouds, rain, lightning, snow)); }