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:
parent
1b6ad2bcc6
commit
92f4e5c945
19 changed files with 692 additions and 19 deletions
|
|
@ -45,7 +45,20 @@ const PHASE_DAWN: StringName = &"dawn"
|
|||
const PHASE_DAY: StringName = &"day"
|
||||
const PHASE_DUSK: StringName = &"dusk"
|
||||
|
||||
# Phase 12 — Season contracts (Agent A fills in current_season() + day_of_season()).
|
||||
# Names locked here so Agent B + C can reference them without race conditions.
|
||||
const SEASON_SPRING: StringName = &"spring"
|
||||
const SEASON_SUMMER: StringName = &"summer"
|
||||
const SEASON_AUTUMN: StringName = &"autumn"
|
||||
const SEASON_WINTER: StringName = &"winter"
|
||||
const SEASONS: Array[StringName] = [SEASON_SPRING, SEASON_SUMMER, SEASON_AUTUMN, SEASON_WINTER]
|
||||
const DAYS_PER_SEASON: int = 12
|
||||
const SEASONS_PER_YEAR: int = 4
|
||||
const DAYS_PER_YEAR: int = DAYS_PER_SEASON * SEASONS_PER_YEAR # 48
|
||||
|
||||
var _last_emitted_phase: StringName = &""
|
||||
## Mirrors _last_emitted_phase — guards the season_changed emit against repeat fires.
|
||||
var _last_emitted_season: StringName = &""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -114,6 +127,33 @@ func time_string() -> String:
|
|||
return "%02d:%02d" % [current_hour(), current_minute()]
|
||||
|
||||
|
||||
# Phase 12 — Season public API (stub; Agent A wires emit + season_changed).
|
||||
|
||||
## Day index since game start (0-indexed, ignores 1-indexed display).
|
||||
func day_index_from_start() -> int:
|
||||
return _offset_ticks() / TICKS_PER_DAY
|
||||
|
||||
|
||||
## Current season index 0..3 (spring/summer/autumn/winter).
|
||||
func current_season_index() -> int:
|
||||
return (day_index_from_start() / DAYS_PER_SEASON) % SEASONS_PER_YEAR
|
||||
|
||||
|
||||
## Current season as a locked StringName constant.
|
||||
func current_season() -> StringName:
|
||||
return SEASONS[current_season_index()]
|
||||
|
||||
|
||||
## Day within the current season, 0..DAYS_PER_SEASON-1.
|
||||
func day_of_season() -> int:
|
||||
return day_index_from_start() % DAYS_PER_SEASON
|
||||
|
||||
|
||||
## Current year (1-indexed; Year 1 starts at boot).
|
||||
func current_year() -> int:
|
||||
return 1 + day_index_from_start() / DAYS_PER_YEAR
|
||||
|
||||
|
||||
# ── internal ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _offset_ticks() -> int:
|
||||
|
|
@ -127,6 +167,14 @@ func _on_sim_tick(_n: int) -> void:
|
|||
emit_signal("phase_changed", phase)
|
||||
Audit.log("clock", "phase → %s (day %d, %s)" % [phase, current_day(), time_string()])
|
||||
|
||||
var season: StringName = current_season()
|
||||
if season != _last_emitted_season:
|
||||
_last_emitted_season = season
|
||||
EventBus.season_changed.emit(season)
|
||||
Audit.log("clock", "season → %s (day %d/%d of season, year %d)" % [
|
||||
season, day_of_season() + 1, DAYS_PER_SEASON, current_year()
|
||||
])
|
||||
|
||||
|
||||
# ── save / load ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
|
|
@ -21,3 +21,7 @@ signal pawn_mood_changed(pawn, mood: float) ## Emitted by Pawn._recompute_mood(
|
|||
signal pawn_took_damage(pawn, amount: float) ## Emitted by Pawn.take_damage() after HP is reduced.
|
||||
signal pawn_status_added(pawn, status) ## Emitted by Pawn.add_status() when a new status is appended.
|
||||
signal pawn_status_removed(pawn, status) ## Emitted by Pawn.remove_status_by_id() when a status is dropped.
|
||||
|
||||
# Phase 12 — Seasons + Weather.
|
||||
signal season_changed(season: StringName) ## Emitted by Clock when current_season() rolls over (Spring → Summer → Autumn → Winter).
|
||||
signal weather_changed(weather: StringName) ## Emitted by Weather autoload when the daily roll resolves to a new weather kind.
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ const TABLE: Dictionary = {
|
|||
&"hud.tick": "Tick: {n}",
|
||||
# Phase 11 — in-game clock display ("{d}" = day, "{t}" = "HH:MM")
|
||||
&"clock.format": "Day {d}, {t}",
|
||||
# Phase 12 — season indicator ("{s}" = season name, "{d}" = 1-indexed day, "{total}" = days per season)
|
||||
&"season.spring": "Spring",
|
||||
&"season.summer": "Summer",
|
||||
&"season.autumn": "Autumn",
|
||||
&"season.winter": "Winter",
|
||||
&"season.format": "{s} {d}/12",
|
||||
# Pawn state labels
|
||||
&"pawn.state.idle": "idle",
|
||||
&"pawn.state.walking": "walking",
|
||||
|
|
|
|||
116
autoload/weather.gd
Normal file
116
autoload/weather.gd
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
extends Node
|
||||
## Daily weather roll + queries.
|
||||
##
|
||||
## Rolls once per in-game day (triggered by EventBus.sim_tick), using
|
||||
## season-weighted probabilities from design.md §"Weather — 4 types, daily roll".
|
||||
## Emits EventBus.weather_changed(weather) when the kind changes.
|
||||
##
|
||||
## Public API (locked — Agents A + C compile against these names):
|
||||
## const WEATHER_CLEAR / RAIN / STORM / COLD_SNAP : StringName
|
||||
## current_weather: StringName
|
||||
## is_raining() -> bool # rain OR storm
|
||||
## is_storming() -> bool # storm only
|
||||
## is_cold_snap() -> bool # cold_snap only
|
||||
## save_dict() / apply_dict() # day_index + current_weather round-trip
|
||||
|
||||
const WEATHER_CLEAR: StringName = &"clear"
|
||||
const WEATHER_RAIN: StringName = &"rain"
|
||||
const WEATHER_STORM: StringName = &"storm"
|
||||
const WEATHER_COLD_SNAP: StringName = &"cold_snap"
|
||||
|
||||
## Current weather kind. Changes once per in-game day.
|
||||
var current_weather: StringName = WEATHER_CLEAR
|
||||
|
||||
## Last day index we rolled for; -1 means no roll yet this session.
|
||||
## Persisted via save_dict / apply_dict so a mid-day reload doesn't double-roll.
|
||||
var _last_day_index: int = -1
|
||||
|
||||
# Season-weighted probability tables.
|
||||
# Each entry is [clear_weight, rain_weight, storm_weight, cold_snap_weight].
|
||||
# Weights are fractions that sum to 1.0 — design.md values (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
|
||||
#
|
||||
# Note: design.md lists slightly different values (e.g. summer 70/20/10).
|
||||
# Agent B's briefing numbers take precedence as they were authored after the
|
||||
# design doc placeholder row — tune both together in Phase 20.
|
||||
const _SEASON_WEIGHTS: Dictionary = {
|
||||
&"spring": [0.60, 0.35, 0.05, 0.00],
|
||||
&"summer": [0.75, 0.18, 0.07, 0.00],
|
||||
&"autumn": [0.50, 0.35, 0.12, 0.03],
|
||||
&"winter": [0.55, 0.15, 0.10, 0.20],
|
||||
}
|
||||
|
||||
# Maps weight-table index → weather kind constant.
|
||||
const _WEATHER_KINDS: Array[StringName] = [
|
||||
WEATHER_CLEAR,
|
||||
WEATHER_RAIN,
|
||||
WEATHER_STORM,
|
||||
WEATHER_COLD_SNAP,
|
||||
]
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
EventBus.sim_tick.connect(_on_sim_tick)
|
||||
|
||||
|
||||
# ── sim tick handler ─────────────────────────────────────────────────────────
|
||||
|
||||
func _on_sim_tick(_tick_n: int) -> void:
|
||||
var day_idx: int = Clock.day_index_from_start()
|
||||
if day_idx == _last_day_index:
|
||||
return # same day — no roll needed
|
||||
_last_day_index = day_idx
|
||||
_roll(day_idx)
|
||||
|
||||
|
||||
func _roll(day_idx: int) -> void:
|
||||
var season: StringName = Clock.current_season()
|
||||
var weights: Array = _SEASON_WEIGHTS.get(season, _SEASON_WEIGHTS[&"spring"])
|
||||
|
||||
var roll: float = randf()
|
||||
var cumulative: float = 0.0
|
||||
var new_weather: StringName = WEATHER_CLEAR
|
||||
|
||||
for i in _WEATHER_KINDS.size():
|
||||
cumulative += weights[i]
|
||||
if roll <= cumulative:
|
||||
new_weather = _WEATHER_KINDS[i]
|
||||
break
|
||||
|
||||
Audit.log("weather", "day %d %s → %s (roll %.3f)" % [day_idx, season, new_weather, roll])
|
||||
|
||||
if new_weather != current_weather:
|
||||
current_weather = new_weather
|
||||
EventBus.weather_changed.emit(current_weather)
|
||||
|
||||
|
||||
# ── public queries ───────────────────────────────────────────────────────────
|
||||
|
||||
func is_raining() -> bool:
|
||||
return current_weather == WEATHER_RAIN or current_weather == WEATHER_STORM
|
||||
|
||||
|
||||
func is_storming() -> bool:
|
||||
return current_weather == WEATHER_STORM
|
||||
|
||||
|
||||
func is_cold_snap() -> bool:
|
||||
return current_weather == WEATHER_COLD_SNAP
|
||||
|
||||
|
||||
# ── save / load ──────────────────────────────────────────────────────────────
|
||||
|
||||
func save_dict() -> Dictionary:
|
||||
return {
|
||||
"weather": String(current_weather),
|
||||
"last_day_index": _last_day_index,
|
||||
}
|
||||
|
||||
|
||||
func apply_dict(d: Dictionary) -> void:
|
||||
current_weather = StringName(d.get("weather", String(WEATHER_CLEAR)))
|
||||
_last_day_index = int(d.get("last_day_index", -1))
|
||||
1
autoload/weather.gd.uid
Normal file
1
autoload/weather.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bi358slq237p5
|
||||
Loading…
Add table
Add a link
Reference in a new issue