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
+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