Task #18: Alien Ray fires a beam

The Alien Ray is now a held beam instead of a copy of the potato shot.
While fire is held it ticks every alien_ray_tick_interval (0.15 s). Each
tick traces a path from the scarecrow's center through the muzzle and on
alien_ray_range (20 m) past it, cut short at the first wall
(AlienBeam.trace on the world layer). It damages every enemy within
alien_ray_width / 2 (0.25 m) plus its hit radius of that path, flyers
included as with shots, nearest first, up to alien_ray_pierce (4), for
alien_ray_damage (1). That is about 6.7 damage a second per enemy on the
beam. Hits stay inside combat.step, so enemies.attacker credits kills.

- EnemySystem.path_hits: every enemy along a polyline, ordered along it,
  with flat ends (nothing behind the scarecrow or past the wall).
  sweep_hit is unchanged.
- AlienBeam: a WeaponModels held effect (hold 1.5 ticks, no fade). It is
  an unshaded HDR green core and glow, a muzzle light, and a flare where a
  wall stops it. Each frame it lays itself out from the muzzle along the
  model's -Z, with the same trace, so the partner's machine recomputes the
  wall clip locally. No protocol change.
- Counters: a beam_ticks counter joins attacks(), and ray ticks no
  longer count as shots_fired.
- Config: alien_ray_speed, alien_ray_lifetime and alien_ray_cooldown are
  removed. alien_ray_range, _width, _tick_interval and _pierce are added.
  The shop text says what it does now. Cost and hidden/reveal are
  unchanged.
- Sound: a zapped signal and a "zap" cue (synth alien_beam.wav, its own
  seed). The other synth files regenerate byte-identical.

Tests (test_weapons) replace the projectile-travel ray check and keep
buy/equip:
- a far target is hit on the same step;
- nothing beside, behind or past the end is hit;
- two in line and a crow are all hit;
- a line is capped at pierce;
- a wall stops it, including a barrel poking through one;
- held ticks repeat and stop on release;
- the beam is lit only while held, ends at the wall clip, follows the
  model's yaw, and the replica and attack-event paths work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:39:00 -04:00
parent 287b6ac6cc
commit a0aee34e3c
13 changed files with 554 additions and 44 deletions

View file

@ -570,6 +570,46 @@ func sweep_hit(x0: float, z0: float, x1: float, z1: float, use_motion: bool) ->
return best
## Every living enemy along a path at combat height (a polyline: the Alien Ray's beam, #18, from
## the scarecrow through the muzzle to where it ends), flyers included like sweep_hit (their hit
## proxy stays at combat height): those whose hit proxy (hit_radius) comes within half_width of
## the path, ordered by how far along it they are (dense slots, at most max_hits; 0: all). Unlike
## sweep_hit (the nearest only, for shots that stop) it's for a beam that pierces. The ends are
## flat: nothing behind the path's start or past its end (a wall that cut it short) is hit, even
## if its proxy reaches across. Current positions (no motion test), every slot checked rather than
## the grid, which misses enemies spawned since the last step.
func path_hits(path: PackedVector2Array, half_width: float, max_hits: int = 0) -> PackedInt32Array:
var out := PackedInt32Array()
var last := path.size() - 2
if last < 0:
return out
var head := path[1] - path[0]
var tail := path[last + 1] - path[last]
var found: Array = [] # [distance along the path, slot]
for i in active_count:
if alive[i] == 0:
continue
var e := Vector2(pos_x[i], pos_z[i])
if (e - path[0]).dot(head) < 0.0 or (e - path[last + 1]).dot(tail) > 0.0:
continue # behind its start, or past its end
var reach := half_width + t_hit_radius[type[i]]
var along := 0.0
for k in last + 1:
var a := path[k]
var ab := path[k + 1] - a
var seg := ab.length()
if seg > 1e-6:
var u := clampf((e - a).dot(ab) / (seg * seg), 0.0, 1.0)
if e.distance_squared_to(a + ab * u) <= reach * reach:
found.append([along + u * seg, i])
break
along += seg
found.sort_custom(func(x: Array, y: Array) -> bool: return x[0] < y[0])
for k in (found.size() if max_hits <= 0 else mini(found.size(), max_hits)):
out.append(found[k][1])
return out
## Releases this tick's removals: emits enemy_removed (handle still valid), then swaps the last
## active enemy into each freed slot and updates every mapping.
func commit_removals() -> void: