WTS/game/scripts/interface/weather.rpy

64 lines
2.2 KiB
Plaintext

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),
}
@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():
# Proxy
return states.env.weather
@staticmethod
def set_weather(value=None):
if value is None or value == "random":
period = Calendar.get_period()
weights = Weather._interpolate_weights(states.env.day, period)
rand = renpy.random.Random(seed=states.env.day)
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
@staticmethod
def forecast(span=35):
forecast = {}
start_day = states.env.day - (states.env.day % 30)
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