feat: indstillinger i sektioner; stald med indbygget silo er aldrig marksilo eller tømmested

This commit is contained in:
2026-10-20 01:11:28 +02:00
parent 1b82b50e0e
commit 8c89e159d5
10 changed files with 149 additions and 44 deletions
+3
View File
@@ -814,6 +814,9 @@ end
-- staldens eget lager (forsyningen henter dér), ikke en marksilo — også når den står op ad en mark.
function ADFields.isStableSilo(building, buildings)
if building == nil or building.kind ~= "silo" or building.placeable == nil or building.placeable.rootNode == nil then return false end
-- stald med indbygget silo (Midwest Moraines' "Cowbarn with manure Pit"): siloen ER staldens (in-game 20/10: stald
-- 120 og 129 stod som "F99/F22 marksilo")
if building.placeable.spec_husbandryAnimals ~= nil then return true end
local okS, sx, _, sz = pcall(getWorldTranslation, building.placeable.rootNode)
if not okS or sx == nil then return false end
local range = ADSettings ~= nil and ADSettings.get("stableSiloRange", building.id) or ADFields.STABLE_SILO_M
+9
View File
@@ -700,6 +700,15 @@ local function startDump(adEnv, vehicle, state)
end
-- marksiloer er ikke tømmesteder (de er til markens høst); siloer der allerede fejlede springes over
local okSet, fieldSilos = pcall(function() return ADFieldSilos ~= nil and ADFieldSilos.fieldSiloPlaceableSet(adEnv) or nil end)
-- stalde med indbygget silo/gyllebeholder er heller ikke tømmesteder: en rest gylle i staldens egen beholder fylder den,
-- og så stopper stalden (review 20/10: de var tidligere kun udelukket, når de fejlagtigt talte som marksiloer)
if okSet then
fieldSilos = fieldSilos or {}
local system = g_currentMission.placeableSystem
for _, placeable in ipairs(system ~= nil and system.placeables or {}) do
if placeable.spec_husbandryAnimals ~= nil and placeable.spec_silo ~= nil then fieldSilos[placeable] = true end
end
end
state.triedMarkers = state.triedMarkers or {}
local need = state.partial and math.min(cargo, ADFlowWagons.PARTIAL_DUMP_MIN) or cargo
local ok, marker, why = pcall(ADLoadSwap.findDumpMarker, adEnv, vehicle, fillType, need, nil, isReachable,
+30
View File
@@ -73,6 +73,36 @@ local values = {global = {}, byBuilding = {}}
-- ---- ren logik ----
-- Sektioner i fanen Indstillinger (brugerønske 20/10 01:06: "der begynder at være meget derinde"). Rækkefølgen er
-- vælgerens; en nøgle uden sektion havner i den første.
ADSettings.SECTIONS = {"general", "flows", "fields", "barns", "animals"}
ADSettings.SECTION_OF = {
playerDrive = "general", playerPopup = "general", morningBriefing = "general", contracts = "general",
startAllStaggerSec = "general",
waitHomeMinutes = "flows", parkLoadedMinutes = "flows", strayFullMinutes = "flows",
autoAll = "fields", farmSurplusPercent = "fields", slurryFertilizer = "fields", slurryMinShare = "fields",
stableSiloRange = "barns", troughRefillPercent = "barns",
sellReadyAnimals = "animals", sellReadySpreadMonths = "animals",
}
-- Ren: sektionen hvis den findes, ellers den første
function ADSettings.validSection(section)
for _, known in ipairs(ADSettings.SECTIONS) do
if known == section then return section end
end
return ADSettings.SECTIONS[1]
end
-- Ren: sektionens nøgler (kun dem med valg), sorteret
function ADSettings.sectionKeys(section)
local keys = {}
for key, spec in pairs(ADSettings.KEYS) do
if spec.choices ~= nil and ADSettings.validSection(ADSettings.SECTION_OF[key]) == section then table.insert(keys, key) end
end
table.sort(keys)
return keys
end
function ADSettings.reset()
values = {global = {}, byBuilding = {}}
end
@@ -1,9 +1,10 @@
-- Smart Pickup — fanen Indstillinger
-- Moddens justeringer (ADSettings): én række pr. nøgle globalt, og pr. stald en række der kan afvige fra det globale
-- ("som globalt" = ingen egen værdi). Nye nøgler i ADSettings.KEYS (med choices) dukker op af sig selv.
-- Moddens justeringer (ADSettings), delt i sektioner (ADSettings.SECTIONS, vælger øverst): én række pr. nøgle globalt,
-- og pr. stald en række der kan afvige fra det globale ("som globalt" = ingen egen værdi). Nye nøgler i ADSettings.KEYS
-- (med choices) dukker op af sig selv — i sektionen fra ADSettings.SECTION_OF, ellers i den første.
-- Klik går til onClickSettingsRow.
SmartPickupFrame.SETTINGS_ROW_KINDS = {setGlobal = true, setBuilding = true, setBarnOnly = true, lockTractor = true}
SmartPickupFrame.SETTINGS_ROW_KINDS = {setGlobal = true, setBuilding = true, setBarnOnly = true, lockTractor = true, settingsSection = true}
local function choiceTexts(spec, i18n, withGlobal)
local texts = {}
@@ -31,44 +32,16 @@ local function keyTitle(i18n, key)
return text
end
local function sortedKeys()
local keys = {}
for key, spec in pairs(ADSettings.KEYS) do
if spec.choices ~= nil then table.insert(keys, key) end
end
table.sort(keys)
return keys
end
function SmartPickupFrame:fillSettingsRows(adEnv)
local i18n = self.i18n
if ADSettings == nil then
self:addTextRow("ADSettings mangler")
return
end
local keys = sortedKeys()
self:addTextRow(i18n:getText("spu_set_globalTitle"))
for _, key in ipairs(keys) do
local spec = ADSettings.KEYS[key]
-- kun pr. stald (barnOnly): ingen global række
if not spec.barnOnly then
local option = self:addFieldSiloChoiceRow("setGlobal", keyTitle(i18n, key), choiceTexts(spec, i18n, false), choiceIndex(spec, ADSettings.get(key)))
self.rowData[option] = {kind = "setGlobal", key = key}
end
end
self:addTextRow(i18n:getText("spu_set_globalHelp"))
-- pr. stald: kun nøgler med perBuilding = true
local farmId = g_currentMission:getFarmId()
-- Stalde til pr.-stald-rækkerne: rene stalde, og stalde med dyr (også dem med indbygget silo, der er klassificeret som
-- silo). Fast rækkefølge også for ens navne (sted, så id — review)
local function collectBarns(adEnv)
local barns, animalBarns = {}, {}
for _, building in ipairs(ADBuildings.list(adEnv, farmId) or {}) do
for _, building in ipairs(ADBuildings.list(adEnv, g_currentMission:getFarmId()) or {}) do
if building.kind == "husbandry" then table.insert(barns, building) end
-- stald med indbygget silo er klassificeret som silo, men har dyr (dyre-indstillinger)
if building.kind == "husbandry" or (building.placeable ~= nil and building.placeable.spec_husbandryAnimals ~= nil) then
table.insert(animalBarns, building)
end
end
-- fast rækkefølge også for ens navne (sted, så id — review)
local function byLabel(a, b)
local la, lb = ADBuildings.labelWithPlace(a), ADBuildings.labelWithPlace(b)
if la ~= lb then return la < lb end
@@ -76,12 +49,53 @@ function SmartPickupFrame:fillSettingsRows(adEnv)
end
table.sort(barns, byLabel)
table.sort(animalBarns, byLabel)
return barns, animalBarns
end
-- Sektionsvælgeren øverst (brugerønske 20/10: fanen deles op)
function SmartPickupFrame:getSettingsSection()
return ADSettings.validSection(self.settingsSection)
end
function SmartPickupFrame:addSettingsSectionRow(section)
local texts, state = {}, 1
for index, name in ipairs(ADSettings.SECTIONS) do
table.insert(texts, self.i18n:getText("spu_set_section_" .. name))
if name == section then state = index end
end
local option = self:addFieldSiloChoiceRow("settingsSection", self.i18n:getText("spu_set_sectionTitle"), texts, state)
self.rowData[option] = {kind = "settingsSection"}
end
-- Gælder hele gården: sektionens nøgler uden barnOnly
function SmartPickupFrame:addSettingsGlobalRows(keys)
local i18n, anyGlobal, anyOverride = self.i18n, false, false
for _, key in ipairs(keys) do
local spec = ADSettings.KEYS[key]
local barns = spec.animalBarns and animalBarns or barns
if spec.perBuilding and #barns > 0 then
if not spec.barnOnly then
if not anyGlobal then self:addTextRow(i18n:getText("spu_set_globalTitle")) end
anyGlobal = true
anyOverride = anyOverride or spec.perBuilding == true
local option = self:addFieldSiloChoiceRow("setGlobal", keyTitle(i18n, key), choiceTexts(spec, i18n, false), choiceIndex(spec, ADSettings.get(key)))
self.rowData[option] = {kind = "setGlobal", key = key}
end
end
-- hjælpen om "som globalt" kun når sektionen har pr.-stald-rækker der kan afvige
if anyOverride then self:addTextRow(i18n:getText("spu_set_globalHelp")) end
end
-- Pr. stald: sektionens nøgler med perBuilding. Spredningen vises kun for stalde, der sælger (skjul det irrelevante)
function SmartPickupFrame:addSettingsBarnRows(keys, barns, animalBarns)
local i18n = self.i18n
for _, key in ipairs(keys) do
local spec = ADSettings.KEYS[key]
local list = {}
for _, barn in ipairs(spec.animalBarns and animalBarns or barns) do
if key ~= "sellReadySpreadMonths" or ADSettings.getOwn("sellReadyAnimals", barn.id) == 1 then table.insert(list, barn) end
end
if spec.perBuilding and #list > 0 then
self:addTextRow(string.format(i18n:getText("spu_set_perBarnTitle"), keyTitle(i18n, key)))
for _, barn in ipairs(barns) do
for _, barn in ipairs(list) do
local own = ADSettings.getOwn(key, barn.id)
if spec.barnOnly then
-- kun staldens egen værdi (ingen "som global"): valgene direkte, intet valgt = standard (fra)
@@ -95,7 +109,20 @@ function SmartPickupFrame:fillSettingsRows(adEnv)
end
end
end
self:fillLivestockTractorRows(adEnv, animalBarns)
end
function SmartPickupFrame:fillSettingsRows(adEnv)
if ADSettings == nil then
self:addTextRow("ADSettings mangler")
return
end
local section = self:getSettingsSection()
self:addSettingsSectionRow(section)
local keys = ADSettings.sectionKeys(section)
self:addSettingsGlobalRows(keys)
local barns, animalBarns = collectBarns(adEnv)
self:addSettingsBarnRows(keys, barns, animalBarns)
if section == "animals" then self:fillLivestockTractorRows(adEnv, animalBarns) end
end
-- Fast traktor til slagtedyr pr. stald (kun stalde med salget slået til): "ledig traktor" eller en bestemt traktor
@@ -137,6 +164,11 @@ end
function SmartPickupFrame:onClickSettingsRow(state, data)
self:safe(function(frame)
if data.kind == "settingsSection" then
frame.settingsSection = ADSettings.SECTIONS[state]
frame:requestRebuild()
return
end
if data.kind == "lockTractor" then
local id = data.ids[state]
ADLivestock.setLock(data.buildingId, id ~= false and id or nil)
+6
View File
@@ -603,6 +603,12 @@
<text name="spu_set_globalTitle" text="Gælder hele gården"/>
<text name="spu_set_globalHelp" text="Pr. stald nedenfor: &quot;som globalt&quot; bruger værdien ovenfor."/>
<text name="spu_set_perBarnTitle" text="%s — pr. stald"/>
<text name="spu_set_sectionTitle" text="Vis"/>
<text name="spu_set_section_general" text="Generelt"/>
<text name="spu_set_section_flows" text="Flows og vogne"/>
<text name="spu_set_section_fields" text="Marker og gylle"/>
<text name="spu_set_section_barns" text="Stalde og foder"/>
<text name="spu_set_section_animals" text="Dyr og slagtesalg"/>
<text name="spu_set_asGlobal" text="som globalt"/>
<text name="spu_set_contracts" text="Hvem kører kontrakter"/>
<text name="spu_set_contracts_ask" text="Spørg hver gang"/>
+6
View File
@@ -603,6 +603,12 @@
<text name="spu_set_globalTitle" text="Whole farm"/>
<text name="spu_set_globalHelp" text="Per barn below: &quot;as global&quot; uses the value above."/>
<text name="spu_set_perBarnTitle" text="%s — per barn"/>
<text name="spu_set_sectionTitle" text="Show"/>
<text name="spu_set_section_general" text="General"/>
<text name="spu_set_section_flows" text="Flows and wagons"/>
<text name="spu_set_section_fields" text="Fields and slurry"/>
<text name="spu_set_section_barns" text="Barns and feed"/>
<text name="spu_set_section_animals" text="Animals and sales"/>
<text name="spu_set_asGlobal" text="as global"/>
<text name="spu_set_contracts" text="Who runs contracts"/>
<text name="spu_set_contracts_ask" text="Ask every time"/>
+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.392.0</version>
<version>1.62.393.0</version>
<title>
<en>AD Smart Pickup</en>
</title>