forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instruments.lua
70 lines (64 loc) · 2.33 KB
/
instruments.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
-- civilization ID of the player civilization
local civ_id = df.global.plotinfo.civ_id
---@type instrument itemdef_instrumentst
---@return reaction|nil
function getAssemblyReaction(instrument)
for _, reaction in ipairs(df.global.world.raws.reactions.reactions) do
if reaction.source_enid == civ_id and
reaction.category == 'INSTRUMENT' and
reaction.name:find(instrument.name, 1, true)
then
return reaction
end
end
return nil
end
-- patch in thread type
---@type reagent reaction_reagent_itemst
---@return string
function reagentString(reagent)
if reagent.code == 'thread' then
local silk = reagent.flags2.silk and "silk " or ""
local yarn = reagent.flags2.yarn and "yarn " or ""
local plant = reagent.flags2.plant and "plant " or ""
return silk..yarn..plant.."thread"
else
return reagent.code
end
end
---@type reaction reaction
---@return string
function describeReaction(reaction)
local skill = df.job_skill[reaction.skill]
local reagents = {}
for _, reagent in ipairs(reaction.reagents) do
table.insert(reagents, reagentString(reagent))
end
return skill .. ": " .. table.concat(reagents, ", ")
end
-- gather instrument piece reactions and index them by the instrument they are part of
local instruments = {}
for _, reaction in ipairs(df.global.world.raws.reactions.reactions) do
if reaction.source_enid == civ_id and reaction.category == 'INSTRUMENT_PIECE' then
local iname = reaction.name:match("[^ ]+ ([^ ]+)")
table.insert(ensure_key(instruments, iname),
reaction.name.." ("..describeReaction(reaction)..")")
end
end
-- go over instruments
for _,instrument in ipairs(df.global.world.raws.itemdefs.instruments) do
if not (instrument.source_enid == civ_id) then goto continue end
local building_tag = instrument.flags.PLACED_AS_BUILDING and " (building, " or " (handheld, "
local reaction = getAssemblyReaction(instrument)
dfhack.print(instrument.name..building_tag)
if #instrument.pieces == 0 then
print(describeReaction(reaction)..")")
else
print(df.job_skill[reaction.skill].."/assemble)")
for _,str in pairs(instruments[instrument.name]) do
print(" "..str)
end
end
print()
::continue::
end