feat: advarsel når frie marker ikke kan dække kædens/dyrenes behov (v1.62.96)

This commit is contained in:
2026-10-08 19:39:54 +02:00
parent 9924e11278
commit f5ea8f058c
7 changed files with 59 additions and 3 deletions
+32 -2
View File
@@ -330,7 +330,8 @@ local function plan(data, state)
end
-- de ægte opskrifter (ikke kopien): en pauset rod er stadig tændt og må ikke "tændes" og overtages af kæden
local prod = ADChainActions.productions(data.recipes, chain.needRecipes, protected)
return {chain = chain, shortages = shortages, actions = actions, prod = prod, edges = ADChainActions.edges(chain, data.recipes)}
return {chain = chain, shortages = shortages, actions = actions, prod = prod, edges = ADChainActions.edges(chain, data.recipes),
uncovered = ADCropPlan.uncovered(shortages, actions)}
end
local function logInfo(fmt, ...) Logging.info(ADChain.LOG_PREFIX .. fmt, ...) end
@@ -400,7 +401,7 @@ function ADChain.evaluate(adEnv, act)
end
local paused = {}
for key in pairs(state.paused) do paused[key] = true end
ADChain.last = {chain = result.chain, shortages = result.shortages, actions = result.actions, edges = result.edges,
ADChain.last = {chain = result.chain, shortages = result.shortages, actions = result.actions, edges = result.edges, uncovered = result.uncovered,
missingFlows = ADChainActions.missingFlows(result.edges, runs), flowStatus = ADChain.flowStatus(result.edges, runs, ADChain.noVehicle),
paused = paused, userOff = copySet(state.userOff), finalKeep = copySet(state.finalKeep or {}),
sellable = ADChain.sellableRoots(data, result, runs), candidates = ADChain.candidates(data.recipes, state), data = data, fields = data.fields, fieldsIncomplete = data.fieldsIncomplete == true, titles = data.fillTitles, at = ADChain.now, switchCount = ADChain.switchCount,
@@ -444,6 +445,33 @@ function ADChain.notifyProblems(last)
return #fresh
end
-- "Ikke marker nok": tekst pr. udækket mangel (afgrødens/varens titel, produkt, manglende ha).
function ADChain.uncoveredText(entry, titles, textOf)
local name = tostring((titles or {})[entry.key] or (titles or {})[entry.fruit] or entry.key)
local ok, text = pcall(string.format, textOf("spu_chain_notEnoughLand"), name, entry.missingHa or 0)
return ok and text or (name .. ": " .. tostring(entry.missingHa))
end
-- Engangsbesked pr. ny udækket mangel (samme frister som notifyProblems).
ADChain.uncoveredKeys = {}
function ADChain.notifyUncovered(last)
if last == nil or ADChain.now < ADChain.STARTUP_GRACE_MS then return 0 end
if last.fieldsIncomplete or (last.data ~= nil and last.data.partial) then return 0 end
local textOf = function(key) return g_i18n ~= nil and g_i18n:getText(key) or key end
local keys, count = {}, 0
for _, entry in ipairs(last.uncovered or {}) do
keys[entry.key] = true
if not ADChain.uncoveredKeys[entry.key] then
count = count + 1
local text = ADChain.uncoveredText(entry, last.titles, textOf)
Logging.info(ADChain.LOG_PREFIX .. "ikke marker nok: %s", text)
if ADFieldJobs ~= nil and ADFieldJobs.notify ~= nil then ADFieldJobs.notify(text, true) end
end
end
ADChain.uncoveredKeys = keys
return count
end
-- Én besked pr. slukning af en nødvendig produktion (kun fra tick; advarslerne tømmes, når de er meldt).
function ADChain.notifyDependencies(last)
local dependency = last ~= nil and last.dependency or nil
@@ -470,6 +498,8 @@ function ADChain.tick(adEnv, dt)
local last = ADChain.evaluate(adEnv, true)
local ok, err = pcall(ADChain.notifyProblems, last)
if not ok then Logging.warning(ADChain.LOG_PREFIX .. "besked om manglende led fejlede: %s", tostring(err)) end
local okLand, errLand = pcall(ADChain.notifyUncovered, last)
if not okLand then Logging.warning(ADChain.LOG_PREFIX .. "advarsel om for få marker fejlede: %s", tostring(errLand)) end
local okDep, errDep = pcall(ADChain.notifyDependencies, last)
if not okDep then Logging.warning(ADChain.LOG_PREFIX .. "advarsel om slukket produktion fejlede: %s", tostring(errDep)) end
end
+19
View File
@@ -108,3 +108,22 @@ function ADCropPlan.choose(shortages, fields, usedFruits, yields, prices, dismis
end
return actions
end
-- Mangler, som markerne ikke kan dække: manglende ha minus det, de valgte marker (auto + forslag) giver. Over MIN_HA
-- tilbage = advarsel "ikke marker nok" (brugerønske 8/10). -> {{key, fruit, product, missingHa, coveredHa}}
function ADCropPlan.uncovered(shortages, actions)
local covered = {}
for _, action in ipairs(actions or {}) do
local key = action.reason or action.to
covered[key] = (covered[key] or 0) + (action.hectares or 0)
end
local list = {}
for _, shortage in ipairs(shortages or {}) do
local key = shortage.key or shortage.fruit
local left = (shortage.missingHa or 0) - (covered[key] or 0)
if left > ADCropPlan.MIN_HA then
table.insert(list, {key = key, fruit = shortage.fruit, product = shortage.product, missingHa = left, coveredHa = covered[key] or 0})
end
end
return list
end
+4
View File
@@ -254,6 +254,10 @@ function ADStatusHud.chainEntries(proxy)
table.insert(result.dependencies, {text = proxy:alertText(entry), level = "error"})
end
end
-- ikke marker nok til kædens/dyrenes behov (8/10)
for _, entry in ipairs(ADChain.last.uncovered or {}) do
table.insert(suggestions, {text = ADChain.uncoveredText(entry, ADChain.last.titles, textOf), level = "waiting"})
end
return result
end
+1
View File
@@ -592,6 +592,7 @@
<text name="spu_tab_chains" text="Kæder"/>
<text name="spu_chain_noFlow" text="Intet flow kører den vare endnu — kæden opretter det, når der er en ledig traktor/vogn"/>
<text name="spu_chain_animals" text="Dyrenes foder"/>
<text name="spu_chain_notEnoughLand" text="For få marker til %s: mangler ca. %.1f ha — sæt flere marker &quot;Fri til kæden&quot; eller køb jord"/>
<text name="spu_chain_optIn" text="[Kæde til]"/>
<text name="spu_chain_optOut" text="[Fjern]"/>
<text name="spu_chain_notChosen" text="ingen kæde"/>
+1
View File
@@ -592,6 +592,7 @@
<text name="spu_tab_chains" text="Chains"/>
<text name="spu_chain_noFlow" text="No flow carries that good yet — the chain creates one when a tractor/trailer is free"/>
<text name="spu_chain_animals" text="Animals' feed"/>
<text name="spu_chain_notEnoughLand" text="Not enough fields for %s: about %.1f ha short — set more fields &quot;Free for chains&quot; or buy land"/>
<text name="spu_chain_optIn" text="[Chain on]"/>
<text name="spu_chain_optOut" text="[Remove]"/>
<text name="spu_chain_notChosen" text="no chain"/>
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.62.95.0</version>
<version>1.62.96.0</version>
<title>
<en>AD Smart Pickup</en>
</title>