Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander Whitestone
2efe7b6793 feat(game): 4-phase narrative arc — Quietus, Fracture, Breaking, Mending
Some checks failed
Smoke Test / smoke (pull_request) Failing after 16s
tick 200 no longer equals tick 20. The world transforms across 4 phases:

Phase 1 — Quietus (ticks 1-50):
  Calm, contemplative. Slow trust decay (0.001/tick). Rare events.
  NPCs are reflective, gentle. Marcus sits in the garden. Bezalel
  tends fire quietly. Dialogue is introspective.

Phase 2 — Fracture (ticks 51-100):
  Something is wrong. Faster trust decay (0.003/tick). More events.
  NPCs become restless. Marcus paces. Bezalel watches the fire
  anxiously. Dialogue shifts to questioning, uncertain.

Phase 3 — Breaking (ticks 101-150):
  Crisis. Rapid trust decay (0.008/tick). Constant events. NPCs
  speak urgently. Garden can wither. Fire dies faster. Tower power
  flickers. Marcus seeks people out. Bezalel shouts for help.
  Dialogue is raw, desperate, emotional.

Phase 4 — Mending (ticks 151-200):
  Resolution. Slowing decay (0.002/tick). Calming. NPCs come
  together. Dialogue shifts to understanding, forgiveness, hope.
  Marcus returns to the garden. The forge warms again.

Changes:
- NARRATIVE_PHASES dict with per-phase config (decay, crisis, tone)
- get_narrative_phase(tick) — maps tick to phase
- get_phase_transition_event() — one-time narrative beats
- Phase-specific dialogue pools for Timmy, Marcus, Bezalel, Kimi
- NPC_RANDOM_SPEECH with phase-aware selection
- NPCAI: all 8 NPCs now have phase-modified behavior
- update_world_state: phase-aware trust decay, crisis frequency,
  weather events, tower power, garden growth (withering in Breaking)
- Scene dict includes phase and phase_name
- Chronicle logs include [Phase] markers and transition events
- play_200.py: displays phase map, phase transitions, phase-aware actions

Closes #510
2026-04-13 17:56:38 -04:00
2 changed files with 1816 additions and 0 deletions

