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:
parent
9cf9b7dbfd
commit
67ec2cce7f
26 changed files with 1306 additions and 33 deletions
125
scenes/entities/corpse.gd
Normal file
125
scenes/entities/corpse.gd
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
class_name Corpse extends Node2D
|
||||
## Phase 14 — pawn corpse. Spawns when a Pawn dies, carries the deceased
|
||||
## pawn's identity for the burial / cremation / grave-marker pipeline.
|
||||
##
|
||||
## DECAY MODEL (design.md "Death & corpses"):
|
||||
## decay 0..50 — fresh (no dirt contribution beyond the existing tile)
|
||||
## decay 50..100 — rotting (DirtinessSystem.bump per tick, "rotting body in colony" thought severity ramps)
|
||||
## decay 100 — rotted: corpse is destroyed, EventBus.corpse_rotted_away fires
|
||||
##
|
||||
## Hauling: corpses haul-route through StorageDestinations exactly like Items,
|
||||
## but accept-filter is gated by Item.TYPE_CORPSE on the destination side.
|
||||
## GraveyardZone (Agent B) is the destination class that opts in.
|
||||
##
|
||||
## When a corpse reaches a GraveSlot (Agent B), the slot consumes it and spawns
|
||||
## a GraveMarker carrying the deceased identity. EventBus.corpse_buried fires.
|
||||
##
|
||||
## When a corpse is fed to a CremationPyre (Agent C), it's consumed and an
|
||||
## ash item drops + "cremated friend" mood thought fires.
|
||||
##
|
||||
## Save round-trip carries: tile, deceased_name, deceased_portrait_color,
|
||||
## decay, death_tick, death_cause.
|
||||
|
||||
const DECAY_PER_TICK: float = 0.05 ## ~33 in-game min from fresh→rotted at 1×
|
||||
const DECAY_FRESH_MAX: float = 50.0
|
||||
const DECAY_ROTTED: float = 100.0
|
||||
|
||||
## Tile position (mirrors Pawn/Item convention).
|
||||
@export var tile: Vector2i = Vector2i.ZERO
|
||||
|
||||
## Deceased identity — carried to the GraveMarker on burial.
|
||||
@export var deceased_name: String = ""
|
||||
@export var deceased_portrait_color: Color = Color.WHITE
|
||||
|
||||
## Decay 0..100. Drives visual + dirty contribution + mood-thought severity.
|
||||
@export var decay: float = 0.0
|
||||
|
||||
## Sim tick at death; useful for "how long ago" alerts.
|
||||
@export var death_tick: int = 0
|
||||
|
||||
## Brief categorization, used by mood thoughts ("died of bleeding", "killed by wolf").
|
||||
@export var death_cause: StringName = &""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
World.register_corpse(self)
|
||||
EventBus.sim_tick.connect(_on_sim_tick)
|
||||
z_index = 4 # above floors, below pawns
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
World.unregister_corpse(self)
|
||||
|
||||
|
||||
## Public setup helper called by the death pipeline. Mirrors Wall.setup() shape.
|
||||
func setup(p_tile: Vector2i, p_name: String, p_color: Color, p_cause: StringName) -> void:
|
||||
tile = p_tile
|
||||
global_position = Vector2(tile.x * 16 + 8, tile.y * 16 + 8)
|
||||
deceased_name = p_name
|
||||
deceased_portrait_color = p_color
|
||||
death_cause = p_cause
|
||||
death_tick = Sim.tick
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## True for HaulingProvider — corpses haul like items.
|
||||
## The matching filter on the StorageDestination side is `Item.TYPE_CORPSE`.
|
||||
func get_item_type() -> StringName:
|
||||
return &"corpse"
|
||||
|
||||
|
||||
## True when decay is past the rotting threshold; mood thought severity ramps from here.
|
||||
func is_rotting() -> bool:
|
||||
return decay >= DECAY_FRESH_MAX
|
||||
|
||||
|
||||
func _on_sim_tick(_n: int) -> void:
|
||||
decay += DECAY_PER_TICK
|
||||
if is_rotting():
|
||||
# Bump dirtiness at this tile (Phase 13 hook). +5/h at decay=100 per design.md.
|
||||
if World.dirtiness_system != null:
|
||||
World.dirtiness_system.bump(tile, 0.04) # ~+8/in-game-min
|
||||
if decay >= DECAY_ROTTED:
|
||||
Audit.log("corpse", "%s rotted away at %s" % [deceased_name, tile])
|
||||
EventBus.corpse_rotted_away.emit(self)
|
||||
queue_free()
|
||||
|
||||
|
||||
# ── visual: simple procedural sprite ─────────────────────────────────────────
|
||||
func _draw() -> void:
|
||||
# Body color desaturates as decay progresses; turns olive-green when rotting.
|
||||
var t := clampf(decay / DECAY_ROTTED, 0.0, 1.0)
|
||||
var fresh := Color(0.70, 0.60, 0.55)
|
||||
var rotten := Color(0.45, 0.50, 0.30)
|
||||
var body_color := fresh.lerp(rotten, t)
|
||||
# Lay-down silhouette: 14×6 rect centered.
|
||||
draw_rect(Rect2(-7, -3, 14, 6), body_color)
|
||||
# Head dot
|
||||
draw_circle(Vector2(-9, 0), 3, deceased_portrait_color.lerp(body_color, 0.3))
|
||||
|
||||
|
||||
# ── save / load ──────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"name": deceased_name,
|
||||
"color_r": deceased_portrait_color.r,
|
||||
"color_g": deceased_portrait_color.g,
|
||||
"color_b": deceased_portrait_color.b,
|
||||
"decay": decay,
|
||||
"death_tick": death_tick,
|
||||
"cause": String(death_cause),
|
||||
}
|
||||
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
tile = Vector2i(int(d.get("tile_x", 0)), int(d.get("tile_y", 0)))
|
||||
global_position = Vector2(tile.x * 16 + 8, tile.y * 16 + 8)
|
||||
deceased_name = d.get("name", "")
|
||||
deceased_portrait_color = Color(d.get("color_r", 1.0), d.get("color_g", 1.0), d.get("color_b", 1.0))
|
||||
decay = d.get("decay", 0.0)
|
||||
death_tick = int(d.get("death_tick", 0))
|
||||
death_cause = StringName(d.get("cause", ""))
|
||||
queue_redraw()
|
||||
1
scenes/entities/corpse.gd.uid
Normal file
1
scenes/entities/corpse.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://2dj83v6n61fq
|
||||
8
scenes/entities/corpse.tscn
Normal file
8
scenes/entities/corpse.tscn
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://corpse_entity"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/entities/corpse.gd" id="1_corpse"]
|
||||
|
||||
[node name="Corpse" type="Node2D"]
|
||||
y_sort_enabled = true
|
||||
z_index = 4
|
||||
script = ExtResource("1_corpse")
|
||||
154
scenes/entities/cremation_pyre.gd
Normal file
154
scenes/entities/cremation_pyre.gd
Normal 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
|
||||
1
scenes/entities/cremation_pyre.gd.uid
Normal file
1
scenes/entities/cremation_pyre.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bpa8pfo8b1057
|
||||
104
scenes/entities/grave_marker.gd
Normal file
104
scenes/entities/grave_marker.gd
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
class_name GraveMarker extends Node2D
|
||||
## Phase 14 — permanent grave marker entity. Spawned by GraveSlot.accept_corpse()
|
||||
## when a corpse is buried. Carries the deceased's identity for the tap-to-inspect
|
||||
## UI (Phase 17).
|
||||
##
|
||||
## Visual: procedural 16×16 stone cross / gravestone (dark grey palette).
|
||||
##
|
||||
## Registered with World.register_grave_marker on _ready; unregistered on
|
||||
## _exit_tree (should never happen in normal play — markers persist for the save).
|
||||
##
|
||||
## Save round-trip: to_dict() / from_dict() for Phase 16. The world scene's
|
||||
## save handler iterates World.grave_markers.
|
||||
##
|
||||
## See docs/implementation.md Phase 14 "GraveMarker".
|
||||
|
||||
const TILE_SIZE_PX: int = 16
|
||||
|
||||
## Tile position — set once at spawn, never changed.
|
||||
@export var tile: Vector2i = Vector2i.ZERO
|
||||
|
||||
## Deceased identity — mirrored from the Corpse at burial time.
|
||||
@export var deceased_name: String = ""
|
||||
@export var deceased_portrait_color: Color = Color(0.70, 0.60, 0.55)
|
||||
|
||||
## Cause of death, carried from Corpse.death_cause.
|
||||
@export var death_cause: StringName = &""
|
||||
|
||||
## Sim tick at death (from Corpse.death_tick — NOT the burial tick).
|
||||
@export var death_tick: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
World.register_grave_marker(self)
|
||||
z_index = 2 # above floors, below pawns
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
World.unregister_grave_marker(self)
|
||||
|
||||
|
||||
## One-shot initialiser. Call after add_child() — _ready() fires first.
|
||||
func setup(p_tile: Vector2i, p_name: String, p_color: Color, p_cause: StringName, p_death_tick: int) -> void:
|
||||
tile = p_tile
|
||||
global_position = Vector2(tile.x * TILE_SIZE_PX + TILE_SIZE_PX / 2.0,
|
||||
tile.y * TILE_SIZE_PX + TILE_SIZE_PX)
|
||||
deceased_name = p_name
|
||||
deceased_portrait_color = p_color
|
||||
death_cause = p_cause
|
||||
death_tick = p_death_tick
|
||||
queue_redraw()
|
||||
Audit.log("grave_marker", "placed at %s for '%s' (cause=%s)" % [tile, deceased_name, death_cause])
|
||||
|
||||
|
||||
# ── visual: procedural gravestone + cross ─────────────────────────────────────
|
||||
|
||||
func _draw() -> void:
|
||||
# Stone base: dark grey rectangular slab, bottom-anchored like walls.
|
||||
# Local origin is at tile bottom-centre (matching Wall._draw convention).
|
||||
var stone_base := Color(0.45, 0.44, 0.42)
|
||||
var stone_dark := Color(0.30, 0.29, 0.27)
|
||||
var stone_light := Color(0.62, 0.60, 0.58)
|
||||
var cross_col := Color(0.25, 0.24, 0.22)
|
||||
|
||||
# Main slab — 10 px wide × 12 px tall, bottom-anchored in the 16×16 cell.
|
||||
draw_rect(Rect2(-5.0, -13.0, 10.0, 13.0), stone_base)
|
||||
# Rounded top hint — just a lighter top strip.
|
||||
draw_rect(Rect2(-5.0, -13.0, 10.0, 3.0), stone_light)
|
||||
# Left shadow edge.
|
||||
draw_line(Vector2(-5.0, -13.0), Vector2(-5.0, 0.0), stone_dark, 1.0)
|
||||
# Cross etched on the slab face: vertical + horizontal bar.
|
||||
draw_line(Vector2(0.0, -11.0), Vector2(0.0, -3.0), cross_col, 1.5)
|
||||
draw_line(Vector2(-3.0, -9.0), Vector2(3.0, -9.0), cross_col, 1.5)
|
||||
# Outline.
|
||||
draw_rect(Rect2(-5.0, -13.0, 10.0, 13.0), stone_dark, false, 1.0)
|
||||
|
||||
|
||||
# ── save / load ──────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"name": deceased_name,
|
||||
"color_r": deceased_portrait_color.r,
|
||||
"color_g": deceased_portrait_color.g,
|
||||
"color_b": deceased_portrait_color.b,
|
||||
"cause": String(death_cause),
|
||||
"death_tick": death_tick,
|
||||
}
|
||||
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
tile = Vector2i(int(d.get("tile_x", 0)), int(d.get("tile_y", 0)))
|
||||
global_position = Vector2(tile.x * TILE_SIZE_PX + TILE_SIZE_PX / 2.0,
|
||||
tile.y * TILE_SIZE_PX + TILE_SIZE_PX)
|
||||
deceased_name = d.get("name", "")
|
||||
deceased_portrait_color = Color(
|
||||
d.get("color_r", 0.70),
|
||||
d.get("color_g", 0.60),
|
||||
d.get("color_b", 0.55)
|
||||
)
|
||||
death_cause = StringName(d.get("cause", ""))
|
||||
death_tick = int(d.get("death_tick", 0))
|
||||
queue_redraw()
|
||||
1
scenes/entities/grave_marker.gd.uid
Normal file
1
scenes/entities/grave_marker.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c8oc06wuoo31w
|
||||
204
scenes/entities/grave_slot.gd
Normal file
204
scenes/entities/grave_slot.gd
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
class_name GraveSlot extends Node2D
|
||||
## Phase 14 — per-tile grave slot entity. Spawned by the designation system when
|
||||
## the player paints TOOL_DIG_GRAVE. Progresses through a two-state build model:
|
||||
##
|
||||
## ghost (BUILD_TICKS not yet reached)
|
||||
## ↓ ConstructionProvider builds it via on_build_tick()
|
||||
## dug (open hole, ready for a corpse)
|
||||
## ↓ HaulingProvider routes a corpse here; accept_corpse() is called
|
||||
## (GraveSlot queue_free-s itself; GraveMarker spawned at same tile)
|
||||
##
|
||||
## Build contract: same duck-type interface as Wall / Floor / Door so that
|
||||
## ConstructionProvider's untyped iteration in World.build_queue picks it up
|
||||
## automatically without any dispatch addition.
|
||||
## site.tile: Vector2i
|
||||
## site.is_buildable() -> bool
|
||||
## site.label() -> String
|
||||
## site.get_path() -> NodePath
|
||||
## site.blocks_pathing_when_complete() -> bool (returns false — grave stays walkable)
|
||||
##
|
||||
## StorageDestination duck-type interface (registered in World.stockpiles):
|
||||
## accepts(item) -> bool
|
||||
## find_drop_position(item) -> Vector2i
|
||||
## covers_tile(tile) -> bool
|
||||
## is_grave_slot_dug() -> bool (queried by GraveyardZone._find_open_grave_slot)
|
||||
##
|
||||
## See docs/implementation.md Phase 14 "GraveSlot".
|
||||
|
||||
const TILE_SIZE_PX: int = 16
|
||||
|
||||
## Sim ticks to dig the grave (80 ticks ≈ 4 s at 1×).
|
||||
const BUILD_TICKS: int = 80
|
||||
|
||||
## Visual colours.
|
||||
const _GHOST_FILL := Color(0.38, 0.28, 0.16, 0.35) # pale dirt, transparent
|
||||
const _DUG_FILL := Color(0.28, 0.18, 0.08, 0.85) # dark open earth
|
||||
const _OUTLINE := Color(0.18, 0.12, 0.06, 0.80)
|
||||
|
||||
## Tile position.
|
||||
@export var tile: Vector2i = Vector2i.ZERO
|
||||
|
||||
var build_progress: int = 0
|
||||
var _dug: bool = false # true once BUILD_TICKS reached (ghost→dug transition)
|
||||
|
||||
|
||||
# ── lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
# Register as a build site so ConstructionProvider picks it up.
|
||||
World.register_build_site(self)
|
||||
# Register as a stockpile destination so HaulingProvider can route corpses here.
|
||||
World.register_stockpile(self)
|
||||
z_index = 1 # above terrain, below items
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
World.unregister_build_site(self)
|
||||
World.unregister_stockpile(self)
|
||||
|
||||
|
||||
# ── public setup ──────────────────────────────────────────────────────────────
|
||||
|
||||
## One-shot initialiser. Call after add_child(). Sets tile + world position.
|
||||
func setup(p_tile: Vector2i) -> void:
|
||||
tile = p_tile
|
||||
# Centre-align within the tile (same convention as Corpse, Item).
|
||||
global_position = Vector2(
|
||||
tile.x * TILE_SIZE_PX + TILE_SIZE_PX / 2.0,
|
||||
tile.y * TILE_SIZE_PX + TILE_SIZE_PX / 2.0
|
||||
)
|
||||
queue_redraw()
|
||||
Audit.log("grave_slot", "ghost placed at %s" % tile)
|
||||
|
||||
|
||||
# ── ConstructionProvider duck-type interface ──────────────────────────────────
|
||||
|
||||
## True while the slot still needs digging. ConstructionProvider checks this.
|
||||
func is_buildable() -> bool:
|
||||
return not _dug
|
||||
|
||||
|
||||
## GraveSlot stays walkable after being dug — the pawn stands on it to deposit.
|
||||
func blocks_pathing_when_complete() -> bool:
|
||||
return false
|
||||
|
||||
|
||||
## Human-readable job label used by ConstructionProvider and Audit logs.
|
||||
func label() -> String:
|
||||
return "grave"
|
||||
|
||||
|
||||
## Called by the BUILD toil in JobRunner once per sim tick while the pawn digs.
|
||||
func on_build_tick() -> void:
|
||||
if _dug:
|
||||
return
|
||||
build_progress += 1
|
||||
queue_redraw()
|
||||
if build_progress >= BUILD_TICKS:
|
||||
_complete_dig()
|
||||
|
||||
|
||||
## True once the slot has finished the ghost-phase (for World._on_designation_cleared).
|
||||
func is_completed() -> bool:
|
||||
return _dug
|
||||
|
||||
|
||||
# ── StorageDestination duck-type interface ────────────────────────────────────
|
||||
|
||||
## Returns true if this slot is dug (open) and ready to accept a corpse.
|
||||
## GraveyardZone calls this to verify an open slot exists in the region.
|
||||
func is_grave_slot_dug() -> bool:
|
||||
return _dug
|
||||
|
||||
|
||||
## Returns true if `item` is a Corpse entity AND this slot is dug.
|
||||
func accepts(item) -> bool:
|
||||
if not _dug:
|
||||
return false
|
||||
return item.has_method("get_item_type") and item.get_item_type() == &"corpse"
|
||||
|
||||
|
||||
## Returns the slot's own tile if it is dug and available; Vector2i(-1,-1) otherwise.
|
||||
func find_drop_position(item) -> Vector2i:
|
||||
if not accepts(item):
|
||||
return Vector2i(-1, -1)
|
||||
return tile
|
||||
|
||||
|
||||
## True when `p_tile` matches this slot's tile.
|
||||
func covers_tile(p_tile: Vector2i) -> bool:
|
||||
return p_tile == tile
|
||||
|
||||
|
||||
## Priority mirrors StorageDestination enum so HaulingProvider's priority
|
||||
## comparison works cleanly. NORMAL for grave slots.
|
||||
var priority: int = StorageDestination.Priority.NORMAL
|
||||
|
||||
|
||||
# ── burial ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
## Called by JobRunner._tick_deposit_corpse when a pawn has carried a corpse
|
||||
## here and is standing on this tile. Instantiates a GraveMarker at this tile,
|
||||
## emits EventBus.corpse_buried, then frees both the corpse and this slot.
|
||||
func accept_corpse(corpse, world_parent: Node) -> void:
|
||||
if not _dug:
|
||||
Audit.log("grave_slot", "accept_corpse called before slot is dug at %s — ignoring" % tile)
|
||||
return
|
||||
|
||||
Audit.log("grave_slot", "burying '%s' at %s" % [corpse.deceased_name, tile])
|
||||
|
||||
# Spawn permanent GraveMarker.
|
||||
var marker_script: Script = load("res://scenes/entities/grave_marker.gd")
|
||||
var marker := Node2D.new()
|
||||
marker.set_script(marker_script)
|
||||
marker.name = "GraveMarker_%s_%s" % [tile.x, tile.y]
|
||||
world_parent.add_child(marker)
|
||||
marker.setup(tile, corpse.deceased_name, corpse.deceased_portrait_color,
|
||||
corpse.death_cause, corpse.death_tick)
|
||||
|
||||
Audit.log("grave_slot", "marker placed for '%s' (cause=%s death_tick=%d)" % [
|
||||
corpse.deceased_name, corpse.death_cause, corpse.death_tick
|
||||
])
|
||||
|
||||
EventBus.corpse_buried.emit(corpse, marker)
|
||||
|
||||
# Free the corpse and the slot — marker persists.
|
||||
corpse.queue_free()
|
||||
queue_free()
|
||||
|
||||
|
||||
# ── visual ────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _draw() -> void:
|
||||
# Drawn centred in tile (origin = tile centre).
|
||||
if _dug:
|
||||
_draw_open_grave()
|
||||
else:
|
||||
_draw_ghost()
|
||||
|
||||
|
||||
func _draw_ghost() -> void:
|
||||
# Transparent dashed outline: dug-grave shape as a ghost.
|
||||
draw_rect(Rect2(-6.0, -4.0, 12.0, 8.0), _GHOST_FILL, true)
|
||||
draw_rect(Rect2(-6.0, -4.0, 12.0, 8.0), Color(_OUTLINE.r, _OUTLINE.g, _OUTLINE.b, 0.40), false, 1.0)
|
||||
# Progress bar — thin strip across bottom.
|
||||
if BUILD_TICKS > 0 and build_progress > 0:
|
||||
var pct := float(build_progress) / float(BUILD_TICKS)
|
||||
var bar_w := 12.0 * pct
|
||||
draw_rect(Rect2(-6.0, 3.0, bar_w, 1.5), Color(0.6, 0.5, 0.3, 0.6), true)
|
||||
|
||||
|
||||
func _draw_open_grave() -> void:
|
||||
# Dark open pit: recessed rectangle to suggest depth.
|
||||
draw_rect(Rect2(-6.0, -4.0, 12.0, 8.0), _DUG_FILL, true)
|
||||
# Lighter near-edge to suggest rim of earth.
|
||||
draw_rect(Rect2(-6.0, -4.0, 12.0, 2.0), Color(0.45, 0.33, 0.18, 0.70), true)
|
||||
draw_rect(Rect2(-6.0, -4.0, 12.0, 8.0), _OUTLINE, false, 1.0)
|
||||
|
||||
|
||||
# ── internal ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _complete_dig() -> void:
|
||||
_dug = true
|
||||
queue_redraw()
|
||||
Audit.log("grave_slot", "grave dug at %s (ready for burial)" % tile)
|
||||
1
scenes/entities/grave_slot.gd.uid
Normal file
1
scenes/entities/grave_slot.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://5g5j6rjof8rf
|
||||
|
|
@ -43,6 +43,9 @@ const TYPE_STONE_BLOCK: StringName = &"stone_block"
|
|||
const TYPE_FLOUR: StringName = &"flour"
|
||||
const TYPE_BREAD: StringName = &"bread"
|
||||
|
||||
# Phase 14 — cremation output. One ash item drops per cremated corpse.
|
||||
const TYPE_ASH: StringName = &"ash"
|
||||
|
||||
const ALL_TYPES: Array[StringName] = [
|
||||
TYPE_WOOD, TYPE_STONE, TYPE_IRON_ORE, TYPE_COPPER_ORE,
|
||||
TYPE_SILVER, TYPE_GOLD, TYPE_CLOTH, TYPE_VEGETABLE,
|
||||
|
|
@ -50,6 +53,7 @@ const ALL_TYPES: Array[StringName] = [
|
|||
TYPE_TOOL, TYPE_WEAPON, TYPE_ARMOR, TYPE_CORPSE,
|
||||
TYPE_PLANK, TYPE_STONE_BLOCK,
|
||||
TYPE_FLOUR, TYPE_BREAD,
|
||||
TYPE_ASH,
|
||||
]
|
||||
|
||||
# ── quality system (docs/architecture.md "Quality system") ───────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue