Stage 5: bosses that move, attacks that warn, and a second boss
ci / verify (push) Successful in 49s

Boss movement is a property of the PHASE, not of the boss -- a fight that
stands still and then starts hunting you is one boss with two phases. Four
modes (STATIC, ORBIT, CHASE, WAYPOINTS) handled generically in
SimWorld._move_boss, so a boss that moves is still data. BossDef.stationary
is gone rather than kept beside the phases: a flag claiming the boss stood
still while a phase walked around would be a second source of truth and the
wrong one, so moves() is derived.

CHASE holds a distance instead of closing, because a boss standing on top of
you is a boss whose bullets cannot be read. Waypoints are fractions of the
arena so one phase works in rooms of different sizes. Every mode is speed
clamped in one place -- ORBIT computes an absolute destination and would
otherwise snap onto its circle on the first tick -- and movement slides
against geometry so a boss cannot walk through the pillars its own arena was
designed around.

The room clamp moved to after movement, where it is finally load-bearing. It
was a no-op while every boss stood still, which is exactly when an invariant
is cheapest to establish: boss rooms deliberately do not lock, so walking out
is always an escape, and that only holds if the boss cannot follow.

TelegraphedStrikeEmitter marks spots and fills them a moment later. The moment
between is the feature: a burst at your feet is a coin flip, the same burst
with a second of notice is a question. It stays stateless like every other
emitter -- they are shared resources and two bosses of the same kind must not
stomp each other -- so strike positions are derived from the volley number and
a test asserts the burst lands where the marker promised. Markers are drawn
through fog and through walls, unlike everything else in the view, because a
warning you cannot see is an unavoidable hit with extra steps.

The Cantor of the Vault fights in the choir vault: static, then a four-corner
circuit, then a chase, then orbiting while marking. It exists to prove the
format stretched, and a test asserts it uses both new mechanisms.

Which boss a run has now comes from its SEED rather than its depth. Depth is a
dev flag nothing in play raises, so the arena was keyed to something no player
can change and the second boss was unreachable in an actual game.

Two things found while finishing:

  - tools/export_content.gd had a hand-maintained boss list and had already
    gone stale, silently not writing the Cantor. Content.ALL_ENEMIES and
    ALL_BOSSES now feed the export tool, the renderer and five tests that each
    kept their own copy.
  - diag_loot failed intermittently after another diagnostic. Taking over from
    the bot cleared its input queue but not its HELD input, so a starved server
    coasted on the bot's last movement vector for half a second and walked the
    player off the item it had been placed on. The press arrived correctly,
    which is why "the press reached the simulation" passed while everything it
    should have caused failed.

check.sh clean, 409 tests, SMOKE PASS (19 assertions), all four diagnostics
green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-06 16:32:12 +02:00
parent cb2c1e7840
commit e0c1e0d5c6
34 changed files with 1498 additions and 49 deletions
+11 -1
View File
@@ -65,6 +65,7 @@ static func _build_lobby() -> Dictionary:
"npc": npc,
"boss_pos": Vector2.ZERO,
"boss_room": Rect2i(),
"boss_id": &"",
}
@@ -85,7 +86,12 @@ static func generate(seed_value: int, depth: int) -> Dictionary:
# The boss arena is placed first and everything else works around it, so a
# generated corridor can never carve through the authored fight.
var stamp := Rooms.warden_hall() if d % 2 == 1 else Rooms.choir_vault()
# Which arena -- and therefore which boss -- comes from the SEED, not the
# depth. Depth is a dev flag that nothing in play raises, so keying the
# arena to it meant the second boss existed and no player could ever reach
# it. Every run rolls a fresh seed, so this is a coin flip per dungeon.
var arena := &"warden_hall" if posmod(seed_value, 2) == 0 else &"choir_vault"
var stamp := Rooms.warden_hall() if arena == &"warden_hall" else Rooms.choir_vault()
var bs := Rooms.size_of(stamp)
var boss_origin := Vector2i(w - bs.x - 2, (h - bs.y) / 2)
var markers := Rooms.stamp(grid, stamp, boss_origin)
@@ -156,6 +162,10 @@ static func generate(seed_value: int, depth: int) -> Dictionary:
"npc": Vector2.ZERO,
"boss_pos": boss_pos,
"boss_room": boss_room,
# Which boss lives here follows from WHICH arena was stamped. Choosing
# it anywhere else would let a dungeon put the Cantor in the Warden's
# hall, where its patterns assume geometry that is not there.
"boss_id": Rooms.boss_for_arena(arena),
}
+20
View File
@@ -22,6 +22,26 @@ var rng: RandomNumberGenerator
var bounds := Rect2(Vector2(-620.0, -340.0), Vector2(1240.0, 680.0))
## Where an emitter announces something before it happens. Points at the
## owning world's event list; emitters fired into a bare pool by a test simply
## append here and nobody reads it.
var events: Array[Dictionary] = []
## Warn that an attack will land at [param at] in [param ticks] ticks.
##
## The only thing an emitter can do besides spawn bullets, and it exists so a
## strike that appears out of thin air is a *choice* the player was given time
## to answer rather than an unavoidable hit.
func telegraph(at: Vector2, warn_radius: float, ticks: int) -> void:
events.append({
"t": SimEvent.Type.TELEGRAPH,
"pos": at,
"r": warn_radius,
"ticks": ticks,
})
func aim_angle() -> float:
if not has_target:
return PI * 0.5
@@ -0,0 +1,84 @@
class_name TelegraphedStrikeEmitter
extends BulletEmitter
## Marks spots in the arena, then fills them with bullets a moment later.
##
## The whole point is the moment in between. A burst that appears at your feet
## with no warning is not a pattern, it is a coin flip; the same burst with a
## second of notice is a question about where you would rather be standing.
## [member warn_ticks] is that second, and the client draws the marker from the
## TELEGRAPH event this emits.
##
## Stateless, like every other emitter -- emitters are shared resources and two
## bosses of the same kind must not stomp each other's timers. The strike
## positions are therefore *derived* from the volley number rather than rolled
## and remembered, so the announcement and the strike compute the same points
## without anything being stored between them.
## Spots marked per volley.
@export var strikes: int = 3
## Ticks between the marker appearing and the burst landing. Must be shorter
## than [member interval], or a volley would land after the next was announced.
@export var warn_ticks: int = 75
## Bullets in each burst, fired outwards from the marked spot.
@export var burst_count: int = 12
## Radius of the marked area, and the ring the burst is born on.
@export var blast_radius: float = 64.0
## Keeps strikes off the arena's walls, where half the burst would be wasted.
@export var margin: float = 72.0
## Distinguishes two strike emitters in one phase, which would otherwise derive
## the same points and stack every burst on top of itself.
@export var pattern_seed: int = 0
## Armed on two ticks per volley: the announcement, and the strike itself.
func should_fire(local_tick: int) -> bool:
if not is_armed(local_tick) or interval <= 0:
return false
var into := posmod(local_tick - start_tick, interval)
return into == 0 or into == posmod(warn_ticks, interval)
func fire(ctx: EmitContext) -> void:
if strikes <= 0 or interval <= 0:
return
var offset := ctx.local_tick - start_tick
var volley := int(floor(float(offset) / float(interval)))
var announcing := posmod(offset, interval) == 0
for i in strikes:
var at := strike_point(volley, i, ctx.bounds)
if announcing:
ctx.telegraph(at, blast_radius, warn_ticks)
else:
_burst(ctx, at)
## The burst leaves the marked spot outwards, so standing on the marker is the
## one place that is certainly wrong and the edge is survivable.
func _burst(ctx: EmitContext, at: Vector2) -> void:
if burst_count <= 0:
return
for i in burst_count:
var a := TAU * (float(i) / float(burst_count))
emit_shot(ctx, a, at + Vector2.RIGHT.rotated(a) * (blast_radius * 0.25))
## Where volley [param volley]'s strike [param index] lands, inside
## [param bounds]. A pure function of its arguments: called once when the
## warning goes up and again when the burst lands, and it has to agree with
## itself both times without anything being remembered in between.
func strike_point(volley: int, index: int, bounds: Rect2) -> Vector2:
var inner := bounds.grow(-margin)
if inner.size.x <= 0.0 or inner.size.y <= 0.0:
inner = bounds
return inner.position + Vector2(
_unit(volley, index * 2) * inner.size.x,
_unit(volley, index * 2 + 1) * inner.size.y)
## A small integer hash in [0, 1). Not a good random number generator and does
## not need to be -- it needs to be scattered, and it needs to give the same
## answer twice.
func _unit(a: int, b: int) -> float:
var h := (a * 374761393 + b * 668265263 + pattern_seed * 2246822519) & 0x7FFFFFFF
h = ((h ^ (h >> 13)) * 1274126177) & 0x7FFFFFFF
return float((h >> 7) & 0xFFFF) / 65536.0
@@ -0,0 +1 @@
uid://dkswilm3f3jc1
+4
View File
@@ -15,6 +15,10 @@ var phase_tick: int = 0
## player can always disengage by walking out -- which is the trade for the
## boss room having no door that locks.
var room := Rect2()
## WAYPOINTS movement: which point it is walking to, and how long it still
## stands at the one it reached.
var waypoint_index: int = 0
var waypoint_wait: int = 0
## Poison doses ticking on the boss. Lazy for the same reason enemies' are.
var poison: PoisonTrack = null
+4
View File
@@ -34,4 +34,8 @@ enum Type {
ITEM_PICKED_UP, ## peer, item
ITEM_USED, ## peer, item
ITEM_DROPPED, ## peer, item
## An attack is about to land somewhere, and the player has to be shown
## where before it does. Carries the spot, its radius and how long the
## warning lasts; the client draws it and the server fires into it later.
TELEGRAPH, ## pos, r, ticks
}
+77 -5
View File
@@ -568,11 +568,14 @@ func _step_boss() -> void:
var phase := boss.current_phase()
if phase == null:
return
# A boss never leaves its arena. Enforced here rather than left to each
# boss's movement code, because boss rooms deliberately do not lock: the
# player can always walk out, and the fight only stays a fight if the boss
# cannot follow. Currently a no-op (every boss is stationary), which is
# exactly when an invariant is cheapest to establish.
_move_boss(phase)
# A boss never leaves its arena. Enforced here rather than inside each
# movement mode, because boss rooms deliberately do not lock: the player can
# always walk out, and the fight only stays a fight if the boss cannot
# follow. It was a no-op while every boss stood still, which is exactly when
# an invariant is cheapest to establish -- now it is load-bearing.
if boss.room.size != Vector2.ZERO:
boss.pos = boss.room.position + Vector2(
clampf(boss.pos.x - boss.room.position.x, 0.0, boss.room.size.x),
@@ -584,6 +587,72 @@ func _step_boss() -> void:
boss.phase_tick += 1
## One tick of boss movement, driven entirely by the phase's data. Every mode
## here is generic: adding a boss that moves is writing a [BossPhase], not
## touching this function.
func _move_boss(phase: BossPhase) -> void:
if not phase.moves():
return
var dt := SimConfig.TICK_DELTA
var step := Vector2.ZERO
match phase.move:
BossPhase.Move.ORBIT:
var centre := boss.room.get_center() if boss.room.size != Vector2.ZERO \
else boss.def.spawn_pos
var angle := float(boss.phase_tick) * dt \
* (phase.move_speed / maxf(phase.move_param, 1.0))
step = centre + Vector2.RIGHT.rotated(angle) * phase.move_param - boss.pos
BossPhase.Move.CHASE:
var quarry := nearest_player(boss.pos)
if quarry == null:
return
var to_player := quarry.pos - boss.pos
var gap := to_player.length()
if gap < 0.001:
return
# Signed, so it backs off when you close inside its preferred
# distance. A boss that ends up standing on you is a boss whose
# bullets you cannot see coming.
step = (to_player / gap) * signf(gap - phase.move_param) * phase.move_speed * dt
BossPhase.Move.WAYPOINTS:
if phase.waypoints.is_empty():
return
if boss.waypoint_wait > 0:
boss.waypoint_wait -= 1
return
var goal := _waypoint_world(phase, boss.waypoint_index)
var to_goal := goal - boss.pos
if to_goal.length() <= phase.move_speed * dt:
boss.pos = goal
boss.waypoint_index = (boss.waypoint_index + 1) % phase.waypoints.size()
boss.waypoint_wait = phase.waypoint_dwell
return
step = to_goal
_:
return
# Clamped here rather than in each branch, so no mode can teleport: ORBIT in
# particular computes an absolute destination and would otherwise snap to
# its circle on the first tick of the phase.
var reach := phase.move_speed * dt
if step.length() > reach:
step = step.normalized() * reach
# Slid rather than assigned, so a boss cannot walk through the pillars its
# own arena was designed around.
boss.pos = map.slide_circle(boss.pos, step, boss.def.radius)
## A phase waypoint, given as a fraction of the arena, in world coordinates.
## Fractions rather than absolutes so one phase can be dropped into any room --
## the Warden's hall and the Choir Vault are different sizes.
func _waypoint_world(phase: BossPhase, index: int) -> Vector2:
var w: Vector2 = phase.waypoints[index]
if boss.room.size == Vector2.ZERO:
return boss.def.spawn_pos
return boss.room.position + Vector2(
clampf(w.x, 0.0, 1.0) * boss.room.size.x,
clampf(w.y, 0.0, 1.0) * boss.room.size.y)
## Shared emitter driver for enemies and bosses -- the reason a boss pattern can
## be dropped onto a trash mob and vice versa.
func _run_emitters(emitters: Array[BulletEmitter], origin: Vector2, local_tick: int,
@@ -592,6 +661,9 @@ func _run_emitters(emitters: Array[BulletEmitter], origin: Vector2, local_tick:
return
var target := nearest_player(origin)
_ctx.pool = pool
# Re-pointed every call: drain_events() replaces the array wholesale, so a
# context holding the old one would announce into a list nobody reads.
_ctx.events = events
_ctx.origin = origin
# Curtain patterns span the room they are fired in. Without a room, fall
# back to a box around the shooter rather than the whole map, or a trash