rimlike/scenes/world/dirtiness_system.gd
megaproxy 9cf9b7dbfd Phase 13: Rooms + Auto-roof + Beauty + Dirtiness + Cleaning
Three-agent fan-out — Opus pre-wrote Room class, World.rooms/room_at_tile/is_indoor,
4 EventBus signals before dispatch so the slices ran fully parallel.

DECISION: Big-room UX = bump auto-roof cap to 16, banner above. Cabin
(24 tiles) intentionally exceeds cap to exercise the warning path; a
5×5 test shed (9 interior tiles) was added to exercise the roof path.

Room detection (Agent A):
- scenes/world/room.gd — class_name Room, tiles/bounds/is_under_roof,
  contains_tile() bounds-then-list-checked, recompute_bounds()
- scenes/world/room_detector.gd — class_name RoomDetector, BFS 4-dir
  from floor/door tiles, walls/terrain as boundary, doors counted as
  room interior. Detects up to 4× cap; auto-roofs only ≤16.
- World.mark_wall_tile/mark_floor_tile/mark_door_tile hook BFS recompute
- Door._complete() now erases wall-layer stamp + registers door tile
- Designation.TOOL_NO_ROOF paint mode wired (UI button deferred Phase 17)
- EventBus.room_changed / room_too_large signals

Indoor/Shelter (Agent B):
- Pawn._is_sheltered() rerouted: World.is_indoor() first, floor-proxy fallback
- IndoorTintOverlay Node2D — _draw fills roofed-room tiles at α=0.10 warm
- Crop._on_sim_tick skips stage advance when World.is_indoor(tile)

Beauty + Dirtiness + Cleaning + Room thoughts (Agent C):
- BeautySystem sparse map, linear falloff radius=3, Quality multiplier
  (SHODDY 0.5 → LEGENDARY 2.5). Base: Bed +2, Workbench +1, Torch +3, Hearth +4
- DirtinessSystem 0-100, tier crossings (clean<25/dirty<60/filthy≥60)
  emit tile_dirtiness_changed. bump/bump_clean/bump_pawn_traffic API
- CleaningProvider priority=2, KIND_CLEAN toil, 2.5 dirt/tick for ~40 ticks
- Bed/Torch/Workbench _complete() now register with BeautySystem
- 7 room mood thoughts: clean_room (+2), dirty_room (-3), filthy_room (-6),
  beautiful_room (+4), ugly_room (-3), slept_in_room (+3 EVENT, wires Ph 17),
  ate_without_table (-3 EVENT, wires Ph 17)
- Pawn._sync_room_thoughts called from _process_thoughts after cold block,
  defensive against null rooms/systems

Integration recovery (Opus):
- Agent C's BeautySystem/DirtinessSystem/CleaningProvider/IndoorTintOverlay
  instantiation in world.gd never landed (only field declarations + entity
  hooks survived). Added preloads + runtime add_child + autoload bindings +
  CleaningProvider registration + furniture pre-seed in _ready
- Added _prestamp_test_shed_for_room_detector with _spawn_complete_wall/floor
  helpers so a 5×5 visible shed exercises the auto-roof path at boot

MCP runtime verified:
- Rooms: cabin Room#2 size=24 roofed=false (room_too_large fires),
  shed Room#3 size=9 roofed=true (auto-roof active)
- beauty_map size=50 around prebuilt furniture; bed at (47,24) beauty=4.0
- Bram teleported to (36, 25) in shed → indoor=true, sheltered=true,
  thoughts=[clean_room +2], mood=52.0
- Screenshot: shed walls + brown floor visible; cabin warmly torch-lit;
  Spring 1/12 indicator; Day 1 07:52

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

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 17:19:23 +01:00

