feat: udvikler-dump af triggerpositioner (v1.62.72)

This commit is contained in:
2026-10-08 00:50:47 +02:00
parent f0204d72a7
commit 6019b4edb9
4 changed files with 75 additions and 1 deletions
+72
View File
@@ -538,3 +538,75 @@ function ADBuildings.getMarkers(building, role)
end
return building.loadMarkers or (building.loadMarker ~= nil and {building.loadMarker} or {})
end
-- ---- udvikler-diagnose: triggerpositioner (til at bygge vejnet/markører uden for spillet) ----
-- Kører én gang ~20 s efter indlæsning, KUN hvis filen modSettings/FS25_ADSmartPickup/dumpTriggers.txt findes.
-- Logger pr. bygning: navn, art, position, rotation, læssepunkter, aflæsningspunkter og trigger-felter i
-- objektlager/silo (palleskurets indlevering). Linjerne starter med "ADSmartPickup: TRIGGER".
ADBuildings.DUMP_DELAY_MS = 20000
local dumpState = {done = false, elapsed = 0}
local function fmt(x, z) return string.format("%.2f %.2f", x or 0, z or 0) end
local function specTriggerNodes(spec)
local result = {}
for key, value in pairs(spec or {}) do
if type(key) == "string" and key:lower():find("trigger") ~= nil and type(value) == "number"
and (entityExists == nil or entityExists(value)) then
local x, z = getNodePosition(value)
if x ~= nil then table.insert(result, key .. "=" .. fmt(x, z)) end
end
end
table.sort(result)
return result
end
function ADBuildings.dumpTriggers(adEnv, farmId)
local placeables = g_currentMission.placeableSystem.placeables or {}
local storage = g_currentMission.storageSystem
local loadStations = storage ~= nil and storage:getLoadingStations() or {}
local unloadStations = storage ~= nil and storage:getUnloadingStations() or {}
local count = 0
for _, placeable in pairs(placeables) do
local kind = getKind(placeable)
if kind == nil and isSellPlaceable(placeable, unloadStations) then kind = "sell" end
if kind == nil and placeable.spec_objectStorage ~= nil then kind = "objectStorage" end
if kind ~= nil then
count = count + 1
local name = getName(placeable, "?")
local x, _, z = getWorldTranslation(placeable.rootNode)
local _, ry = getWorldRotation(placeable.rootNode)
Logging.info("ADSmartPickup: TRIGGER bygning '%s' art=%s pos=%s rotY=%.1f fil=%s", tostring(name), kind, fmt(x, z),
math.deg(ry or 0), tostring(placeable.configFileName))
local okNodes, loadGroups, unloadNodes = pcall(collectNodes, placeable, loadStations, unloadStations)
if okNodes then
for index, nodes in ipairs(loadGroups or {}) do
for _, node in ipairs(nodes) do
local nx, nz = getNodePosition(node)
if nx ~= nil then Logging.info("ADSmartPickup: TRIGGER '%s' læs%d%s %s", tostring(name), index, nodes.isSpawner and " (spawner)" or "", fmt(nx, nz)) end
end
end
for _, node in ipairs(unloadNodes or {}) do
local nx, nz = getNodePosition(node)
if nx ~= nil then Logging.info("ADSmartPickup: TRIGGER '%s' aflæs %s", tostring(name), fmt(nx, nz)) end
end
end
for _, specName in ipairs({"spec_objectStorage", "spec_silo", "spec_bunkerSilo"}) do
local nodes = specTriggerNodes(placeable[specName])
if #nodes > 0 then Logging.info("ADSmartPickup: TRIGGER '%s' %s: %s", tostring(name), specName, table.concat(nodes, "; ")) end
end
end
end
Logging.info("ADSmartPickup: TRIGGER færdig: %d bygninger", count)
end
function ADBuildings.tickDump(adEnv, dt)
if dumpState.done then return end
dumpState.elapsed = dumpState.elapsed + (dt or 0)
if dumpState.elapsed < ADBuildings.DUMP_DELAY_MS then return end
dumpState.done = true
local path = getUserProfileAppPath ~= nil and (getUserProfileAppPath() .. "modSettings/FS25_ADSmartPickup/dumpTriggers.txt") or nil
if path == nil or fileExists == nil or not fileExists(path) then return end
local ok, err = pcall(ADBuildings.dumpTriggers, adEnv, g_currentMission:getFarmId())
if not ok then Logging.warning("ADSmartPickup: TRIGGER-dump fejlede: %s", tostring(err)) end
end