Phase 12: Seasons + Weather (rolls, rain, storm, wet/cold)

48-day year (4 seasons × 12 days), daily weather rolls, rain visual,
storm flash, Wet/Cold statuses with mood thoughts.

Three-agent fan-out — Opus prepped contracts up front (event_bus
signals, Clock season constants, Weather autoload stub) so the three
slices could run fully parallel and integrate on first try.

Calendar (Agent A):
- Clock season API — SEASON_SPRING/SUMMER/AUTUMN/WINTER constants,
  current_season(), current_season_index(), day_of_season(),
  current_year(), DAYS_PER_SEASON=12, DAYS_PER_YEAR=48
- EventBus.season_changed emitted on transition (mirrors phase_changed)
- Top-bar SeasonLabel ('Spring 1/12') with localized season names via
  Strings.t() — season.spring/summer/autumn/winter + season.format
- Terrain TileMapLayer seasonal palette modulate
  (spring=warm-green, summer=neutral, autumn=warm-orange, winter=cool-blue)

Weather (Agent B):
- autoload/weather.gd — daily roll triggered by Clock day-index change
  Probability tables per season (placeholders, tune Phase 20):
    spring  60% clear / 35% rain /  5% storm
    summer  75% clear / 18% rain /  7% storm
    autumn  50% clear / 35% rain / 12% storm /  3% cold_snap
    winter  55% clear / 15% rain / 10% storm / 20% cold_snap
- EventBus.weather_changed signal
- scenes/world/rain_overlay.tscn — procedural _draw() diagonal raindrops
  on a CanvasLayer (chosen over CPUParticles2D for pixel-art exactness
  and to colocate storm-flash logic in one weather-aware script)
- Storm flash — Tween-driven ColorRect at random 4-8s intervals
- Save round-trip preserves _last_day_index to prevent double-rolling

Wet + Cold + Mood (Agent C):
- StatusCatalog.wet(severity 1-2) — Damp at 25, Soaked at 60 (of 100)
- StatusCatalog.cold(severity 1-3) — Mild at 25, Severe at 60, Extreme at 85
- ThoughtCatalog.damp(-3), soaked(-6), cold_thought(-4)
- Pawn._wet_accum / _cold_accum floats, ticked in _process_statuses:
  +0.02/tick rain (×2 storm), -0.05/tick decay when sheltered
  +0.015/tick cold winter-or-snap (×2 cold_snap)
- _sync_wet_status / _sync_cold_status — severity-flip detection with
  one Audit line per transition
- _is_sheltered() v1: World.floor_layer.get_cell_source_id != -1
  Phase 13 replaces with proper Room BFS
- _wet_accum / _cold_accum round-trip through Pawn.to_dict / from_dict
- Persistent thought sync in _process_thoughts after in_darkness

MCP runtime verified:
- Top-bar 'Spring 1/12' renders; green seasonal terrain tint visible
- Rain droplets render across screen; storm flash captured mid-animation
- Bram wet=26 (Damp) → wet=65 (Soaked) with mood thought (-6), mood=30
- Cora cold=30 cold_snap → Cold status sev=1 + Cold thought (-4), mood=32
- Daily weather rolls visible day 0-5 (rain → clear → rain → clear → rain)

Quick-edit fixup mid-flight: Variant inference errors on
'var old_sev := s.severity' (untyped Array loop var). Same trap as
the Phase 7 crop fix; pattern is now to always explicit-type ':='
when the rhs is non-typed-Array element access.

Delegation: 3× gdscript-refactor agents in parallel, 1× quick-edit
for the Variant-inference fix; integration + MCP verify on Opus.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-11 16:39:34 +01:00
parent 1b6ad2bcc6
commit 92f4e5c945
19 changed files with 692 additions and 19 deletions

View file