109 lines
4.4 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name DirtinessSystem extends Node
## Phase 13 — per-tile dirtiness accumulation and tier tracking.
##
## dirt_map: Dictionary[Vector2i, float], 0..100 scale. Only tiles with non-zero
## dirt are keyed (sparse).
##
## Public API:
## bump(tile, amount) — add dirtiness to a tile. Positive adds dirt; use
## negative values to reduce (cleaning does this via
## bump_clean). Phase 14 calls bump(tile, +5) per hour
## for corpse decay and bump(tile, +20) for combat blood.
## bump_clean(tile, amount) — specialised helper for the CleaningProvider;
## reduces dirt and removes the tile from the map at 0.
## dirt_at(tile) — returns the current dirtiness for a tile (0.0 default).
##
## Tier thresholds (per design.md):
## Clean < 25
## Dirty 25..60
## Filthy >= 60
##
## EventBus.tile_dirtiness_changed fires on TIER crossings only, not every bump.
## This keeps signal volume low since bumps fire 20×/s per pawn crossing.
##
## Pawn tile-change hook:
## World scene calls bump_pawn_traffic(tile, indoor) each time a pawn advances
## a tile. Indoor traffic adds 0.2; outdoor-tracked-in adds 0.5.
## (world.gd bridges _advance_walk → DirtinessSystem via the arrived_at_destination
## signal on each Pawn — wired in world.gd _spawn_sample_pawns / _on_pawn_ready.)
##
## Wire as child of the World scene (after Pathfinder). world.gd exposes the
## instance on the World autoload as World.dirtiness_system for entity code.
## Sparse map: only tiles with non-zero dirt are stored.
## Keys = Vector2i tile coords; Values = float in [0, 100].
var dirt_map: Dictionary = {}
## Tier boundaries (thresholds match design.md; tune Phase 20).
const DIRT_DIRTY_THRESHOLD: float = 25.0
const DIRT_FILTHY_THRESHOLD: float = 60.0
## Traffic bump amounts per pawn step.
const BUMP_OUTDOOR_TRACKED: float = 0.5 # boots bringing dirt in from outside
const BUMP_INDOOR_TRAFFIC: float = 0.2 # indoor walking
# ── public API ────────────────────────────────────────────────────────────────
## Returns the dirtiness score for `tile` (0.0 if clean / not in map).
func dirt_at(tile: Vector2i) -> float:
return float(dirt_map.get(tile, 0.0))
## Add `amount` of dirt to `tile`. Clamped to [0, 100].
## Emits EventBus.tile_dirtiness_changed when a tier boundary is crossed.
## Phase 14 calls this for blood (+20) and corpse decay (+5/h).
func bump(tile: Vector2i, amount: float) -> void:
var old_val: float = float(dirt_map.get(tile, 0.0))
var new_val: float = clampf(old_val + amount, 0.0, 100.0)
if is_equal_approx(new_val, old_val):
return
_set_dirt(tile, old_val, new_val)
## Reduce dirt by `amount`, flooring at 0. Removes tile from map when clean.
## Used by CleaningProvider's KIND_CLEAN toil each tick.
func bump_clean(tile: Vector2i, amount: float) -> void:
var old_val: float = float(dirt_map.get(tile, 0.0))
if old_val <= 0.0:
return
var new_val: float = maxf(0.0, old_val - amount)
_set_dirt(tile, old_val, new_val)
## Traffic-driven dirt bump. Called by World when a pawn arrives at a new tile.
## `indoor` = true when the tile is inside a roofed room (World.is_indoor check).
func bump_pawn_traffic(tile: Vector2i, indoor: bool) -> void:
var amount := BUMP_INDOOR_TRAFFIC if indoor else BUMP_OUTDOOR_TRACKED
bump(tile, amount)
# ── internal ──────────────────────────────────────────────────────────────────
## Apply a dirt change from old_val to new_val for `tile`.
## Updates the map and emits the tier-crossing signal when the tier changes.
func _set_dirt(tile: Vector2i, old_val: float, new_val: float) -> void:
var old_tier: int = _tier_for(old_val)
var new_tier: int = _tier_for(new_val)
if new_val <= 0.0:
dirt_map.erase(tile)
else:
dirt_map[tile] = new_val
if old_tier != new_tier:
EventBus.tile_dirtiness_changed.emit(tile, new_val)
Audit.log(
"dirtiness",
"tile %s tier %d%d (dirt=%.1f)" % [tile, old_tier, new_tier, new_val]
)
## Returns the dirtiness tier for a given value.
## 0 = clean, 1 = dirty, 2 = filthy.
func _tier_for(val: float) -> int:
if val >= DIRT_FILTHY_THRESHOLD:
return 2
if val >= DIRT_DIRTY_THRESHOLD:
return 1
return 0