feat(lagre): staldenes produktion for alle dyretyper (mælk, gødning, gylle, æg, uld, gedemælk) fra output-kurver × antal dyr (v1.15.1.0)
This commit is contained in:
@@ -678,6 +678,46 @@ local function addHusbandryRates(rates, placeable)
|
||||
end
|
||||
end
|
||||
|
||||
-- Staldens produktion: dyrenes output-kurver (liter pr. dyr pr. døgn efter alder) × antal dyr pr.
|
||||
-- klynge. Output-navne uden fillType: milk -> MILK, manure -> MANURE, liquidManure -> LIQUIDMANURE.
|
||||
local OUTPUT_DEFAULTS = {milk = "MILK", manure = "MANURE", liquidManure = "LIQUIDMANURE"}
|
||||
|
||||
local function resolveFillType(value, outputName)
|
||||
if type(value) == "number" then return value end
|
||||
local name = type(value) == "string" and value or OUTPUT_DEFAULTS[outputName]
|
||||
if name == nil or g_fillTypeManager == nil or g_fillTypeManager.getFillTypeIndexByName == nil then return nil end
|
||||
return g_fillTypeManager:getFillTypeIndexByName(name)
|
||||
end
|
||||
|
||||
local function curveValue(def, age)
|
||||
local curve = type(def) == "table" and def.curve or def
|
||||
if curve == nil or curve.get == nil then return nil end
|
||||
local ok, value = pcall(curve.get, curve, age)
|
||||
return ok and type(value) == "number" and value or nil
|
||||
end
|
||||
|
||||
local function addAnimalProduction(rates, placeable)
|
||||
local animalSystem = g_currentMission ~= nil and g_currentMission.animalSystem or nil
|
||||
if placeable.getClusters == nil or animalSystem == nil or animalSystem.getSubTypeByIndex == nil then return end
|
||||
local ok, clusters = pcall(placeable.getClusters, placeable)
|
||||
if not ok or type(clusters) ~= "table" then return end
|
||||
for _, cluster in ipairs(clusters) do
|
||||
local subTypeIndex = cluster.getSubTypeIndex ~= nil and cluster:getSubTypeIndex() or cluster.subTypeIndex
|
||||
local subType = subTypeIndex ~= nil and animalSystem:getSubTypeByIndex(subTypeIndex) or nil
|
||||
local age = cluster.getAge ~= nil and cluster:getAge() or cluster.age
|
||||
local count = cluster.getNumAnimals ~= nil and cluster:getNumAnimals() or cluster.numAnimals or 0
|
||||
if subType ~= nil and type(subType.output) == "table" and age ~= nil and count > 0 then
|
||||
for outputName, def in pairs(subType.output) do
|
||||
local perAnimal = curveValue(def, age)
|
||||
local fillType = resolveFillType(type(def) == "table" and (def.fillType or def.fillTypeIndex) or nil, outputName)
|
||||
if perAnimal ~= nil and perAnimal > 0 then
|
||||
addRate(rates, fillType, "production", perAnimal * count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- {[fillType] = {consumption, production}} i liter pr. døgn for gårdens fabrikker og stalde.
|
||||
function ADSources.getFarmRates(adEnv, farmId)
|
||||
local placeables = g_currentMission ~= nil and g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||
@@ -688,6 +728,7 @@ function ADSources.getFarmRates(adEnv, farmId)
|
||||
addFactoryRates(rates, placeable)
|
||||
elseif placeable.getHusbandryFillLevel ~= nil then
|
||||
addHusbandryRates(rates, placeable)
|
||||
pcall(addAnimalProduction, rates, placeable)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.15.0.0</version>
|
||||
<version>1.15.1.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user