debug: sample per-candidate distances when filter matches but nothing within OMNI_HACK_RANGE (measured: enemies=8-10 yet selected=nil all mission — suspect NaN/long distances from position reads)

This commit is contained in:
2026-10-03 14:52:21 -04:00
parent 2cabef7661
commit 15994ed04e
@@ -240,6 +240,7 @@ local function find_hackable_target_unit_omni()
if mod_settings.debug_mode then if mod_settings.debug_mode then
diag_total = 0 diag_total = 0
end end
local diag_samples = mod_settings.debug_mode and {} or nil
for unit, target_extension in pairs(smart_tag_system._unit_extension_data) do for unit, target_extension in pairs(smart_tag_system._unit_extension_data) do
if unit ~= player_unit and HEALTH_ALIVE[unit] and target_extension._target_type == "breed" and not mod._hack_blacklist[unit] then if unit ~= player_unit and HEALTH_ALIVE[unit] and target_extension._target_type == "breed" and not mod._hack_blacklist[unit] then
local unit_data_extension = ScriptUnit_extension(unit, "unit_data_system") local unit_data_extension = ScriptUnit_extension(unit, "unit_data_system")
@@ -249,6 +250,9 @@ local function find_hackable_target_unit_omni()
diag_total = diag_total + 1 diag_total = diag_total + 1
end end
local distance = Vector3_distance(Unit_world_position(unit, 1), player_position) local distance = Vector3_distance(Unit_world_position(unit, 1), player_position)
if diag_samples and #diag_samples < 10 then
diag_samples[#diag_samples + 1] = breed_data.name .. "=" .. tostring(distance)
end
if distance <= OMNI_HACK_RANGE and (not selected_distance or distance < selected_distance) then if distance <= OMNI_HACK_RANGE and (not selected_distance or distance < selected_distance) then
selected_unit, selected_distance = unit, distance selected_unit, selected_distance = unit, distance
end end
@@ -260,6 +264,9 @@ local function find_hackable_target_unit_omni()
if mod.omni_hack_diag_counter % 10 == 1 then if mod.omni_hack_diag_counter % 10 == 1 then
mod:diag(string.format("OMNI-HACK-DIAG enemies=%d selected=%s dist=%s", diag_total, tostring(selected_unit), tostring(selected_distance))) mod:diag(string.format("OMNI-HACK-DIAG enemies=%d selected=%s dist=%s", diag_total, tostring(selected_unit), tostring(selected_distance)))
end end
if not selected_unit and diag_total > 0 and mod.omni_hack_diag_counter % 50 == 1 then
mod:diag("OMNI-HACK-DIAG no-selection samples: " .. table.concat(diag_samples, " "))
end
end end
if selected_unit then if selected_unit then
-- don't retarget the same unit forever if the game refuses to accept the tag -- don't retarget the same unit forever if the game refuses to accept the tag