diff --git a/unretire-anyone.lua b/unretire-anyone.lua index c977ebdfd..00ccdb886 100644 --- a/unretire-anyone.lua +++ b/unretire-anyone.lua @@ -1,3 +1,5 @@ +--@module=true + local options = {} local argparse = require('argparse') @@ -5,15 +7,10 @@ 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 +local dialogs = require('gui.dialogs') --luacheck: in=df.viewscreen_setupadventurest,df.nemesis_record -function addNemesisToUnretireList(advSetUpScreen, nemesis, index) +local 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 @@ -39,46 +36,60 @@ function addNemesisToUnretireList(advSetUpScreen, nemesis, index) advSetUpScreen.nemesis_index:insert('#', index) end +function getHistfigShortSummary(histFig) + local race = df.creature_raw.find(histFig.race) + local name = 'Unknown Creature' + local sym = nil + if race then + local creature = race.caste[histFig.caste] + name = creature.caste_name[0] + sym = df.pronoun_type.attrs[creature.sex].symbol + end + 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 histFig.flags.ghost then + name = name .. " ghost" + end + 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 + return name +end + --luacheck: in=table -function showNemesisPrompt(advSetUpScreen) +local 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 + if nemesis.figure then 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 + if (histFig.died_year == -1 or histFig.flags.ghost or options.dead) and + not histFig.flags.deity and + not histFig.flags.force then - local creature = df.creature_raw.find(histFig.race).caste[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' + if histFig.died_year == -1 and nemesis.flags.ADVENTURER then + -- already available for unretiring + goto continue end + local name = getHistfigShortSummary(histFig) table.insert(choices, { text = name, nemesis = nemesis, search_key = name:lower(), idx = i }) end end + ::continue:: end dialogs.ListBox{ @@ -86,12 +97,19 @@ function showNemesisPrompt(advSetUpScreen) 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, + on_select = function(id, choice) addNemesisToUnretireList(advSetUpScreen, choice.nemesis, choice.idx) end, with_filter = true, row_height = 3, }:show() end +if dfhack_flags.module then + return +end + +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 + showNemesisPrompt(viewscreen)