feat: kæden planlægger hø og ensilage — græs med produkt, mangel/afvisning pr. vare (v1.62.29)
This commit is contained in:
@@ -95,10 +95,11 @@ function ADChain.stateFromRecords(records)
|
||||
return state
|
||||
end
|
||||
|
||||
-- Afviste forslag beholdes kun mens manglen for afgrøden findes og har ændret sig højst 25 %.
|
||||
-- Afviste forslag beholdes kun mens manglen for afgrøden findes og har ændret sig højst 25 %. entry.fruit er
|
||||
-- mangelens nøgle: afgrøden, eller varen for hø/ensilage (DRYGRASS_WINDROW) — samme felt i savegamet.
|
||||
function ADChain.pruneDismissed(dismissed, shortages)
|
||||
local byFruit = {}
|
||||
for _, shortage in ipairs(shortages or {}) do byFruit[shortage.fruit] = shortage.missingHa end
|
||||
for _, shortage in ipairs(shortages or {}) do byFruit[shortage.key or shortage.fruit] = shortage.missingHa end
|
||||
local kept = {}
|
||||
for id, entry in pairs(dismissed or {}) do
|
||||
local now = byFruit[entry.fruit]
|
||||
@@ -117,10 +118,14 @@ function ADChain.dismissedFruits(dismissed)
|
||||
return result
|
||||
end
|
||||
|
||||
function ADChain.unionFruits(usedFruits, fieldDemand)
|
||||
-- fieldProducts[nøgle] = {fruit, product}: en markvares behov (hø) gør dens afgrøde (græs) brugt
|
||||
function ADChain.unionFruits(usedFruits, fieldDemand, fieldProducts)
|
||||
local result = {}
|
||||
for fruit in pairs(usedFruits or {}) do result[fruit] = true end
|
||||
for fruit in pairs(fieldDemand or {}) do result[fruit] = true end
|
||||
for key in pairs(fieldDemand or {}) do
|
||||
local spec = (fieldProducts or {})[key]
|
||||
result[spec ~= nil and spec.fruit or key] = true
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -303,17 +308,17 @@ end
|
||||
|
||||
local function plan(data, state)
|
||||
local recipes = ADChain.modelRecipes(data.recipes, state.paused, state.userOff, state.optIn)
|
||||
local chain = ADChainModel.build(recipes, data.husbandry, data.crops, data.fieldGoods)
|
||||
local chain = ADChainModel.build(recipes, data.husbandry, data.crops, data.fieldGoods, data.fieldGoodCrops)
|
||||
-- pausede rødder: det de bruger, er beskyttet mod slukning (modellen regnet som om de ikke var pauset)
|
||||
local protected = {}
|
||||
if next(state.paused) ~= nil then
|
||||
protected = ADChainModel.build(ADChain.modelRecipes(data.recipes, {}, state.userOff, state.optIn), data.husbandry, data.crops, data.fieldGoods).needRecipes
|
||||
protected = ADChainModel.build(ADChain.modelRecipes(data.recipes, {}, state.userOff, state.optIn), data.husbandry, data.crops, data.fieldGoods, data.fieldGoodCrops).needRecipes
|
||||
end
|
||||
local used = ADChain.unionFruits(data.usedFruits, chain.fieldDemand)
|
||||
local used = ADChain.unionFruits(data.usedFruits, chain.fieldDemand, chain.fieldProducts)
|
||||
-- ufuldstændig markliste: udbuddet ville være undervurderet -> ingen mangler, forslag eller markskift endnu
|
||||
local shortages, actions = {}, {}
|
||||
if not data.fieldsIncomplete then
|
||||
shortages = ADCropPlan.shortages(chain.fieldDemand, data.stock, data.fields, data.yields)
|
||||
shortages = ADCropPlan.shortages(chain.fieldDemand, data.stock, data.fields, data.yields, chain.fieldProducts)
|
||||
state.dismissed = ADChain.pruneDismissed(state.dismissed, shortages)
|
||||
actions = ADCropPlan.choose(shortages, data.fields, used, data.yields, data.priceOf or data.prices, ADChain.dismissedFruits(state.dismissed), data.harvesting)
|
||||
end
|
||||
@@ -482,7 +487,7 @@ function ADChain.approve(fieldId)
|
||||
local plan = ADFieldJobs.getField(fieldId).plan or {}
|
||||
if plan.targetSource == "user" then error("spilleren har selv valgt afgrøde") end
|
||||
end
|
||||
ADFieldJobs.setTarget(fieldId, action.to, "chain")
|
||||
ADFieldJobs.setTarget(fieldId, action.to, "chain", action.product)
|
||||
end)
|
||||
if not ok then
|
||||
Logging.warning(ADChain.LOG_PREFIX .. "F%s: forslag kunne ikke godkendes: %s", tostring(fieldId), tostring(err))
|
||||
@@ -497,10 +502,12 @@ function ADChain.dismiss(fieldId)
|
||||
local action = suggestionFor(fieldId)
|
||||
if action == nil then return false end
|
||||
local missingHa = action.hectares or 0
|
||||
-- nøglen = handlingens grund (afgrøden, eller varen for hø/ensilage)
|
||||
local key = action.reason or action.to
|
||||
for _, shortage in ipairs(ADChain.last.shortages or {}) do
|
||||
if shortage.fruit == action.to then missingHa = shortage.missingHa end
|
||||
if (shortage.key or shortage.fruit) == key then missingHa = shortage.missingHa end
|
||||
end
|
||||
ADChain.state.dismissed[fieldId] = {fruit = action.to, missingHa = missingHa}
|
||||
ADChain.state.dismissed[fieldId] = {fruit = key, missingHa = missingHa}
|
||||
Logging.info(ADChain.LOG_PREFIX .. "F%s: forslag %s afvist", tostring(fieldId), tostring(action.to))
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -248,6 +248,34 @@ local function converterTargets(converter, add)
|
||||
end
|
||||
end
|
||||
|
||||
-- Slåafgrøder (græs, lucerne, kløver): vinduet kan tørres af venderen. Vinduet = afgrøden med produkt ensilage,
|
||||
-- det tørrede = med produkt hø; udbytte = vinduets l/m² (× venderens faktor). Halm (kornets vindue) tørres ikke og
|
||||
-- får ingen plan. data.fieldGoodCrops = {[vare] = {fruit, product}}, data.yields[vare] = l/ha.
|
||||
local function readFieldGoodCrops(data, nameOf)
|
||||
if g_fillTypeManager.getConverterDataByName == nil then return end
|
||||
local tedder = g_fillTypeManager:getConverterDataByName("TEDDER") or {}
|
||||
for _, fruit in ipairs(g_fruitTypeManager ~= nil and g_fruitTypeManager.fruitTypes or {}) do
|
||||
local windrow = windrowIndex(fruit)
|
||||
local dried = windrow ~= nil and tedder[windrow] or nil
|
||||
local driedIndex = type(dried) == "table" and (dried.targetFillTypeIndex or dried.fillTypeIndex) or nil
|
||||
-- kun når venderen ændrer varen (FS25 har også STRAW -> STRAW: halm er ingen hø-afgrøde)
|
||||
if driedIndex ~= nil and driedIndex ~= windrow and fruit.name ~= nil then
|
||||
local windrowName, driedName = nameOf(windrow), nameOf(driedIndex)
|
||||
-- vinduet har sjældent egne liter (græs: <windrow fillType="grass_windrow"/>): så afgrødens høstudbytte
|
||||
local perSqm = tonumber(fruit.windrowLiterPerSqm) or tonumber(fruit.literPerSqm) or 0
|
||||
local perHa = perSqm * 10000
|
||||
if windrowName ~= nil then
|
||||
data.fieldGoodCrops[windrowName] = {fruit = fruit.name, product = "silage"}
|
||||
data.yields[windrowName] = perHa
|
||||
end
|
||||
if driedName ~= nil then
|
||||
data.fieldGoodCrops[driedName] = {fruit = fruit.name, product = "hay"}
|
||||
data.yields[driedName] = perHa * (tonumber(dried.conversionFactor) or tonumber(dried.factor) or 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- data.fieldGoods = {[navn] = true}. Kun eksisterende fill types; fejl logges én gang og gør ikke læsningen delvis
|
||||
-- (en ændret spil-API må ikke blokere kæden for altid) — værst tænkeligt meldes en markvare som "køb".
|
||||
local function readFieldGoods(data, nameOf)
|
||||
@@ -288,6 +316,7 @@ local function readFieldGoods(data, nameOf)
|
||||
local ok, name = pcall(nameOf, index)
|
||||
if ok and name ~= nil and data.crops[name] == nil then data.fieldGoods[name] = true end
|
||||
end
|
||||
guarded("goodCrops", function() readFieldGoodCrops(data, nameOf) end)
|
||||
end
|
||||
|
||||
-- Læs i gårdens køretøjer (vogne, høstertanke, marksilo-vogne) tæller som lager: kun afgrøder og markvarer, ikke
|
||||
@@ -299,6 +328,7 @@ function ADChainData.addVehicleLoads(data, loads)
|
||||
if liters > 0 and (fruit ~= nil or (data.fieldGoods or {})[name]) then
|
||||
data.stockByFill[name] = (data.stockByFill[name] or 0) + liters
|
||||
if fruit ~= nil then data.stock[fruit] = (data.stock[fruit] or 0) + liters end
|
||||
if (data.fieldGoodCrops or {})[name] ~= nil then data.stock[name] = (data.stock[name] or 0) + liters end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -329,6 +359,7 @@ local function readStock(data, adEnv, farmId, nameOf)
|
||||
if name ~= nil then data.stockByFill[name] = (data.stockByFill[name] or 0) + liters end
|
||||
local fruit = data.crops[name or ""]
|
||||
if fruit ~= nil then data.stock[fruit] = (data.stock[fruit] or 0) + liters end
|
||||
if (data.fieldGoodCrops or {})[name or ""] ~= nil then data.stock[name] = (data.stock[name] or 0) + liters end
|
||||
end
|
||||
end)
|
||||
if not ok then failed(data, "stock", "lager kunne ikke læses: %s", tostring(err)) end
|
||||
@@ -382,7 +413,7 @@ local function readFields(data)
|
||||
-- høst i gang: ingen forslag/skift for afgrøden, mens læssene er på vej hjem
|
||||
if field.stage == "harvesting" and info.fruitName ~= nil then data.harvesting[info.fruitName] = true end
|
||||
return {id = info.id, areaHa = ADFields.polygonAreaHa(info.verts), fruit = fruit,
|
||||
targetFruit = plan.targetFruit, targetSource = plan.targetSource, chainFree = plan.chainFree == true,
|
||||
targetFruit = plan.targetFruit, targetSource = plan.targetSource, chainFree = plan.chainFree == true, product = plan.product,
|
||||
permanent = ADChainData.isPermanent(info.fruitName or field.lastFruit), excluded = info.kind == "mowable"}
|
||||
end)
|
||||
if ok then
|
||||
@@ -496,7 +527,7 @@ end
|
||||
-- ikke har nået alle marker.
|
||||
function ADChainData.collect(adEnv, farmId, byChain)
|
||||
local data = {recipes = {}, husbandry = {}, crops = {}, stock = {}, fields = {}, yields = {}, fruitFillIndex = {},
|
||||
usedFruits = {}, points = {}, fillTitles = {}, fillIndex = {}, placeables = {}, barnFood = {}, stockByFill = {}, rates = {}, fieldGoods = {}, harvesting = {}}
|
||||
usedFruits = {}, points = {}, fillTitles = {}, fillIndex = {}, placeables = {}, barnFood = {}, stockByFill = {}, rates = {}, fieldGoods = {}, fieldGoodCrops = {}, harvesting = {}}
|
||||
local nameOf = nameResolver(data)
|
||||
data.priceOf = priceResolver(data)
|
||||
readPlaceables(data, farmId, byChain, nameOf)
|
||||
|
||||
@@ -49,8 +49,10 @@ end
|
||||
|
||||
-- fieldGoods = {[vare] = true}: varer der høstes/laves på marken uden at være en afgrødes hovedvare (hø, hakkelse,
|
||||
-- halm …). Uden producent/stald er kilden "field" uden afgrøde: intet markbehov og intet problem.
|
||||
function ADChainModel.build(recipes, husbandry, crops, fieldGoods)
|
||||
local chain = {roots = {}, demand = {}, fieldDemand = {}, needRecipes = {}, problems = {}}
|
||||
-- goodCrops = {[vare] = {fruit, product}}: markvarer der kommer fra en bestemt afgrøde med et produkt (hø = græs med
|
||||
-- produkt hø, græsvindue = græs med ensilage) — de får markbehov pr. vare (fieldDemand[vare], fieldProducts[vare]).
|
||||
function ADChainModel.build(recipes, husbandry, crops, fieldGoods, goodCrops)
|
||||
local chain = {roots = {}, demand = {}, fieldDemand = {}, fieldProducts = {}, needRecipes = {}, problems = {}}
|
||||
local producers, herds = indexProducers(recipes), indexHerds(husbandry)
|
||||
-- Rødderne kører for sig selv med fuld fart: deres egne input kræves af deres eget træ. Som leverandør til en
|
||||
-- anden rod har de derfor fuld kapacitet, men deres input regnes ikke med igen (standalone = ingen rekursion).
|
||||
@@ -138,7 +140,15 @@ function ADChainModel.build(recipes, husbandry, crops, fieldGoods)
|
||||
chain.fieldDemand[node.fruit] = (chain.fieldDemand[node.fruit] or 0) + rest
|
||||
rest = 0
|
||||
end
|
||||
-- c2) markvare uden egen afgrøde (fx hø, hakkelse): kommer fra markerne, ingen afgrødeplan
|
||||
-- c2) markvare fra en afgrøde med produkt (hø = græs/hø): markbehov pr. vare, så kæden planlægger marken
|
||||
local goodCrop = goodCrops ~= nil and goodCrops[name] or nil
|
||||
if rest > 1e-9 and #node.producers == 0 and #node.herds == 0 and goodCrop ~= nil then
|
||||
node.source, node.fruit, node.product, node.shortKey = "field", goodCrop.fruit, goodCrop.product, name
|
||||
chain.fieldDemand[name] = (chain.fieldDemand[name] or 0) + rest
|
||||
chain.fieldProducts[name] = {fruit = goodCrop.fruit, product = goodCrop.product}
|
||||
rest = 0
|
||||
end
|
||||
-- c3) markvare uden egen afgrøde (fx hakkelse, halm): kommer fra markerne, ingen afgrødeplan
|
||||
if rest > 1e-9 and #node.producers == 0 and #node.herds == 0 and fieldGoods ~= nil and fieldGoods[name] then
|
||||
node.source, node.fruit = "field", nil
|
||||
rest = 0
|
||||
|
||||
@@ -57,12 +57,13 @@ function ADChainRun.switchFields(data, actions)
|
||||
local field = fieldById(data.fields, action.fieldId)
|
||||
-- brugerens egen målafgrøde røres aldrig (dobbelttjek oven i ADCropPlan)
|
||||
if action.mode == "auto" and field ~= nil and field.targetSource ~= "user" then
|
||||
local ok, err = pcall(ADFieldJobs.setTarget, action.fieldId, action.to, "chain")
|
||||
local ok, err = pcall(ADFieldJobs.setTarget, action.fieldId, action.to, "chain", action.product)
|
||||
if ok then
|
||||
switched = switched + 1
|
||||
ADChain.switchCount = ADChain.switchCount + 1
|
||||
local text = string.format("F%s: %s -> %s (%.1f ha) til %s", tostring(action.fieldId), tostring(action.from),
|
||||
tostring(action.to), action.hectares or 0, tostring(action.reason))
|
||||
local text = string.format("F%s: %s -> %s%s (%.1f ha) til %s", tostring(action.fieldId), tostring(action.from),
|
||||
tostring(action.to), action.product ~= nil and (" (" .. tostring(action.product) .. ")") or "", action.hectares or 0,
|
||||
tostring(action.reason))
|
||||
log("%s", text)
|
||||
pcall(ADFieldJobs.notify, text, false)
|
||||
else
|
||||
|
||||
@@ -26,7 +26,7 @@ ADChainView.TEXT_KEYS = {"spu_chain_optIn", "spu_chain_optOut", "spu_chain_notCh
|
||||
"spu_chain_pause", "spu_chain_resume", "spu_chain_scanning", "spu_chain_rootOk", "spu_chain_rootError", "spu_chain_rootWaiting",
|
||||
"spu_chain_rootPaused", "spu_chain_rootSummary", "spu_chain_free", "spu_chain_switches", "spu_chain_gone", "spu_chain_col_item",
|
||||
"spu_chain_col_source", "spu_chain_col_perMonth", "spu_chain_col_status", "spu_chain_col_stock",
|
||||
"spu_chain_flowAuto", "spu_chain_problem_buy", "spu_chain_problem_bottleneck", "spu_chain_problem_off", "spu_chain_problem_cycle", "spu_chain_problem_barn"}
|
||||
"spu_chain_flowAuto", "spu_chain_problem_buy", "spu_chain_problem_bottleneck", "spu_chain_problem_off", "spu_chain_problem_cycle", "spu_chain_problem_barn", "spu_field_plan_hay", "spu_field_plan_silage"}
|
||||
|
||||
local FLOW_KEYS = {ok = "spu_chain_flowOk", missing = "spu_chain_flowNone", stopped = "spu_chain_flowStopped", noVehicle = "spu_chain_flowMissing",
|
||||
pallet = "spu_chain_flowPallet", auto = "spu_chain_flowAuto"}
|
||||
@@ -86,12 +86,15 @@ local function edgeKey(node)
|
||||
return tostring(node.consumer) .. "|" .. tostring(node.fillType)
|
||||
end
|
||||
|
||||
-- Mangler pr. nøgle: afgrøden, eller varen for en markvare med produkt (hø: DRYGRASS_WINDROW)
|
||||
local function shortageByFruit(last)
|
||||
local result = {}
|
||||
for _, shortage in ipairs(last.shortages or {}) do result[shortage.fruit] = shortage end
|
||||
for _, shortage in ipairs(last.shortages or {}) do result[shortage.key or shortage.fruit] = shortage end
|
||||
return result
|
||||
end
|
||||
|
||||
local function shortKey(node) return node.shortKey or node.fruit end
|
||||
|
||||
local function stockOf(last, fruit)
|
||||
local stock = last.data ~= nil and last.data.stock or nil
|
||||
return stock ~= nil and fruit ~= nil and stock[fruit] or nil
|
||||
@@ -99,15 +102,15 @@ end
|
||||
|
||||
-- Lager for en mark-node: afgrødens lager, eller varens eget lager for en markvare uden afgrøde (hø, hakkelse …).
|
||||
local function fieldStockOf(last, node)
|
||||
if node.fruit ~= nil then return stockOf(last, node.fruit) end
|
||||
if node.fruit ~= nil and node.product == nil then return stockOf(last, node.fruit) end
|
||||
local byFill = last.data ~= nil and last.data.stockByFill or nil
|
||||
return byFill ~= nil and byFill[node.fillType] or nil
|
||||
end
|
||||
|
||||
-- Mark-afgrøde uden mangel men med lager under TIGHT_MONTHS måneders behov.
|
||||
local function isTight(node, last, short)
|
||||
if node.source ~= "field" or node.fruit == nil or short[node.fruit] ~= nil then return false end
|
||||
return (stockOf(last, node.fruit) or 0) < ADChainView.TIGHT_MONTHS * (node.perMonth or 0)
|
||||
if node.source ~= "field" or node.fruit == nil or short[shortKey(node)] ~= nil then return false end
|
||||
return (fieldStockOf(last, node) or 0) < ADChainView.TIGHT_MONTHS * (node.perMonth or 0)
|
||||
end
|
||||
|
||||
local function eachNode(nodes, fn, depth)
|
||||
@@ -126,7 +129,7 @@ function ADChainView.rootLevel(root, last)
|
||||
local short, flowStatus = shortageByFruit(last), last.flowStatus or {}
|
||||
local hasShortage, hasWaiting = false, false
|
||||
eachNode(root.children, function(node)
|
||||
if node.fruit ~= nil and short[node.fruit] ~= nil then hasShortage = true end
|
||||
if node.fruit ~= nil and short[shortKey(node)] ~= nil then hasShortage = true end
|
||||
if (node.shortPerMonth or 0) > 0 then hasShortage = true end
|
||||
local status = node.consumer ~= nil and flowStatus[edgeKey(node)] or nil
|
||||
if (status ~= nil and status ~= "ok" and status ~= "auto") or isTight(node, last, short) then hasWaiting = true end
|
||||
@@ -197,7 +200,9 @@ local function sourceText(node, last, textOf)
|
||||
-- markvare uden egen afgrøde (hø, hakkelse …): ingen afgrødeplan, bare "fra marker"
|
||||
if node.fruit == nil then return textOf("spu_chain_fromFields") end
|
||||
for _, field in ipairs(last.fields or {}) do
|
||||
if plannedFruit(field) == node.fruit then table.insert(names, "F" .. tostring(field.id)) end
|
||||
if plannedFruit(field) == node.fruit and (node.product == nil or ADCropPlan.fieldProduct(field) == node.product) then
|
||||
table.insert(names, "F" .. tostring(field.id))
|
||||
end
|
||||
end
|
||||
if #names == 0 then return textOf("spu_chain_noField") end
|
||||
elseif node.source == "buy" then
|
||||
@@ -215,7 +220,7 @@ local function nodeStatus(node, last, fmt, textOf, short)
|
||||
local key = node.source == "production" and "spu_chain_bottleneck" or "spu_chain_buy"
|
||||
return string.format(textOf(key), fmt(node.shortPerMonth)), "error"
|
||||
end
|
||||
local shortage = node.fruit ~= nil and short[node.fruit] or nil
|
||||
local shortage = node.fruit ~= nil and short[shortKey(node)] or nil
|
||||
if shortage ~= nil then return string.format(textOf("spu_chain_fieldShort"), haText(shortage.missingHa)), "error" end
|
||||
local status = node.consumer ~= nil and (last.flowStatus or {})[edgeKey(node)] or nil
|
||||
-- udgangen står på Fordel: spillet leverer selv
|
||||
@@ -242,7 +247,9 @@ end
|
||||
local function suggestRow(action, indent, titleOf, textOf)
|
||||
local pad = string.rep(ADChainView.INDENT, indent)
|
||||
local from = (action.from ~= nil and action.from ~= "") and titleOf(action.from) or "-"
|
||||
local cells = {pad .. "F" .. tostring(action.fieldId) .. " " .. from, "→ " .. titleOf(action.to), haText(action.hectares) .. " ha"}
|
||||
local to = titleOf(action.to)
|
||||
if action.product ~= nil then to = to .. " (" .. textOf("spu_field_plan_" .. tostring(action.product)) .. ")" end
|
||||
local cells = {pad .. "F" .. tostring(action.fieldId) .. " " .. from, "→ " .. to, haText(action.hectares) .. " ha"}
|
||||
if action.mode == "suggest" then
|
||||
cells[4], cells[5] = textOf("spu_chain_approve"), textOf("spu_chain_dismiss")
|
||||
return makeRow("suggest", indent, "waiting", cells,
|
||||
@@ -252,22 +259,23 @@ local function suggestRow(action, indent, titleOf, textOf)
|
||||
return makeRow("auto", indent, "running", cells)
|
||||
end
|
||||
|
||||
-- Handlinger for de afgrøder (i rækkefølge) der hentes fra mark under roden.
|
||||
-- Mark-noderne (i rækkefølge, én pr. mangel-nøgle) under roden: afgrøden, eller hø/ensilage hver for sig.
|
||||
local function rootFruits(root)
|
||||
local fruits, seen = {}, {}
|
||||
local nodes, seen = {}, {}
|
||||
eachNode(root.children, function(node)
|
||||
if node.source == "field" and node.fruit ~= nil and not seen[node.fruit] then
|
||||
seen[node.fruit] = true
|
||||
table.insert(fruits, node.fruit)
|
||||
if node.source == "field" and node.fruit ~= nil and not seen[shortKey(node)] then
|
||||
seen[shortKey(node)] = true
|
||||
table.insert(nodes, node)
|
||||
end
|
||||
end)
|
||||
return fruits
|
||||
return nodes
|
||||
end
|
||||
|
||||
local function actionsFor(last, fruit, modes)
|
||||
-- Handlinger for en mark-node: samme afgrøde og samme produkt (hø-forslag hører ikke under en ensilage-node)
|
||||
local function actionsFor(last, node, modes)
|
||||
local list = {}
|
||||
for _, action in ipairs(last.actions or {}) do
|
||||
if action.to == fruit and modes[action.mode] then table.insert(list, action) end
|
||||
if action.to == node.fruit and action.product == node.product and modes[action.mode] then table.insert(list, action) end
|
||||
end
|
||||
return list
|
||||
end
|
||||
@@ -309,8 +317,8 @@ local function rootRows(rows, root, last, ctx, isExpanded)
|
||||
local level = ADChainView.rootLevel(root, last)
|
||||
local paused = (last.paused or {})[root.key] == true
|
||||
local suggestions = {}
|
||||
for _, fruit in ipairs(rootFruits(root)) do
|
||||
for _, action in ipairs(actionsFor(last, fruit, {suggest = true})) do table.insert(suggestions, action) end
|
||||
for _, fieldNode in ipairs(rootFruits(root)) do
|
||||
for _, action in ipairs(actionsFor(last, fieldNode, {suggest = true})) do table.insert(suggestions, action) end
|
||||
end
|
||||
local status = ctx.textOf(ROOT_STATUS[level])
|
||||
if #suggestions > 0 then status = string.format(ctx.textOf("spu_chain_rootSummary"), status, #suggestions) end
|
||||
@@ -349,9 +357,9 @@ local function rootRows(rows, root, last, ctx, isExpanded)
|
||||
if node.consumer ~= nil then row.openConsumer, row.openFillType = node.consumer, node.fillType end
|
||||
table.insert(rows, row)
|
||||
problemRows(node.fillType, depth + 1)
|
||||
if node.source == "field" and node.fruit ~= nil and not shown[node.fruit] then
|
||||
shown[node.fruit] = true
|
||||
for _, action in ipairs(actionsFor(last, node.fruit, {auto = true})) do
|
||||
if node.source == "field" and node.fruit ~= nil and not shown[shortKey(node)] then
|
||||
shown[shortKey(node)] = true
|
||||
for _, action in ipairs(actionsFor(last, node, {auto = true})) do
|
||||
table.insert(rows, suggestRow(action, depth + 1, ctx.titleOf, ctx.textOf))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,26 +14,40 @@ function ADCropPlan.plannedFruit(field)
|
||||
return field.fruit
|
||||
end
|
||||
|
||||
function ADCropPlan.shortages(demand, stock, fields, yields)
|
||||
-- Markens produkt for slåafgrøder: "auto" (standard) er ensilage.
|
||||
function ADCropPlan.fieldProduct(field)
|
||||
local product = field.product
|
||||
if product == nil or product == "" or product == "auto" then return "silage" end
|
||||
return product
|
||||
end
|
||||
|
||||
-- demand/stock/yields er pr. afgrøde, eller pr. markvare når products[nøgle] = {fruit, product} (hø = græs med
|
||||
-- produkt hø): så tæller kun marker med samme afgrøde OG produkt som udbud, og manglen bærer afgrøde + produkt.
|
||||
function ADCropPlan.shortages(demand, stock, fields, yields, products)
|
||||
local list = {}
|
||||
for fruit, perMonth in pairs(demand or {}) do
|
||||
local perHa = (yields or {})[fruit] or 0
|
||||
for key, perMonth in pairs(demand or {}) do
|
||||
local perHa = (yields or {})[key] or 0
|
||||
local spec = (products or {})[key]
|
||||
local fruit, product = spec ~= nil and spec.fruit or key, spec ~= nil and spec.product or nil
|
||||
if perHa > 0 and (perMonth or 0) > 0 then
|
||||
local need = perMonth * ADCropPlan.HORIZON_MONTHS
|
||||
local supply = (stock or {})[fruit] or 0
|
||||
local supply = (stock or {})[key] or 0
|
||||
for _, field in ipairs(fields or {}) do
|
||||
if ADCropPlan.plannedFruit(field) == fruit then supply = supply + (field.areaHa or 0) * perHa end
|
||||
if ADCropPlan.plannedFruit(field) == fruit and (product == nil or ADCropPlan.fieldProduct(field) == product) then
|
||||
supply = supply + (field.areaHa or 0) * perHa
|
||||
end
|
||||
end
|
||||
local missing = need - supply
|
||||
local missingHa = missing / perHa
|
||||
if missing > need * ADCropPlan.MIN_SHARE and missingHa > ADCropPlan.MIN_HA then
|
||||
table.insert(list, {fruit = fruit, needLiters = need, supplyLiters = supply, missingLiters = missing, missingHa = missingHa})
|
||||
table.insert(list, {fruit = fruit, product = product, key = key, needLiters = need, supplyLiters = supply,
|
||||
missingLiters = missing, missingHa = missingHa})
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(list, function(a, b)
|
||||
if a.missingHa ~= b.missingHa then return a.missingHa > b.missingHa end
|
||||
return a.fruit < b.fruit
|
||||
return a.key < b.key
|
||||
end)
|
||||
return list
|
||||
end
|
||||
@@ -61,7 +75,8 @@ function ADCropPlan.choose(shortages, fields, usedFruits, yields, prices, dismis
|
||||
local remaining = (harvesting or {})[shortage.fruit] and 0 or shortage.missingHa
|
||||
local candidates = {}
|
||||
for _, field in ipairs(fields or {}) do
|
||||
if not taken[field.id] and isCandidate(field, used, (dismissed or {})[field.id], shortage.fruit) then
|
||||
-- afvisninger gemmes pr. nøgle (afgrøden, eller varen for hø/ensilage), så hø og ensilage ikke blandes
|
||||
if not taken[field.id] and isCandidate(field, used, (dismissed or {})[field.id], shortage.key or shortage.fruit) then
|
||||
local planned = ADCropPlan.plannedFruit(field) or ""
|
||||
local value = valueOf(planned)
|
||||
table.insert(candidates, {field = field, value = value})
|
||||
@@ -80,7 +95,8 @@ function ADCropPlan.choose(shortages, fields, usedFruits, yields, prices, dismis
|
||||
local auto = field.chainFree == true and field.targetSource ~= "user"
|
||||
if auto or suggested < ADCropPlan.MAX_SUGGEST_PER_FRUIT then
|
||||
table.insert(actions, {fieldId = field.id, from = ADCropPlan.plannedFruit(field) or "", to = shortage.fruit,
|
||||
hectares = field.areaHa or 0, reason = shortage.fruit, mode = auto and "auto" or "suggest"})
|
||||
product = shortage.product, hectares = field.areaHa or 0, reason = shortage.key or shortage.fruit,
|
||||
mode = auto and "auto" or "suggest"})
|
||||
taken[field.id] = true
|
||||
remaining = remaining - (field.areaHa or 0)
|
||||
if not auto then suggested = suggested + 1 end
|
||||
|
||||
@@ -328,9 +328,9 @@ function ADFieldJobs.forceReady(id)
|
||||
ADFieldJobs.setField(ADFieldModel.forceReady(ADFieldJobs.getField(id)))
|
||||
end
|
||||
|
||||
function ADFieldJobs.setTarget(id, fruitName, source)
|
||||
ADFieldJobs.setField(ADFieldModel.setTarget(ADFieldJobs.getField(id), fruitName, source))
|
||||
ADFieldJobs.log(id, "mål-afgrøde: %s", fruitName ~= "" and fruitName or "ingen")
|
||||
function ADFieldJobs.setTarget(id, fruitName, source, product)
|
||||
ADFieldJobs.setField(ADFieldModel.setTarget(ADFieldJobs.getField(id), fruitName, source, product))
|
||||
ADFieldJobs.log(id, "mål-afgrøde: %s%s", fruitName ~= "" and fruitName or "ingen", product ~= nil and (" (" .. tostring(product) .. ")") or "")
|
||||
ADFieldJobs.save()
|
||||
end
|
||||
|
||||
|
||||
@@ -160,9 +160,11 @@ end
|
||||
|
||||
-- Vælg mål-afgrøde fra menuen ("" = ingen). Med mål kører marken automatisk; en færdig/klar mark sættes
|
||||
-- til venter, så den kan starte forfra. Uden mål: tilbage til manuel.
|
||||
function ADFieldModel.setTarget(field, fruitName, source)
|
||||
-- product (valgfri, "silage"/"hay"): kæden sætter slåafgrødens produkt sammen med afgrøden (græs til hø)
|
||||
function ADFieldModel.setTarget(field, fruitName, source, product)
|
||||
local copy = copyField(field)
|
||||
copy.plan.targetFruit = fruitName or ""
|
||||
if product == "silage" or product == "hay" then copy.plan.product = product end
|
||||
-- kilden huskes kun mens der er et mål; standard er at spilleren valgte det
|
||||
copy.plan.targetSource = copy.plan.targetFruit ~= "" and (source or "user") or ""
|
||||
copy.held = nil
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.28.0</version>
|
||||
<version>1.62.29.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user