Skip to content

Commit 5cf887a

Browse files
authored
Update instruments.lua
Lines 140–156 (order_instruments helper) This helper implements bulk ordering for instruments. It gathers all instruments belonging to the player’s civilization that pass a given filter and errors if none match. Each matched instrument is then ordered by calling the existing order_instrument function with the normalized name, amount, and quiet flag. This helper is the shared backend for all bulk-order CLI commands. Lines 180–188 (CLI options: all, handheld, building) These CLI options enable bulk ordering. The all option orders every instrument for the player’s civilization, handheld orders only non-building instruments, and building orders only building-based instruments. Each option reads an amount (defaulting to one) and calls order_instruments with the appropriate filter.
1 parent 178cfe1 commit 5cf887a

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

instruments.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ local function order_instrument(name, amount, quiet)
137137
end
138138
end
139139

140+
local function order_instruments(filter_fn, amount, quiet)
141+
local matched = {}
142+
143+
for _, instr in ipairs(raws.itemdefs.instruments) do
144+
if instr.source_enid == civ_id and filter_fn(instr) then
145+
table.insert(matched, instr)
146+
end
147+
end
148+
149+
if #matched == 0 then
150+
qerror("No instruments matched the selection")
151+
end
152+
153+
for _, instr in ipairs(matched) do
154+
order_instrument(dfhack.toSearchNormalized(instr.name), amount, quiet)
155+
end
156+
end
157+
140158
local help = false
141159
local quiet = false
142160
local positionals = argparse.processArgsGetopt({...}, {
@@ -159,4 +177,14 @@ elseif positionals[1] == "order" then
159177

160178
local amount = positionals[3] or 1
161179
order_instrument(instrument_name, amount, quiet)
180+
elseif positionals[1] == "all" then
181+
local amount = positionals[2] or 1
182+
order_instruments(function() return true end, amount, quiet)
183+
elseif positionals[1] == "handheld" then
184+
local amount = positionals[2] or 1
185+
order_instruments(function(instr) return not instr.flags.PLACED_AS_BUILDING end, amount, quiet)
186+
elseif positionals[1] == "building" then
187+
local amount = positionals[2] or 1
188+
order_instruments(function(instr) return instr.flags.PLACED_AS_BUILDING end, amount, quiet)
162189
end
190+
`

0 commit comments

Comments
 (0)