feat: dyrenes foderforbrug som kædebehov — frie marker lægges om til det dyrene mangler (v1.62.95)

This commit is contained in:
2026-10-08 19:38:19 +02:00
parent 20d86fc0b2
commit 9924e11278
7 changed files with 21 additions and 7 deletions
+3 -3
View File
@@ -308,11 +308,11 @@ 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, data.fieldGoodCrops)
local chain = ADChainModel.build(recipes, data.husbandry, data.crops, data.fieldGoods, data.fieldGoodCrops, data.animalDemand)
-- 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, data.fieldGoodCrops).needRecipes
protected = ADChainModel.build(ADChain.modelRecipes(data.recipes, {}, state.userOff, state.optIn), data.husbandry, data.crops, data.fieldGoods, data.fieldGoodCrops, data.animalDemand).needRecipes
end
local used = ADChain.unionFruits(data.usedFruits, chain.fieldDemand, chain.fieldProducts)
-- ufuldstændig markliste: udbuddet ville være undervurderet -> ingen mangler, forslag eller markskift endnu
@@ -426,7 +426,7 @@ function ADChain.notifyProblems(last)
if #fresh == 0 or ADFieldJobs == nil or ADFieldJobs.notify == nil then return 0 end
local textOf = function(key) return g_i18n ~= nil and g_i18n:getText(key) or key end
local fmt = SmartPickupFrame ~= nil and SmartPickupFrame.formatCompact or nil
local rootNames = {}
local rootNames = {animals = textOf("spu_chain_animals")}
for _, root in ipairs(last.chain ~= nil and last.chain.roots or {}) do
rootNames[root.key] = tostring((last.titles or {})[root.name] or root.name)
end
+6 -1
View File
@@ -154,6 +154,11 @@ local function readBarnFood(data, placeable, nameOf)
local barnName
for index, perDay in pairs(ADSources.getHusbandryConsumption(placeable) or {}) do
local name = nameOf(index)
-- dyrenes forbrug er et behov i kæden (brugerønske 8/10: frie marker lægges om til det dyrene mangler).
-- Samme enhed som fabrikkernes cyklusser pr. måned (spillets rå rate pr. 24-timers dag). Vand dyrkes ikke.
if name ~= nil and name ~= "WATER" and (perDay or 0) > 0 and data.animalDemand ~= nil then
data.animalDemand[name] = (data.animalDemand[name] or 0) + perDay
end
if name ~= nil and (perDay or 0) > 0 then
barnName = barnName or placeableName(placeable, placeableId(placeable) or "?")
data.barnFood[name] = data.barnFood[name] or {}
@@ -564,7 +569,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 = {}, barnAccepts = {}, stockByFill = {}, rates = {}, fieldGoods = {}, fieldGoodCrops = {}, unswitchable = {}, harvesting = {}}
usedFruits = {}, points = {}, fillTitles = {}, fillIndex = {}, placeables = {}, barnFood = {}, barnAccepts = {}, animalDemand = {}, stockByFill = {}, rates = {}, fieldGoods = {}, fieldGoodCrops = {}, unswitchable = {}, harvesting = {}}
local nameOf = nameResolver(data)
data.priceOf = priceResolver(data)
readPlaceables(data, farmId, byChain, nameOf)
+8 -2
View File
@@ -51,8 +51,10 @@ end
-- halm …). Uden producent/stald er kilden "field" uden afgrøde: intet markbehov og intet problem.
-- 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 = {}}
-- animalDemand (valgfri): {[vare] = liter/md} dyrenes foder — regnes som et behov efter fabrikkernes rødder, så
-- afgrødeplanen også lægger frie marker om til det dyrene mangler (brugerønske 8/10: "dyrene først").
function ADChainModel.build(recipes, husbandry, crops, fieldGoods, goodCrops, animalDemand)
local chain = {roots = {}, animals = {}, 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).
@@ -174,5 +176,9 @@ function ADChainModel.build(recipes, husbandry, crops, fieldGoods, goodCrops)
table.insert(chain.roots, {key = root.key, name = root.name, building = root.building, buildingName = root.buildingName,
children = inputsOf(root, cycles, 0, {}, root.key)})
end
for _, name in ipairs(sortedNames(animalDemand or {})) do
local perMonth = animalDemand[name] or 0
if perMonth > 0 then table.insert(chain.animals, need(name, perMonth, 0, {}, "animals")) end
end
return chain
end
+1
View File
@@ -591,6 +591,7 @@
<text name="spu_item_share" text="%d %% af varen"/>
<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_optIn" text="[Kæde til]"/>
<text name="spu_chain_optOut" text="[Fjern]"/>
<text name="spu_chain_notChosen" text="ingen kæde"/>
+1
View File
@@ -591,6 +591,7 @@
<text name="spu_item_share" text="%d %% of the good"/>
<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_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.94.0</version>
<version>1.62.95.0</version>
<title>
<en>AD Smart Pickup</en>
</title>