LoafyLemon
7535e0b756
* Redesigned weather systems and added seasons along with seeded weights for each quarter. * Added weather forecast to the calendar * Bug fixes
66 lines
2.3 KiB
Plaintext
66 lines
2.3 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),
|
|
}
|
|
_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()
|
|
weights = Weather._interpolate_weights(game.day, period)
|
|
rand = renpy.random.Random(seed=game.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
|
|
|
|
weather = property(get_weather, set_weather)
|
|
|
|
@staticmethod
|
|
def forecast(span=35):
|
|
forecast = {}
|
|
start_day = game.day - (game.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
|
|
|