Complete lab, quest, garrison, and energy tickets

This commit is contained in:
Loïc Wisniewski 2026-09-03 00:12:08 +02:00
commit 0f7edff15a
20 changed files with 238 additions and 45 deletions

View file

@ -1,6 +1,8 @@
class_name VesselGarrisonComponent
extends Node
const COMBAT_TARGET = preload("res://core/CombatTarget.gd")
# #105 (#97g): "When a vessel is assigned to an outpost, it navigates around
# the outpost by itself, attacking nearby ennemies if any are detected."
#
@ -66,7 +68,7 @@ func is_engaging() -> bool:
func tick(delta: float) -> void:
var ship: Node2D = get_parent()
var target: Node2D = _nearest_enemy(ship)
var target: Node2D = _nearest_target(ship)
_engaging = target != null
if target == null:
_patrol(ship, delta)
@ -176,20 +178,27 @@ func _hold_fire(ship: Node2D) -> void:
weapon.set_fire_direction(Vector2.ZERO)
func _nearest_enemy(ship: Node2D) -> Node2D:
func _nearest_target(ship: Node2D) -> Node2D:
var nearest: Node2D = null
var best: float = detection_range
for enemy in get_tree().get_nodes_in_group("enemies"):
if not is_instance_valid(enemy) or enemy.is_queued_for_deletion():
var best_distance: float = INF
var best_priority: int = -1
for target_node in get_tree().get_nodes_in_group(COMBAT_TARGET.GROUP):
if not is_instance_valid(target_node) or not (target_node is Node2D) \
or target_node.is_queued_for_deletion():
continue
var at: Vector2 = (enemy as Node2D).global_position
var target: Node2D = target_node as Node2D
var at: Vector2 = target.global_position
# Judged from the POST, not from the vessel: otherwise a garrison
# that had drifted out to its leash would see further still, and
# could be walked away from its outpost one enemy at a time.
if station.distance_to(at) > leash_range + engage_distance:
continue
var d: float = ship.global_position.distance_to(at)
if d < best:
best = d
nearest = enemy
if d > detection_range:
continue
var priority: int = COMBAT_TARGET.priority(target)
if priority > best_priority or (priority == best_priority and d < best_distance):
best_priority = priority
best_distance = d
nearest = target
return nearest