Turret vessel spawner enemy #52

Closed
opened 2026-08-15 20:29:58 +00:00 by metaheavens · 1 comment
Owner

A stationary, high-health enemy placeable from the map editor that continuously spawns basic vessels which chase the fleet and destroy it on contact.

Enemy behaviour is composed from capability components (see #44) and the editor palette is generated from EnemyDefinitions.all() (see #48), so this needs no editor or palette change - registering the definition is enough.

Scope

  1. EnemySpawnerComponent.tscn + .gd, capability_id = "spawner":
    • @export var spawn_interval: float = 4.0
    • @export var spawned_enemy_id: String = "chaser"
    • @export var max_alive: int = 6
    • @export var spawn_radius: float = 90.0
    • On each tick(delta) past the interval, instantiate res://Enemy.tscn with enemy_id = spawned_enemy_id at a random point on spawn_radius around the parent enemy, added to the spawner's own parent (so a surface-hosted spawner keeps its spawns in the same host - see #44's note on why ../Fleet-style assumptions break).
    • Track spawned children in an Array filtered with is_instance_valid() each tick, so destroyed spawns free their slot and max_alive is respected.
    • Do not spawn when there is no fleet (get_tree().get_first_node_in_group("player_fleet") null or its ships empty) - otherwise a preview or an unattended scene accumulates enemies forever.
    • Killing the spawner must not kill its already-spawned children; they are siblings, not children, so this falls out of the parenting choice above - assert it in the test.
  2. TurretSpawnerEnemyDefinition.tres: enemy_id = "turret_spawner", max_hp = 20 (the "decent amount of life" - roughly 7x a chaser), speed = 0.0 (stationary; no pursuit or standoff component), a bulky distinct hull, and its own glow colour distinct from chaser red, sniper blue, artillery orange and gas-bomb pink.
  3. Register in EnemyDefinitions.ORDER and DEFINITIONS.

Out of scope

The enemy mothership (separate ticket) - though it reuses this component, so keep EnemySpawnerComponent free of anything turret-specific.

Acceptance criteria

  • Placed from the map editor palette with no editor code change.
  • Spawns one enemy per spawn_interval, stops at max_alive, resumes when a spawn dies.
  • Never moves.
  • Survives 19 damage and dies on the 20th.
  • Its spawns survive its death and keep chasing the fleet.
  • Spawns nothing when no fleet is present.

Tests

tests/test_turret_spawner_enemy.gd (bash tests/run_tests.sh turret), plus a 720x1280 screenshot beside a chaser showing the two are visually distinguishable. Freeze the scene for the screenshot the way tests/_sniper_vs_chaser_preview.gd does.

Repo notes (read before starting)

  • Godot 4.7.1, portrait 720x1280, touch UI. Project dir: /storage/emulated/0/GodotProjects/SpaceshipTest.
  • After editing any project file, run touch on it. Android FUSE does not bump mtime under ~/storage/shared, and Godot's import cache will silently keep serving the old version, making a correct fix look like it did nothing.
  • Headless tests: bash tests/run_tests.sh <substring>; full suite with no argument. Tests are SceneTree scripts printing TEST_NAME: PASS / TEST_NAME: FAIL (reason) and calling quit(0|1) - copy the shape of tests/test_capture_points.gd.
  • Real screenshots: bash tests/screenshot.sh <res://Scene.tscn> <out.png> <frames> 720x1280. Use few frames (~15); the software rasterizer is slow. --headless renders nothing at all, so it cannot validate visuals.
  • Drawing goes through NeonDraw / NeonPiece; do not introduce a different visual idiom.
  • The repo has no type switches (tickets #31-#35): behaviour comes from *Definition resources plus capability component scenes. Do not add if type == "..." branches.
  • There is no persistence layer (no FileAccess, no user://). GameState is an in-memory autoload. Do not invent a save system.
  • Commit this ticket separately and run the affected test groups plus the full suite before pushing.

Traps that have already cost hours on this codebase

  1. Never put a top-level const X = preload(...) in a test file that is itself the -s entry point. It evaluates during that file's own early compilation, which can run before autoloads are registered; any script it pulls in that references GameState inside a function body then fails to compile with Identifier not found: GameState. Use var X: Script plus load() inside _initialize() instead. See the header comment in tests/test_capture_points.gd.
  2. Assigning a plain [] to a typed Array[Resource] export from another script fails at runtime - the compiler only sees the target as Resource and cannot confirm the element type. Leave the declared default alone, or build the typed array inside the owning script.
  3. Fleet.spawn_ships(0, ...) does not empty the fleet - it falls back to one default interceptor by design. Clear fleet.ships explicitly if a test or preview needs genuinely zero ships.
  4. Setting ship.position without also setting ship.move_target lets Ship._physics_process steer it straight back toward the stale target within a few frames.
  5. Physics ticks can run ahead of a SceneTree test's own _process() clock under device load, even with --fixed-fps 60. Gate waits on the system's own state (a component's timer or flag), not on elapsed >= duration.
  6. A node that queue_free()s itself (projectiles, shells) must not be re-read inside a per-frame wait condition - cache the scalar you need before the wait.
  7. Preview scenes for screenshots are added to the tree from inside _screenshot_tool.gd's _initialize(), so their _ready() races the game scene's own _ready(). Do setup on the first _process() tick, and get_tree().paused = true once everything is placed if the scene must hold still.
A stationary, high-health enemy placeable from the map editor that continuously spawns basic vessels which chase the fleet and destroy it on contact. Enemy behaviour is composed from capability components (see #44) and the editor palette is generated from `EnemyDefinitions.all()` (see #48), so this needs no editor or palette change - registering the definition is enough. ### Scope 1. `EnemySpawnerComponent.tscn` + `.gd`, `capability_id = "spawner"`: - `@export var spawn_interval: float = 4.0` - `@export var spawned_enemy_id: String = "chaser"` - `@export var max_alive: int = 6` - `@export var spawn_radius: float = 90.0` - On each `tick(delta)` past the interval, instantiate `res://Enemy.tscn` with `enemy_id = spawned_enemy_id` at a random point on `spawn_radius` around the parent enemy, added to **the spawner's own parent** (so a surface-hosted spawner keeps its spawns in the same host - see #44's note on why `../Fleet`-style assumptions break). - Track spawned children in an `Array` filtered with `is_instance_valid()` each tick, so destroyed spawns free their slot and `max_alive` is respected. - Do not spawn when there is no fleet (`get_tree().get_first_node_in_group("player_fleet")` null or its `ships` empty) - otherwise a preview or an unattended scene accumulates enemies forever. - Killing the spawner must **not** kill its already-spawned children; they are siblings, not children, so this falls out of the parenting choice above - assert it in the test. 2. `TurretSpawnerEnemyDefinition.tres`: `enemy_id = "turret_spawner"`, `max_hp = 20` (the "decent amount of life" - roughly 7x a chaser), `speed = 0.0` (stationary; no pursuit or standoff component), a bulky distinct hull, and its own glow colour distinct from chaser red, sniper blue, artillery orange and gas-bomb pink. 3. Register in `EnemyDefinitions.ORDER` and `DEFINITIONS`. ### Out of scope The enemy mothership (separate ticket) - though it reuses this component, so keep `EnemySpawnerComponent` free of anything turret-specific. ### Acceptance criteria - Placed from the map editor palette with no editor code change. - Spawns one enemy per `spawn_interval`, stops at `max_alive`, resumes when a spawn dies. - Never moves. - Survives 19 damage and dies on the 20th. - Its spawns survive its death and keep chasing the fleet. - Spawns nothing when no fleet is present. ### Tests `tests/test_turret_spawner_enemy.gd` (`bash tests/run_tests.sh turret`), plus a 720x1280 screenshot beside a chaser showing the two are visually distinguishable. Freeze the scene for the screenshot the way `tests/_sniper_vs_chaser_preview.gd` does. ### Repo notes (read before starting) - Godot 4.7.1, portrait 720x1280, touch UI. Project dir: `/storage/emulated/0/GodotProjects/SpaceshipTest`. - **After editing any project file, run `touch` on it.** Android FUSE does not bump mtime under `~/storage/shared`, and Godot's import cache will silently keep serving the old version, making a correct fix look like it did nothing. - Headless tests: `bash tests/run_tests.sh <substring>`; full suite with no argument. Tests are `SceneTree` scripts printing `TEST_NAME: PASS` / `TEST_NAME: FAIL (reason)` and calling `quit(0|1)` - copy the shape of `tests/test_capture_points.gd`. - Real screenshots: `bash tests/screenshot.sh <res://Scene.tscn> <out.png> <frames> 720x1280`. Use few frames (~15); the software rasterizer is slow. `--headless` renders nothing at all, so it cannot validate visuals. - Drawing goes through `NeonDraw` / `NeonPiece`; do not introduce a different visual idiom. - The repo has **no type switches** (tickets #31-#35): behaviour comes from `*Definition` resources plus capability component scenes. Do not add `if type == "..."` branches. - There is **no persistence layer** (no `FileAccess`, no `user://`). `GameState` is an in-memory autoload. Do not invent a save system. - Commit this ticket separately and run the affected test groups plus the full suite before pushing. ### Traps that have already cost hours on this codebase 1. **Never put a top-level `const X = preload(...)` in a test file that is itself the `-s` entry point.** It evaluates during that file's own early compilation, which can run before autoloads are registered; any script it pulls in that references `GameState` inside a function body then fails to compile with `Identifier not found: GameState`. Use `var X: Script` plus `load()` inside `_initialize()` instead. See the header comment in `tests/test_capture_points.gd`. 2. **Assigning a plain `[]` to a typed `Array[Resource]` export from another script fails at runtime** - the compiler only sees the target as `Resource` and cannot confirm the element type. Leave the declared default alone, or build the typed array inside the owning script. 3. **`Fleet.spawn_ships(0, ...)` does not empty the fleet** - it falls back to one default interceptor by design. Clear `fleet.ships` explicitly if a test or preview needs genuinely zero ships. 4. **Setting `ship.position` without also setting `ship.move_target`** lets `Ship._physics_process` steer it straight back toward the stale target within a few frames. 5. **Physics ticks can run ahead of a `SceneTree` test's own `_process()` clock** under device load, even with `--fixed-fps 60`. Gate waits on the system's own state (a component's timer or flag), not on `elapsed >= duration`. 6. **A node that `queue_free()`s itself** (projectiles, shells) must not be re-read inside a per-frame wait condition - cache the scalar you need before the wait. 7. **Preview scenes for screenshots** are added to the tree from inside `_screenshot_tool.gd`'s `_initialize()`, so their `_ready()` races the game scene's own `_ready()`. Do setup on the first `_process()` tick, and `get_tree().paused = true` once everything is placed if the scene must hold still.
Author
Owner

Done in commit 1bd25c6, pushed to main.

New EnemySpawnerComponent.gd (capability_id "spawner"): continuously instantiates another enemy type beside its host at a fixed interval, capped at max_alive concurrently, refilling as spawns die. Spawned enemies are parented under the spawner's OWN PARENT rather than the spawner itself, so they're siblings, not descendants - killing the spawner can't free them, and a surface-hosted spawner (under PlanetSetupHost) keeps its spawns under the same host instead of leaking them to a hardcoded path, the same hazard #44 already closed for the pursuit/standoff/ranged-weapon components.

TurretSpawnerEnemyDefinition.tres: stationary (speed 0, no pursuit or standoff component), max_hp 20 (~7x a chaser), a bulky octagon hull, and its own acid-green glow distinct from chaser/sniper/artillery. Registered in EnemyDefinitions.ORDER/DEFINITIONS - the map editor palette (#48) picks it up with no editor code change.

Tests: new tests/test_turret_spawner_enemy.gd covers registration and the real definition defaults, no spawns without a fleet, spawning capped at max_alive, a dead spawn's slot refilling, never moving, surviving 19 damage and dying on the 20th, and its spawns surviving its death with their pursuit component intact. Screenshot beside a chaser (shots/turret_vs_chaser.png) confirms the two read as visually distinct enemies - small red diamond vs. bulky green octagon. Full suite: 79/79.

Three things worth keeping in mind for later tickets:

  1. A node's set_process(false) call made before it has fully finished entering the tree doesn't reliably stick (already documented in tests/test_planet_atmosphere_transition.gd, and it bit this test too): BuildController._check_fleet_wipe() kept rebuilding a ship during an intended "empty fleet" test window even after disabling it in _initialize(). Do it in _process()'s first real tick instead, once _ready() cascades are confirmed complete.
  2. Overriding an @export interval (like spawn_interval) on an already-running component does NOT reset its own in-progress countdown timer - only changes what it resets TO on its next expiry. If the countdown already started at the OLD value before your override lands, reset the timer variable itself too, or the first real interval after the override silently uses the stale value.
  3. A capped spawner's freed-slot refill can land within a couple of frames once its interval is short - don't assert on an intermediate "just dropped by one" count that a fast interval can blow straight through before your next check runs. Assert the net effect instead (the specific killed instance is gone AND a replacement filled the slot).
Done in commit 1bd25c6, pushed to main. New `EnemySpawnerComponent.gd` (capability_id `"spawner"`): continuously instantiates another enemy type beside its host at a fixed interval, capped at `max_alive` concurrently, refilling as spawns die. Spawned enemies are parented under the spawner's OWN PARENT rather than the spawner itself, so they're siblings, not descendants - killing the spawner can't free them, and a surface-hosted spawner (under `PlanetSetupHost`) keeps its spawns under the same host instead of leaking them to a hardcoded path, the same hazard #44 already closed for the pursuit/standoff/ranged-weapon components. `TurretSpawnerEnemyDefinition.tres`: stationary (speed 0, no pursuit or standoff component), `max_hp` 20 (~7x a chaser), a bulky octagon hull, and its own acid-green glow distinct from chaser/sniper/artillery. Registered in `EnemyDefinitions.ORDER`/`DEFINITIONS` - the map editor palette (#48) picks it up with no editor code change. Tests: new `tests/test_turret_spawner_enemy.gd` covers registration and the real definition defaults, no spawns without a fleet, spawning capped at `max_alive`, a dead spawn's slot refilling, never moving, surviving 19 damage and dying on the 20th, and its spawns surviving its death with their pursuit component intact. Screenshot beside a chaser (`shots/turret_vs_chaser.png`) confirms the two read as visually distinct enemies - small red diamond vs. bulky green octagon. Full suite: 79/79. Three things worth keeping in mind for later tickets: 1. A node's `set_process(false)` call made before it has fully finished entering the tree doesn't reliably stick (already documented in `tests/test_planet_atmosphere_transition.gd`, and it bit this test too): `BuildController._check_fleet_wipe()` kept rebuilding a ship during an intended "empty fleet" test window even after disabling it in `_initialize()`. Do it in `_process()`'s first real tick instead, once `_ready()` cascades are confirmed complete. 2. Overriding an `@export` interval (like `spawn_interval`) on an already-running component does NOT reset its own in-progress countdown timer - only changes what it resets TO on its next expiry. If the countdown already started at the OLD value before your override lands, reset the timer variable itself too, or the first real interval after the override silently uses the stale value. 3. A capped spawner's freed-slot refill can land within a couple of frames once its interval is short - don't assert on an intermediate "just dropped by one" count that a fast interval can blow straight through before your next check runs. Assert the net effect instead (the specific killed instance is gone AND a replacement filled the slot).
metaheavens referenced this issue from a commit 2026-08-16 08:19:19 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
metaheavens/spaceship#52
No description provided.