spaceship/PlanetSetupHost.gd
Loïc Wisniewski c4e2ee7178 Add capture points and the planet conquest loop (#43)
CapturePoint tracks neutral/blocked/capturing/captured state by polling
proximity each frame (a ship in capture_radius, no enemy within
enemy_clear_radius), draining gradually rather than resetting when
interrupted, and calling GameState.mark_point_captured() on completion.
PlanetSetupHost now instantiates the real CapturePoint scene per
authored point (restoring already-captured state immediately on
re-landing) and spawns each setup's authored enemies, replacing the
placeholder markers from #42. CaptureLabel is a small self-polling HUD
(same convention as ResourceCounter) showing "CAPTURED n/m" or
"CONQUERED" with a one-shot fade on completion, themed per surface
profile alongside the existing bank/fleet captions.

test_planet_atmosphere_transition.gd's "no enemies on a landed
surface" assumption no longer holds now that setups can place guard
enemies by design - narrowed the check to what it actually needs to
prove: no space-side EnemySpawner/AsteroidField node leaks across the
scene swap.

Part of the #40 conquest-mechanic breakdown.
2026-08-15 21:22:10 +02:00

42 lines
1.3 KiB
GDScript

class_name PlanetSetupHost
extends Node2D
# Instantiates the contents of a PlanetSetup onto a landed surface: one
# CapturePoint per authored point - registering/restoring conquest progress
# through GameState so re-landing on a partly-taken planet keeps its
# progress - and one enemy per authored spawn.
const CAPTURE_POINT_SCENE: PackedScene = preload("res://CapturePoint.tscn")
const ENEMY_SCENE: PackedScene = preload("res://Enemy.tscn")
var setup: Resource
func apply_setup(new_setup: Resource) -> void:
setup = new_setup
for child in get_children():
child.queue_free()
if setup == null:
return
GameState.register_capture_points(GameState.planet_id, setup.capture_points.size())
for i in range(setup.capture_points.size()):
_add_capture_point(i, setup.capture_points[i])
for spawn in setup.enemy_spawns:
_add_enemy(spawn)
func _add_capture_point(index: int, at: Vector2) -> void:
var point: Node = CAPTURE_POINT_SCENE.instantiate()
point.point_index = index
point.position = at
add_child(point)
if GameState.is_point_captured(GameState.planet_id, index):
point.mark_captured()
func _add_enemy(spawn: Resource) -> void:
var enemy: Node = ENEMY_SCENE.instantiate()
enemy.enemy_id = spawn.enemy_id
enemy.position = spawn.position
add_child(enemy)