fix: detect duplicate ResourceNode node_id and use interaction_point for distance calc

- Push error and disable node when duplicate node_id is registered
  to prevent silent conflict during find_available()
- Use interaction_point.global_position instead of self.global_position
  in find_available() so distance is measured to the marker NPCs
  actually navigate toward
This commit is contained in:
2026-07-04 19:24:19 +02:00
parent 41bfc8d90a
commit 1837bc0d2d
+7 -1
View File
@@ -24,6 +24,12 @@ var reserved_by: int = -1
func _ready(): func _ready():
if node_id.is_empty(): if node_id.is_empty():
push_error("ResourceNode at %s has empty node_id" % get_path()) push_error("ResourceNode at %s has empty node_id" % get_path())
enabled = false
else:
var existing := get_by_id(node_id)
if existing != null:
push_error("Duplicate ResourceNode node_id '%s' at %s; first registered at %s" % [node_id, get_path(), existing.get_path()])
enabled = false
_all.append(self) _all.append(self)
add_to_group("resource_nodes") add_to_group("resource_nodes")
amount_changed.connect(_update_debug_label) amount_changed.connect(_update_debug_label)
@@ -93,7 +99,7 @@ static func find_available(action: StringName, agent_id: int, from_position: Vec
continue continue
if not node.is_available_for(agent_id): if not node.is_available_for(agent_id):
continue continue
var dist := from_position.distance_squared_to(node.global_position) var dist := from_position.distance_squared_to(node.interaction_point.global_position)
if dist < best_dist: if dist < best_dist:
best_dist = dist best_dist = dist
best = node best = node