2026-08-15 14:43:29 +02:00
|
|
|
class_name EnemyDefinitions
|
|
|
|
|
extends RefCounted
|
|
|
|
|
|
|
|
|
|
const DEFAULT_ID: String = "chaser"
|
Enemy mothership (#53)
A large, slow capital enemy that periodically launches chasers and
artillery on their own intervals and fires a heavily telegraphed line
beam capable of killing several player vessels at once.
Spawning reuses #52's EnemySpawnerComponent as-is via two preset
scenes (EnemySpawnerComponentChaser.tscn: 5s/chaser,
EnemySpawnerComponentArtillery.tscn: 18s/max 2/artillery) rather than
adding multi-type support to the component - two instances of a
single-purpose component is the composition this codebase already
uses everywhere ("enemy bomber" in the original request is read here
as the existing artillery enemy's slow telegraphed AOE, not a new
enemy type - flagged as a judgment call in the ticket).
New EnemyBigLaserComponent.gd ("big_laser") fires a standalone
EnemyBigLaserBeam on a long cooldown - the beam owns its whole charge/
fire/flash sequence once launched, so the mothership dying mid-charge
doesn't cancel an already-telegraphed shot, same design as
EnemyArtilleryComponent/ArtilleryShell. The aim direction is locked
once in launch() and never re-read - nothing in the charging phase
touches the fleet's position again, which is what makes it dodgeable.
Damage is a line-segment check (projection + perpendicular distance)
against every player_ships member; Ship.take_damage() already handles
shield absorption per-ship.
MothershipEnemyDefinition.tres: max_hp 60, speed 35 (slow), a ~96-unit
hull, pursuit + two spawners + big_laser, no type switch anywhere -
every stat from the definition, every behaviour from a component.
Tests: new tests/test_enemy_mothership.gd, split into beam mechanics
(tested directly, not through the component's own cooldown timing,
which would make the geometry assertions timing-fragile) and the
composed definition (tested through a real Enemy.tscn instance).
Screenshot of the charge telegraph mid-countdown. Full suite: 80/80.
Found and fixed a real bug along the way, in EnemySpawnerComponent.gd
(#52): its `enemy_scene: PackedScene = preload("res://Enemy.tscn")`
member-level preload could get permanently baked in as a broken,
empty PackedScene when a definition's component_scenes chain led back
to Enemy.tscn while it was still mid-load - confirmed empirically via
ResourceLoader.has_cached() being true (a good copy existed) while the
preloaded reference's own resource_path was empty. This only
surfaces when a SINGLE definition composes two instances of a script
carrying such a preload (the mothership's chaser/artillery spawner
presets; #52's single-spawner turret never hit it). Fixed by
resolving enemy_scene lazily via load() on first use instead of at
compile time, and additionally made a fresh spawner count down from a
full interval before its first spawn rather than firing on tick one,
which also happens to keep two sibling spawners with different
intervals from ever landing their first attempt on the same frame.
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 10:19:02 +02:00
|
|
|
const ORDER: PackedStringArray = ["chaser", "sniper", "artillery", "turret_spawner", "enemy_mothership"]
|
2026-08-15 14:43:29 +02:00
|
|
|
const DEFINITIONS: Dictionary = {
|
|
|
|
|
"chaser": preload("res://ChaserEnemyDefinition.tres"),
|
2026-08-15 21:23:01 +02:00
|
|
|
"sniper": preload("res://SniperEnemyDefinition.tres"),
|
2026-08-15 21:23:43 +02:00
|
|
|
"artillery": preload("res://ArtilleryEnemyDefinition.tres"),
|
Turret vessel spawner enemy (#52)
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 are 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 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
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
confirms the two read as visually distinct enemies. Full suite: 79/79.
Repo notes for the next agent, confirmed empirically this session:
- 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.
- 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.
- 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) rather than an exact mid-transition snapshot.
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 09:43:44 +02:00
|
|
|
"turret_spawner": preload("res://TurretSpawnerEnemyDefinition.tres"),
|
Enemy mothership (#53)
A large, slow capital enemy that periodically launches chasers and
artillery on their own intervals and fires a heavily telegraphed line
beam capable of killing several player vessels at once.
Spawning reuses #52's EnemySpawnerComponent as-is via two preset
scenes (EnemySpawnerComponentChaser.tscn: 5s/chaser,
EnemySpawnerComponentArtillery.tscn: 18s/max 2/artillery) rather than
adding multi-type support to the component - two instances of a
single-purpose component is the composition this codebase already
uses everywhere ("enemy bomber" in the original request is read here
as the existing artillery enemy's slow telegraphed AOE, not a new
enemy type - flagged as a judgment call in the ticket).
New EnemyBigLaserComponent.gd ("big_laser") fires a standalone
EnemyBigLaserBeam on a long cooldown - the beam owns its whole charge/
fire/flash sequence once launched, so the mothership dying mid-charge
doesn't cancel an already-telegraphed shot, same design as
EnemyArtilleryComponent/ArtilleryShell. The aim direction is locked
once in launch() and never re-read - nothing in the charging phase
touches the fleet's position again, which is what makes it dodgeable.
Damage is a line-segment check (projection + perpendicular distance)
against every player_ships member; Ship.take_damage() already handles
shield absorption per-ship.
MothershipEnemyDefinition.tres: max_hp 60, speed 35 (slow), a ~96-unit
hull, pursuit + two spawners + big_laser, no type switch anywhere -
every stat from the definition, every behaviour from a component.
Tests: new tests/test_enemy_mothership.gd, split into beam mechanics
(tested directly, not through the component's own cooldown timing,
which would make the geometry assertions timing-fragile) and the
composed definition (tested through a real Enemy.tscn instance).
Screenshot of the charge telegraph mid-countdown. Full suite: 80/80.
Found and fixed a real bug along the way, in EnemySpawnerComponent.gd
(#52): its `enemy_scene: PackedScene = preload("res://Enemy.tscn")`
member-level preload could get permanently baked in as a broken,
empty PackedScene when a definition's component_scenes chain led back
to Enemy.tscn while it was still mid-load - confirmed empirically via
ResourceLoader.has_cached() being true (a good copy existed) while the
preloaded reference's own resource_path was empty. This only
surfaces when a SINGLE definition composes two instances of a script
carrying such a preload (the mothership's chaser/artillery spawner
presets; #52's single-spawner turret never hit it). Fixed by
resolving enemy_scene lazily via load() on first use instead of at
compile time, and additionally made a fresh spawner count down from a
full interval before its first spawn rather than firing on tick one,
which also happens to keep two sibling spawners with different
intervals from ever landing their first attempt on the same frame.
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 10:19:02 +02:00
|
|
|
"enemy_mothership": preload("res://MothershipEnemyDefinition.tres"),
|
2026-08-15 14:43:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func get_definition(enemy_id: String) -> Resource:
|
|
|
|
|
return DEFINITIONS.get(enemy_id, DEFINITIONS[DEFAULT_ID])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func all() -> Array:
|
|
|
|
|
var result: Array = []
|
|
|
|
|
for enemy_id in ORDER:
|
|
|
|
|
result.append(DEFINITIONS[enemy_id])
|
|
|
|
|
return result
|