Weather changes on time; repeat rolls lengthen the spell
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5bcf26f379
commit
0b7e4a722f
3 changed files with 41 additions and 8 deletions
31
game.py
31
game.py
|
|
@ -1563,6 +1563,7 @@ def tick(world: dict, now: float, rng: random.Random | None = None) -> bool:
|
|||
_happenings_hour(world, city["last_tick"], rng)
|
||||
_city_hour(world, city["last_tick"])
|
||||
changed = True
|
||||
changed = advance_weather(world, now, rng) or changed
|
||||
changed = _happenings_tracks(world, now, rng) or changed
|
||||
construction = city["construction"]
|
||||
if construction and construction["labour"] >= construction["needed"]:
|
||||
|
|
@ -2134,6 +2135,30 @@ def _roll_weather(world: dict, now: float, rng: random.Random, current: str | No
|
|||
return _pick(SEASON_WEATHER[season(world, now)["index"]], rng)
|
||||
|
||||
|
||||
def advance_weather(world: dict, now: float, rng: random.Random) -> bool:
|
||||
"""Change the weather when its spell ends. Returns True if it changed."""
|
||||
weather = world["city"]["weather"]
|
||||
if now < weather["until"]:
|
||||
return False
|
||||
while now >= weather["until"]:
|
||||
weather["kind"] = weather["next"]
|
||||
_plan_spell(world, weather, rng)
|
||||
return True
|
||||
|
||||
|
||||
def _plan_spell(world: dict, weather: dict, rng: random.Random) -> None:
|
||||
"""Set how long the current weather lasts and what follows. Rolls that keep the
|
||||
same weather lengthen the spell, so `until` is when it really changes."""
|
||||
for _ in range(3):
|
||||
weather["until"] += rng.uniform(4, 8) * HOUR / speed(world)
|
||||
weather["next"] = _roll_weather(world, weather["until"], rng, weather["kind"])
|
||||
if weather["next"] != weather["kind"]:
|
||||
return
|
||||
# Three spells of the same is long enough: something else comes next.
|
||||
weights = SEASON_WEATHER[season(world, weather["until"])["index"]]
|
||||
weather["next"] = _pick({kind: w for kind, w in weights.items() if kind != weather["kind"]}, rng)
|
||||
|
||||
|
||||
def _modifier_sources(world: dict) -> list[dict]:
|
||||
city = world["city"]
|
||||
sources = [WEATHER[city["weather"]["kind"]]] + city["effects"]
|
||||
|
|
@ -2437,11 +2462,7 @@ def hire_mercenaries(world: dict, player: dict, now: float) -> str | None:
|
|||
def _happenings_hour(world: dict, now: float, rng: random.Random) -> None:
|
||||
"""Weather, firewood, thieves and expiries, once per game hour."""
|
||||
city = world["city"]
|
||||
weather = city["weather"]
|
||||
if now >= weather["until"]:
|
||||
weather["kind"] = weather["next"]
|
||||
weather["until"] = now + rng.uniform(4, 8) * HOUR / speed(world)
|
||||
weather["next"] = _roll_weather(world, weather["until"], rng, weather["kind"])
|
||||
advance_weather(world, now, rng)
|
||||
city["effects"] = [e for e in city["effects"] if e["until"] > now]
|
||||
for problem in list(city["problems"]):
|
||||
if problem.get("until") and problem["until"] <= now:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue