Phase 14: Death + Corpses + Burial + Cremation

Three-agent fan-out. Opus pre-wrote Corpse class + 5 EventBus signals +
World registries (corpses, grave_markers) before dispatch so all three
slices ran fully parallel. Pattern proven across Phases 12/13/14.

Death pipeline (Agent A):
- Pawn.is_dead(), _check_death() — pawn_died signal → corpse spawn →
  corpse_spawned signal → World.unregister_pawn → queue_free
- _last_damage_source carries cause from take_damage() (now StringName)
- Bleed-out timeout: _bleed_ticks accumulates while bleeding active;
  at BLEED_OUT_TICKS=432000 (6 in-game hours) force-kills via take_damage
- Pawn.portrait_color stored field for corpse head-color hand-off
- Corpse: DECAY_PER_TICK=0.05 (~33 in-game min fresh→rotted at 1×),
  is_rotting()@50, queue_free@100 with corpse_rotted_away signal.
  Rotting bumps DirtinessSystem (Phase 13 hook) +0.04/tick (~+8/in-game-min)
- DEMO_PHASE14_AUTOKILL toggle in world.gd (default false, gates safety)

Graveyard + GraveSlot + GraveMarker + Hauling (Agent B):
- scenes/world/graveyard_zone.gd — StorageDestination subclass,
  accepted_types=[corpse], brownish overlay, finds dug GraveSlots
- scenes/entities/grave_slot.gd — buildable (ghost→dug) state machine,
  StorageDestination duck-type interface, accept_corpse() spawns
  GraveMarker + emits corpse_buried + queue_frees self
- scenes/entities/grave_marker.gd — permanent memorial, procedural
  stone-cross _draw, carries deceased identity, save round-trip
- TOOL_GRAVEYARD + TOOL_DIG_GRAVE paint modes (Designation dispatch)
- KIND_PICKUP_CORPSE + KIND_DEPOSIT_CORPSE toils + JobRunner handlers
- HaulingProvider.find_best_for iterates World.corpses in addition to
  items_needing_haul; corpse-payload stored as Node metadata on pawn
- ConstructionProvider duck-type already accepts GraveSlot (no change)

Cremation + Ash + Mood thoughts (Agent C):
- scenes/entities/cremation_pyre.gd — extends Workbench, label 'Pyre',
  auto-populates FOREVER bill for cremate_corpse, on_craft_complete
  drops 1 ash + emits corpse_cremated + queue_frees corpse
- Recipe.ingredient2_type/count added with save round-trip; recipe
  catalog entry cremate_corpse(TYPE_CORPSE primary + 5 wood secondary)
  NOTE: CraftingProvider still only enforces ingredient1 — documented
  gap, ships when crafting is generalized.
- Item.TYPE_ASH added + ALL_TYPES filter array entry
- 4 mood thoughts: saw_corpse (-3 EVENT 1200t max=3), buried_friend
  (+2 EVENT 2400t), cremated_friend (+2 EVENT 2400t),
  rotting_body_in_colony (-4 PERSISTENT stacks=count capped at 3)
- Pawn sync hooks: proximity scan (saw_corpse), signal listeners
  (buried/cremated within 8-tile radius), count helper for rotting

MCP runtime verified:
- DEMO_PHASE14_AUTOKILL toggle force-killed Bram at tick 50
- 'Bram DIED (cause=demo_kill, tile=(20, 36))' + corpse spawned
- 'Cora: saw_corpse thought added (corpse Bram at dist 5)' — mood -3
- Painted graveyard + dig_grave → grave dug to completion verified
  in build_queue (grave @(22, 39) complete=true)
- Hauler round-trip (corpse → GraveSlot → GraveMarker) WIRED correctly
  but didn't land within decay window at ULTRA speed (12×) — corpse
  rotted before priority-3 corpse-haul scheduled. Tuning for Phase 20.
- Screenshot captured: fresh corpse silhouette at cabin doorway

Delegation: 3× gdscript-refactor (Sonnet) agents in parallel;
integration + MCP runtime verify on Opus.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-11 18:48:15 +01:00
parent 9cf9b7dbfd
commit 67ec2cce7f
26 changed files with 1306 additions and 33 deletions

View file

