Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
62 lines
2.2 KiB
GDScript
62 lines
2.2 KiB
GDScript
class_name EnemyStandoffComponent
|
|
extends Node
|
|
|
|
# Holds a preferred distance from the nearest player ship instead of
|
|
# ramming: advances when too far, retreats when too close, drifts
|
|
# laterally in the comfortable band between so it still reads as alive
|
|
# rather than frozen. Never pair with a pursuit component on the same
|
|
# enemy - the two would fight over velocity every tick.
|
|
|
|
var capability_id: String = "standoff"
|
|
|
|
@export var preferred_range: float = 620.0
|
|
@export var retreat_range_factor: float = 0.75
|
|
# #69: kept comfortably beyond preferred_range so it still has room to close
|
|
# in before settling at stand-off distance, but the fleet has to actually be
|
|
# somewhere on the board first - see EnemyPursuitComponent's identical fix.
|
|
@export var detection_range: float = 1200.0
|
|
|
|
var velocity: Vector2 = Vector2.ZERO
|
|
|
|
|
|
func tick(delta: float) -> void:
|
|
var enemy: Node2D = get_parent()
|
|
var target: Node2D = _nearest_ship(enemy)
|
|
if target == null:
|
|
return
|
|
var to_target: Vector2 = target.position - enemy.position
|
|
var distance: float = to_target.length()
|
|
if distance < 1.0 or distance > detection_range:
|
|
return
|
|
var direction: Vector2 = to_target / distance
|
|
var retreat_range: float = preferred_range * retreat_range_factor
|
|
|
|
var desired_velocity: Vector2
|
|
if distance > preferred_range:
|
|
desired_velocity = direction * enemy.speed
|
|
elif distance < retreat_range:
|
|
desired_velocity = -direction * enemy.speed
|
|
else:
|
|
var lateral: Vector2 = Vector2(-direction.y, direction.x)
|
|
desired_velocity = lateral * enemy.speed * 0.5
|
|
|
|
velocity = velocity.move_toward(desired_velocity, enemy.acceleration * delta)
|
|
enemy.position += velocity * delta
|
|
|
|
if velocity.length() > 5.0:
|
|
var target_angle: float = velocity.angle() + PI / 2.0
|
|
enemy.rotation = lerp_angle(enemy.rotation, target_angle, enemy.rotation_speed * delta)
|
|
|
|
|
|
func _nearest_ship(enemy: Node2D) -> Node2D:
|
|
var fleet: Node2D = get_tree().get_first_node_in_group("player_fleet")
|
|
if fleet == null or fleet.ships.is_empty():
|
|
return null
|
|
var nearest: Node2D = fleet.ships[0]
|
|
var best_dist: float = enemy.position.distance_to(nearest.position)
|
|
for ship in fleet.ships:
|
|
var d: float = enemy.position.distance_to(ship.position)
|
|
if d < best_dist:
|
|
best_dist = d
|
|
nearest = ship
|
|
return nearest
|