Task #9: Workbench auto-grants after Night 1, destructible/repairable

Gate the Workbench to appear once Night 1 is survived instead of being
buildable: StructureSystem.grant_workbench() (an unvalidated, unpurchased
place() variant, grant()) adds a "workbench" structure record at the scene
node's position, reusing the existing damage/repair/targeting/save pipeline
end to end. The grant happens on CampaignController.night_ending (so it
lands in state before the morning snapshot, like #13's crop growth) and is
re-derived from FarmState.nights_survived on load/retry (sync_from_state).

The Workbench's view is the scene's own node (hidden until granted, shown
by StructureSystem._add_view) instead of a second built mesh, so it gets
the standard HP bar, damage tint, and wobble for free. It's repair-only:
damage() never removes its record at 0 HP ("broken" instead of destroyed),
and it can't be dismantled. Interactions refuses to open its shop before
it exists or while broken (and no longer treats it as focusable), and
coop_session.gd's "buy" request handler refuses a workbench-shop item
(Upgrades.shop_of) the same way for a co-op partner. review_panel.gd's
pre-grant summary line no longer promises the work area from night one.

No FarmState.VERSION bump: a "workbench" record is a new type string, not
a new field, and from_dict() already validates types generically.

Tests: a new test_structures.gd check covers absent/no-prompt/shop-refused
before Night 1 (including a co-op "buy" request), granted after, damaged
by an enemy (thief_behavior.gd's generic BREAK state), broken-not-destroyed
at 0 HP with its shop refused, repaired at the normal proportional cost,
and persistence through a save/retry round trip. test_cycle.gd and
test_nights.gd pre-grant the workbench in setup (grant_workbench()) so
their per-night structure-count invariants aren't thrown off by the
night-1 grant itself.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 16:27:55 -04:00
parent ff2ace9d3c
commit df10a1967c
10 changed files with 272 additions and 21 deletions

View file

@ -13,7 +13,9 @@ extends Node3D
## Letting go, a hit, fear, nightfall, or a full pouch cancels it.
## * Workbench / shed counter: press interact by day to open that shop's menu (UpgradePanel,
## shop "workbench" or "shed"); interact again, walking away, or nightfall closes it. Nothing
## else happens here while one is open.
## else happens here while one is open. The Workbench itself doesn't exist (no prompt, no
## focus, its shop can't be opened) until StructureSystem grants it, after Night 1 (#9); once
## it exists but is broken (0 HP), its shop is refused until it's repaired instead.
## * Repair: a damaged structure within REPAIR_REACH comes first. Hold interact for
## repair_time (any phase) to repair it fully for StructureSystem.repair_cost (paid at the
## end); it is refused, once per press, without the materials.
@ -258,7 +260,9 @@ func step(dt: float) -> void:
_denied = true
message.emit(why, Color(1.0, 0.8, 0.5))
elif focus is Workbench and pressed:
if not campaign.is_daytime():
if structures != null and structures.is_broken(structures.workbench_id()):
message.emit("Broken -- repair it", Color(1.0, 0.8, 0.5))
elif not campaign.is_daytime():
message.emit("The work area is for daytime", Color(1.0, 0.8, 0.5))
elif upgrade_panel != null:
upgrade_panel.open()
@ -349,7 +353,7 @@ func _nearest(p: Vector2) -> Node3D:
if d <= n.reach and score < best_d:
best = n
best_d = score
if workbench != null:
if workbench != null and structures != null and structures.has_workbench():
var d := Vector2(workbench.global_position.x, workbench.global_position.z).distance_to(p)
if d <= workbench.reach and d < best_d:
best = workbench
@ -389,8 +393,9 @@ func _process(delta: float) -> void:
prompt = "[E / X] Gather" if why == "" else why
n.show_state(charges(n), near and kit.alive, prompt)
if workbench != null and show_labels:
var near := Vector2(workbench.global_position.x - p.x, workbench.global_position.z - p.z).length() < LABEL_RANGE
workbench.show_state(campaign, near and kit.alive, focus == workbench)
var granted := structures != null and structures.has_workbench()
var near := granted and Vector2(workbench.global_position.x - p.x, workbench.global_position.z - p.z).length() < LABEL_RANGE
workbench.show_state(campaign, near and kit.alive, focus == workbench, granted and structures.is_broken(structures.workbench_id()))
if shed_counter != null and show_labels:
var near := Vector2(shed_counter.global_position.x - p.x, shed_counter.global_position.z - p.z).length() < LABEL_RANGE
shed_counter.show_state(campaign, near and kit.alive, focus == shed_counter)