class_name PlanetSetupHost extends Node2D # Instantiates the contents of a PlanetSetup onto a landed surface: one enemy # per authored spawn, registered with GameState as the planet's garrison so # that killing the last of them takes the planet. # # #211 removed the capture points this used to place alongside them. Holding a # ring for four seconds, once per ring, was a second task laid on top of the # fight the player had already won; conquest is the fight now. const ENEMY_SCENE: PackedScene = preload("res://enemies/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 # Registered with the count about to be placed, every landing. A planet # already taken keeps that status and gets no garrison at all. GameState.register_planet_garrison(GameState.planet_id, setup.enemy_spawns.size(), GameState.planet_definition_id, int(setup.research_point_reward)) if GameState.is_planet_conquered(GameState.planet_id): return for spawn in setup.enemy_spawns: _add_enemy(spawn) func _add_enemy(spawn: Resource) -> void: var enemy: Node = ENEMY_SCENE.instantiate() enemy.enemy_id = spawn.enemy_id enemy.position = spawn.position # The planet is captured by the count reaching zero, so the tally is bound # to the enemy's own death rather than to whatever killed it. Bound to the # id captured NOW: the player may have left the surface by the time a # straggler dies, and the planet that was being fought over is this one. var planet_key: String = GameState.planet_id enemy.destroyed.connect(func(): GameState.mark_garrison_enemy_destroyed(planet_key)) add_child(enemy)