Caravans: crewed wagons, town stock by vote, roads, ambushes; war table shows all scouted threats and march impact
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4c9977e5c
commit
3486897630
6 changed files with 724 additions and 24 deletions
14
app.py
14
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"]},
|
||||
|
|
|
|||
359
game.py
359
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."),
|
||||
|
|
|
|||
118
static/app.js
118
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 `<p class="small muted">No threat rumoured</p>`;
|
||||
const size = t.strength ? fmt(t.strength) : t.range ? `${fmt(t.range[0])} - ${fmt(t.range[1])}` : t.size || "?";
|
||||
return `<p class="small">${eventIcon(t.kind)} ${eventWhen(t, true)} · ${esc(String(size))}${t.main ? ` <span class="tag warn" title="The bandits' main assault">Main assault</span>` : ""}</p>`;
|
||||
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 ? `<p class="small">${problems.map((p) => `${p.icon} ${esc(p.name)}`).join(" · ")}</p>` : "";
|
||||
if (!t) return `<p class="small muted">No threat rumoured</p>${trouble}`;
|
||||
const pips = [1, 2, 3].map((n) => n <= t.intel ? "●" : "○").join("");
|
||||
return `<p class="small" title="${esc(t.headline)}">${eventIcon(t.kind)} <span title="Intel ${t.intel} / 3">${pips}</span> ${eventWhen(t, true)} · ${esc(String(threatSize(t)))}${t.main ? ` <span class="tag warn" title="The bandits' main assault">Main assault</span>` : ""}</p>
|
||||
${t.group || t.trait || t.sabotage ? `<p class="small muted">${[t.group && upperFirst(t.group), t.trait, t.sabotage && `-${t.sabotage}%`].filter(Boolean).map((x) => esc(String(x))).join(" · ")}</p>` : ""}${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) => `<span>${esc(c.name)} 🛡️ ${fmt(now)} → <b>${fmt(after)}</b> vs ${c.threat ? eventIcon(c.threat.kind) : ""} ${esc(String(threatSize(c.threat)))} ${holds(after, c.threat)}</span>`;
|
||||
return `<div class="impact small">${row(from, from.defence, from.defence - power)}${row(to, to.defence + incoming, to.defence + incoming + power)}</div>`;
|
||||
}
|
||||
|
||||
function convoyPanel() {
|
||||
const k = S.kingdom, me = S.me, here = me.at;
|
||||
const others = k.cities.filter((c) => c.id !== here);
|
||||
const mine = k.caravans.find((c) => c.crew.includes(S.uid));
|
||||
const list = (items) => Object.entries(items || {}).map(([id, qty]) => itemChip(id, qty, undefined, false)).join(" ");
|
||||
const row = (c) => {
|
||||
const lead = c.leader === S.uid, aboard = c.crew.includes(S.uid), loading = c.status === "loading";
|
||||
const state = loading ? `📦 ${fmt(c.load)} / ${fmt(c.room)}` : `🛤️ ${dur(Math.max(0, c.arrive - S.now))}${c.ambush ? ` · ${c.ambush === "won" ? "⚔️ Beat an ambush" : "💀 Robbed"}` : ""}`;
|
||||
const buttons = !loading || me.travel ? "" : lead
|
||||
? `<button class="btn sm primary" data-caravan-depart="${c.id}">🛤️ Set off</button> <button class="btn sm" data-caravan-cancel="${c.id}">✖</button>`
|
||||
: c.from === here && !mine ? `<button class="btn sm" data-caravan-join="${c.id}">Join</button>` : "";
|
||||
return `<div class="council-row small"><span>🐎 ${esc(townName(c.from))} → ${esc(townName(c.to))} · ${c.crew.map((uid) => esc(playerName(uid))).join(", ")}</span><span>${state}</span><span>${buttons}</span></div>
|
||||
${aboard && (c.mine || Object.keys(c.freight).length) ? `<p class="small">${list(c.mine)} ${list(c.freight)}</p>` : ""}`;
|
||||
};
|
||||
const waiting = k.freight.map((f) => `<div class="council-row small"><span>📦 ${list(f.items)} ${esc(townName(f.from))} → ${esc(townName(f.to))}</span><span>${f.from === here && !me.travel ? `<button class="btn sm ${cargoFreight.has(f.id) ? "primary" : ""}" data-cargo-freight="${f.id}">${cargoFreight.has(f.id) ? "✓ Taking" : "Take"}</button>` : ""}</span><span></span></div>`).join("");
|
||||
const bank = Object.keys(me.bank).filter((id) => !cargo[id]).sort((a, b) => item(a).name.localeCompare(item(b).name));
|
||||
const stock = Object.keys(S.city.stockpile).sort((a, b) => item(a).name.localeCompare(item(b).name));
|
||||
const towns = others.map((c) => `<option value="${esc(c.id)}">${esc(c.name)}</option>`).join("");
|
||||
const chosen = others.find((c) => c.id === $("[data-keep=caravan-to]")?.value) || others[0];
|
||||
const route = chosen?.route;
|
||||
const forming = me.travel ? "" : `
|
||||
<h2 style="margin-top:16px">${mine && mine.status === "loading" ? "Load more" : "Load a caravan"}</h2>
|
||||
<p class="small">${Object.entries(cargo).map(([id, qty]) => `<button class="btn sm" data-cargo-drop="${id}" title="Take out">${itemChip(id, qty, undefined, false)} ✖</button>`).join(" ") || `<span class="muted">Your bank goods, none yet</span>`}</p>
|
||||
<div class="pouch-row"><select data-keep="cargo-item-${Object.keys(cargo).length}">${bank.map((id) => `<option value="${id}">${esc(item(id).name)} (${fmt(me.bank[id])})</option>`).join("")}</select>
|
||||
<input type="number" min="1" value="100" data-keep="cargo-qty" style="width:90px"><button class="btn sm" data-cargo-add ${bank.length ? "" : "disabled"}>+</button></div>
|
||||
${mine && mine.status === "loading" ? `<div class="pouch-row"><button class="btn primary" data-caravan-load="${mine.id}">📦 Load</button></div>`
|
||||
: `<div class="pouch-row"><select data-keep="caravan-to">${towns}</select><button class="btn primary" data-caravan-form>🐎 Form caravan</button></div>
|
||||
${route ? `<p class="small muted">⏱ ${dur(route.time)} · 📦 ${fmt(route.load)} per crew · ⚔️ up to ${Math.round(route.odds * 100)}% ambush · 🛤️ ${route.level}</p>` : ""}`}
|
||||
<h2 style="margin-top:16px">Send town stock</h2>
|
||||
<div class="pouch-row"><select data-keep="freight-item">${stock.map((id) => `<option value="${id}">${esc(item(id).name)} (${fmt(S.city.stockpile[id])})</option>`).join("")}</select>
|
||||
<input type="number" min="1" value="100" data-keep="freight-qty" style="width:90px"><select data-keep="freight-to">${towns}</select>
|
||||
<button class="btn" data-freight-propose>📜 Propose</button></div>`;
|
||||
return `<div class="panel" style="margin-top:14px"><h2>Caravans</h2>
|
||||
${k.caravans.map(row).join("")}${waiting}
|
||||
${k.caravans.length || k.freight.length ? "" : `<p class="small muted">None on the road</p>`}
|
||||
${forming}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function warTable() {
|
||||
|
|
@ -950,9 +1016,11 @@ function warTable() {
|
|||
const proposal = (p) => {
|
||||
const open = p.status === "open", mine = p.yes.includes(S.uid) ? "yes" : p.no.includes(S.uid) ? "no" : null;
|
||||
const result = { sent: "🛤️ Sent", rejected: "Kept home", failed: "No guards" }[p.status];
|
||||
return `<div class="council-row small"><span>💂 ${fmt(p.guards)} · ${esc(townName(p.from))} → ${esc(townName(p.to))} · ${esc(playerName(p.by))}</span>
|
||||
const freight = p.items ? Object.entries(p.items).map(([id, qty]) => itemChip(id, qty, undefined, false)).join(" ") : null;
|
||||
return `<div class="council-row small"><span>${freight ? `📦 ${freight}` : `💂 ${fmt(p.guards)}`} · ${esc(townName(p.from))} → ${esc(townName(p.to))} · ${esc(playerName(p.by))}</span>
|
||||
<span>✅ ${p.yes.length} ❌ ${p.no.length}${open ? ` · ⏳ ${dur(Math.max(0, p.ends - S.now))}` : ` · ${result}`}</span>
|
||||
${open ? `<span><button class="btn sm ${mine === "yes" ? "primary" : ""}" data-vote="${p.id}" data-yes="1">✅</button> <button class="btn sm ${mine === "no" ? "primary" : ""}" data-vote="${p.id}" data-yes="0">❌</button></span>` : "<span></span>"}</div>`;
|
||||
${open ? `<span><button class="btn sm ${mine === "yes" ? "primary" : ""}" data-vote="${p.id}" data-yes="1">✅</button> <button class="btn sm ${mine === "no" ? "primary" : ""}" data-vote="${p.id}" data-yes="0">❌</button></span>` : "<span></span>"}</div>
|
||||
${open && !p.items ? marchImpact(p.from, p.to, p.guards) : ""}`;
|
||||
};
|
||||
const march = (m) => {
|
||||
const target = k.cities.find((c) => c.id === m.to);
|
||||
|
|
@ -969,6 +1037,7 @@ function warTable() {
|
|||
<div class="pouch-row"><select data-keep="march-from">${options(home)}</select> → <select data-keep="march-to">${options(other)}</select>
|
||||
<input type="number" min="1" value="10" data-keep="march-guards" style="width:80px" title="Guards">
|
||||
<button class="btn primary" data-march-propose>📜 Propose</button></div>
|
||||
${marchImpact($("[data-keep=march-from]")?.value || home, $("[data-keep=march-to]")?.value || other, Number($("[data-keep=march-guards]")?.value ?? 10))}
|
||||
<p class="small muted">🛤️ ${dur(C.march_time / S.city_speed)} · vote ${dur(C.vote_time / S.city_speed)} · one fight, then home</p>
|
||||
</div>`;
|
||||
}
|
||||
|
|
@ -990,8 +1059,8 @@ function kingdom() {
|
|||
const region = k.regions[c.region];
|
||||
return `<div class="panel">
|
||||
<h2>${esc(c.name)} ${here ? `<span class="tag">📍 Here</span>` : ""}</h2>
|
||||
<p class="small">${esc(c.tier)} · 👥 ${fmt(c.population)} · 🏆 ${fmt(c.repelled)}${road ? ` · 🛤️ ${road}` : ""}</p>
|
||||
${threatLine(c.threat)}
|
||||
<p class="small">${esc(c.tier)} · 👥 ${fmt(c.population)} · 🏆 ${fmt(c.repelled)}${road ? ` · 🚶 ${road}` : ""}${c.roads ? ` · 🛤️ ${c.roads}` : ""}</p>
|
||||
${threatLine(c.threat, c.problems)}
|
||||
<p class="small" title="Defence · guards paid and at their posts · away">🛡️ ${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(", ")}` : ""}</p>
|
||||
${region ? `<p class="small" title="More per trip, by material tier. Grows with the town.">${region.icon} ${esc(region.name)} · ${regionPerks(region, c.town_scale)}</p>` : ""}
|
||||
<p class="small">${c.people.length ? c.people.map((uid) => esc(playerName(uid))).join(", ") : `<span class="muted">Nobody here</span>`}</p>
|
||||
|
|
@ -1025,7 +1094,7 @@ function kingdom() {
|
|||
<div class="panel"><h2>${me.travel ? "On the road" : "Travel pouch"}</h2>${pack}</div>
|
||||
<div class="panel"><h2>Found a town</h2>${founding}</div>
|
||||
</div>
|
||||
${k.cities.length > 1 ? warTable() : ""}`;
|
||||
${k.cities.length > 1 ? warTable() + convoyPanel() : ""}`;
|
||||
}
|
||||
|
||||
// Where an item comes from: the recipe that makes it, else what finds it, else the fight that drops it.
|
||||
|
|
@ -3387,6 +3456,32 @@ document.addEventListener("click", (e) => {
|
|||
if (d.install) return act("/api/install", { fitting: d.install, source: d.source });
|
||||
if ("plot" in d) return act("/api/plot", { id: d.plot || null });
|
||||
if (d.garrison) return act("/api/garrison", { join: d.garrison === "1" });
|
||||
if ("cargoAdd" in d) {
|
||||
const id = $("[data-keep^=cargo-item]").value, qty = Math.min(Number($("[data-keep=cargo-qty]").value) || 0, S.me.bank[id] || 0);
|
||||
if (id && qty > 0) cargo[id] = qty;
|
||||
return render();
|
||||
}
|
||||
if (d.cargoDrop) { delete cargo[d.cargoDrop]; return render(); }
|
||||
if (d.cargoFreight) {
|
||||
const id = Number(d.cargoFreight);
|
||||
if (cargoFreight.has(id)) cargoFreight.delete(id); else cargoFreight.add(id);
|
||||
return render();
|
||||
}
|
||||
if ("caravanForm" in d || d.caravanJoin || d.caravanLoad) {
|
||||
const body = { goods: cargo, freight: [...cargoFreight] };
|
||||
cargo = {};
|
||||
cargoFreight.clear();
|
||||
if ("caravanForm" in d) return act("/api/caravan/form", { ...body, to: $("[data-keep=caravan-to]").value });
|
||||
return act("/api/caravan/board", { ...body, id: Number(d.caravanJoin || d.caravanLoad) });
|
||||
}
|
||||
if (d.caravanDepart) {
|
||||
if (!confirm("Set off? Everyone aboard stops work until it arrives.")) return;
|
||||
return act("/api/caravan/depart", { id: Number(d.caravanDepart) });
|
||||
}
|
||||
if (d.caravanCancel) return act("/api/caravan/cancel", { id: Number(d.caravanCancel) });
|
||||
if ("freightPropose" in d) {
|
||||
return act("/api/council/freight", { to: $("[data-keep=freight-to]").value, item: $("[data-keep=freight-item]").value, qty: Number($("[data-keep=freight-qty]").value) });
|
||||
}
|
||||
if ("marchPropose" in d) {
|
||||
return act("/api/council/propose", { from: $("[data-keep=march-from]").value, to: $("[data-keep=march-to]").value, guards: Number($("[data-keep=march-guards]").value) });
|
||||
}
|
||||
|
|
@ -3468,7 +3563,12 @@ function pickOrderItem(id) {
|
|||
draft.reward = draft.item && !draft.city ? item(draft.item).value * (draft.kind === "craft" ? draft.qty : 1) : 0;
|
||||
}
|
||||
|
||||
document.addEventListener("change", (e) => {
|
||||
if (e.target.matches?.("[data-keep^=march-], [data-keep=caravan-to]")) render();
|
||||
});
|
||||
|
||||
document.addEventListener("input", (e) => {
|
||||
if (e.target.matches?.("[data-keep=march-guards]")) render();
|
||||
if (e.target.dataset.keep !== "order-search" || !draft) return;
|
||||
draft.search = e.target.value;
|
||||
render();
|
||||
|
|
|
|||
|
|
@ -252,6 +252,7 @@
|
|||
<symbol id="steak" viewBox="0 0 512 512"><path fill="currentColor" d="M294.818 43.27q-1.435.004-2.88.035c-46.15.993-96.56 23.687-128.614 54.82c-41.965 40.758-91.926 108.163-118.896 173.047c-13.486 32.442-21.17 64.22-19.93 91.305s10.723 49.188 32.54 65.546c15.71 11.78 28.638 10.986 44.814 2.72c16.175-8.268 34.067-25.324 52.433-45.405c36.732-40.162 74.766-92.452 121.008-107.932c61.794-20.685 98.278-34.43 120.926-46.785c22.646-12.353 31.392-22.466 40.74-39.08c7.302-12.974 8.365-26.067 5.03-39.882s-11.388-28.167-22.45-41.62c-22.127-26.903-56.253-49.946-83.706-60.003c-12.75-4.67-26.652-6.79-41.016-6.764zm3.418 24.26c21.21-.103 42.145 4.338 58.493 16.677c47.554 35.895 86.454 58.96 54.377 111.88c-32.076 52.923-177.004 58.17-217.56 20.06c-1.663-10.596-12.613-91.45 10.176-121.653c12.52-10.007 54.02-26.77 94.513-26.965zm-119.87 43.66c-1.058 1.99-7.086 83.113-10.403 98.937c-19.397 9.728-71.78 21.074-73.92 6.977c3.618-16.654 37.1-71.993 84.324-105.915zm278.095 26.248a94 94 0 0 1 3.026 9.996c4.2 17.4 2.736 35.916-6.84 52.933c-10.34 18.374-23.007 32.528-47.808 46.057s-61.8 27.285-123.832 48.05c-36.878 12.346-75.83 61.892-113.438 103.012c-18.804 20.56-37.417 39.008-57.525 49.285c-5.895 3.014-12.05 5.204-18.322 6.418c3.03 1.73 6.143 3.338 9.165 4.728c8.116 3.734 16.547 5.668 17.197 5.686c14.037-.65 29.08-8.326 44.816-21.024c15.82-12.764 32.063-30.284 48.493-48.676c32.86-36.784 65.744-77.523 104.444-90.478c61.817-20.694 98.67-34.278 121.465-46.543c22.794-12.264 31.4-22.235 40.044-39.028c9.733-18.912 10.244-32.256 4.506-46.28c-4.33-10.583-12.968-21.73-25.39-34.135zm-314.546 95.466c33.96-.19 69.09 16.75 104.688 36.092c-71.258 37.318-141.89 180.326-187.133 133.99c-18.206-20.105-19.433-119.77 30.147-153.564c17.043-11.616 34.51-16.418 52.297-16.518zm-36.463 73.213c-5.436.103-10.92 1.77-14.74 4.787c-12.34 9.753-21.72 34.145-11.206 45.844c10.057 11.19 35.46 5.816 44.728-6.012c8.262-10.544 5.69-31.088-4.32-40.02c-3.632-3.24-9.023-4.7-14.46-4.6z"/></symbol>
|
||||
<symbol id="stone-block" viewBox="0 0 512 512"><path fill="currentColor" d="m209.875 44.156l-182 106.47l119.625 54.31l148.344 11.72l41.97-24.312l17.342 11.562L309 230.656V379.53l53.563-14.624l-64.625 51.97l-110.875-59.626l-2.157-1.53l-71.28 6.56l75.936-31.967l100.75 52.125v-147.5l-145.906-11.5l-1.625-.125l-1.5-.688l-121.093-55V391.47L44 423.186l82 20.97l21.875-21.282l11.156 29.72l131.282 33.592V434l4.25 2.28l5.47 2.94l4.812-3.908L309 431.97v52.155L491.375 377.78v-96.405L466.78 269.47l24.595-38.75V125l-90.25 52.28l-1.094 34.095l-88-58.688l84.97 5.375L476.5 112L291.562 64.937l1.625.563l-64.406 5.78l5.345-20.936l-24.25-6.188z"/></symbol>
|
||||
<symbol id="stone-bust" viewBox="0 0 512 512"><path fill="currentColor" d="M256 25c14.33 0 27.676 7.905 37.977 22.068S311 81.468 311 104s-6.723 42.768-17.023 56.932C283.676 175.095 270.329 183 256 183c-14.33 0-27.676-7.905-37.977-22.068S201 126.532 201 104s6.722-42.768 17.023-56.932C228.324 32.905 241.671 25 256 25m40 78h-80v18h31v23h18v-23h31zm4.777 77.732c22.269 3.505 48.815 9.312 84.93 17.334c-18.385 31.94-30.507 71.784-36.947 105.024c-30.784 3.249-71.261 9.48-92.76-11.819c-23.106 21.245-68.115 17.842-92.838 11.424c-6.459-33.161-18.556-72.814-36.869-104.629c36.115-8.022 62.661-13.829 84.93-17.334C223.35 193.18 238.89 201 256 201s32.65-7.82 44.777-20.268M265 224h-18v48h18zm-8.992 91.117c25.254 11.781 65.5 11.202 89.556 7.113c-1.059 7.611-1.768 14.623-2.12 20.77H168.556c-.358-6.232-1.08-13.351-2.164-21.084c29 2.217 65.796 6.81 89.615-6.799zM315 361v94h-18v-64h-82v64h-18v-94zm-36 48v46h-46v-46zm69.271 64l14 18H149.73l14-18z"/></symbol>
|
||||
<symbol id="stone-path" viewBox="0 0 512 512"><path fill="currentColor" d="M158.8 18c-8.4 20.13-22.8 56.15-36.1 95.9l28.9.9c4.9-26.18 15.9-51.18 27.5-77.02L186 18zm46.3 0l-8.3 23.72l46.7 10.36l66.6-7.47c9.6-10.68 9.3-19.68 11.7-26.61zm-14.3 40.83c-13.5 17.65-17.5 36.95-19.7 56.57l42.2 1.3l21.1-.3c-1-15.8-1.1-31.5 4.8-46.79zm111.5 4.78l-44.9 5.03c-5.2 15.82-6.1 31.66-4.8 47.46l31.1-.4c11.2-16.81 15.2-35.36 18.6-52.09M117 131.7c-11.3 6.8-11.5 18.9-9.4 32.1c31.9 11.8 56.8 14 89.2 17.4c-.1-15.6-1.6-31.3 3.7-46.9zm161.4 2.1c-19.7 2.3-39.4 4.1-59.8.8l-3.9 48.8c28.8-.5 42.3 5.4 52.4 7.4c1.7-17.9 5.8-37.5 11.3-57m-175.2 47.4c-11.75 28.4-14.76 56.3-8.94 83.1l41.54-25.2l11.1-46.2zm61.7 13.8l-11.7 48.4l79.3 35.4l51.7 1.8c-8.9-25-17.2-47.6-17.8-71.8c-33.8-7.8-67.7-14.4-101.5-13.8m-24.6 62.3l-44.34 27c2 18.4 5.14 38.1 9.14 57.9l106.4-53.1zm101.1 39.8l10.2 66.1c24.5 3.8 42.7-3.9 63.3-7.1l1.1-12c-8.6-15-16.7-30.2-23.7-45.3zm-25.8 9.5l-89 44.9l59.2 19.1c18.7 4.7 35.9.8 47.9-5.4c-1.4-20.1-3.8-42.8-18.1-58.6m-105.7 58.5c-14.64 3.8 9.1 92.3 23 88.7l62.3-20.2l-20-47.4zm221.9 5.4c.7 21.3.2 42-5.4 59.8c9.9 6.5 49 14.2 57.6 16.5c-5.7-28-27.8-52.4-52.2-76.3m-18.5 3.8c-38.3 7.1-76.2 15.1-117.9 13.3l17 40.4l46.3-15.1c12.9 6.6 34.9 10.2 49.9 14.1c5.2-17.6 5.1-35.1 4.7-52.7m-61.6 59.8c-36.2 16.2-74 28.7-113.7 37.1c-11.5 7.9-1.5 20.6 7.1 22.8h148.6zm23.9 2.9l40.1 57h104.9c-5.2-6.4-11.5-14.2-19.1-24z"/></symbol>
|
||||
<symbol id="stone-sphere" viewBox="0 0 512 512"><path fill="currentColor" d="M255.875 19.5C206.14 19.5 160.037 34.86 122 61.063c33.35 9.71 66.81 10.924 98.563 4.624c23.058-19.33 50.26-33.13 81.156-41.75a238 238 0 0 0-45.845-4.437zm84.28 15.47c-39.835 5.745-73.35 19.004-100.78 39.874c31.776 38.663 58.146 80.623 77.063 126.937l2.125 1.064l67.906 33.812c9.494-23.477 16.547-46.637 16.124-70.47c-14.33-36.806-21.36-73.78-21.375-110.75a235.3 235.3 0 0 0-41.064-20.467zm60.033 33.686c1.4 29.016 7.45 58.036 18.406 87.188L478 175.188c-15.394-42.552-42.668-79.38-77.813-106.532zm-294.25 6.75c-4.492 30.815-4.006 59.867 2.624 90.75l137.22 72.438c19.06-5.428 37.233-15.08 54.124-27.813c-18.547-46.068-44.764-87.854-76.875-126.5c-37.813 7.266-77.826 4.59-117.093-8.874zm-20.72 16.938c-38.897 40.635-63.402 95.16-65.374 155.437c12.708-9.902 24.53-20.713 35.625-32.31c-.035-.084-.06-.17-.095-.25l.53-.22c12.524-13.14 24.12-27.26 34.94-42.25c-6.154-27.393-7.755-53.692-5.626-80.406zm335.844 83.97c-1.416 25.13-9.332 48.69-18.75 71.342c27.002 39.79 45.036 85.1 54.188 132.72c22.526-36.18 35.53-78.914 35.53-124.72c0-20.237-2.535-39.886-7.31-58.625l-63.658-20.718zm-316.25 9c-8.685 11.924-17.89 23.38-27.687 34.28c17.71 47.887 24.35 96.876 27.625 145.72c19.492 1.947 44.6-.948 65.28-9.252c14.61-38.1 33.473-73.77 58.94-105.218l-124.157-65.53zm210.75 36.905c-20.514 16.267-43.27 28.78-67.937 35.218c-25.362 29.9-44.158 64.425-58.875 102.03c25.945 16.47 49.38 35.766 66.5 60.844c53.625-28.136 118.39-54.17 174.875-69.625c-9.758-33.28-24.35-64.76-43.72-93.156zM62.688 234.812C49.61 247.83 35.511 259.882 20.22 270.78c2.602 41.27 15.764 79.64 36.843 112.44c10.402-1.57 19.94-6.687 29.187-14.22c-2.964-45.772-8.778-90.685-23.563-134.188zm372.25 133.968c-56.05 15.36-121.654 41.877-174.593 70c-10.558 17.43-13.517 34.648-13.938 52.814c3.145.124 6.294.187 9.47.187c75.177 0 142.078-35.016 185.31-89.655a364 364 0 0 0-6.248-33.344zm-258.843 4.876c-25.448 10.093-54.342 12.98-77.875 9.594c-8.802 7.15-18.705 13.085-29.595 16.375c37.79 49.093 94.466 82.86 159.22 90.5c.59-18.247 3.69-37.243 13.874-56.156c-15.817-24.467-38.78-43.577-65.626-60.314z"/></symbol>
|
||||
<symbol id="stone-stack" viewBox="0 0 512 512"><path fill="currentColor" d="M278.735 112.385c-6.45-.022-13.001.204-19.541.683c-26.16 1.918-52.24 7.912-71.295 17.338c-19.054 9.426-30.102 21.32-31.21 35.473c-.491 6.258 1.674 12.378 6.886 18.9s13.484 13.055 23.86 18.725c20.75 11.34 49.723 19.217 77.925 20.578s55.456-3.89 73.447-16.592c17.992-12.701 28.163-31.942 23.477-64.853c-.647-4.546-3.149-8.605-8.393-12.748c-5.244-4.144-13.144-7.946-22.834-10.828c-14.534-4.324-32.974-6.611-52.322-6.676m-58.385 27.773a15.021 30.242 71.137 0 1 16.541 7.426a15.021 30.242 71.137 0 1-23.646 24.008a15.021 30.242 71.137 0 1-33.557-4.356a15.021 30.242 71.137 0 1 23.647-24.006a15.021 30.242 71.137 0 1 17.015-3.072m41.203 101.729c-37.759-.033-75.243 5.18-102.252 16.006c-13.504 5.412-24.3 12.2-31.423 19.904c-7.123 7.703-10.792 16.021-10.834 26.406c-.027 6.585 2.827 11.537 10.013 16.832c7.187 5.295 18.653 9.967 32.887 13.277c28.467 6.621 67.726 8.057 106.684 5.051c38.957-3.005 77.792-10.437 105.572-20.668c13.89-5.115 24.986-11.006 31.701-16.691c6.715-5.686 8.59-10.002 8.066-14.201c-.602-4.834-4.196-10.34-12.113-16.06s-19.702-11.174-33.931-15.651c-28.459-8.955-66.61-14.172-104.37-14.205m-76.722 28a15.623 30.966 72.083 0 1 16.52 8.297a15.623 30.966 72.083 0 1-25.08 24.324a15.623 30.966 72.083 0 1-33.964-5.639a15.623 30.966 72.083 0 1 25.078-24.324a15.623 30.966 72.083 0 1 17.446-2.658m105.074 87.545a737 737 0 0 0-36.129.824c-48.367 2.29-96.637 9.383-132.682 20.898c-18.022 5.758-32.96 12.664-43.14 20.12c-10.181 7.455-15.225 14.927-16.135 22.431c-.771 6.358 2.69 13.296 12.693 21.38c10.004 8.086 25.876 16.155 45.407 23.048c39.06 13.786 92.694 23.167 145.267 24.806c52.574 1.64 104.231-4.626 139.022-20.488c17.395-7.93 30.393-18.095 37.974-30.289c7.582-12.194 10.317-26.587 6.166-45.414c-.984-4.464-5.912-10.175-16.506-15.58c-10.593-5.405-25.998-10.126-44.365-13.654c-27.55-5.292-61.777-8.017-97.572-8.082m-159.727 42.4a18.747 35.889 83.498 0 1 28.702 14.086a18.747 35.889 83.498 0 1-31.659 23.371a18.747 35.889 83.498 0 1-39.367-13.441a18.747 35.889 83.498 0 1 31.658-23.371a18.747 35.889 83.498 0 1 10.666-.645"/></symbol>
|
||||
<symbol id="stone-wall" viewBox="0 0 512 512"><path fill="currentColor" d="m18.08 23l.1 18H494V23zM254.3 54.93L133 61.6l30.1 68.5l98.1-3.6zm115.9.28l-92.9.53l3 71.96l96.8-.9zM18.23 56.43l.35 74.67l72.27-2.4l24.35-72.27zM393 64.24l-.5 47.16l15.7 21.5l85.8-6.3V64.93zM120.8 84.68l-17.6 49.82l41.1-1l-8.2-34.02zm354.7 56.02l-4 75.5l22.5-.6v-74.9zm-25.7 3.5l-97.3 10.7L346 219l110.7-3.2zm-243.8.7l-4 75.5l126.1-3.9l7-71.1zm-145.33 2.7l-3.9 75.5l126.13-3.9l-6.9-71.6zm-42 1.5l.33 72.4l24.77-.8l-6.9-71.6zm278.93 84.3L276 277.2l2.1 42l128.7-1.9l-7.6-79.7zm-40.2 1.4l-127.2 6l8 69.5l124.7 6.6zm236.6 3.1l-66.5 2.9l-7.5 75.8l74-5.2zm-474.89 7l.31 65.8l100.78-3.1l-6.9-62.7zm470.29 81.2l-115.9 10.5l-3.3 65l121.5-3.5zm-422.36 4.1l-47.52 2l.34 72.9l51.1-1.3zm17.84 0l3.98 68.5l138.64 9.6l-3-78.1zm161.22 4.3l-5.5 69l107.5 5.4l-1-73.5zm185.4 81.1l-4 75.5l66.5-.6v-73.8zm-9.8 1.2l-39 3.6l27.4 28zm-399.46 1.8l-2.13 40.6l.16 34.8H145.4v-68.9l-46.56-2.5l-18.4 14L68.56 421zm247.96.3l-111.3 1.5l3.5 72.5l114.7-2.4zm101.2 4.3l-72.2 5.9l-8.9 62.1l125.6.6l-6.2-27z"/></symbol>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 468 KiB After Width: | Height: | Size: 469 KiB |
|
|
@ -958,3 +958,4 @@ button.swatch { width: 36px; height: 36px; }
|
|||
.council-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
|
||||
@media (max-width: 520px) { .council-row { grid-template-columns: minmax(0, 1fr) auto; } }
|
||||
.pouch-row select.wide { flex-basis: 100%; }
|
||||
.impact { display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 6px 0; }
|
||||
|
|
|
|||
|
|
@ -4126,6 +4126,261 @@ class KingdomTest(unittest.TestCase):
|
|||
game._loot_banks(new, {"slot": 5}, 0.4, T0)
|
||||
self.assertEqual(self.a["bank"]["stone"], 900)
|
||||
|
||||
def caravan(self, new, goods=None, freight=(), now=T0):
|
||||
self.assertIsNone(game.form_caravan(self.world, self.a, new.here, goods or {}, list(freight), now))
|
||||
return self.world["convoys"][-1]
|
||||
|
||||
def raid_on(self, world, strength=1000.0, at=T0 + 10**6):
|
||||
raid = {"id": 900 + len(world["events"]), "kind": "raid", "status": "upcoming", "fire_at": at, "slot": at, "strength": strength,
|
||||
"sabotage": 0.0, "recon": 0, "jitter": 0, "group": "the Red Hand", "trait": "x", "announced": T0}
|
||||
world["events"].append(raid)
|
||||
return raid
|
||||
|
||||
def test_a_caravan_carries_your_goods_to_your_bank_there(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": 1000}
|
||||
convoy = self.caravan(new, {"stone": 800})
|
||||
self.assertEqual(self.a["bank"]["stone"], 200)
|
||||
self.assertEqual(convoy["status"], "loading")
|
||||
self.assertIsNone(game.depart_caravan(self.world, self.a, convoy["id"], T0))
|
||||
arrive = convoy["arrive"]
|
||||
self.assertEqual(arrive, T0 + game.CARAVAN_TIME)
|
||||
convoy["rolled"] = True
|
||||
game.tick(self.world, arrive, random.Random(1))
|
||||
game.catch_up(self.world, arrive, random.Random(1))
|
||||
self.assertEqual(self.a["at"], new.here)
|
||||
self.assertEqual(self.a["bank"]["stone"], 800)
|
||||
self.assertEqual(self.a["banks"][game.HOME_CITY]["stone"], 200)
|
||||
self.assertEqual(self.world["convoys"], [])
|
||||
|
||||
def test_the_crew_stops_work_on_the_road(self):
|
||||
new = self.found()
|
||||
self.assertIsNone(game.start_action(self.world, self.a, "mine_stone", T0))
|
||||
convoy = self.caravan(new)
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
xp = self.a["xp"]["mining"]
|
||||
game.process_player(self.world, self.a, convoy["arrive"] - 1)
|
||||
self.assertEqual(self.a["xp"]["mining"], xp)
|
||||
|
||||
def test_more_crew_means_more_load(self):
|
||||
new = self.found()
|
||||
self.a["bank"], self.b["bank"] = {"stone": 5000}, {"stone": 5000}
|
||||
limit = game.CARAVAN_LOAD
|
||||
self.assertIn("hold", game.form_caravan(self.world, self.a, new.here, {"stone": limit + 1}, [], T0))
|
||||
convoy = self.caravan(new, {"stone": limit})
|
||||
self.assertIn("hold", game.board_caravan(self.world, self.b, convoy["id"], {"stone": limit + 1}, [], T0))
|
||||
self.assertIsNone(game.board_caravan(self.world, self.b, convoy["id"], {"stone": limit}, [], T0))
|
||||
self.assertEqual(convoy["crew"], ["a", "b"])
|
||||
self.assertEqual(game._convoy_load(convoy), 2 * limit)
|
||||
|
||||
def test_road_works_at_either_end_help(self):
|
||||
new = self.found()
|
||||
bare = game.caravan_route(self.world, game.HOME_CITY, new.here)
|
||||
self.world["city"]["buildings"]["roads"]["level"] = 3
|
||||
new["city"]["buildings"]["roads"]["level"] = 1
|
||||
paved = game.caravan_route(self.world, game.HOME_CITY, new.here)
|
||||
self.assertEqual(paved["level"], 4)
|
||||
self.assertAlmostEqual(paved["time"], bare["time"] * 0.6)
|
||||
self.assertEqual(paved["load"], bare["load"] * 2)
|
||||
self.assertAlmostEqual(paved["odds"], bare["odds"] * 0.6)
|
||||
|
||||
def test_roads_dont_speed_up_guards(self):
|
||||
new = self.found()
|
||||
self.garrisoned_home()
|
||||
self.world["city"]["buildings"]["roads"]["level"] = 3
|
||||
march = self.march(new)
|
||||
self.assertEqual(march["arrive"], T0 + game.MARCH_TIME)
|
||||
|
||||
def test_town_stock_needs_the_council(self):
|
||||
new = self.found()
|
||||
self.a["last_active"] = self.b["last_active"] = T0
|
||||
stock = self.world["city"]["stockpile"]
|
||||
self.assertIn("holds", game.propose_freight(self.world, self.a, new.here, "provisions", 10**6, T0))
|
||||
self.assertIsNone(game.propose_freight(self.world, self.a, new.here, "provisions", 100, T0))
|
||||
proposal = self.world["council"][-1]
|
||||
self.assertEqual((proposal["status"], stock["provisions"]), ("open", 300))
|
||||
game.vote_march(self.world, self.b, proposal["id"], True, T0)
|
||||
self.assertEqual((proposal["status"], stock["provisions"]), ("sent", 200))
|
||||
self.assertEqual(self.world["freight"][0]["items"], {"provisions": 100})
|
||||
|
||||
def ship(self, new, qty=100):
|
||||
self.a["last_active"] = self.b["last_active"] = T0
|
||||
game.propose_freight(self.world, self.a, new.here, "provisions", qty, T0)
|
||||
game.vote_march(self.world, self.b, self.world["council"][-1]["id"], True, T0)
|
||||
return self.world["freight"][-1]
|
||||
|
||||
def test_a_caravan_delivers_town_stock_and_earns_its_crew_favour_there(self):
|
||||
new = self.found()
|
||||
shipment = self.ship(new)
|
||||
convoy = self.caravan(new, freight=[shipment["id"]])
|
||||
self.assertEqual(self.world["freight"], [])
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
convoy["rolled"] = True
|
||||
before = new["city"]["stockpile"]["provisions"]
|
||||
self.a["favour"] = 0
|
||||
game.tick(self.world, convoy["arrive"], random.Random(1))
|
||||
self.assertEqual(new["city"]["stockpile"]["provisions"], before + 100)
|
||||
game.catch_up(self.world, convoy["arrive"], random.Random(1))
|
||||
self.assertEqual(self.a["favour"], game.ITEMS["provisions"]["value"] * 100 * game.CARRIAGE)
|
||||
|
||||
def test_too_much_freight_leaves_the_rest_waiting(self):
|
||||
new = self.found()
|
||||
self.world["city"]["stockpile"]["provisions"] = game.CARAVAN_LOAD + 500
|
||||
shipment = self.ship(new, game.CARAVAN_LOAD + 500)
|
||||
convoy = self.caravan(new, freight=[shipment["id"]])
|
||||
self.assertEqual(convoy["freight"]["provisions"], game.CARAVAN_LOAD)
|
||||
self.assertEqual(self.world["freight"][0]["items"]["provisions"], 500)
|
||||
|
||||
def test_unclaimed_freight_goes_home(self):
|
||||
new = self.found()
|
||||
self.ship(new)
|
||||
stock = self.world["city"]["stockpile"]
|
||||
game._caravan_road_tick(self.world, T0 + game.FREIGHT_WAIT, random.Random(1))
|
||||
self.assertEqual(stock["provisions"], 300)
|
||||
self.assertEqual(self.world["freight"], [])
|
||||
|
||||
def test_calling_off_a_caravan_gives_it_all_back(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": 100}
|
||||
shipment = self.ship(new)
|
||||
convoy = self.caravan(new, {"stone": 50}, [shipment["id"]])
|
||||
self.assertIn("isn't yours", game.cancel_caravan(self.world, self.b, convoy["id"]))
|
||||
self.assertIsNone(game.cancel_caravan(self.world, self.a, convoy["id"]))
|
||||
self.assertEqual(self.a["bank"]["stone"], 100)
|
||||
self.assertEqual(self.world["freight"][0]["items"], {"provisions": 100})
|
||||
|
||||
def test_a_caravan_that_never_leaves_unloads(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": 100}
|
||||
self.caravan(new, {"stone": 100})
|
||||
game.tick(self.world, T0 + game.CARAVAN_WAIT, random.Random(1))
|
||||
self.assertEqual(self.world["convoys"], [])
|
||||
self.assertEqual(self.a["bank"]["stone"], 100)
|
||||
|
||||
def test_who_left_town_stays_behind_with_their_goods(self):
|
||||
new = self.found()
|
||||
self.b["bank"] = {"stone": 100}
|
||||
convoy = self.caravan(new)
|
||||
game.board_caravan(self.world, self.b, convoy["id"], {"stone": 100}, [], T0)
|
||||
self.go(self.b, new.here)
|
||||
self.assertIsNone(game.depart_caravan(self.world, self.a, convoy["id"], T0))
|
||||
self.assertEqual(convoy["crew"], ["a"])
|
||||
self.assertEqual(self.b["banks"].get(game.HOME_CITY, self.b["bank"])["stone"], 100)
|
||||
|
||||
def ambushed(self, new, power, raid, cargo=None):
|
||||
self.a["bank"] = {"stone": 1000}
|
||||
convoy = self.caravan(new, cargo or {})
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
convoy["odds"] = 1.0
|
||||
self.a["xp"]["combat"] = power
|
||||
game._ambush(self.world, convoy, T0, random.Random(1))
|
||||
return convoy
|
||||
|
||||
def test_beating_an_ambush_weakens_the_coming_raid(self):
|
||||
new = self.found()
|
||||
raid = self.raid_on(self.world, 100.0)
|
||||
convoy = self.ambushed(new, 10**7, raid, {"stone": 1000})
|
||||
self.assertEqual(convoy["ambush"], "won")
|
||||
self.assertEqual(raid["sabotage"], game.AMBUSH_WEAKEN)
|
||||
self.assertEqual(convoy["goods"]["a"]["stone"], 1000)
|
||||
|
||||
def test_losing_an_ambush_costs_cargo_and_feeds_the_raid(self):
|
||||
new = self.found()
|
||||
raid = self.raid_on(self.world, 100000.0)
|
||||
convoy = self.ambushed(new, 0, raid, {"stone": 1000})
|
||||
self.assertEqual(convoy["ambush"], "lost")
|
||||
self.assertEqual(convoy["goods"]["a"]["stone"], 700)
|
||||
self.assertEqual(raid["strength"], 102000.0)
|
||||
self.assertEqual(raid["sabotage"], 0.0)
|
||||
|
||||
def test_the_ambush_comes_from_the_bigger_raid(self):
|
||||
new = self.found()
|
||||
small, big = self.raid_on(new, 10.0), self.raid_on(self.world, 1000.0)
|
||||
self.ambushed(new, 10**7, big)
|
||||
self.assertEqual((small["sabotage"], big["sabotage"]), (0.0, game.AMBUSH_WEAKEN))
|
||||
|
||||
def test_an_empty_wagon_isnt_worth_robbing(self):
|
||||
new = self.found()
|
||||
self.raid_on(self.world, 1000.0)
|
||||
convoy = self.caravan(new)
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
self.assertEqual(convoy["odds"], 0.0)
|
||||
|
||||
def test_fuller_wagons_draw_more_ambushes(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": game.CARAVAN_LOAD}
|
||||
convoy = self.caravan(new, {"stone": game.CARAVAN_LOAD // 2})
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
self.assertAlmostEqual(convoy["odds"], game.AMBUSH_ODDS / 2)
|
||||
|
||||
def test_only_so_many_ambushes_count_for_one_raid(self):
|
||||
new = self.found()
|
||||
raid = self.raid_on(self.world, 100.0)
|
||||
self.a["xp"]["combat"] = 10**7
|
||||
for _ in range(game.AMBUSH_MOST + 3):
|
||||
convoy = {"from": game.HOME_CITY, "to": new.here, "crew": ["a"], "goods": {}, "freight": {}, "odds": 1.0}
|
||||
game._ambush(self.world, convoy, T0, random.Random(1))
|
||||
self.assertAlmostEqual(raid["sabotage"], game.AMBUSH_MOST * game.AMBUSH_WEAKEN)
|
||||
|
||||
def test_no_raid_no_ambush(self):
|
||||
new = self.found()
|
||||
convoy = self.ambushed(new, 0, None, {"stone": 1000})
|
||||
self.assertNotIn("ambush", convoy)
|
||||
|
||||
def test_a_second_crew_member_can_win_an_ambush_one_would_lose(self):
|
||||
new = self.found()
|
||||
for member in (self.a, self.b):
|
||||
member["xp"]["combat"] = game.XP_TABLE[50]
|
||||
solo = game.combat_power(self.a)
|
||||
results = []
|
||||
for crew in (1, 2):
|
||||
raid = self.raid_on(self.world, 1.5 * solo / game.AMBUSH_SHARE)
|
||||
convoy = self.caravan(new)
|
||||
if crew == 2:
|
||||
game.board_caravan(self.world, self.b, convoy["id"], {}, [], T0)
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
convoy["odds"] = 1.0
|
||||
game._ambush(self.world, convoy, T0, random.Random(5))
|
||||
results.append(convoy["ambush"])
|
||||
self.world["events"].remove(raid)
|
||||
self.world["convoys"].remove(convoy)
|
||||
for member in (self.a, self.b):
|
||||
member["travel"] = None
|
||||
self.assertEqual(results, ["lost", "won"])
|
||||
|
||||
def test_the_curve_matches_a_real_march(self):
|
||||
new = self.found()
|
||||
self.garrisoned_home()
|
||||
curve = game.march_curve(self.world)
|
||||
before = game.defence(self.world)["total"]
|
||||
march = self.march(new, 30)
|
||||
self.assertAlmostEqual(curve[30], game.march_power(march), delta=1)
|
||||
self.assertAlmostEqual(before - game.defence(self.world)["total"], curve[30], delta=1)
|
||||
self.assertEqual(curve[0], 0.0)
|
||||
|
||||
def test_the_war_table_shows_scouted_threats_at_their_level(self):
|
||||
new = self.found()
|
||||
game.tick(self.world, T0 + 13 * game.HOUR, random.Random(4))
|
||||
game.tick(self.world, T0 + 13 * game.HOUR + 1, random.Random(4))
|
||||
view = game.kingdom_view(self.world, T0 + 13 * game.HOUR + 1, "a")
|
||||
far = next(c for c in view["cities"] if c["id"] == new.here)
|
||||
self.assertEqual(far["threat"]["intel"], 0)
|
||||
self.assertNotIn("strength", far["threat"])
|
||||
self.assertNotIn("range", far["threat"])
|
||||
raid = game.upcoming_raid(new)
|
||||
raid["recon"] = 10**6
|
||||
now = raid["fire_at"] - 3600
|
||||
far = next(c for c in game.kingdom_view(self.world, now, "a")["cities"] if c["id"] == new.here)
|
||||
self.assertEqual(far["threat"]["intel"], 3)
|
||||
self.assertEqual(far["threat"]["strength"], round(raid["strength"]))
|
||||
self.assertIn("group", far["threat"])
|
||||
|
||||
def test_minor_troubles_show_on_the_war_table(self):
|
||||
new = self.found()
|
||||
new["city"]["problems"].append({"kind": "wolves", "work": 0})
|
||||
far = next(c for c in game.kingdom_view(self.world, T0, "a")["cities"] if c["id"] == new.here)
|
||||
self.assertEqual(far["problems"][0]["name"], game.PROBLEMS["wolves"]["name"])
|
||||
|
||||
def test_old_saves_gain_towns(self):
|
||||
doc = json.loads(json.dumps(self.world.doc))
|
||||
doc["version"] = 39
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue