diff --git a/app.py b/app.py index 1f5178f..f230cd9 100644 --- a/app.py +++ b/app.py @@ -152,6 +152,8 @@ def player_view(world: dict, player: dict, now: float) -> dict: view["recon_gain"] = {action["id"]: game.recon_gain(world, player, action) for action in game.ACTIONS if action.get("special") == "recon"} level = game.skill_level(player, "firekeeping") + view["region_yield"] = {action["id"]: round(game.region_yield(world, action) - 1, 3) for action in game.ACTIONS + if game.region_yield(world, action) > 1} view["firekeeping"] = {"minutes": game.fire_minutes(level), "bank": game.fire_bank(level)} # Inputs as the fires leave them: a lit fire pays the log. view["fuelled"] = {action["id"]: game.fire_inputs(world, action) for action in game.ACTIONS if action.get("fire")} @@ -363,7 +365,7 @@ class Handler(BaseHTTPRequestHandler): pouch = body.get("pouch") return game.travel(world, player, str(body.get("to")), pouch if isinstance(pouch, dict) else {}, now) if path == "/api/charter": - return game.propose_charter(world, player, body.get("name"), now) + return game.propose_charter(world, player, body.get("name"), body.get("region"), now) if path == "/api/charter/sign": return game.sign_charter(world, player, now) if path == "/api/charter/cancel": diff --git a/game.py b/game.py index 99a4948..2e911a8 100644 --- a/game.py +++ b/game.py @@ -1690,7 +1690,17 @@ CITY_KEYS = ("events", "next_event_at", "next_minor_at", "next_hardship_at", "ne TRAVEL_TIME = 12 * 60 # game seconds on the road between two towns POUCH_SLOTS = 6 # kinds of item you can carry on the road... POUCH_STACK = 100 # ...and how many of each -MAX_CITIES = 3 +# Where a town stands: one town to a region, between them every gathering trade. Each trip out brings +# back more, most of all of the commonest stuff, and more as the town grows. XP stays the same. +REGIONS = { + "mountains": {"name": "Mountains", "icon": "⛰️", "skills": ["mining"]}, + "forest": {"name": "Forest", "icon": "🌲", "skills": ["woodcutting", "hunting"]}, + "coast": {"name": "Coast", "icon": "🌊", "skills": ["fishing"]}, + "plains": {"name": "Plains", "icon": "🌾", "skills": ["farming"]}, +} +REGION_YIELD = [1.0, 0.75, 0.5, 0.3, 0.2, 0.1] # more per trip at each material tier, for a full city +TOWN_SCALE = [0.5, 0.7, 0.85, 1.0] # how much of that a hamlet, village, town and city get +MAX_CITIES = 1 + len(REGIONS) FOUNDING = {"settlers": 20, "gold": 5000, "provisions": 200} # what a new town takes from the one it leaves FOUNDING_GRACE = 24 # game hours a new town gets before its first threat lands @@ -4427,9 +4437,13 @@ def _store(world: dict, order: dict, qty: int, now: float) -> None: def _hand_over(world: dict, order: dict, owner: dict, now: float) -> None: - """Put delivered items in the requester's bank; what doesn't fit waits on the order, - as it does while they're in another town.""" + """Put delivered items in the requester's bank in the order's town, whether or not they're + there; if they are, what doesn't fit waits on the order.""" if owner["at"] != world.here: + bank = owner["banks"].setdefault(world.here, {}) + bank[order["item"]] = bank.get(order["item"], 0) + order["held"] + note(world, owner, now, "Received", order["item"], order["held"], label=f"Work order · {world['city']['name']}") + order["held"] = 0 return fits = min(order["held"], bank_room(world, owner, order["item"])) if fits: @@ -4583,11 +4597,15 @@ def arrive(world: World, player: dict) -> None: note(world, player, trip["arrive"], "Arrived", label=world["city"]["name"]) -def propose_charter(world: World, player: dict, name, now: float) -> str | None: +def propose_charter(world: World, player: dict, name, region, now: float) -> str | None: """Ask the guild to found a new town. A second founder has to sign before it happens.""" name = str(name or "").strip() if not 3 <= len(name) <= 24: return "A town's name takes 3 to 24 letters" + if region not in REGIONS: + return "Pick a region" + if any(city.get("region") == region for city in world.doc["cities"].values()): + return f"There's already a town in the {REGIONS[region]['name'].lower()}" if world["charter"]: return "A charter is already waiting to be signed" if len(world.doc["cities"]) >= MAX_CITIES: @@ -4597,7 +4615,7 @@ def propose_charter(world: World, player: dict, name, now: float) -> str | None: error = _founding_short(world) if error: return error - world["charter"] = {"name": name, "by": player["id"], "from": world.here, "at": now} + world["charter"] = {"name": name, "region": region, "by": player["id"], "from": world.here, "at": now} log(world, now, "tier", f"{player['name']} drew up a charter for a new town: {name}") return None @@ -4633,6 +4651,7 @@ def sign_charter(world: World, player: dict, now: float) -> str | None: del giving["stockpile"]["provisions"] city = _new_city(now, speed(world), charter["name"]) city["population"] = float(FOUNDING["settlers"]) + city["region"] = charter["region"] city["stockpile"]["provisions"] = FOUNDING["provisions"] city["next_event_at"] = now world.doc["cities"][_slug(charter["name"])] = city @@ -4653,12 +4672,14 @@ def kingdom_view(world: World, now: float) -> dict: cities = [] for key, city in world.doc["cities"].items(): people = [p for p in world["players"].values() if p["at"] == key and not p["travel"]] - cities.append({"id": key, "name": city["name"], "population": int(city["population"]), + cities.append({"id": key, "name": city["name"], "region": city.get("region"), "town_scale": TOWN_SCALE[city["tier"]], + "population": int(city["population"]), "tier": TIERS[city["tier"]]["name"], "repelled": city["repelled"], "people": [p["id"] for p in people], "founded": city["founded"]}) charter = world["charter"] return {"cities": cities, "charter": charter, "pouch": {"slots": POUCH_SLOTS, "stack": POUCH_STACK}, "founding": FOUNDING, "max": MAX_CITIES, "short": _founding_short(world), + "regions": REGIONS, "region_yield": REGION_YIELD, "road": [{"id": p["id"], **{k: p["travel"][k] for k in ("from", "to", "arrive")}} for p in world["players"].values() if p["travel"]]} @@ -5944,10 +5965,20 @@ def _modifier_sources(world: dict) -> list[dict]: return sources +def region_yield(world: dict, action: dict) -> float: + """How much more this gathering brings back in this town, for standing where it does.""" + city = world["city"] + region = REGIONS.get(city.get("region")) + if not region or action["skill"] not in region["skills"] or not action["outputs"]: + return 1.0 + tier = sum(action["level"] >= level for level in TIER_LEVELS) - 1 + return 1 + REGION_YIELD[tier] * TOWN_SCALE[city["tier"]] + + def skill_mods(world: dict, action: dict) -> dict: """How weather, happenings and problems change this action right now.""" skill = action["skill"] - mods = {"speed": 1.0, "yield": 1.0, "xp": 1.0, "blocked": None} + mods = {"speed": 1.0, "yield": region_yield(world, action), "xp": 1.0, "blocked": None} for source in _modifier_sources(world): mods["speed"] *= source.get("speed", {}).get(skill, 1) mods["yield"] *= source.get("yield", {}).get(skill, 1) diff --git a/static/app.js b/static/app.js index 2934c38..77c3b7c 100644 --- a/static/app.js +++ b/static/app.js @@ -935,6 +935,11 @@ function pageHtml() { // --- kingdom ---------------------------------------------------------------- let pouch = {}; +function regionPerks(region, scale) { + const y = S.kingdom.region_yield; + return `${region.skills.map((id) => skillOf(id).icon).join("")} +${pct(y[0] * scale)} → +${pct(y.at(-1) * scale)}`; +} + function townName(id) { return S.kingdom.cities.find((c) => c.id === id)?.name || id; } @@ -944,9 +949,11 @@ function kingdom() { const towns = k.cities.map((c) => { const here = c.id === me.at && !me.travel; const road = k.road.filter((r) => r.to === c.id).length; + const region = k.regions[c.region]; return `
${esc(c.tier)} · 👥 ${fmt(c.population)} · 🛡️ ${fmt(c.repelled)}${road ? ` · 🛤️ ${road}` : ""}
+ ${region ? `${region.icon} ${esc(region.name)} · ${regionPerks(region, c.town_scale)}
` : ""}${c.people.length ? c.people.map((uid) => esc(playerName(uid))).join(", ") : `Nobody here`}
${here || me.travel ? "" : ``}📜 ${esc(charter.name)} · ${esc(playerName(charter.by))}
+ ? `📜 ${esc(charter.name)} · ${k.regions[charter.region].icon} ${esc(k.regions[charter.region].name)} · ${esc(playerName(charter.by))}
${charter.by === me.id ? `` : ``}` : full ? `${k.cities.length} / ${k.max} towns
` : `${cost}
${S.city.next_tier ? `${esc(k.short)}
` : `