fix(flows): udkørselsregler vises kun når en vare bruger dem

Rent lager-flow viste 'sælg fra 90 %' / 'pris >= 90 %' selv om det aldrig
sælger. Guidens Regler-trin, resuméet og statuslinjen viser nu kun
salgsgrænser ved salg og lagergrænsen ved lager (v1.60.11.0).
This commit is contained in:
2026-09-29 21:02:10 +02:00
parent 089fb98782
commit 76f51c7be7
8 changed files with 73 additions and 12 deletions
+19 -8
View File
@@ -327,15 +327,23 @@ local function rowsStore(guide)
return rows return rows
end end
local function productPolicies(draft)
local policies = {}
for _, product in ipairs(draft.products or {}) do table.insert(policies, product.policy) end
return policies
end
-- Kun regler varernes politik bruger: rent lager-flow viser ikke salgsgrænser og omvendt (in-game 29/9).
local function rowsRules(guide) local function rowsRules(guide)
local draft = guide.draft local draft = guide.draft
if isOut(guide) then if isOut(guide) then
return { local sells, stores = ADFlowView.policyUse(productPolicies(draft))
choice("sellAtPercent", L("spu_sellAt"), percentOptions(ADRuns.MIN_SELL_AT_PERCENT, ADRuns.MAX_SELL_AT_PERCENT, 5), draft.sellAtPercent), local rows = {}
choice("storeAbovePercent", L("spu_storeAbove"), percentOptions(ADRuns.MIN_STORE_ABOVE_PERCENT, ADRuns.MAX_STORE_ABOVE_PERCENT, 5), draft.storeAbovePercent), if sells then table.insert(rows, choice("sellAtPercent", L("spu_sellAt"), percentOptions(ADRuns.MIN_SELL_AT_PERCENT, ADRuns.MAX_SELL_AT_PERCENT, 5), draft.sellAtPercent)) end
choice("sellAbovePercent", L("spu_sellAbove"), sellAboveOptions(), draft.sellAbovePercent), if stores then table.insert(rows, choice("storeAbovePercent", L("spu_storeAbove"), percentOptions(ADRuns.MIN_STORE_ABOVE_PERCENT, ADRuns.MAX_STORE_ABOVE_PERCENT, 5), draft.storeAbovePercent)) end
toggle("collectRound", L("spu_collectRound"), draft.collectRound), if sells then table.insert(rows, choice("sellAbovePercent", L("spu_sellAbove"), sellAboveOptions(), draft.sellAbovePercent)) end
} table.insert(rows, toggle("collectRound", L("spu_collectRound"), draft.collectRound))
return rows
end end
local loops = {{label = L("spu_loops_infinite"), value = 0}} local loops = {{label = L("spu_loops_infinite"), value = 0}}
for count = 1, ADRuns.MAX_LOOPS do table.insert(loops, {label = T(tostring(count)), value = count}) end for count = 1, ADRuns.MAX_LOOPS do table.insert(loops, {label = T(tostring(count)), value = count}) end
@@ -479,8 +487,11 @@ local SUMMARY = {
rules = function(guide) rules = function(guide)
local draft = guide.draft local draft = guide.draft
if isOut(guide) then if isOut(guide) then
local parts = {L("spu_guide_flow_sumSellAt", {draft.sellAtPercent}), L("spu_guide_flow_sumStoreAbove", {draft.storeAbovePercent})} local sells, stores = ADFlowView.policyUse(productPolicies(draft))
if (draft.sellAbovePercent or 0) > 0 then table.insert(parts, L("spu_guide_flow_sumSellAbove", {draft.sellAbovePercent})) end local parts = {}
if sells then table.insert(parts, L("spu_guide_flow_sumSellAt", {draft.sellAtPercent})) end
if stores then table.insert(parts, L("spu_guide_flow_sumStoreAbove", {draft.storeAbovePercent})) end
if sells and (draft.sellAbovePercent or 0) > 0 then table.insert(parts, L("spu_guide_flow_sumSellAbove", {draft.sellAbovePercent})) end
if draft.collectRound then table.insert(parts, L("spu_guide_flow_sumRound")) end if draft.collectRound then table.insert(parts, L("spu_guide_flow_sumRound")) end
return parts return parts
end end
+12
View File
@@ -177,6 +177,18 @@ ADFlowView.LEVEL_COLORS = {
} }
-- s = {running, total, stopped, canStop, warning, reason, lastStartFailed} -> "running"|"waiting"|"error"|"stopped" -- s = {running, total, stopped, canStop, warning, reason, lastStartFailed} -> "running"|"waiting"|"error"|"stopped"
-- Hvilke udkørselsregler betyder noget for varernes politik? policies = {"store"|"sell"|"sellElseStore"|"off"}
-- -> sells, stores. Ingen varer med salg/lager endnu = begge (reglerne kan sættes før varerne vælges).
function ADFlowView.policyUse(policies)
local sells, stores = false, false
for _, policy in ipairs(policies or {}) do
if policy == "sell" or policy == "sellElseStore" then sells = true end
if policy == "store" or policy == "sellElseStore" then stores = true end
end
if not sells and not stores then return true, true end
return sells, stores
end
function ADFlowView.flowStatus(s) function ADFlowView.flowStatus(s)
if s.stopped then return "stopped" end if s.stopped then return "stopped" end
if s.warning ~= nil then return "error" end if s.warning ~= nil then return "error" end
@@ -49,7 +49,11 @@ function SmartPickupFrame:flowCells(adEnv, run)
end end
local rule local rule
if row.kind == "outbound" then if row.kind == "outbound" then
rule = string.format(i18n:getText("spu_flow_ruleOut"), row.sellAtPercent or 90, row.storeAbovePercent or 80) local sells, stores = ADFlowView.policyUse(row.policies)
local parts = {}
if sells then table.insert(parts, string.format(i18n:getText("spu_flow_ruleSell"), row.sellAtPercent or 90)) end
if stores then table.insert(parts, string.format(i18n:getText("spu_flow_ruleStore"), row.storeAbovePercent or 80)) end
rule = table.concat(parts, ", ")
if row.collectRound then rule = rule .. ", " .. i18n:getText("spu_flow_round") end if row.collectRound then rule = rule .. ", " .. i18n:getText("spu_flow_round") end
else else
rule = row.loops ~= nil and row.loops > 0 and string.format(i18n:getText("spu_flow_ruleInLoops"), row.loops) or i18n:getText("spu_flow_ruleIn") rule = row.loops ~= nil and row.loops > 0 and string.format(i18n:getText("spu_flow_ruleInLoops"), row.loops) or i18n:getText("spu_flow_ruleIn")
+2
View File
@@ -349,6 +349,8 @@
<text name="spu_flow_noSource" text="(ingen kilde)"/> <text name="spu_flow_noSource" text="(ingen kilde)"/>
<text name="spu_flow_noTarget" text="(intet mål)"/> <text name="spu_flow_noTarget" text="(intet mål)"/>
<text name="spu_flow_noVehicle" text="(ingen traktor)"/> <text name="spu_flow_noVehicle" text="(ingen traktor)"/>
<text name="spu_flow_ruleSell" text="pris >= %d %%"/>
<text name="spu_flow_ruleStore" text="lager > %d %%"/>
<text name="spu_flow_ruleOut" text="pris >= %d %%, lager > %d %%"/> <text name="spu_flow_ruleOut" text="pris >= %d %%, lager > %d %%"/>
<text name="spu_flow_round" text="runde"/> <text name="spu_flow_round" text="runde"/>
<text name="spu_flow_ruleIn" text="efter behov — laveste først"/> <text name="spu_flow_ruleIn" text="efter behov — laveste først"/>
+2
View File
@@ -349,6 +349,8 @@
<text name="spu_flow_noSource" text="(no source)"/> <text name="spu_flow_noSource" text="(no source)"/>
<text name="spu_flow_noTarget" text="(no target)"/> <text name="spu_flow_noTarget" text="(no target)"/>
<text name="spu_flow_noVehicle" text="(no tractor)"/> <text name="spu_flow_noVehicle" text="(no tractor)"/>
<text name="spu_flow_ruleSell" text="price >= %d %%"/>
<text name="spu_flow_ruleStore" text="storage > %d %%"/>
<text name="spu_flow_ruleOut" text="price >= %d %%, storage > %d %%"/> <text name="spu_flow_ruleOut" text="price >= %d %%, storage > %d %%"/>
<text name="spu_flow_round" text="round"/> <text name="spu_flow_round" text="round"/>
<text name="spu_flow_ruleIn" text="by need — lowest first"/> <text name="spu_flow_ruleIn" text="by need — lowest first"/>
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107"> <modDesc descVersion="107">
<author>masterdraco</author> <author>masterdraco</author>
<version>1.60.10.0</version> <version>1.60.11.0</version>
<title> <title>
<en>AD Smart Pickup</en> <en>AD Smart Pickup</en>
</title> </title>
+18 -2
View File
@@ -214,8 +214,9 @@ check("FL11 fra tom", partText(lineFor(sumOut, "buildings")), "spu_guide_flow_no
check("FL11 varer", partText(lineFor(sumOut, "goods")), "spu_policy_store") check("FL11 varer", partText(lineFor(sumOut, "goods")), "spu_policy_store")
check("FL11 varenavn foran", lineFor(sumOut, "goods").parts[1].prefix, "Mælk: ") check("FL11 varenavn foran", lineFor(sumOut, "goods").parts[1].prefix, "Mælk: ")
check("FL11 lager auto", partText(lineFor(sumOut, "store")), "spu_guide_sum_auto") check("FL11 lager auto", partText(lineFor(sumOut, "store")), "spu_guide_sum_auto")
check("FL11 regler", partText(lineFor(sumOut, "rules")), "spu_guide_flow_sumSellAt,spu_guide_flow_sumStoreAbove,spu_guide_flow_sumRound") -- varen er kun "lager": salgsgrænsen vises ikke (in-game 29/9)
check("FL11 sælg 95", lineFor(sumOut, "rules").parts[1].args[1], 95) check("FL11 regler (kun lager)", partText(lineFor(sumOut, "rules")), "spu_guide_flow_sumStoreAbove,spu_guide_flow_sumRound")
check("FL11 lager over", lineFor(sumOut, "rules").parts[1].args[1], 80)
check("FL11 ingen traktorer", partText(lineFor(sumOut, "tractors")), "spu_guide_flow_sumNoTractors") check("FL11 ingen traktorer", partText(lineFor(sumOut, "tractors")), "spu_guide_flow_sumNoTractors")
local manyGoods = FG.summary(FG.choose(FG.choose(FG.choose(supply, "ingredientMode", "manual"), "ingredients", {item = "HAY", on = true}), "ingredients", {item = "STRAW", on = true})) local manyGoods = FG.summary(FG.choose(FG.choose(FG.choose(supply, "ingredientMode", "manual"), "ingredients", {item = "HAY", on = true}), "ingredients", {item = "STRAW", on = true}))
check("FL12 valgte varer", partText(lineFor(manyGoods, "goods")), "=Hø + Halm") check("FL12 valgte varer", partText(lineFor(manyGoods, "goods")), "=Hø + Halm")
@@ -294,5 +295,20 @@ check("WG9 husket vogn i kladden", reopened.draft.wagons.s2, "w2")
check("WG9 ny solo tager ikke den huskede", FG.choose(reopened, "vehicleIds", {item = "s1", on = true}).draft.wagons.s1, "w1") check("WG9 ny solo tager ikke den huskede", FG.choose(reopened, "vehicleIds", {item = "s1", on = true}).draft.wagons.s1, "w1")
check("WG9 kladden kopierer (run urørt)", (function() local g = FG.choose(reopened, "wagon", {item = "s2", value = "w1"}); return remembered.wagons.s2 end)(), "w2") check("WG9 kladden kopierer (run urørt)", (function() local g = FG.choose(reopened, "wagon", {item = "s2", value = "w1"}); return remembered.wagons.s2 end)(), "w2")
-- regler: kun de relevante for varernes politik
local storeOnly = FG.open(newRun("outbound", {products = {{fillType = "MILK", policy = "store"}}}), ctx())
local function keys(rows) local r = {} for _, row in ipairs(rows) do if row.id then table.insert(r, row.id) end end return table.concat(r, ",") end
check("RL1 kun lager: ingen salgsvalg", keys(FG.rows(at(storeOnly, "rules"))), "storeAbovePercent,collectRound")
local sellOnly = FG.open(newRun("outbound", {products = {{fillType = "MILK", policy = "sell"}}}), ctx())
check("RL2 kun salg: ingen lagervalg", keys(FG.rows(at(sellOnly, "rules"))), "sellAtPercent,sellAbovePercent,collectRound")
local function ruleKeys(guide)
for _, line in ipairs(FG.summary(guide)) do
if line.step == "rules" then local r = {} for _, p in ipairs(line.parts) do table.insert(r, p.key) end return table.concat(r, ",") end
end
end
check("RL3 resumé kun lager", ruleKeys(storeOnly), "spu_guide_flow_sumStoreAbove")
check("RL4 resumé kun salg", ruleKeys(sellOnly), "spu_guide_flow_sumSellAt")
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1) os.exit(failures == 0 and 0 or 1)
+14
View File
@@ -87,5 +87,19 @@ check("FVwrap intet ord tabt", table.concat(wrapped, " "):gsub("%s+", " "):gsub(
check("FVwrap kort tekst", V.wrapText("Kort", 30)[1], "Kort") check("FVwrap kort tekst", V.wrapText("Kort", 30)[1], "Kort")
check("FVwrap langt ord deles ikke", V.wrapText("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 10)[1], "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") check("FVwrap langt ord deles ikke", V.wrapText("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 10)[1], "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
-- salgs-/lagerregler vises kun når en vare bruger dem (in-game 29/9: 'sell from 90 %' på et rent lager-flow)
local sells, stores = ADFlowView.policyUse({"store"})
check("politik: kun lager -> sælger ikke", sells, false)
check("politik: kun lager -> lagrer", stores, true)
sells, stores = ADFlowView.policyUse({"sell"})
check("politik: kun salg", tostring(sells) .. tostring(stores), "truefalse")
sells, stores = ADFlowView.policyUse({"sellElseStore", "off"})
check("politik: sælg ellers lager -> begge", tostring(sells) .. tostring(stores), "truetrue")
sells, stores = ADFlowView.policyUse({})
check("politik: ingen varer endnu -> vis begge", tostring(sells) .. tostring(stores), "truetrue")
sells, stores = ADFlowView.policyUse({"off"})
check("politik: kun fra -> vis begge", tostring(sells) .. tostring(stores), "truetrue")
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1) os.exit(failures == 0 and 0 or 1)