diff --git a/app.py b/app.py index bbba87c..36d1c50 100644 --- a/app.py +++ b/app.py @@ -366,6 +366,18 @@ class Handler(BaseHTTPRequestHandler): return game.travel(world, player, str(body.get("to")), pouch if isinstance(pouch, dict) else {}, now) if path == "/api/council/propose": return game.propose_march(world, player, str(body.get("from")), str(body.get("to")), body.get("guards"), now) + if path == "/api/council/freight": + return game.propose_freight(world, player, str(body.get("to")), body.get("item"), body.get("qty"), now) + if path in ("/api/caravan/form", "/api/caravan/board"): + goods = body.get("goods") if isinstance(body.get("goods"), dict) else {} + freight = body.get("freight") if isinstance(body.get("freight"), list) else [] + if path == "/api/caravan/form": + return game.form_caravan(world, player, str(body.get("to")), goods, freight, now) + return game.board_caravan(world, player, body.get("id"), goods, freight, now) + if path == "/api/caravan/depart": + return game.depart_caravan(world, player, body.get("id"), now) + if path == "/api/caravan/cancel": + return game.cancel_caravan(world, player, body.get("id")) if path == "/api/council/vote": return game.vote_march(world, player, body.get("id"), bool(body.get("yes")), now) if path == "/api/charter": @@ -658,7 +670,7 @@ class Handler(BaseHTTPRequestHandler): "happenings": game.happenings_view(world, now), "history": history, "orders": world["orders"], - "kingdom": game.kingdom_view(world, now), + "kingdom": game.kingdom_view(world, now, uid), "city_speed": game.speed(world), "threat_report": unseen and {"id": unseen["id"], "kind": unseen["kind"], "at": unseen["resolved"], "report": unseen["report"]}, diff --git a/game.py b/game.py index 8b7d599..a6d24a1 100644 --- a/game.py +++ b/game.py @@ -1650,6 +1650,13 @@ BUILDINGS = { "final": {"yew_logs": 40, "yew_frame": 4, "bear_leather": 40, "rune_lock": 6}, "effect": "Per level: +3 bank slots, +250 stack size", }, + "roads": { + "name": "Roads", "icon": "๐ค๏ธ", "max": 3, "gold": 200, + "base": {"stone": 600, "logs": 300, "provisions": 60, "copper_rivets": 40}, + "advanced": {"cut_stone": 80, "beam": 10, "iron_nails": 100}, + "late": {"oak_frame": 4, "hide_glue": 30, "steel_hinges": 15}, + "effect": "Caravans on this town's roads: faster, bigger, fewer ambushes", + }, } # Buildings rise by labour: players working the site, and a slow trickle from # the townsfolk so nothing stalls completely while everyone is away. @@ -1684,7 +1691,7 @@ RAID_TRAITS = ["lightly armoured, heavy on archers", "mounted and fast, few bows # --- world --------------------------------------------------------------- -WORLD_VERSION = 42 +WORLD_VERSION = 43 HOME_CITY = "guildhall" CITY_KEYS = ("events", "next_event_at", "next_minor_at", "next_hardship_at", "next_fortune_at", "caravan", "orders") TRAVEL_TIME = 12 * 60 # game seconds on the road between two towns @@ -1705,6 +1712,21 @@ MARCH_TIME = 20 * HOUR # guards on the road, as a unit, between any two towns VOTE_TIME = HOUR # how long the war council has before the votes cast decide MAIN_ASSAULT = (1.5, 0.75) # how the bandits weigh their main target against the rest, kingdom total unchanged MAIN_TIER = 2 # a town has to be this big to draw it, and it takes two such towns +# Caravans: players crew a wagon train. Each road level, at either end, helps every caravan on that road. +CARAVAN_TIME = HOUR # game seconds town to town, on bare tracks +CARAVAN_LOAD = 1000 # items each crew member can carry +CARAVAN_WAIT = 2 * HOUR # a caravan that never sets off unloads again after this +FREIGHT_WAIT = 48 * HOUR # town stock the council sent, if no caravan takes it, goes back after this +CARRIAGE = 0.05 # of a town shipment's worth, paid in favour to the crew at the far end +ROAD_SPEED = 0.1 # less time per road level... +ROAD_LOAD = 0.25 # ...more load... +ROAD_SAFETY = 0.1 # ...and fewer ambushes +AMBUSH_ODDS = 0.3 # a full caravan's chance of an ambush, on bare tracks: bandits go for what's worth robbing +AMBUSH_MOST = 5 # how many ambushes can count for or against any one raid +AMBUSH_SHARE = 0.05 # an ambush party's size, against the raid it's from +AMBUSH_WEAKEN = 0.02 # the raid loses this much if its ambush is beaten... +AMBUSH_FEED = 0.02 # ...and gains this much if the ambush succeeds +AMBUSH_LOSS = 0.3 # of the cargo gone when it does 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 @@ -1795,7 +1817,7 @@ def new_world(now: float, speed: float = 1.0) -> World: "players": {}, "cities": {HOME_CITY: _new_city(now, speed, "Guildhall")}, "charter": None, - "marches": [], "council": [], "next_march_id": 1, + "marches": [], "council": [], "next_march_id": 1, "convoys": [], "freight": [], "next_event_id": 1, "ledger": [], "board": [], @@ -2073,6 +2095,12 @@ def migrate(world: dict, now: float | None = None) -> World: if player["at"] != HOME_CITY: player["town_favour"][HOME_CITY], player["favour"] = player["favour"], 0 world["version"] = 42 + if world["version"] < 43: + # Caravans, and roads for them. + for city in world.doc["cities"].values(): + city["buildings"].setdefault("roads", {"level": 0, "damaged": False, "fund": {}, "fittings": []}) + world.doc.update(convoys=[], freight=[]) + world["version"] = 43 return world @@ -4704,7 +4732,7 @@ def propose_march(world: World, player: dict, source: str, target: str, guards, return "Pick two towns" if not isinstance(guards, int) or guards < 1: return "Send at least one guard" - if any(p["status"] == "open" and p["from"] == source for p in world["council"]): + if any(p["status"] == "open" and p["from"] == source and "items" not in p for p in world["council"]): return f"{cities[source]['name']} already has a march before the council" ready = guards_on_duty(world.at(source)) if guards > ready: @@ -4745,13 +4773,16 @@ def _count_votes(world: World, proposal: dict, now: float) -> None: def _close_vote(world: World, proposal: dict, passed: bool, now: float) -> None: proposal["closed"] = now proposal["status"] = "rejected" + freight = "items" in proposal if passed: - proposal["status"] = "sent" if _send_guards(world, proposal, now) else "failed" + proposal["status"] = "sent" if (_ship_freight if freight else _send_guards)(world, proposal, now) else "failed" cities = world.doc["cities"] if proposal["status"] == "failed": - log(world, now, "raid", f"The war council's march from {cities[proposal['from']]['name']} found no guards at their posts") + log(world, now, "raid", f"The war council's shipment from {cities[proposal['from']]['name']} found nothing left to send" if freight + else f"The war council's march from {cities[proposal['from']]['name']} found no guards at their posts") elif proposal["status"] == "rejected": - log(world, now, "raid", f"The war council kept the guards in {cities[proposal['from']]['name']}") + log(world, now, "raid", f"The war council kept the goods in {cities[proposal['from']]['name']}" if freight + else f"The war council kept the guards in {cities[proposal['from']]['name']}") def _send_guards(world: World, proposal: dict, now: float) -> bool: @@ -4776,16 +4807,300 @@ def _send_guards(world: World, proposal: dict, now: float) -> bool: return True +def propose_freight(world: World, player: dict, target: str, item, qty, now: float) -> str | None: + """Ask the war council to send town stock to another town. A caravan still has to carry it.""" + if target not in world.doc["cities"] or target == world.here: + return "Pick another town" + if item not in ITEMS: + return "No such item" + if not isinstance(qty, int) or qty < 1: + return "Send at least one" + have = world["city"]["stockpile"].get(item, 0) + if qty > have: + return f"The stockpile holds {have:,} / {qty:,}" + proposal = {"id": world["next_march_id"], "by": player["id"], "from": world.here, "to": target, "items": {item: qty}, + "at": now, "ends": now + VOTE_TIME / speed(world), "yes": [player["id"]], "no": [], "status": "open"} + world["next_march_id"] += 1 + world["council"].append(proposal) + del world["council"][:-20] + log(world, now, "order", f"{player['name']} asked the war council to send {amount(item, qty)} to " + f"{world.doc['cities'][target]['name']}", player["id"]) + _count_votes(world, proposal, now) + return None + + +def _ship_freight(world: World, proposal: dict, now: float) -> bool: + """The goods leave the stockpile and wait at the gate for a caravan.""" + stock = world.at(proposal["from"])["city"]["stockpile"] + items = {} + for item, qty in proposal["items"].items(): + take = min(qty, stock.get(item, 0)) + if take: + take_stock_qty(stock, item, take) + items[item] = take + if items: + world["freight"].append({"id": proposal["id"], "from": proposal["from"], "to": proposal["to"], "items": items, "at": now}) + log(world.at(proposal["from"]), now, "order", f"{_listing(items)} waits at the gate for a caravan to {world.doc['cities'][proposal['to']]['name']}") + return bool(items) + + +def road_level(world: World, source: str, target: str) -> int: + """How good the road between two towns is: both ends' road works count.""" + return building_level(world.at(source), "roads") + building_level(world.at(target), "roads") + + +def caravan_route(world: World, source: str, target: str) -> dict: + """How long a caravan takes on this road, what each crew member carries, and its odds of an ambush.""" + level = road_level(world, source, target) + return {"time": CARAVAN_TIME * (1 - ROAD_SPEED * level) / speed(world), "load": int(CARAVAN_LOAD * (1 + ROAD_LOAD * level)), + "odds": AMBUSH_ODDS * (1 - ROAD_SAFETY * level), "level": level} + + +def _store_for(player: dict, town: str, item: str, qty: int) -> None: + """Put something in the player's bank in that town, wherever they are.""" + bank = player["bank"] if player["at"] == town else player["banks"].setdefault(town, {}) + bank[item] = bank.get(item, 0) + qty + + +def _convoy_load(convoy: dict) -> int: + return sum(qty for goods in convoy["goods"].values() for qty in goods.values()) + sum(convoy["freight"].values()) + + +def _in_caravan(world: World, player: dict) -> dict | None: + return next((c for c in world["convoys"] if player["id"] in c["crew"]), None) + + +def _load_caravan(world: World, convoy: dict, player: dict, goods: dict, freight: list, crew: int) -> str | None: + """Your own goods from your bank, then as much of the town's waiting shipments as fits.""" + room = caravan_route(world, convoy["from"], convoy["to"])["load"] * crew - _convoy_load(convoy) + for item, qty in goods.items(): + if not isinstance(qty, int) or qty < 1: + return "Load at least one" + if player["bank"].get(item, 0) < qty: + return "You don't have that" + if sum(goods.values()) > room: + return f"The wagons hold {room:,} more" + room -= sum(goods.values()) + mine = convoy["goods"].setdefault(player["id"], {}) + for item, qty in goods.items(): + bank_take(player, item, qty) + mine[item] = mine.get(item, 0) + qty + for shipment in world["freight"]: + if shipment["id"] not in freight or shipment["from"] != convoy["from"] or shipment["to"] != convoy["to"]: + continue + for item in list(shipment["items"]): + take = min(room, shipment["items"][item]) + if take: + take_stock_qty(shipment["items"], item, take) + convoy["freight"][item] = convoy["freight"].get(item, 0) + take + room -= take + world["freight"] = [shipment for shipment in world["freight"] if shipment["items"]] + return None + + +def form_caravan(world: World, player: dict, target: str, goods: dict, freight: list, now: float) -> str | None: + """Start loading a caravan here. Others can join it until you set off.""" + if target not in world.doc["cities"] or target == world.here: + return "Pick another town" + if _in_caravan(world, player): + return "You're already with a caravan" + convoy = {"id": world["next_march_id"], "from": world.here, "to": target, "leader": player["id"], "crew": [player["id"]], + "goods": {}, "freight": {}, "status": "loading", "at": now} + error = _load_caravan(world, convoy, player, goods, freight, 1) + if error: + return error + world["next_march_id"] += 1 + world["convoys"].append(convoy) + log(world, now, "order", f"{player['name']} is loading a caravan for {world.doc['cities'][target]['name']}", player["id"]) + return None + + +def board_caravan(world: World, player: dict, convoy_id, goods: dict, freight: list, now: float) -> str | None: + """Join a caravan loading here, or load more on the one you're with.""" + convoy = next((c for c in world["convoys"] if c["id"] == convoy_id), None) + if not convoy or convoy["status"] != "loading": + return "That caravan has gone" + if convoy["from"] != world.here: + return "That caravan is in another town" + other = _in_caravan(world, player) + if other and other is not convoy: + return "You're already with a caravan" + joining = player["id"] not in convoy["crew"] + error = _load_caravan(world, convoy, player, goods, freight, len(convoy["crew"]) + joining) + if error: + return error + if joining: + convoy["crew"].append(player["id"]) + return None + + +def _unload(world: World, convoy: dict) -> None: + """A caravan that won't go: goods back to their owners, town goods back to the gate.""" + for uid, goods in convoy["goods"].items(): + owner = world["players"].get(uid) + for item, qty in goods.items(): + if owner: + _store_for(owner, convoy["from"], item, qty) + if convoy["freight"]: + world["freight"].append({"id": convoy["id"], "from": convoy["from"], "to": convoy["to"], "items": convoy["freight"], "at": convoy["at"]}) + + +def cancel_caravan(world: World, player: dict, convoy_id) -> str | None: + convoy = next((c for c in world["convoys"] if c["id"] == convoy_id and c["status"] == "loading"), None) + if not convoy or convoy["leader"] != player["id"]: + return "It isn't yours to call off" + _unload(world, convoy) + world["convoys"].remove(convoy) + return None + + +def depart_caravan(world: World, player: dict, convoy_id, now: float) -> str | None: + """Set off. Everyone aboard goes on the road: no work until it arrives. Anyone who left town stays behind, and their goods with them.""" + convoy = next((c for c in world["convoys"] if c["id"] == convoy_id and c["status"] == "loading"), None) + if not convoy or convoy["leader"] != player["id"]: + return "It isn't yours to send off" + route = caravan_route(world, convoy["from"], convoy["to"]) + source = world.at(convoy["from"]) + for uid in list(convoy["crew"]): + member = world["players"][uid] + if member["at"] != convoy["from"] or member["travel"]: + convoy["crew"].remove(uid) + for item, qty in convoy["goods"].pop(uid, {}).items(): + _store_for(member, convoy["from"], item, qty) + if not convoy["crew"]: + return "Nobody's left to crew it" + arrive = now + route["time"] + for uid in convoy["crew"]: + member = world["players"][uid] + current = member["action"] + if current and (current.get("party") or "order" in current): + drop_out(source, member, now, "Left with a caravan") + member["garrison"] = False + member["travel"] = {"from": convoy["from"], "to": convoy["to"], "left": now, "arrive": arrive, "pouch": {}, "convoy": convoy["id"]} + fullness = _convoy_load(convoy) / (route["load"] * len(convoy["crew"])) + convoy.update(status="road", left=now, arrive=arrive, midway=now + route["time"] / 2, odds=route["odds"] * fullness, rolled=False) + log(source, now, "order", f"A caravan set off for {world.doc['cities'][convoy['to']]['name']} with {len(convoy['crew'])} crew") + return None + + +def _ambush(world: World, convoy: dict, now: float, rng: random.Random) -> None: + """Halfway down the road, bandits may strike. They come from the bigger raid at either end: beat them + and that raid goes in weaker; lose and they make off with cargo and come back the stronger for it.""" + convoy["rolled"] = True + if rng.random() >= convoy["odds"]: + return + raids = [threat for threat in (upcoming_raid(world.at(convoy["from"])), upcoming_raid(world.at(convoy["to"]))) if threat and threat["kind"] == "raid"] + if not raids: + return + raid = max(raids, key=lambda threat: threat["strength"]) + counted = raid.get("ambushes", 0) < AMBUSH_MOST + raid["ambushes"] = raid.get("ambushes", 0) + 1 + band = raid["strength"] * AMBUSH_SHARE * rng.uniform(0.7, 1.3) + crew = [world["players"][uid] for uid in convoy["crew"]] + won = sum(combat_power(member) for member in crew) >= band + town = world.at(convoy["to"]) + if won: + if counted: + raid["sabotage"] = min(0.3, raid["sabotage"] + AMBUSH_WEAKEN) + for member in crew: + gain_xp(here(world, member), member, "combat", round(band), now) + note(world, member, now, "Ambushed", label="Beat them off") + log(town, now, "raid", f"Bandits fell on the caravan from {world.doc['cities'][convoy['from']]['name']} and were beaten off. The coming raid is weaker for it") + else: + for owner, goods in [*convoy["goods"].items(), (None, convoy["freight"])]: + for item in list(goods): + gone = max(1, int(goods[item] * AMBUSH_LOSS)) + take_stock_qty(goods, item, min(gone, goods[item])) + if counted: + raid["strength"] = round(raid["strength"] * (1 + AMBUSH_FEED), 1) + for member in crew: + note(world, member, now, "Ambushed", label="Lost cargo") + log(town, now, "raid", f"Bandits robbed the caravan from {world.doc['cities'][convoy['from']]['name']}. The coming raid is stronger for it") + convoy["ambush"] = "won" if won else "lost" + + +def _caravan_arrives(world: World, convoy: dict, now: float) -> None: + """The caravan is in: goods to their owners' banks there, town goods to its stockpile, and the crew earn their favour there.""" + target = convoy["to"] + for uid, goods in convoy["goods"].items(): + owner = world["players"].get(uid) + for item, qty in goods.items(): + if owner: + _store_for(owner, target, item, qty) + town = world.at(target) + stock = town["city"]["stockpile"] + for item, qty in convoy["freight"].items(): + stock[item] = stock.get(item, 0) + qty + fee = sum(ITEMS[item]["value"] * qty for item, qty in convoy["freight"].items()) * CARRIAGE / max(1, len(convoy["crew"])) + for uid in convoy["crew"] if fee else []: + member = world["players"][uid] + if member["at"] == target: + member["favour"] += fee + else: + member["town_favour"][target] = member["town_favour"].get(target, 0) + fee + log(town, now, "order", f"A caravan came in from {world.doc['cities'][convoy['from']]['name']}" + + (f" with {_listing(convoy['freight'])}" if convoy["freight"] else "")) + world["convoys"].remove(convoy) + + +def _caravan_road_tick(world: World, now: float, rng: random.Random) -> bool: + changed = False + for convoy in list(world["convoys"]): + if convoy["status"] == "loading": + if now >= convoy["at"] + CARAVAN_WAIT / speed(world): + _unload(world, convoy) + world["convoys"].remove(convoy) + changed = True + continue + if not convoy["rolled"] and now >= convoy["midway"]: + _ambush(world, convoy, now, rng) + changed = True + if now >= convoy["arrive"]: + _caravan_arrives(world, convoy, now) + changed = True + for shipment in list(world["freight"]): + if now >= shipment["at"] + FREIGHT_WAIT / speed(world): + stock = world.at(shipment["from"])["city"]["stockpile"] + for item, qty in shipment["items"].items(): + stock[item] = stock.get(item, 0) + qty + log(world.at(shipment["from"]), now, "order", f"{_listing(shipment['items'])} went back to the stockpile: no caravan came") + world["freight"].remove(shipment) + changed = True + return changed + + +def march_curve(world: World) -> list[float]: + """What sending 0, 1, 2โฆ of this town's guards takes from it and adds elsewhere: drill plus their kit, best first.""" + stock = world["city"]["stockpile"] + armed = guards_on_duty(world) + each = _militia(world) / max(1, guard_posts(world)) + values = {} + for slot, (stat, rate) in KIT_DEFENCE.items(): + line = [] + for item in sorted((i for i in stock if kit_slot(i) == slot), key=lambda i: -ITEMS[i].get(stat, 0)): + line += [ITEMS[item].get(stat, 0) * rate] * min(stock[item], armed - len(line)) + values[slot] = line + [0] * (armed - len(line)) + curve = [0.0] + kit = {slot: 0.0 for slot in KIT_DEFENCE} + for n in range(armed): + for slot in KIT_DEFENCE: + kit[slot] += values[slot][n] + total = sum(value for slot, value in kit.items() if slot != "salve") + min(SALVE_CAP, kit["salve"]) + curve.append(round(each * (n + 1) + total, 1)) + return curve + + def _threat_glance(world: World, now: float) -> dict | None: """What this town's scouts know of its coming threat, for the war table.""" threat = upcoming_raid(world) if not threat: return None view = event_view(world, threat, now) - return {key: view[key] for key in ("id", "kind", "intel", "at_gates", "earliest", "latest", "exact", "size", "range", "strength", "main") if key in view} + return {key: view[key] for key in ("id", "kind", "intel", "at_gates", "earliest", "latest", "exact", "headline", "size", "range", "strength", + "main", "group", "trait", "camp", "sabotage", "recon", "recon_next") if key in view} -def kingdom_view(world: World, now: float) -> dict: +def kingdom_view(world: World, now: float, viewer: str | None = None) -> dict: """Every town at a glance, and what's on the road.""" cities = [] for key, city in world.doc["cities"].items(): @@ -4797,7 +5112,11 @@ def kingdom_view(world: World, now: float) -> dict: "tier": TIERS[city["tier"]]["name"], "repelled": city["repelled"], "people": [p["id"] for p in people], "founded": city["founded"], "defence": guard["total"], "guards": guard["guards"], "posts": guard["posts"], "away": guard["away"], - "garrison": [entry["id"] for entry in guard["garrison"]], "threat": _threat_glance(town, now)}) + "garrison": [entry["id"] for entry in guard["garrison"]], "threat": _threat_glance(town, now), + "problems": [{"name": PROBLEMS[problem["kind"]]["name"], "icon": PROBLEMS[problem["kind"]]["icon"]} + for problem in city["problems"] if problem["kind"] in MINOR_THREATS], + "curve": march_curve(town), "roads": building_level(town, "roads"), + "route": None if key == world.here else caravan_route(world, world.here, key)}) charter = world["charter"] return {"cities": cities, "charter": charter, "pouch": {"slots": POUCH_SLOTS, "stack": POUCH_STACK}, "founding": FOUNDING, "max": MAX_CITIES, "short": _founding_short(world), @@ -4805,6 +5124,11 @@ def kingdom_view(world: World, now: float) -> dict: "council": [p for p in world["council"] if p["status"] == "open" or now - p.get("closed", now) < 6 * HOUR / speed(world)], "marches": [{key: march[key] for key in ("id", "from", "to", "guards", "arrive", "status")} | {"power": march_power(march)} for march in world["marches"]], + "caravans": [{key: convoy.get(key) for key in ("id", "from", "to", "leader", "crew", "status", "arrive", "ambush")} + | {"load": _convoy_load(convoy), "room": caravan_route(world, convoy["from"], convoy["to"])["load"] * len(convoy["crew"]), + "mine": convoy["goods"].get(viewer) if viewer else None, "freight": convoy["freight"]} + for convoy in world["convoys"]], + "freight": world["freight"], "road": [{"id": p["id"], **{k: p["travel"][k] for k in ("from", "to", "arrive")}} for p in world["players"].values() if p["travel"]]} @@ -5327,9 +5651,9 @@ def _pay_guards(world: dict, report: dict) -> None: city["wages"] = city.get("wages", 0) - report["guards"] * GUARD_WAGE -def _muster_tick(world: World, now: float) -> bool: - """Close the votes whose hour is up and move the companies on the road.""" - changed = False +def _muster_tick(world: World, now: float, rng: random.Random | None = None) -> bool: + """Close the votes whose hour is up and move the companies and caravans on the road.""" + changed = _caravan_road_tick(world, now, rng or random.Random()) for proposal in world["council"]: if proposal["status"] == "open" and now >= proposal["ends"]: _close_vote(world, proposal, len(proposal["yes"]) > len(proposal["no"]), now) @@ -5363,7 +5687,7 @@ def _march_on(world: World, march: dict, now: float) -> None: def tick(world: World, now: float, rng: random.Random | None = None) -> bool: """Advance every town and its events to `now`. Returns True if anything changed.""" rng = rng or random.Random() - changed = _muster_tick(world, now) + changed = _muster_tick(world, now, rng) for key in list(world.doc["cities"]): changed = _tick_city(world.at(key), now, rng) or changed return changed @@ -7231,7 +7555,7 @@ BUILDING_GLYPHS = { "houses": ("house", "#d0a060"), "walls": ("stone-wall", "#a8a29e"), "barracks": ("barracks-tent", "#c06a4a"), "smithy": ("anvil", "#d07a3c"), "temple": ("temple-gate", "#e9dfc6"), "granary": ("granary", "#e3c060"), "lumber_shed": ("wood-pile", "#b9844e"), "well": ("well", "#5aa0d8"), "spymaster": ("hooded-figure", "#8a7fd0"), - "storehouse": ("wooden-crate", "#b9844e"), + "storehouse": ("wooden-crate", "#b9844e"), "roads": ("stone-path", "#b6a587"), } ACTION_GLYPHS = { "fight_wolves": ("wolf-head", "#9aa1ab"), "fight_scouts": ("hooded-assassin", "#a08060"), @@ -7426,6 +7750,13 @@ ORDER_RECIPES, ORDER_RAW = _order_sources() # What changed, shown on the Patch notes page. Newest first; every shipped change adds a # line here (new / balance / fix), and a new release a new entry on top. PATCH_NOTES = [ + {"date": "2026-11-04", "title": "Caravans", "notes": [ + ("new", "Caravans: carry goods between towns. 1h, 1,000 items per crew member. Everyone aboard stops work until it arrives."), + ("new", "Town stock: war council vote, then a caravan carries it. Crew earn 5% of its worth in favour at the far end."), + ("new", "Roads: new building, 3 levels. Each level at either end: -10% time, +25% load, -10% ambush odds."), + ("new", "Ambushes: up to 30% per trip, the fuller the likelier. Win: the coming raid -2%. Lose: 30% of the cargo gone, raid +2%. Up to 5 count per raid."), + ("new", "War table: every town's threat and minor troubles, as far as its scouts know. Marches show defence before and after, for both towns."), + ]}, {"date": "2026-11-04", "title": "Favour per town", "notes": [ ("new", "Favour is earned and spent per town. What you've saved so far stays in Guildhall."), ("new", "Bank slots: favour price starts at 500 and gold at 1,000 in each town, rising there. New ones work only in that town. Ones you already own work everywhere."), diff --git a/static/app.js b/static/app.js index 394e6f4..5f010cd 100644 --- a/static/app.js +++ b/static/app.js @@ -934,15 +934,81 @@ function pageHtml() { // --- kingdom ---------------------------------------------------------------- let pouch = {}; +let cargo = {}; +const cargoFreight = new Set(); function votesWaiting() { return S.kingdom.council.filter((p) => p.status === "open" && !p.yes.includes(S.uid) && !p.no.includes(S.uid)).length; } -function threatLine(t) { - if (!t) return `
No threat rumoured
`; - const size = t.strength ? fmt(t.strength) : t.range ? `${fmt(t.range[0])} - ${fmt(t.range[1])}` : t.size || "?"; - return `${eventIcon(t.kind)} ${eventWhen(t, true)} ยท ${esc(String(size))}${t.main ? ` Main assault` : ""}
`; +function threatSize(t) { + return t?.strength ? fmt(t.strength) : t?.range ? `${fmt(t.range[0])} - ${fmt(t.range[1])}` : t?.size || "?"; +} + +function threatLine(t, problems) { + const trouble = problems.length ? `${problems.map((p) => `${p.icon} ${esc(p.name)}`).join(" ยท ")}
` : ""; + if (!t) return `No threat rumoured
${trouble}`; + const pips = [1, 2, 3].map((n) => n <= t.intel ? "โ" : "โ").join(""); + return `${eventIcon(t.kind)} ${pips} ${eventWhen(t, true)} ยท ${esc(String(threatSize(t)))}${t.main ? ` Main assault` : ""}
+ ${t.group || t.trait || t.sabotage ? `${[t.group && upperFirst(t.group), t.trait, t.sabotage && `-${t.sabotage}%`].filter(Boolean).map((x) => esc(String(x))).join(" ยท ")}
` : ""}${trouble}`; +} + +const upperFirst = (s) => s[0].toUpperCase() + s.slice(1); + +// How a town's defence stands up to what its scouts know: โ holds, โ ๏ธ too close to call, โ falls, โ unknown. +function holds(defence, t) { + if (!t || !(t.strength || t.range)) return "โ"; + const low = t.strength || t.range[0], high = t.strength || t.range[1]; + return defence >= high ? "โ " : defence < low ? "โ" : "โ ๏ธ"; +} + +// What a march does to both towns: defence now โ after, against each town's threat as scouted. +function marchImpact(source, target, guards) { + const k = S.kingdom, from = k.cities.find((c) => c.id === source), to = k.cities.find((c) => c.id === target); + if (!from || !to || source === target) return ""; + const n = Math.max(0, Math.min(guards || 0, from.curve.length - 1)), power = from.curve[n]; + const incoming = k.marches.filter((m) => m.to === to.id && m.status === "marching").reduce((sum, m) => sum + m.power, 0); + const row = (c, now, after) => `${esc(c.name)} ๐ก๏ธ ${fmt(now)} โ ${fmt(after)} vs ${c.threat ? eventIcon(c.threat.kind) : ""} ${esc(String(threatSize(c.threat)))} ${holds(after, c.threat)}`; + return `${list(c.mine)} ${list(c.freight)}
` : ""}`; + }; + const waiting = k.freight.map((f) => `${Object.entries(cargo).map(([id, qty]) => ``).join(" ") || `Your bank goods, none yet`}
+โฑ ${dur(route.time)} ยท ๐ฆ ${fmt(route.load)} per crew ยท โ๏ธ up to ${Math.round(route.odds * 100)}% ambush ยท ๐ค๏ธ ${route.level}
` : ""}`} +None on the road
`} + ${forming} +๐ค๏ธ ${dur(C.march_time / S.city_speed)} ยท vote ${dur(C.vote_time / S.city_speed)} ยท one fight, then home
`; } @@ -990,8 +1059,8 @@ function kingdom() { const region = k.regions[c.region]; return `${esc(c.tier)} ยท ๐ฅ ${fmt(c.population)} ยท ๐ ${fmt(c.repelled)}${road ? ` ยท ๐ค๏ธ ${road}` : ""}
- ${threatLine(c.threat)} +${esc(c.tier)} ยท ๐ฅ ${fmt(c.population)} ยท ๐ ${fmt(c.repelled)}${road ? ` ยท ๐ถ ${road}` : ""}${c.roads ? ` ยท ๐ค๏ธ ${c.roads}` : ""}
+ ${threatLine(c.threat, c.problems)}๐ก๏ธ ${fmt(c.defence)} ยท ๐ ${fmt(c.guards)} / ${fmt(c.posts - c.away)}${c.away ? ` ยท ๐ค๏ธ ${fmt(c.away)}` : ""}${c.garrison.length ? ` ยท ๐ฐ ${c.garrison.map((uid) => esc(playerName(uid))).join(", ")}` : ""}
${region ? `${region.icon} ${esc(region.name)} ยท ${regionPerks(region, c.town_scale)}
` : ""}${c.people.length ? c.people.map((uid) => esc(playerName(uid))).join(", ") : `Nobody here`}
@@ -1025,7 +1094,7 @@ function kingdom() {