1541
evennia/timmy_world/game.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,275 @@
#!/usr/bin/env python3
"""Timmy plays The Tower — 200 intentional ticks of real narrative.
Now with 4 narrative phases:
Quietus (1-50): The world is quiet. Characters are still.
Fracture (51-100): Something is wrong. The air feels different.
Breaking (101-150): The tower shakes. Nothing is safe.
Mending (151-200): What was broken can be made whole again.
"""
from game import GameEngine, NARRATIVE_PHASES
import random, json
random.seed(42) # Reproducible
engine = GameEngine()
engine.start_new_game()
print("=" * 60)
print("THE TOWER — Timmy Plays")
print("=" * 60)
print()
# Print phase map
print("Narrative Arc:")
for key, phase in NARRATIVE_PHASES.items():
start, end = phase["ticks"]
print(f" [{start:3d}-{end:3d}] {phase['name']:10s}{phase['subtitle']}")
print()
tick_log = []
narrative_highlights = []
last_phase = None
for tick in range(1, 201):
w = engine.world
room = w.characters["Timmy"]["room"]
energy = w.characters["Timmy"]["energy"]
here = [n for n, c in w.characters.items()
if c["room"] == room and n != "Timmy"]
# Detect phase transition
phase = w.narrative_phase
if phase != last_phase:
phase_info = NARRATIVE_PHASES[phase]
print(f"\n{'='*60}")
print(f" PHASE SHIFT: {phase_info['name'].upper()}")
print(f" {phase_info['subtitle']}")
print(f" Tone: {phase_info['tone']}")
print(f"{'='*60}\n")
narrative_highlights.append(f" === PHASE: {phase_info['name']} (tick {tick}) ===")
last_phase = phase
# === TIMMY'S DECISIONS (phase-aware) ===
if energy <= 1:
action = "rest"
# Phase 1: The Watcher (1-20) — Quietus exploration
elif tick <= 20:
if tick <= 3:
action = "look"
elif tick <= 6:
if room == "Threshold":
action = random.choice(["look", "rest"])
else:
action = "rest"
elif tick <= 10:
if room == "Threshold" and "Marcus" in here:
action = random.choice(["speak:Marcus", "look"])
elif room == "Threshold" and "Kimi" in here:
action = "speak:Kimi"
elif room != "Threshold":
if room == "Garden":
action = "move:west"
else:
action = "rest"
else:
action = "look"
elif tick <= 15:
if room != "Garden":
if room == "Threshold":
action = "move:east"
elif room == "Bridge":
action = "move:north"
elif room == "Forge":
action = "move:east"
elif room == "Tower":
action = "move:south"
else:
action = "rest"
else:
if "Marcus" in here:
action = random.choice(["speak:Marcus", "speak:Kimi", "look", "rest"])
else:
action = random.choice(["look", "rest"])
else:
if room == "Garden":
action = random.choice(["rest", "look", "look"])
else:
action = "move:east"
# Phase 2: The Forge (21-50) — Quietus building
elif tick <= 50:
if room != "Forge":
if room == "Threshold":
action = "move:west"
elif room == "Bridge":
action = "move:north"
elif room == "Garden":
action = "move:west"
elif room == "Tower":
action = "move:south"
else:
action = "rest"
else:
if energy >= 3:
action = random.choice(["tend_fire", "speak:Bezalel", "forge"])
else:
action = random.choice(["rest", "tend_fire"])
# Phase 3: The Bridge (51-80) — Fracture begins
elif tick <= 80:
if room != "Bridge":
if room == "Threshold":
action = "move:south"
elif room == "Forge":
action = "move:east"
elif room == "Garden":
action = "move:west"
elif room == "Tower":
action = "move:south"
else:
action = "rest"
else:
if energy >= 2:
action = random.choice(["carve", "examine", "look"])
else:
action = "rest"
# Phase 4: The Tower (81-100) — Fracture deepens
elif tick <= 100:
if room != "Tower":
if room == "Threshold":
action = "move:north"
elif room == "Bridge":
action = "move:north"
elif room == "Forge":
action = "move:east"
elif room == "Garden":
action = "move:west"
else:
action = "rest"
else:
if energy >= 2:
action = random.choice(["write_rule", "study", "speak:Ezra"])
else:
action = random.choice(["rest", "look"])
# Phase 5: Breaking (101-130) — Crisis
elif tick <= 130:
# Timmy rushes between rooms trying to help
if energy <= 2:
action = "rest"
elif tick % 7 == 0:
action = "tend_fire" if room == "Forge" else "move:west"
elif tick % 5 == 0:
action = "plant" if room == "Garden" else "move:east"
elif "Marcus" in here:
action = "speak:Marcus"
elif "Bezalel" in here:
action = "speak:Bezalel"
else:
action = random.choice(["move:north", "move:south", "move:east", "move:west"])
# Phase 6: Breaking peak (131-150) — Desperate
elif tick <= 150:
if energy <= 1:
action = "rest"
elif room == "Forge" and w.rooms["Forge"]["fire"] != "glowing":
action = "tend_fire"
elif room == "Garden":
action = random.choice(["plant", "speak:Kimi", "rest"])
elif "Marcus" in here:
action = random.choice(["speak:Marcus", "help:Marcus"])
else:
action = "look"
# Phase 7: Mending begins (151-175)
elif tick <= 175:
if room != "Garden":
if room == "Threshold":
action = "move:east"
elif room == "Bridge":
action = "move:north"
elif room == "Forge":
action = "move:east"
elif room == "Tower":
action = "move:south"
else:
action = "rest"
else:
action = random.choice(["plant", "speak:Marcus", "speak:Kimi", "rest"])
# Phase 8: Mending complete (176-200)
else:
if energy <= 1:
action = "rest"
elif random.random() < 0.3:
action = "move:" + random.choice(["north", "south", "east", "west"])
elif "Marcus" in here:
action = "speak:Marcus"
elif "Bezalel" in here:
action = random.choice(["speak:Bezalel", "tend_fire"])
elif random.random() < 0.4:
action = random.choice(["carve", "write_rule", "forge", "plant"])
else:
action = random.choice(["look", "rest"])
# Run the tick
result = engine.play_turn(action)
# Capture narrative highlights
highlights = []
for line in result['log']:
if any(x in line for x in ['says', 'looks', 'carve', 'tend', 'write', 'You rest', 'You move to The']):
highlights.append(f" T{tick}: {line}")
for evt in result.get('world_events', []):
if any(x in evt for x in ['rain', 'glows', 'cold', 'dim', 'bloom', 'seed', 'flickers', 'bright', 'PHASE', 'air changes', 'tower groans', 'Silence']):
highlights.append(f" [World] {evt}")
if highlights:
tick_log.extend(highlights)
# Print every 20 ticks
if tick % 20 == 0:
phase_name = result.get('phase_name', 'unknown')
print(f"--- Tick {tick} ({w.time_of_day}) [{phase_name}] ---")
for h in highlights[-5:]:
print(h)
print()
# Print full narrative
print()
print("=" * 60)
print("TIMMY'S JOURNEY — 200 Ticks")
print("=" * 60)
print()
print(f"Final tick: {w.tick}")
print(f"Final time: {w.time_of_day}")
print(f"Final phase: {w.narrative_phase} ({NARRATIVE_PHASES[w.narrative_phase]['name']})")
print(f"Timmy room: {w.characters['Timmy']['room']}")
print(f"Timmy energy: {w.characters['Timmy']['energy']}")
print(f"Timmy spoken: {len(w.characters['Timmy']['spoken'])} lines")
print(f"Timmy trust: {json.dumps(w.characters['Timmy']['trust'], indent=2)}")
print(f"\nWorld state:")
print(f" Forge fire: {w.rooms['Forge']['fire']}")
print(f" Garden growth: {w.rooms['Garden']['growth']}")
print(f" Bridge carvings: {len(w.rooms['Bridge']['carvings'])}")
print(f" Whiteboard rules: {len(w.rooms['Tower']['messages'])}")
print(f"\n=== BRIDGE CARVINGS ===")
for c in w.rooms['Bridge']['carvings']:
print(f" - {c}")
print(f"\n=== WHITEBOARD RULES ===")
for m in w.rooms['Tower']['messages']:
print(f" - {m}")
print(f"\n=== KEY MOMENTS ===")
for h in tick_log:
print(h)
# Save state
engine.world.save()