feat: udkørsel "Lever også til" (fodring med samme vogn) + låst traktor og vogn til flowet
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
-- fillTypes = {{name, title}} -- varer målet tager (forsyning, Vælg selv)
|
||||
-- products = {{name, title}} -- varer kilderne har (udkørsel)
|
||||
-- storeBuildings = {{id, name, text}} -- lagre der kan tage flowets lagervarer
|
||||
-- feedBuildings = {{id, name, text}} -- "Lever også til": bygninger der tager kildernes varer
|
||||
-- waitPools = {{group, count}}
|
||||
-- vehicles = {{id, label, text, otherRunId, otherRunName, blocked, solo}} -- label = kort navn (resumé)
|
||||
-- wagons = {{id, label}}} -- ledige vogne til solo-traktorer (bedste først)
|
||||
@@ -15,7 +16,7 @@
|
||||
|
||||
ADFlowGuide = {}
|
||||
|
||||
ADFlowGuide.ORDER = {"name", "direction", "buildings", "goods", "store", "rules", "wait", "tractors", "summary"}
|
||||
ADFlowGuide.ORDER = {"name", "direction", "buildings", "goods", "store", "feed", "rules", "wait", "tractors", "summary"}
|
||||
ADFlowGuide.POLICIES = {"off", "store", "sell", "sellElseStore", "keep"}
|
||||
ADFlowGuide.MAX_NAMED_TRACTORS = 3
|
||||
ADFlowGuide.MAX_NAMED_GOODS = 3
|
||||
@@ -35,6 +36,10 @@ end
|
||||
local VISIBLE = {
|
||||
name = function(guide) return guide.draft.isNew == true end,
|
||||
store = function(guide) return isOut(guide) and hasStorePolicy(guide.draft) end,
|
||||
-- kun når der er noget at vælge (eller noget er valgt): skjul det irrelevante
|
||||
feed = function(guide)
|
||||
return isOut(guide) and (#((guide.context or {}).feedBuildings or {}) > 0 or #(guide.draft.feedBuildingIds or {}) > 0)
|
||||
end,
|
||||
}
|
||||
|
||||
function ADFlowGuide.isVisible(step, guide)
|
||||
@@ -70,12 +75,13 @@ local RUN_FIELDS = {
|
||||
"id", "name", "kind", "sourceBuildingIds", "targetBuildingIds", "storeBuildingIds", "products",
|
||||
"ingredientMode", "ingredients", "sellAtPercent", "storeAbovePercent", "sellAbovePercent", "minSourcePercent", "collectRound", "loops",
|
||||
"returnBelowPercent", "waitPoolGroup", "vehicleIds", "wagons", "chain", "spareWagons", "borrowWagonId", "sellUnused",
|
||||
"feedBuildingIds", "lockSet",
|
||||
}
|
||||
|
||||
local function draftFrom(run, isNew)
|
||||
local draft = {}
|
||||
for _, key in ipairs(RUN_FIELDS) do draft[key] = ADGuide.deepCopy(run[key]) end
|
||||
for _, key in ipairs({"sourceBuildingIds", "targetBuildingIds", "storeBuildingIds", "products", "ingredients", "vehicleIds"}) do
|
||||
for _, key in ipairs({"sourceBuildingIds", "targetBuildingIds", "storeBuildingIds", "feedBuildingIds", "products", "ingredients", "vehicleIds"}) do
|
||||
draft[key] = draft[key] or {}
|
||||
end
|
||||
draft.kind = draft.kind == "outbound" and "outbound" or "supply"
|
||||
@@ -90,6 +96,7 @@ local function draftFrom(run, isNew)
|
||||
draft.wagons = draft.wagons or {}
|
||||
draft.spareWagons = draft.spareWagons or {}
|
||||
draft.collectRound = draft.collectRound == true
|
||||
draft.lockSet = draft.lockSet == true
|
||||
draft.isNew = isNew == true
|
||||
draft.showAllBuildings = false
|
||||
draft.storeAuto = #draft.storeBuildingIds == 0
|
||||
@@ -180,8 +187,8 @@ local SET_VALUES = {
|
||||
kind = true, ingredientMode = true, sellAtPercent = true, storeAbovePercent = true, sellAbovePercent = true, minSourcePercent = true, loops = true,
|
||||
returnBelowPercent = true, waitPoolGroup = true, borrowWagonId = true,
|
||||
}
|
||||
local BOOL_VALUES = {showAllBuildings = true, storeAuto = true, collectRound = true, borrowTractor = true, sellUnused = true}
|
||||
local LIST_VALUES = {ingredients = true, storeBuildingIds = true, vehicleIds = true}
|
||||
local BOOL_VALUES = {showAllBuildings = true, storeAuto = true, collectRound = true, borrowTractor = true, sellUnused = true, lockSet = true}
|
||||
local LIST_VALUES = {ingredients = true, storeBuildingIds = true, feedBuildingIds = true, vehicleIds = true}
|
||||
|
||||
local function setPolicy(products, name, policy)
|
||||
local result = {}
|
||||
@@ -242,6 +249,7 @@ ADFlowGuide.TOOLTIPS = {
|
||||
storeAbovePercent = "spu_storeAbove_tooltip", sellAbovePercent = "spu_sellAbove_tooltip", minSourcePercent = "spu_minSource_tooltip",
|
||||
collectRound = "spu_collectRound_tooltip", loops = "spu_loops_tooltip", returnBelowPercent = "spu_returnBelow_tooltip",
|
||||
waitPoolGroup = "spu_waitPool_tooltip", sellUnused = "spu_guide_flow_sellUnused_tooltip", borrowTractor = "spu_guide_flow_borrow_tooltip", borrowWagonId = "spu_guide_flow_borrowWagon_tooltip",
|
||||
lockSet = "spu_guide_flow_lockSet_tooltip",
|
||||
}
|
||||
|
||||
local function choice(id, title, options, value, item)
|
||||
@@ -364,6 +372,17 @@ local function rowsStore(guide)
|
||||
return rows
|
||||
end
|
||||
|
||||
-- "Lever også til" (20/10): bygninger der fodres først med kildernes varer (fiskefoder til Young Fish Breeding)
|
||||
local function rowsFeed(guide)
|
||||
local draft, rows = guide.draft, {text("spu_guide_flow_feedText")}
|
||||
local chosen = chosenSet(draft.feedBuildingIds)
|
||||
for _, building in ipairs(guide.context.feedBuildings or {}) do
|
||||
table.insert(rows, check("feedBuildingIds", building.id, building.text, chosen[building.id]))
|
||||
end
|
||||
if #(guide.context.feedBuildings or {}) == 0 then table.insert(rows, text("spu_guide_flow_noFeedBuildings")) end
|
||||
return rows
|
||||
end
|
||||
|
||||
local function productPolicies(draft)
|
||||
local policies = {}
|
||||
for _, product in ipairs(draft.products or {}) do table.insert(policies, product.policy) end
|
||||
@@ -504,6 +523,8 @@ local function rowsTractors(guide)
|
||||
local draft, rows = guide.draft, {}
|
||||
if draft.borrowTractor then return rowsBorrow(guide) end
|
||||
table.insert(rows, toggle("borrowTractor", L("spu_guide_flow_borrow"), false))
|
||||
-- låst sæt (20/10): traktor + vogn lånes aldrig ud og køres ikke hjem
|
||||
table.insert(rows, toggle("lockSet", L("spu_guide_flow_lockSet"), draft.lockSet))
|
||||
local inRun = chosenSet(draft.vehicleIds)
|
||||
local entries = {}
|
||||
local other, blocked = 0, 0
|
||||
@@ -537,7 +558,7 @@ local function rowsTractors(guide)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #rows == 1 then table.insert(rows, text("spu_guide_flow_noTractors")) end
|
||||
if #rows == 2 then table.insert(rows, text("spu_guide_flow_noTractors")) end
|
||||
if other > 0 then table.insert(rows, text("spu_guide_flow_otherFlows", {other})) end
|
||||
if blocked > 0 then
|
||||
-- foldet sammen som standard; linjen med antallet folder navn + grund ud/ind
|
||||
@@ -560,7 +581,7 @@ local function rowsSummary(guide)
|
||||
end
|
||||
|
||||
local ROWS = {
|
||||
name = rowsName, direction = rowsDirection, buildings = rowsBuildings, goods = rowsGoods, store = rowsStore,
|
||||
name = rowsName, direction = rowsDirection, buildings = rowsBuildings, goods = rowsGoods, store = rowsStore, feed = rowsFeed,
|
||||
rules = rowsRules, wait = rowsWait, tractors = rowsTractors, summary = rowsSummary,
|
||||
}
|
||||
|
||||
@@ -616,6 +637,12 @@ local SUMMARY = {
|
||||
if #draft.storeBuildingIds > 2 then return {L("spu_guide_sum_stores", {#draft.storeBuildingIds})} end
|
||||
return {T(table.concat(namesFor(draft.storeBuildingIds, guide.context.storeBuildings, "name"), " + "))}
|
||||
end,
|
||||
feed = function(guide)
|
||||
local ids = guide.draft.feedBuildingIds or {}
|
||||
if #ids == 0 then return {L("spu_guide_flow_none")} end
|
||||
if #ids > 2 then return {L("spu_guide_flow_sumFeed", {#ids})} end
|
||||
return {T(table.concat(namesFor(ids, guide.context.feedBuildings, "name"), " + "))}
|
||||
end,
|
||||
rules = function(guide)
|
||||
local draft = guide.draft
|
||||
if isOut(guide) then
|
||||
@@ -656,7 +683,9 @@ local SUMMARY = {
|
||||
local present = {}
|
||||
for _, id in ipairs(ids) do if known[id] then table.insert(present, id) end end
|
||||
if #present == 0 then return {L("spu_guide_flow_sumNoTractors")} end
|
||||
return {T(table.concat(namesFor(present, guide.context.vehicles, "label"), ", "))}
|
||||
local parts = {T(table.concat(namesFor(present, guide.context.vehicles, "label"), ", "))}
|
||||
if guide.draft.lockSet then table.insert(parts, L("spu_guide_flow_sumLocked")) end
|
||||
return parts
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -687,6 +716,8 @@ function ADFlowGuide.result(guide)
|
||||
minSourcePercent = draft.minSourcePercent or 0, sellUnused = draft.sellUnused == true,
|
||||
collectRound = draft.collectRound, loops = draft.loops,
|
||||
returnBelowPercent = draft.returnBelowPercent, waitPoolGroup = draft.waitPoolGroup or "",
|
||||
feedBuildingIds = draft.kind == "outbound" and ADGuide.deepCopy(draft.feedBuildingIds or {}) or {},
|
||||
lockSet = draft.lockSet == true and not draft.borrowTractor, -- en lånt traktor kan ikke låses
|
||||
}
|
||||
if draft.name ~= nil and draft.name:match("%S") then changes.name = draft.name end
|
||||
-- lånt traktor: ingen faste traktorer (de slippes ved gem), kun vognen huskes; uden ledig vogn = faste traktorer
|
||||
@@ -695,6 +726,7 @@ function ADFlowGuide.result(guide)
|
||||
if borrowWagonId ~= nil then
|
||||
-- spillerens eget flow nu: kæden må ikke regne det som sit tomme flow (slette/lægge sammen/bemande — review 19/10)
|
||||
changes.chain = ""
|
||||
changes.lockSet = false -- en lånt traktor kan ikke låses til flowet
|
||||
return {isNew = draft.isNew == true, runId = draft.id, name = draft.name, kind = draft.kind, changes = changes,
|
||||
vehicleIds = {}, wagons = {}, spareWagons = {}, borrow = true}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user