-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathunretire-anyone.lua
97 lines (87 loc) · 3.56 KB
/
unretire-anyone.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
local options = {}
local argparse = require('argparse')
local commands = argparse.processArgsGetopt({ ... }, {
{ 'd', 'dead', handler = function() options.dead = true end }
})
local dialogs = require 'gui.dialogs'
local viewscreen = dfhack.gui.getDFViewscreen(true)
if viewscreen._type ~= df.viewscreen_setupadventurest then
qerror("This script can only be used during adventure mode setup!")
end
--luacheck: in=df.viewscreen_setupadventurest,df.nemesis_record
function addNemesisToUnretireList(advSetUpScreen, nemesis, index)
local unretireOption = false
for i = #advSetUpScreen.valid_race - 1, 0, -1 do
if advSetUpScreen.valid_race[i] == -2 then -- this is the "Specific Person" option on the menu
unretireOption = true
break
end
end
if not unretireOption then
advSetUpScreen.valid_race:insert('#', -2)
end
-- Revive the historical figure
local histFig = nemesis.figure
if histFig.died_year >= -1 then
histFig.died_year = -1
histFig.died_seconds = -1
end
nemesis.flags.ADVENTURER = true
-- nemesis.id and df.global.world.nemesis.all index should *usually* align but there may be bugged scenarios where they don't.
-- This is a workaround for the issue by using the vector index rather than nemesis.id
advSetUpScreen.nemesis_index:insert('#', index)
end
--luacheck: in=table
function showNemesisPrompt(advSetUpScreen)
local choices = {}
for i, nemesis in ipairs(df.global.world.nemesis.all) do
if nemesis.figure and not nemesis.flags.ADVENTURER then -- these are already available for unretiring
local histFig = nemesis.figure
local histFlags = histFig.flags
if (histFig.died_year == -1 or histFlags.ghost or options.dead) and
not histFlags.deity and
not histFlags.force
then
local creature = dfhack.units.getCasteRaw(histFig.race, histFig.caste)
local name = creature.caste_name[0]
if histFig.info and histFig.info.curse then
local curse = histFig.info.curse
if curse.name ~= '' then
name = name .. ' ' .. curse.name
end
if curse.undead_name ~= '' then
name = curse.undead_name .. " - reanimated " .. name
end
end
if histFlags.ghost then
name = name .. " ghost"
end
local sym = df.pronoun_type.attrs[creature.sex].symbol
if sym then
name = name .. ' (' .. sym .. ')'
end
if histFig.name.has_name then
name = name ..
'\n' .. dfhack.TranslateName(histFig.name) ..
'\n"' .. dfhack.TranslateName(histFig.name, true) .. '"'
else
name = name ..
'\nUnnamed'
end
table.insert(choices, { text = name, nemesis = nemesis, search_key = name:lower(), idx = i })
end
end
end
dialogs.ListBox{
frame_title = 'unretire-anyone',
text = 'Select someone to add to the "Specific Person" list:',
text_pen = COLOR_WHITE,
choices = choices,
on_select = function(id, choice)
addNemesisToUnretireList(advSetUpScreen, choice.nemesis, choice.idx)
end,
with_filter = true,
row_height = 3,
}:show()
end
showNemesisPrompt(viewscreen)