Count days and seasons by calendar day

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-19 09:42:36 +01:00
parent 75327f30e0
commit 70246f78ea
3 changed files with 23 additions and 4 deletions

17
game.py
View file

@ -10,6 +10,7 @@ from __future__ import annotations
import math
import random
from datetime import date
HOUR = 3600
DAY = 24 * HOUR
@ -1881,11 +1882,21 @@ FORTUNES = {"merchant": [12] * 4, "refugees": [10] * 4, "master": [16] * 4, "har
TRACK_HOURS = {"minor": (48, 96), "hardship": (48, 96), "fortune": (36, 72)}
def calendar_day(world: dict, now: float) -> int:
"""Days since the world began, counting midnights in the server's timezone (0 on the first day).
A sped-up dev world has no calendar to speak of, so it counts 24-hour stretches instead.
"""
if speed(world) != 1:
return int((now - world["created"]) * speed(world) // DAY)
return (date.fromtimestamp(now) - date.fromtimestamp(world["created"])).days
def season(world: dict, now: float) -> dict:
day = (now - world["created"]) * speed(world) / DAY
index = int(day // SEASON_DAYS) % len(SEASONS)
day = calendar_day(world, now)
index = day // SEASON_DAYS % len(SEASONS)
name, icon = SEASONS[index]
return {"index": index, "name": name, "icon": icon, "day": int(day % SEASON_DAYS) + 1}
return {"index": index, "name": name, "icon": icon, "day": day % SEASON_DAYS + 1}
def _pick(weights: dict, rng: random.Random) -> str: