Skip to content

Commit bc34f38

Browse files
committed
Add instruments script and documentation
1 parent ff1b95a commit bc34f38

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

docs/instruments.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Usage
2626

2727
instruments [list]
2828
instruments order <instrument_name> [<quantity>] [<options>]
29+
instruments all <quantity> [<options>]
30+
instruments handheld <quantity> [<options>]
31+
instruments building <quantity> [<options>]
2932

3033
When ordering, the default is to order one of the specified instrument
3134
(including all of its components).
@@ -43,6 +46,14 @@ Examples
4346
``instruments order ilul``
4447
Creates work orders to assemble one ïlul. Spelling does not need to include
4548
the special ï character.
49+
``instruments all 5``
50+
Creates work orders to produce five of every instrument available to your
51+
civilization.
52+
``instruments handheld 2``
53+
Creates work orders to produce two of each handheld instrument.
54+
``instruments building 3``
55+
Creates work orders to produce three of each instrument that is placed as a
56+
building.
4657

4758
Options
4859
-------

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)