feat: spuWindrows — skår på gårdens marker i liter pr. mark (1.62.346)
This commit is contained in:
@@ -189,3 +189,75 @@ function ADWindrowCheck.forget(fieldId)
|
||||
soilCache[fieldId] = nil
|
||||
soilPasses[fieldId] = nil
|
||||
end
|
||||
|
||||
-- ---- oversigt: skår på alle marker (konsol: spuWindrows) ----
|
||||
-- Brugerønske 18/10 23:40: "hvilke marker ligger der græs eller hø på som ikke er hentet hjem?" Markscanningen måler
|
||||
-- ikke skår; her måles alle gårdens marker én gang (fuld sum, ingen grænse) og skrives i loggen/konsollen.
|
||||
ADWindrowCheck.SURVEY_FILL_TYPES = {"GRASS_WINDROW", "DRYGRASS_WINDROW", "ALFALFA_WINDROW", "DRYALFALFA_WINDROW",
|
||||
"CLOVER_WINDROW", "DRYCLOVER_WINDROW", "STRAW"}
|
||||
|
||||
-- Ren: {{id, parts = {{name, liters}}}} -> tekstlinjer, marker med mest først; kun varer ≥ MIN_LITERS
|
||||
function ADWindrowCheck.surveyLines(results)
|
||||
local rows = {}
|
||||
for _, r in ipairs(results or {}) do
|
||||
local total, kept = 0, {}
|
||||
for _, part in ipairs(r.parts or {}) do
|
||||
if part.liters >= ADWindrowCheck.MIN_LITERS then
|
||||
total = total + part.liters
|
||||
table.insert(kept, string.format("%s %.0f l", part.name, part.liters))
|
||||
end
|
||||
end
|
||||
if #kept > 0 then table.insert(rows, {id = r.id, total = total, text = table.concat(kept, ", ")}) end
|
||||
end
|
||||
table.sort(rows, function(a, b) if a.total ~= b.total then return a.total > b.total end return a.id < b.id end)
|
||||
local lines = {}
|
||||
for _, row in ipairs(rows) do table.insert(lines, string.format("F%s: %s", tostring(row.id), row.text)) end
|
||||
return lines
|
||||
end
|
||||
|
||||
-- loft over opslag i ét billede (review: ~31 marker x 1600 felter x 7 varer kan fryse spillet i sekunder)
|
||||
ADWindrowCheck.SURVEY_MAX_READS = 150000
|
||||
|
||||
function ADWindrowCheck.consoleSurvey()
|
||||
if DensityMapHeightUtil == nil or DensityMapHeightUtil.getFillLevelAtArea == nil or ADFields == nil or g_fillTypeManager == nil then
|
||||
return "skår-oversigt: spillets højdekort er ikke tilgængeligt"
|
||||
end
|
||||
local fillTypes = {}
|
||||
for _, fillName in ipairs(ADWindrowCheck.SURVEY_FILL_TYPES) do
|
||||
local index = g_fillTypeManager:getFillTypeIndexByName(fillName)
|
||||
if index ~= nil then table.insert(fillTypes, {index = index, name = fillName}) end
|
||||
end
|
||||
if #fillTypes == 0 then return "skår-oversigt: ingen af skår-varerne findes i spillet" end
|
||||
local results, fields, tooBig, reads, stoppedAt = {}, 0, {}, 0, nil
|
||||
for _, info in ipairs(ADFields.list() or {}) do
|
||||
local cells = ADWindrowCheck.cells(info.verts, ADWindrowCheck.CELL_M)
|
||||
if reads + #cells * #fillTypes > ADWindrowCheck.SURVEY_MAX_READS then
|
||||
stoppedAt = stoppedAt or info.id
|
||||
elseif ADWindrowCheck.MAX_CELLS > 0 and #cells > ADWindrowCheck.MAX_CELLS then
|
||||
table.insert(tooBig, "F" .. tostring(info.id))
|
||||
elseif #cells > 0 then
|
||||
fields = fields + 1
|
||||
local parts = {}
|
||||
for _, ft in ipairs(fillTypes) do
|
||||
local liters, n = litersOnField(cells, {ft.index}, math.huge)
|
||||
reads = reads + n
|
||||
table.insert(parts, {name = ft.name, liters = liters})
|
||||
end
|
||||
table.insert(results, {id = info.id, parts = parts})
|
||||
end
|
||||
end
|
||||
local lines = ADWindrowCheck.surveyLines(results)
|
||||
local notes = {}
|
||||
if #tooBig > 0 then table.insert(notes, "for store: " .. table.concat(tooBig, " ")) end
|
||||
if stoppedAt ~= nil then table.insert(notes, string.format("afbrudt ved F%s (loft %d opslag)", tostring(stoppedAt), ADWindrowCheck.SURVEY_MAX_READS)) end
|
||||
if fields > 0 and reads == 0 then table.insert(notes, "opslag fejlede — resultatet siger intet") end
|
||||
local head = string.format("skår-oversigt: %d marker målt — %d med skår (≥ %d l)%s", fields, #lines, ADWindrowCheck.MIN_LITERS,
|
||||
#notes > 0 and (" [" .. table.concat(notes, "; ") .. "]") or "")
|
||||
Logging.info(ADWindrowCheck.LOG_PREFIX .. "%s", head)
|
||||
for _, line in ipairs(lines) do Logging.info(ADWindrowCheck.LOG_PREFIX .. "skår-oversigt %s", line) end
|
||||
return head .. (#lines > 0 and ("\n" .. table.concat(lines, "\n")) or "")
|
||||
end
|
||||
|
||||
if addConsoleCommand ~= nil then
|
||||
addConsoleCommand("spuWindrows", "Skår (græs/hø/lucerne/kløver/halm) der ligger på gårdens marker, i liter (kan hakke et øjeblik)", "consoleSurvey", ADWindrowCheck)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user