Siegeworks: traps, engines, Outworks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2bfc430f19
commit
c35c2289e2
5 changed files with 242 additions and 14 deletions
127
game.py
127
game.py
|
|
@ -157,6 +157,17 @@ BAG_STACK = [250, 500, 750, 1000, 1500, 2000]
|
|||
# planks and hardware. A building takes one in place of FRAME_FOR_PLANKS planks.
|
||||
FRAME_PLANKS = 4
|
||||
FRAME_FOR_PLANKS = 5
|
||||
FRAME_XP = [24, 52, 80, 112, 148, 192]
|
||||
# Siegeworks: what frames are finally for. Both stand in the Outworks. Traps are sprung and gone
|
||||
# in every raid and can't reach a dragon; engines stay, wear like guard kit and shoot at both.
|
||||
TRAP_NAMES = ["Stake field", "Spike pit", "Snare line", "Spike trap", "Deadfall", "Runed pit"]
|
||||
ENGINE_NAMES = ["Bolt thrower", "Scorpion", "Ballista", "Catapult", "Trebuchet", "Spellbound trebuchet"]
|
||||
TRAP_POWER = [1, 2.5, 4.5, 7, 10, 14]
|
||||
ENGINE_POWER = [5, 12, 22, 35, 50, 70]
|
||||
ENGINE_FRAMES = 3
|
||||
OUTWORKS_TRAPS = 20 # per Outworks level
|
||||
OUTWORKS_TRAPS_PER_WIN = 2 # per Outworks level, per win since the Outworks came in
|
||||
OUTWORKS_ENGINES = 4 # per Outworks level
|
||||
|
||||
# item id, name, icon, value, action id, verb
|
||||
TREES = [
|
||||
|
|
@ -419,6 +430,10 @@ for _tier, _wood in enumerate(WOODS):
|
|||
_hardware, *_rest, _made = HARDWARE[_tier]
|
||||
ITEMS[f"{_wood}_frame"] = {"name": f"{WOOD_NAMES[_tier]} frame", "icon": "🪟", "tier": _tier, "value": round(
|
||||
(FRAME_PLANKS * ITEMS[PLANKS[_tier][0]]["value"] + _made * ITEMS[_hardware]["value"]) * CRAFT_MARKUP)}
|
||||
ITEMS[f"{_wood}_trap"] = {"name": TRAP_NAMES[_tier], "plural": f"{TRAP_NAMES[_tier]}s", "icon": "🪤", "tier": _tier,
|
||||
"siege": "trap", "siege_power": TRAP_POWER[_tier], "value": 0}
|
||||
ITEMS[f"{_wood}_engine"] = {"name": ENGINE_NAMES[_tier], "plural": f"{ENGINE_NAMES[_tier]}s", "icon": "🏹", "tier": _tier,
|
||||
"siege": "engine", "siege_power": ENGINE_POWER[_tier], "value": 0}
|
||||
for _tier, (_fibre, _level, _time, _xp, _cloth, _prefix, _label) in enumerate(CLOTHS):
|
||||
ITEMS[f"{_prefix}_bag"] = {"name": f"{_label} bag", "icon": "👜", "tier": _tier, "slot": "bag",
|
||||
"stack": BAG_STACK[_tier], "value": 0}
|
||||
|
|
@ -1422,9 +1437,15 @@ ACTIONS = [
|
|||
[6, 14, 22, 32, 44, 58][tier], {TREES[tier][0]: 2}, {plank: 1}, group="Planks")
|
||||
for tier, (plank, name) in enumerate(PLANKS)],
|
||||
*[_action(f"make_{wood}_frame", "construction", f"{WOOD_NAMES[tier]} frame", TIER_LEVELS[tier] + 11, 45 + 2 * tier,
|
||||
[24, 52, 80, 112, 148, 192][tier], {PLANKS[tier][0]: FRAME_PLANKS, HARDWARE[tier][0]: HARDWARE[tier][4]},
|
||||
FRAME_XP[tier], {PLANKS[tier][0]: FRAME_PLANKS, HARDWARE[tier][0]: HARDWARE[tier][4]},
|
||||
{f"{wood}_frame": 1}, group="Frames")
|
||||
for tier, wood in enumerate(WOODS)],
|
||||
*[_action(f"make_{wood}_trap", "construction", TRAP_NAMES[tier], TIER_LEVELS[tier] + 14, 60 + 3 * tier,
|
||||
2 * FRAME_XP[tier], {f"{wood}_frame": 1}, {f"{wood}_trap": 1}, group="Siegeworks")
|
||||
for tier, wood in enumerate(WOODS)],
|
||||
*[_action(f"make_{wood}_engine", "construction", ENGINE_NAMES[tier], TIER_LEVELS[tier] + 18, 150 + 5 * tier,
|
||||
5 * FRAME_XP[tier], {f"{wood}_frame": ENGINE_FRAMES}, {f"{wood}_engine": 1}, group="Siegeworks")
|
||||
for tier, wood in enumerate(WOODS)],
|
||||
_action("mason_bricks", "construction", "Bricks", 1, 25, 6, {"stone": 2, "logs": 1}, {"bricks": 2}, group="Masonry",
|
||||
fire="kiln", fuel=0),
|
||||
_action("mason_cut_stone", "construction", "Cut stone", 10, 30, 12, {"stone": 3}, {"cut_stone": 1}, group="Masonry"),
|
||||
|
|
@ -1657,6 +1678,14 @@ BUILDINGS = {
|
|||
"late": {"oak_frame": 4, "hide_glue": 30, "steel_hinges": 15},
|
||||
"effect": "Caravans on this town's roads: faster, bigger, fewer ambushes",
|
||||
},
|
||||
"outworks": {
|
||||
"name": "Outworks", "icon": "🪤", "max": 5, "gold": 300,
|
||||
"base": {"logs": 300, "stone": 300, "rope": 30, "provisions": 60, "copper_rivets": 40},
|
||||
"advanced": {"cut_stone": 80, "beam": 15, "iron_nails": 100},
|
||||
"late": {"maple_frame": 20, "hide_glue": 40, "steel_hinges": 30},
|
||||
"final": {"yew_frame": 30, "bear_leather": 40, "adamant_chain": 15},
|
||||
"effect": "Per level: 20 traps (+2 per win), 4 engines",
|
||||
},
|
||||
}
|
||||
# Buildings rise by labour: players working the site, and a slow trickle from
|
||||
# the townsfolk so nothing stalls completely while everyone is away.
|
||||
|
|
@ -1691,7 +1720,7 @@ RAID_TRAITS = ["lightly armoured, heavy on archers", "mounted and fast, few bows
|
|||
|
||||
# --- world ---------------------------------------------------------------
|
||||
|
||||
WORLD_VERSION = 43
|
||||
WORLD_VERSION = 44
|
||||
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
|
||||
|
|
@ -1796,6 +1825,7 @@ def _new_city(now: float, speed: float, name: str) -> dict:
|
|||
"food_due": 0.0,
|
||||
"starving": False,
|
||||
"repelled": 0,
|
||||
"works_base": 0,
|
||||
"fires": {key: new_fire(now) for key in FIRES},
|
||||
"wages": 0, "monuments": {}, "built": [], "carving": None,
|
||||
"happiness": 0.5, "clothes_due": 0.0, "unheated": False,
|
||||
|
|
@ -2101,6 +2131,12 @@ def migrate(world: dict, now: float | None = None) -> World:
|
|||
city["buildings"].setdefault("roads", {"level": 0, "damaged": False, "fund": {}, "fittings": []})
|
||||
world.doc.update(convoys=[], freight=[])
|
||||
world["version"] = 43
|
||||
if world["version"] < 44:
|
||||
# Siegeworks. Trap slots grow with wins from here on, not with the ones already won.
|
||||
for city in world.doc["cities"].values():
|
||||
city["buildings"].setdefault("outworks", {"level": 0, "damaged": False, "fund": {}, "fittings": []})
|
||||
city["works_base"] = city["repelled"]
|
||||
world["version"] = 44
|
||||
return world
|
||||
|
||||
|
||||
|
|
@ -5441,7 +5477,7 @@ def _trouble(world: dict, now: float, rng: random.Random) -> None:
|
|||
|
||||
def kit_slot(item: str) -> str | None:
|
||||
"""Where a defender carries it: a gear slot, or city-only kit like guard jerkins."""
|
||||
return ITEMS[item].get("slot") or ITEMS[item].get("kit")
|
||||
return ITEMS[item].get("slot") or ITEMS[item].get("kit") or ITEMS[item].get("siege")
|
||||
|
||||
|
||||
def best_kit(stock: dict, slot: str, stat: str, people: int) -> float:
|
||||
|
|
@ -5510,6 +5546,14 @@ def wear_kit(world: dict, share: float, rng: random.Random) -> dict:
|
|||
take_stock_qty(stock, item, lost)
|
||||
broken[item] = lost
|
||||
breaks -= lost
|
||||
placed = placed_works(world, "engine")
|
||||
breaks = int(sum(take for _item, take in placed) * share + rng.random()) if placed else 0
|
||||
for item, take in reversed(placed):
|
||||
lost = min(breaks, take)
|
||||
if lost:
|
||||
take_stock_qty(stock, item, lost)
|
||||
broken[item] = lost
|
||||
breaks -= lost
|
||||
return broken
|
||||
|
||||
|
||||
|
|
@ -5558,6 +5602,47 @@ def _militia(world: World) -> float:
|
|||
* mood(world)["militia"])
|
||||
|
||||
|
||||
def trap_slots(world: World) -> int:
|
||||
"""How many traps the Outworks can have laid. Every win since the Outworks came in makes room for more."""
|
||||
wins = max(0, world["city"]["repelled"] - world["city"]["works_base"])
|
||||
return building_level(world, "outworks") * (OUTWORKS_TRAPS + OUTWORKS_TRAPS_PER_WIN * wins)
|
||||
|
||||
|
||||
def engine_slots(world: World) -> int:
|
||||
return building_level(world, "outworks") * OUTWORKS_ENGINES
|
||||
|
||||
|
||||
def placed_works(world: World, kind: str) -> list[tuple[str, int]]:
|
||||
"""The traps or engines standing in the Outworks, best first. The rest are spares in the stockpile."""
|
||||
stock = world["city"]["stockpile"]
|
||||
room = trap_slots(world) if kind == "trap" else engine_slots(world)
|
||||
placed = []
|
||||
for item in sorted((i for i in stock if ITEMS[i].get("siege") == kind), key=lambda i: -ITEMS[i]["siege_power"]):
|
||||
if not room:
|
||||
break
|
||||
take = min(room, stock[item])
|
||||
placed.append((item, take))
|
||||
room -= take
|
||||
return placed
|
||||
|
||||
|
||||
def works_defence(world: World, kind: str) -> float:
|
||||
return round(sum(ITEMS[item]["siege_power"] * qty for item, qty in placed_works(world, kind)), 1)
|
||||
|
||||
|
||||
def placed_value(world: World) -> float:
|
||||
"""What's standing in the Outworks is no plunder: only spares count towards a town's wealth."""
|
||||
return sum(ITEMS[item]["value"] * qty for kind in ("trap", "engine") for item, qty in placed_works(world, kind))
|
||||
|
||||
|
||||
def use_traps(world: World) -> dict:
|
||||
"""A raid springs every trap laid for it, win or lose."""
|
||||
sprung = dict(placed_works(world, "trap"))
|
||||
for item, qty in sprung.items():
|
||||
take_stock_qty(world["city"]["stockpile"], item, qty)
|
||||
return sprung
|
||||
|
||||
|
||||
def marched_here(world: World) -> list[dict]:
|
||||
"""Guards from other towns standing here now."""
|
||||
return [march for march in world["marches"] if march["to"] == world.here and march["status"] == "there"]
|
||||
|
|
@ -5569,7 +5654,7 @@ def march_power(march: dict) -> float:
|
|||
return round(march["militia"] + kit + min(SALVE_CAP, kit_defence(march["kit"], "salve", march["guards"])), 1)
|
||||
|
||||
|
||||
def defence(world: dict, guards: int | None = None) -> dict:
|
||||
def defence(world: dict, guards: int | None = None, dragon: bool = False) -> dict:
|
||||
"""The city's defence right now, part by part. `guards` overrides how many are on duty."""
|
||||
city = world["city"]
|
||||
pop = city["population"]
|
||||
|
|
@ -5586,6 +5671,8 @@ def defence(world: dict, guards: int | None = None) -> dict:
|
|||
"jerkins": kit_defence(stock, "jerkin", armed),
|
||||
"salves": min(SALVE_CAP, kit_defence(stock, "salve", armed)),
|
||||
"arrows": min(100, stock.get("arrows", 0) // 10),
|
||||
"traps": 0 if dragon else works_defence(world, "trap"),
|
||||
"engines": works_defence(world, "engine"),
|
||||
"drilled": round(drilled(world), 1),
|
||||
"rallied": city.get("rally", 0), # favour bought before drilling existed; gone after the next raid
|
||||
"ward": ward(world),
|
||||
|
|
@ -5609,13 +5696,15 @@ def defence(world: dict, guards: int | None = None) -> dict:
|
|||
return {"parts": parts, "garrison": garrison, "total": round(total, 1), "starving": city["starving"],
|
||||
"guards": armed, "posts": posts, "away": guards_away(world), "wages": int(city.get("wages", 0)), "wage": GUARD_WAGE,
|
||||
"helping": [{"from": march["from"], "guards": march["guards"], "power": march_power(march)} for march in helping],
|
||||
"kit": {slot: issued_kit(world, slot, max(0, posts - guards_away(world))) for slot in KIT_DEFENCE}}
|
||||
"kit": {slot: issued_kit(world, slot, max(0, posts - guards_away(world))) for slot in KIT_DEFENCE},
|
||||
"works": {"trap": placed_works(world, "trap"), "engine": placed_works(world, "engine"),
|
||||
"trap_slots": trap_slots(world), "engine_slots": engine_slots(world)}}
|
||||
|
||||
|
||||
def standing_defence(world: dict) -> float:
|
||||
"""What the city holds with every guard post paid and no one preparing: walls, guards, kit, arrows."""
|
||||
parts = defence(world, guards=guard_posts(world))["parts"]
|
||||
return sum(v for k, v in parts.items() if k not in ("drilled", "rallied", "ward", "mercenaries", "garrison"))
|
||||
return sum(v for k, v in parts.items() if k not in ("traps", "drilled", "rallied", "ward", "mercenaries", "garrison"))
|
||||
|
||||
|
||||
def pay_wages(world: dict, player: dict, qty, source: str, now: float) -> str | None:
|
||||
|
|
@ -5823,7 +5912,7 @@ def city_age(world: World, now: float) -> float:
|
|||
def threat_base(world: World, now: float) -> float:
|
||||
"""Bigger, richer and older towns draw bigger threats; every win draws a bolder one."""
|
||||
city = world["city"]
|
||||
wealth = city["treasury"] + stockpile_value(city)
|
||||
wealth = city["treasury"] + stockpile_value(city) - placed_value(world)
|
||||
return (15 + 5 * city_age(world, now) + 1.5 * city["population"] + 1.6 * math.sqrt(wealth)) * (1 + 0.08 * city["repelled"])
|
||||
|
||||
|
||||
|
|
@ -6047,6 +6136,9 @@ def raid_readiness(world: dict, event: dict) -> list[dict]:
|
|||
wants.append(("iron_shield", kit, "Shields (any)", "shield"))
|
||||
wants += [("leather_guard_jerkin", kit, "Body armour (any)", "jerkin"),
|
||||
("guam_leaf_salve", kit, "Salves (any)", "salve")]
|
||||
if building_level(world, "outworks"):
|
||||
wants += [("wooden_trap", trap_slots(world), "Traps (any)", "trap"),
|
||||
("wooden_engine", engine_slots(world), "Engines (any)", "engine")]
|
||||
requests = []
|
||||
for item, qty, label, counts in wants:
|
||||
if counts == "food":
|
||||
|
|
@ -6152,6 +6244,9 @@ def _resolve_raid(world: dict, event: dict, now: float, rng: random.Random) -> N
|
|||
lines = []
|
||||
if event["sabotage"]:
|
||||
lines.append(f"Sabotage weakened the raiders by {round(event['sabotage'] * 100)}%.")
|
||||
sprung = use_traps(world)
|
||||
if sprung:
|
||||
lines.append(f"The raiders ran into {_listing(sprung)}.")
|
||||
report = {
|
||||
"group": event["group"], "attack": round(attack), "defence": guard["total"],
|
||||
"parts": guard["parts"], "garrison": garrison, "guards": guard["guards"],
|
||||
|
|
@ -6183,8 +6278,9 @@ def _resolve_raid(world: dict, event: dict, now: float, rng: random.Random) -> N
|
|||
city["population"] = max(5.0, city["population"] - lost_people)
|
||||
share = min(0.9, (0.2 + 0.5 * severity) * shelter)
|
||||
taken = {}
|
||||
bolted = dict(placed_works(world, "engine"))
|
||||
for item in list(stock):
|
||||
gone = int(stock[item] * share)
|
||||
gone = int((stock[item] - bolted.get(item, 0)) * share)
|
||||
if gone:
|
||||
taken[item] = gone
|
||||
stock[item] -= gone
|
||||
|
|
@ -6231,7 +6327,7 @@ def _resolve_dragon(world: dict, event: dict, now: float, rng: random.Random) ->
|
|||
city = world["city"]
|
||||
stock = city["stockpile"]
|
||||
attack = event["strength"]
|
||||
guard = defence(world)
|
||||
guard = defence(world, dragon=True)
|
||||
garrison = guard["garrison"]
|
||||
report = {"group": event["group"], "attack": round(attack), "defence": guard["total"],
|
||||
"parts": guard["parts"], "garrison": garrison, "guards": guard["guards"], "icon": "🐉"}
|
||||
|
|
@ -6437,7 +6533,7 @@ for _jewel in [*_jewel_actions(), *_storage_actions()]:
|
|||
for _craft in ACTIONS:
|
||||
_made = next(iter(_craft["outputs"]), None)
|
||||
if _made in ITEMS and (ITEMS[_made].get("slot") in ("weapon", "shield", "helmet", "body", "legs")
|
||||
or "kit" in ITEMS[_made]):
|
||||
or "kit" in ITEMS[_made] or "siege" in ITEMS[_made]):
|
||||
ITEMS[_made]["value"] = round(sum(ITEMS[i]["value"] * q for i, q in _craft["inputs"].items()) * CRAFT_MARKUP)
|
||||
_dungeon_loot() # masterworks are reforged from all of the above
|
||||
FITTING_BY_ID = {}
|
||||
|
|
@ -7559,6 +7655,7 @@ BUILDING_GLYPHS = {
|
|||
"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"), "roads": ("stone-path", "#b6a587"),
|
||||
"outworks": ("catapult", "#b9844e"),
|
||||
}
|
||||
ACTION_GLYPHS = {
|
||||
"fight_wolves": ("wolf-head", "#9aa1ab"), "fight_scouts": ("hooded-assassin", "#a08060"),
|
||||
|
|
@ -7683,6 +7780,8 @@ def _assign_glyphs() -> None:
|
|||
ITEMS[f"{wood}_{suffix}"].update(glyph=glyph, tint=tint)
|
||||
ITEMS[f"{wood}_strongbox"].update(glyph="locked-chest", tint=tint)
|
||||
ITEMS[f"{wood}_frame"].update(glyph="wood-frame", tint=tint)
|
||||
ITEMS[f"{wood}_trap"].update(glyph=["stakes-fence", "spiky-pit", "tripwire", "wolf-trap", "mantrap", "spikes"][tier], tint=tint)
|
||||
ITEMS[f"{wood}_engine"].update(glyph=["crossbow", "ballista", "ballista", "catapult", "trebuchet", "trebuchet"][tier], tint=tint)
|
||||
for cloth, tint in zip(CLOTHS, CLOTH_TINTS):
|
||||
ITEMS[f"{cloth[5]}_bag"].update(glyph="shoulder-bag", tint=tint)
|
||||
for gem, _name, _value, tint, glyph in GEMS:
|
||||
|
|
@ -7736,6 +7835,7 @@ def _assign_glyphs() -> None:
|
|||
# Emoji in the UI and in what the server sends are drawn as these glyphs wherever the page renders, see iconed() in app.js.
|
||||
_EMOJI_GLYPHS = {
|
||||
# kingdom, roads and war
|
||||
"🪤": ("wolf-trap", "#c9a06a"),
|
||||
"🗺️": ("treasure-map", "#d9c6a0"), "🛤️": ("stone-path", "#b6a587"), "🐎": ("horse-head", "#b9844e"), "🚶": ("walk", "#b6a587"),
|
||||
"📍": ("position-marker", "#e2645c"), "🏠": ("house", "#d0a060"), "🏰": ("castle", "#a8a29e"), "💂": ("guards", "#c06a4a"),
|
||||
"⚔️": ("crossed-swords", "#d8574c"), "🛡️": ("checked-shield", "#8fb8d0"), "🐉": ("dragon-head", "#e05a5a"), "💀": ("death-skull", "#d9c6a0"),
|
||||
|
|
@ -7790,6 +7890,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-10", "title": "Siegeworks", "notes": [
|
||||
("new", "Construction: Siegeworks. 6 traps (Lv 15–89, 1 frame) and 6 engines (Lv 19–93, 3 frames)."),
|
||||
("new", "Outworks: 5 levels. Per level: 20 traps, 4 engines, +2 trap slots per win."),
|
||||
("new", "Traps: raids only, +1 to +14 defence, all used up each raid."),
|
||||
("new", "Engines: raids + dragons, +5 to +70 defence, wear like guard kit, safe from looting."),
|
||||
("new", "Traps and engines in the Outworks don't count as raid wealth. Spares do."),
|
||||
]},
|
||||
{"date": "2026-11-09", "title": "Jewelcrafting", "notes": [
|
||||
("balance", "Hourglass XP: 2 / 3 / 5 / 6 / 8 / 10% → 3 / 6 / 9 / 12 / 15 / 18%."),
|
||||
]},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue