2024-04-25 15:33:49 +00:00
|
|
|
init python:
|
|
|
|
class Weather():
|
|
|
|
weather_types = ("clear", "cloudy", "overcast", "blizzard", "snow", "storm", "rain")
|
|
|
|
weather_weights = {
|
|
|
|
"Janemar": (8, 9, 10, 3, 4, 7, 7),
|
|
|
|
"Aprimju": (9, 10, 9, 2, 3, 8, 8),
|
|
|
|
"Juliasep": (10, 10, 8, 1, 2, 6, 9),
|
|
|
|
"Octobrinde": (6, 7, 9, 9, 10, 6, 6),
|
|
|
|
}
|
|
|
|
_weather = None
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _interpolate_weights(day, period):
|
|
|
|
current_weights = Weather.weather_weights[period]
|
|
|
|
current_index = Calendar.periods.index(period)
|
|
|
|
|
|
|
|
next_index = (current_index + 1) % len(Calendar.periods)
|
|
|
|
next_weights = Weather.weather_weights[Calendar.periods[next_index]]
|
|
|
|
|
|
|
|
interpolation_factor = (day / 30) * 0.25
|
|
|
|
|
|
|
|
# Interpolate between current season and next season
|
|
|
|
adjusted_weights = tuple(
|
|
|
|
max(0.01, (1 - interpolation_factor) * current_weight + interpolation_factor * next_weights[i])
|
|
|
|
for i, current_weight in enumerate(current_weights)
|
|
|
|
)
|
|
|
|
|
|
|
|
return adjusted_weights
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_weather():
|
|
|
|
return Weather._weather
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def set_weather(value=None):
|
|
|
|
if value is None or value == "random":
|
|
|
|
period = Calendar.get_period()
|
2024-04-25 19:14:25 +00:00
|
|
|
weights = Weather._interpolate_weights(states.env.day, period)
|
|
|
|
rand = renpy.random.Random(seed=states.env.day)
|
2024-04-25 15:33:49 +00:00
|
|
|
value = rand.choices(Weather.weather_types, weights=weights)[0]
|
|
|
|
|
|
|
|
elif value not in Weather.weather_types:
|
|
|
|
raise ValueError(f"Unsupported weather type: {value!r}")
|
|
|
|
|
|
|
|
Weather._weather = value
|
|
|
|
return value
|
|
|
|
|
|
|
|
weather = property(get_weather, set_weather)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def forecast(span=35):
|
|
|
|
forecast = {}
|
2024-04-25 19:14:25 +00:00
|
|
|
start_day = states.env.day - (states.env.day % 30)
|
2024-04-25 15:33:49 +00:00
|
|
|
period = Calendar.get_period()
|
|
|
|
|
|
|
|
for i in range(span):
|
|
|
|
day = start_day + i
|
|
|
|
weights = Weather._interpolate_weights(day, period)
|
|
|
|
rand = renpy.random.Random(seed=day)
|
|
|
|
value = rand.choices(Weather.weather_types, weights=weights)[0]
|
|
|
|
|
|
|
|
forecast[i] = value
|
|
|
|
|
|
|
|
return forecast
|
|
|
|
|