1
+ -- @module =true
2
+
1
3
local options = {}
2
4
3
5
local argparse = require (' argparse' )
4
6
local commands = argparse .processArgsGetopt ({ ... }, {
5
7
{ ' d' , ' dead' , handler = function () options .dead = true end }
6
8
})
7
9
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' )
14
11
15
12
-- luacheck: in=df.viewscreen_setupadventurest,df.nemesis_record
16
- function addNemesisToUnretireList (advSetUpScreen , nemesis , index )
13
+ local function addNemesisToUnretireList (advSetUpScreen , nemesis , index )
17
14
local unretireOption = false
18
15
for i = # advSetUpScreen .valid_race - 1 , 0 , - 1 do
19
16
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)
39
36
advSetUpScreen .nemesis_index :insert (' #' , index )
40
37
end
41
38
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
+
42
75
-- luacheck: in=table
43
- function showNemesisPrompt (advSetUpScreen )
76
+ local function showNemesisPrompt (advSetUpScreen )
44
77
local choices = {}
45
78
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
47
80
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
52
84
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
78
88
end
89
+ local name = getHistfigShortSummary (histFig )
79
90
table.insert (choices , { text = name , nemesis = nemesis , search_key = name :lower (), idx = i })
80
91
end
81
92
end
93
+ :: continue::
82
94
end
83
95
84
96
dialogs .ListBox {
85
97
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) ' ,
87
99
text_pen = COLOR_WHITE ,
88
100
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 ,
92
102
with_filter = true ,
93
103
row_height = 3 ,
94
104
}:show ()
95
105
end
96
106
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
+
97
116
showNemesisPrompt (viewscreen )
0 commit comments