1+ -- @module =true
2+
13local options = {}
24
35local argparse = require (' argparse' )
46local commands = argparse .processArgsGetopt ({ ... }, {
57 { ' d' , ' dead' , handler = function () options .dead = true end }
68})
79
8- local dialogs = require ' gui.dialogs'
9-
10- local viewscreen = dfhack .gui .getDFViewscreen (true )
11- if viewscreen ._type ~= df .viewscreen_setupadventurest then
12- qerror (" This script can only be used during adventure mode setup!" )
13- end
10+ local dialogs = require (' gui.dialogs' )
1411
1512-- luacheck: in=df.viewscreen_setupadventurest,df.nemesis_record
16- function addNemesisToUnretireList (advSetUpScreen , nemesis , index )
13+ local function addNemesisToUnretireList (advSetUpScreen , nemesis , index )
1714 local unretireOption = false
1815 for i = # advSetUpScreen .valid_race - 1 , 0 , - 1 do
1916 if advSetUpScreen .valid_race [i ] == - 2 then -- this is the "Specific Person" option on the menu
@@ -39,59 +36,81 @@ function addNemesisToUnretireList(advSetUpScreen, nemesis, index)
3936 advSetUpScreen .nemesis_index :insert (' #' , index )
4037end
4138
39+ function getHistfigShortSummary (histFig )
40+ local race = df .creature_raw .find (histFig .race )
41+ local name = ' Unknown Creature'
42+ local sym = nil
43+ if race then
44+ local creature = race .caste [histFig .caste ]
45+ name = creature .caste_name [0 ]
46+ sym = df .pronoun_type .attrs [creature .sex ].symbol
47+ end
48+ if histFig .info and histFig .info .curse then
49+ local curse = histFig .info .curse
50+ if curse .name ~= ' ' then
51+ name = name .. ' ' .. curse .name
52+ end
53+ if curse .undead_name ~= ' ' then
54+ name = curse .undead_name .. " - reanimated " .. name
55+ end
56+ end
57+ if histFig .flags .ghost then
58+ name = name .. " ghost"
59+ end
60+ if sym then
61+ name = name .. ' (' .. sym .. ' )'
62+ end
63+ name = name ..
64+ ' \n ' .. dfhack .units .getReadableName (histFig )
65+ if histFig .name .has_name then
66+ name = name ..
67+ ' \n "' .. dfhack .translation .translateName (histFig .name , true ) .. ' "'
68+ else
69+ name = name ..
70+ ' \n Unnamed'
71+ end
72+ return name
73+ end
74+
4275-- luacheck: in=table
43- function showNemesisPrompt (advSetUpScreen )
76+ local function showNemesisPrompt (advSetUpScreen )
4477 local choices = {}
4578 for i , nemesis in ipairs (df .global .world .nemesis .all ) do
46- if nemesis .figure and not nemesis . flags . ADVENTURER then -- these are already available for unretiring
79+ if nemesis .figure then
4780 local histFig = nemesis .figure
48- local histFlags = histFig .flags
49- if (histFig .died_year == - 1 or histFlags .ghost or options .dead ) and
50- not histFlags .deity and
51- not histFlags .force
81+ if (histFig .died_year == - 1 or histFig .flags .ghost or options .dead ) and
82+ not histFig .flags .deity and
83+ not histFig .flags .force
5284 then
53- local creature = dfhack .units .getCasteRaw (histFig .race , histFig .caste )
54- local name = creature .caste_name [0 ]
55- if histFig .info and histFig .info .curse then
56- local curse = histFig .info .curse
57- if curse .name ~= ' ' then
58- name = name .. ' ' .. curse .name
59- end
60- if curse .undead_name ~= ' ' then
61- name = curse .undead_name .. " - reanimated " .. name
62- end
63- end
64- if histFlags .ghost then
65- name = name .. " ghost"
66- end
67- local sym = df .pronoun_type .attrs [creature .sex ].symbol
68- if sym then
69- name = name .. ' (' .. sym .. ' )'
70- end
71- if histFig .name .has_name then
72- name = name ..
73- ' \n ' .. dfhack .translation .translateName (histFig .name ) ..
74- ' \n "' .. dfhack .translation .translateName (histFig .name , true ) .. ' "'
75- else
76- name = name ..
77- ' \n Unnamed'
85+ if histFig .died_year == - 1 and nemesis .flags .ADVENTURER then
86+ -- already available for unretiring
87+ goto continue
7888 end
89+ local name = getHistfigShortSummary (histFig )
7990 table.insert (choices , { text = name , nemesis = nemesis , search_key = name :lower (), idx = i })
8091 end
8192 end
93+ :: continue::
8294 end
8395
8496 dialogs .ListBox {
8597 frame_title = ' unretire-anyone' ,
86- text = ' Select someone to add to the "Specific Person" list: ' ,
98+ text = ' Select someone to add to the "Specific Person" list ( ' .. # choices .. ' entries) ' ,
8799 text_pen = COLOR_WHITE ,
88100 choices = choices ,
89- on_select = function (id , choice )
90- addNemesisToUnretireList (advSetUpScreen , choice .nemesis , choice .idx )
91- end ,
101+ on_select = function (id , choice ) addNemesisToUnretireList (advSetUpScreen , choice .nemesis , choice .idx ) end ,
92102 with_filter = true ,
93103 row_height = 3 ,
94104 }:show ()
95105end
96106
107+ if dfhack_flags .module then
108+ return
109+ end
110+
111+ local viewscreen = dfhack .gui .getDFViewscreen (true )
112+ if viewscreen ._type ~= df .viewscreen_setupadventurest then
113+ qerror (" This script can only be used during adventure mode setup!" )
114+ end
115+
97116showNemesisPrompt (viewscreen )
0 commit comments