@ -127,6 +127,15 @@ var hp: float = HP_MAX
# remove_status_by_id() which emit EventBus signals and enforce stack-merge logic.
var statuses: Array = [] # Array[Status]
# Phase 12 — wet / cold accumulators (0100).
# _wet_accum rises while the pawn is outdoors in rain; decays otherwise.
# Crosses WET_DAMP_THRESHOLD (25) → Damp status; WET_SOAKED_THRESHOLD (60) → Soaked.
# _cold_accum rises in winter or during a cold snap outdoors; decays otherwise.
# Mirroring StatusCatalog constants — do not read StatusCatalog inside property
# access paths; use _wet_severity() / _cold_severity() helpers instead.
var _wet_accum: float = 0.0
var _cold_accum: float = 0.0
var _path: Array[Vector2i] = []
var _step_progress: float = 0.0
var _selected: bool = false
@ -386,6 +395,11 @@ func _process_thoughts() -> void:
var _dark_time := Clock.darkness_factor() > 0.3
var _lit := World.is_tile_lit(tile)
_sync_persistent_thought(&"in_darkness", _dark_time and not _lit, ThoughtCatalog.in_darkness())
# Phase 12 — wet mood thoughts (mutually exclusive tiers; damp removed when soaked kicks in).
_sync_persistent_thought(&"damp", has_status(&"wet") and _wet_severity() == StatusCatalog.WET_DAMP_LEVEL, ThoughtCatalog.damp())
_sync_persistent_thought(&"soaked", has_status(&"wet") and _wet_severity() == StatusCatalog.WET_SOAKED_LEVEL, ThoughtCatalog.soaked())
# Phase 12 — cold mood thought (any cold severity triggers the single cold thought).
_sync_persistent_thought(&"cold", has_status(&"cold"), ThoughtCatalog.cold_thought())
# 3. Recompute if EVENT thoughts expired (persistent syncs call _recompute_mood internally).
if dirty:
_recompute_mood()
@ -443,6 +457,7 @@ func _process_sulking() -> void:
## Sequence:
## 1. Decay EVENT statuses — remove expired ones.
## 2. Apply per-tick effects (Bleeding drains HP).
## 3. Phase 12 — tick wet / cold accumulators and sync statuses.
##
## Bleeding does NOT log per-tick — would flood Audit. Named-source logging
## happens in take_damage() only when source is non-empty.
@ -461,6 +476,126 @@ func _process_statuses() -> void:
hp = maxf(0.0, hp - StatusCatalog.BLEED_HP_PER_TICK * float(s.severity))
EventBus.pawn_took_damage.emit(self, StatusCatalog.BLEED_HP_PER_TICK * float(s.severity))
_check_downed()
# 3. Phase 12 — wet / cold environment exposure.
_tick_wet()
_tick_cold()
## Tick the wet accumulator and sync the Wet status severity.
## Called every sim tick from _process_statuses().
func _tick_wet() -> void:
var sheltered := _is_sheltered()
if Weather.is_raining() and not sheltered:
var rate := StatusCatalog.WET_GAIN_PER_TICK * (2.0 if Weather.is_storming() else 1.0)
_wet_accum = clampf(_wet_accum + rate, 0.0, 100.0)
else:
_wet_accum = clampf(_wet_accum - StatusCatalog.WET_DECAY_PER_TICK, 0.0, 100.0)
_sync_wet_status()
## Tick the cold accumulator and sync the Cold status severity.
## Cold accumulates outdoors in winter OR during any cold snap regardless of season.
func _tick_cold() -> void:
var sheltered := _is_sheltered()
var cold_conditions := (Clock.current_season() == Clock.SEASON_WINTER or Weather.is_cold_snap())
if cold_conditions and not sheltered:
var rate := StatusCatalog.COLD_GAIN_PER_TICK * (2.0 if Weather.is_cold_snap() else 1.0)
_cold_accum = clampf(_cold_accum + rate, 0.0, 100.0)
else:
_cold_accum = clampf(_cold_accum - StatusCatalog.COLD_DECAY_PER_TICK, 0.0, 100.0)
_sync_cold_status()
## Compute the target wet severity from the current accumulator.
## Returns 0 (no status), 1 (Damp), or 2 (Soaked).
func _wet_severity() -> int:
for s in statuses:
if s.id == &"wet":
return s.severity
return 0
## Compute the target cold severity from the current accumulator.
## Returns 0 (no status), 1, 2, or 3.
func _cold_severity() -> int:
for s in statuses:
if s.id == &"cold":
return s.severity
return 0
## Sync the Wet status to match the current _wet_accum tier.
## Adds, updates severity, or removes the status with one Audit log per transition.
func _sync_wet_status() -> void:
var target: int
if _wet_accum >= StatusCatalog.WET_SOAKED_THRESHOLD:
target = StatusCatalog.WET_SOAKED_LEVEL
elif _wet_accum >= StatusCatalog.WET_DAMP_THRESHOLD:
target = StatusCatalog.WET_DAMP_LEVEL
else:
target = 0
var current := _wet_severity()
if target == current:
return
if target == 0:
remove_status_by_id(&"wet")
Audit.log("pawn", "%s dried off (wet=%.1f)" % [pawn_name, _wet_accum])
elif current == 0:
# Not wet → newly wet.
var label := "Damp" if target == StatusCatalog.WET_DAMP_LEVEL else "Soaked"
add_status(StatusCatalog.wet(target))
Audit.log("pawn", "%s now %s (wet=%.1f)" % [pawn_name, label, _wet_accum])
else:
# Severity shift — update in place to preserve the status object.
for s in statuses:
if s.id == &"wet":
var old_sev: int = s.severity
s.severity = target
var label := "Soaked" if target == StatusCatalog.WET_SOAKED_LEVEL else "Damp"
Audit.log("pawn", "%s now %s (wet=%.1f, sev %d%d)" % [pawn_name, label, _wet_accum, old_sev, target])
break
## Sync the Cold status to match the current _cold_accum tier.
## Adds, updates severity, or removes the status with one Audit log per transition.
func _sync_cold_status() -> void:
var target: int
if _cold_accum >= StatusCatalog.COLD_EXTREME_THRESHOLD:
target = 3
elif _cold_accum >= StatusCatalog.COLD_SEVERE_THRESHOLD:
target = 2
elif _cold_accum >= StatusCatalog.COLD_MILD_THRESHOLD:
target = 1
else:
target = 0
var current := _cold_severity()
if target == current:
return
if target == 0:
remove_status_by_id(&"cold")
Audit.log("pawn", "%s warmed up (cold=%.1f)" % [pawn_name, _cold_accum])
elif current == 0:
add_status(StatusCatalog.cold(target))
Audit.log("pawn", "%s now Cold severity %d (cold=%.1f)" % [pawn_name, target, _cold_accum])
else:
for s in statuses:
if s.id == &"cold":
var old_sev: int = s.severity
s.severity = target
Audit.log("pawn", "%s Cold sev %d%d (cold=%.1f)" % [pawn_name, old_sev, target, _cold_accum])
break
## Phase 12 — returns true if the pawn's current tile has a floor beneath it.
## This is a Phase 13 stand-in for full Room/Roof detection. A tile is considered
## sheltered when World.floor_layer reports a valid cell at the pawn's tile position.
## Replace with Room.contains(tile) once the Room BFS system lands (Phase 13+).
func _is_sheltered() -> bool:
return World.floor_layer.get_cell_source_id(tile) != -1
# ── save / load ─────────────────────────────────────────────────────────────
@ -500,6 +635,9 @@ func to_dict() -> Dictionary:
"statuses": statuses_data,
"sulk_low_ticks": _sulk_low_ticks,
"sulking": sulking,
# Phase 12 — wet / cold accumulators. Default 0 for pre-Phase-12 save compat.
"wet_accum": _wet_accum,
"cold_accum": _cold_accum,
}
@ -546,6 +684,10 @@ func from_dict(d: Dictionary) -> void:
if sd is Dictionary:
statuses.append(Status.from_dict(sd))
# Phase 12 — restore wet / cold accumulators; default 0 for pre-Phase-12 saves.
_wet_accum = clampf(float(d.get("wet_accum", 0.0)), 0.0, 100.0)
_cold_accum = clampf(float(d.get("cold_accum", 0.0)), 0.0, 100.0)
# Restore skills — set directly on the dict to bypass the ALL_SKILLS assert
# (from_dict must be resilient to saves that pre-date a new skill being added).
var saved_skills: Variant = d.get("skills")