Work orders: gather straight into the order

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-11 13:48:08 +00:00
parent 5809be59de
commit 450abc9be9
4 changed files with 79 additions and 19 deletions

51
game.py
View file

@ -2377,9 +2377,8 @@ def _tally(action: dict, summary: dict) -> tuple:
for key in ("items", "overflow", "sold"):
for item, qty in summary[key].items():
got[item] = got.get(item, 0) + qty
if summary.get("delivered") and action["outputs"]:
made = next(iter(action["outputs"]))
got[made] = got.get(made, 0) + summary["delivered"]
for item, qty in summary.get("delivered", {}).items():
got[item] = got.get(item, 0) + qty
return got, sum(summary["xp"].values()), summary["gold"], summary["wins"], summary["losses"]
@ -3324,7 +3323,8 @@ def can_start(world: dict, player: dict, action: dict) -> str | None:
return f"Needs {BUILDINGS[key]['name']} level {level}"
order = working_order(world, player, action)
if order is not None or "order" in (player["action"] or {}) and player["action"]["id"] == action["id"]:
if not order or order["status"] != "open" or order["claimed"] != player["id"] and not order.get("city"):
if not order or order["status"] != "open" or order["claimed"] != player["id"] and not order.get("city") \
and order["kind"] != "gather":
return "Work order done" if order and order["status"] == "done" else "Work order closed"
short = [ITEMS[item]["name"].lower() for item, qty in fire_inputs(world, action).items()
if (order["provided"].get(item, 0) if order else 0) + player["bank"].get(item, 0) < qty]
@ -3528,7 +3528,8 @@ def _finish_action(world: dict, player: dict, action: dict, now: float, rng: ran
if sent:
outputs[order["item"]] -= sent
_deliver(world, order, player, sent, now, used, inputs)
summary["delivered"] = summary.get("delivered", 0) + sent
given = summary.setdefault("delivered", {})
given[order["item"]] = given.get(order["item"], 0) + sent
for item, qty in outputs.items():
if not qty:
continue
@ -3615,8 +3616,9 @@ def process_player(world: dict, player: dict, now: float, rng: random.Random | N
stop(player, reason)
summary["stopped"] = reason
break
if player["overflow"] == "stop" and any(bank_room(world, player, item) < qty
for item, qty in action["outputs"].items()):
order = working_order(world, player, action)
if player["overflow"] == "stop" and any(bank_room(world, player, item) < qty for item, qty in action["outputs"].items()
if not (order and order["status"] == "open" and order["item"] == item)):
stop(player, "Bank full")
summary["stopped"] = "Bank full"
break
@ -4402,17 +4404,21 @@ def drop_order(world: dict, player: dict, order_id, now: float) -> str | None:
return None
def work_order(world: dict, player: dict, order_id, now: float) -> str | None:
"""Claim a crafting order and start making it. A make that was running goes back to the
front of the queue with what it had left; anything else is what comes after."""
def work_order(world: dict, player: dict, order_id, now: float, via: str | None = None) -> str | None:
"""Claim a crafting order and start making it, or start gathering for a materials order
(`via` any gathering that turns it up): what's made or gathered goes straight to the order.
A make that was running goes back to the front of the queue with what it had left; anything
else is what comes after."""
order = order_by_id(world, order_id)
had = order and order["claimed"] == player["id"]
error = claim_order(world, player, order_id)
gather = bool(order) and order["kind"] == "gather"
via = (via or order["action"]) if gather else order and order["action"]
error = _gather_for(player, order, via) if gather else claim_order(world, player, order_id)
if error:
return error
previous = player["action"]
player["action"] = {"id": order["action"], "start": now, "order": order["id"]}
reason = can_start(world, player, ACTION_BY_ID[order["action"]])
player["action"] = {"id": via, "start": now, "order": order["id"]}
reason = can_start(world, player, ACTION_BY_ID[via])
if reason:
player["action"] = previous
if not had:
@ -4426,10 +4432,26 @@ def work_order(world: dict, player: dict, order_id, now: float) -> str | None:
elif "left" not in previous:
previous = {"resume": previous["id"], "resume_plot2": previous.get("plot2")}
player["action"].update({k: v for k, v in (previous or {}).items() if k in ("resume", "resume_plot2") and v})
if gather:
# Once the order's filled, gathering carries on into the bank unless there's something to go back to.
player["action"].setdefault("resume", via)
player["stopped"] = None
return None
def _gather_for(player: dict, order: dict, via: str) -> str | None:
"""Why the player can't gather for this materials order by action `via`, or None."""
if order["status"] != "open":
return "No such order"
if order["by"] == player["id"] and not order.get("city"):
return "That's your own order"
action = ACTION_BY_ID.get(via)
if not action or action["skill"] not in GATHERING or action.get("special") or "enemy" in action \
or order["item"] not in [*action["outputs"], *(item for item, _qty, _odds in action.get("finds", []))]:
return "That doesn't gather it"
return None
def deliver_order(world: dict, player: dict, order_id, now: float) -> str | None:
"""Hand over what's asked for straight from your bank."""
order = order_by_id(world, order_id)
@ -7901,6 +7923,9 @@ 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-11", "title": "Work orders", "notes": [
("new", "Work orders: Gather sends materials straight to the order. Gathering carries on once it's filled."),
]},
{"date": "2026-11-10", "title": "Siegeworks", "notes": [
("balance", "Rebalanced rings and fixed swing timers"),
("new", "Construction: Siegeworks. 6 traps (Lv 15–89, 1 frame) and 6 engines (Lv 19–93, 3 frames)."),