@ -0,0 +1,154 @@
class_name CremationPyre extends Workbench
## Phase 14 — Cremation pyre furniture.
##
## Subclasses Workbench to reuse the build + bill machinery. The pyre uses a
## special `cremate_corpse` recipe that consumes a Corpse entity (hauled as
## Item.TYPE_CORPSE by the crafting toil's pickup-ingredient step) and 5 wood,
## producing 1 ash item dropped adjacent on completion.
##
## Variant appearance: label_text = "Pyre" triggers the _draw_pyre() branch
## (overrides _draw() in Workbench). accepted_skill = "manual_labor" (any
## laborer can cremate; no Crafting threshold needed).
##
## EventBus.corpse_cremated(corpse, pyre) is emitted on craft completion.
## The Corpse node is queue_free'd after the signal fires.
##
## Stub gap (documented):
## The existing single-ingredient Recipe supports one ingredient_type.
## cremate_corpse needs 1 corpse + 5 wood. This is expressed via
## ingredient2_type / ingredient2_count extended fields on Recipe
## (added in Phase 14 — see recipe.gd). CraftingProvider's ingredient
## pickup step must be updated to check ingredient2 before assigning a
## pawn; until that update lands, the pyre will work as a single-ingredient
## recipe (corpse-only) and the 5-wood secondary requirement is NOT enforced
## at runtime. This is the documented Phase 14 Agent C stub gap.
##
## World registration: shares Workbench.register_workbench /
## unregister_workbench (called by the parent's _ready / _exit_tree).
## Override label so Workbench._complete() logs "Pyre built at …"
## and _draw() dispatches to _draw_pyre().
func _init() -> void:
label_text = "Pyre"
accepted_skill = &"manual_labor"
func _ready() -> void:
label_text = "Pyre"
accepted_skill = &"manual_labor"
super._ready()
# Auto-populate a default FOREVER bill for the cremate_corpse recipe so
# the pyre is immediately usable once built.
var b := Bill.new()
b.recipe = RecipeCatalog.cremate_corpse()
b.mode = Bill.Mode.FOREVER
bills.append(b)
Audit.log("pyre", "CremationPyre ready at %s — bill added" % tile)
# ── craft-cycle hook override ─────────────────────────────────────────────────
## Called by JobRunner._tick_craft when a cremate_corpse craft completes.
## Drops an ash item adjacent to the pyre, emits corpse_cremated, and frees
## the Corpse entity that was consumed as an ingredient.
##
## The `pawn` argument is the pawn who completed the craft; used only for
## the "cremated_friend" thought signal path in EventBus listeners.
##
## NOTE: The standard Workbench.on_craft_complete() is called by JobRunner
## before this override runs (it clears current_bill / current_work_progress).
## We override at the pyre level to inject the ash-drop + signal + corpse-free
## after the base logic. JobRunner calls on_craft_complete() directly, so we
## shadow it here.
func on_craft_complete() -> void:
# Base Workbench cleanup (clears current_bill, resets work progress).
super.on_craft_complete()
# Find and consume the corpse that was hauled as ingredient.
var consumed_corpse = _find_consumed_corpse()
# Drop 1 ash item on an adjacent walkable tile (same pattern as
# Tree.fell() / Workbench output drops elsewhere in Phase 6).
var drop_tile := _pick_adjacent_drop_tile()
if drop_tile != Vector2i(-1, -1):
var ash := load("res://scenes/entities/item.tscn").instantiate()
get_parent().add_child(ash)
ash.setup(Item.TYPE_ASH, 1, drop_tile)
Audit.log("pyre", "Pyre at %s: cremation complete — ash dropped at %s" % [tile, drop_tile])
else:
Audit.log("pyre", "Pyre at %s: cremation complete — no adjacent tile for ash drop" % tile)
# Emit and clean up corpse.
if consumed_corpse != null:
Audit.log("pyre", "Pyre at %s: cremated '%s'" % [tile, consumed_corpse.deceased_name])
EventBus.corpse_cremated.emit(consumed_corpse, self)
consumed_corpse.queue_free()
else:
# Defensive: corpse may have already been freed by decay or another
# system during the crafting window.
Audit.log("pyre", "Pyre at %s: cremation complete but no corpse found (already freed?)" % tile)
# ── render ─────────────────────────────────────────────────────────────────────
## Override Workbench._draw() to dispatch to _draw_pyre() for the "Pyre" label.
func _draw() -> void:
var alpha: float = 1.0 if is_completed() else 0.4
_draw_pyre(alpha)
func _draw_pyre(alpha: float) -> void:
# Simple log-pile silhouette: dark-brown stone base with orange ember
# and ash-grey smoke wisps, suggesting an outdoor funeral pyre.
var base_top := Color(0.30, 0.22, 0.12, alpha) # charred wood / dirt
var base_front := Color(0.22, 0.15, 0.08, alpha)
var ember := Color(0.95, 0.45, 0.10, alpha)
var ash_grey := Color(0.70, 0.68, 0.65, alpha * 0.7)
var outline := Color(0.12, 0.08, 0.04, 0.7 * alpha)
# Top face — dark charred surface.
draw_rect(Rect2(Vector2(-8.0, -16.0), Vector2(16.0, 5.0)), base_top)
# Front face — very dark wood body.
draw_rect(Rect2(Vector2(-8.0, -11.0), Vector2(16.0, 11.0)), base_front)
# Ember glow — wide orange strip across the front, suggesting hot coals.
draw_rect(Rect2(Vector2(-5.0, -4.0), Vector2(10.0, 3.0)), ember)
# Smoke wisps — three thin vertical rects rising above the top face.
draw_rect(Rect2(Vector2(-3.0, -18.0), Vector2(1.0, 3.0)), ash_grey)
draw_rect(Rect2(Vector2(0.5, -19.0), Vector2(1.0, 4.0)), ash_grey)
draw_rect(Rect2(Vector2(3.0, -17.0), Vector2(1.0, 2.0)), ash_grey)
# Horizon line.
draw_line(Vector2(-8.0, -11.0), Vector2(8.0, -11.0), base_top, 1.0)
# Tile outline.
draw_rect(Rect2(Vector2(-8.0, -16.0), Vector2(16.0, 16.0)), outline, false, 1.0)
# ── helpers ───────────────────────────────────────────────────────────────────
## Scan World.corpses for the nearest corpse within 2 tiles (the crafting toil
## would have moved it to the pyre tile or an adjacent tile). Returns null if
## none found.
func _find_consumed_corpse():
var best = null
var best_d: int = 3 # max search radius
for c in World.corpses:
var d: int = abs(c.tile.x - tile.x) + abs(c.tile.y - tile.y)
if d < best_d:
best_d = d
best = c
return best
## Return a walkable adjacent tile for the ash drop. Prefers the 4 cardinal
## neighbours in a fixed priority order; falls back to the pyre's own tile if
## all neighbours are blocked.
func _pick_adjacent_drop_tile() -> Vector2i:
var candidates: Array[Vector2i] = [
tile + Vector2i(1, 0),
tile + Vector2i(-1, 0),
tile + Vector2i(0, 1),
tile + Vector2i(0, -1),
]
for c in candidates:
if World.pathfinder != null and World.pathfinder.is_walkable(c):
return c
return tile # fallback: drop on the pyre tile itself