From 4795ff5ee707f74c7fe95db1d557f5be6c5e8b3e Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 13 Sep 2024 14:30:44 -0700 Subject: [PATCH 1/2] show descriptive names for races still takes IDs on the commandline, though --- changelog.txt | 1 + exterminate.lua | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/changelog.txt b/changelog.txt index d4b6641e5..ae1b4851e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -57,6 +57,7 @@ Template for new versions: - `position`: option to copy keyboard cursor position to the clipboard - `assign-minecarts`: reassign vehicles to routes where the vehicle has been destroyed (or has otherwise gone missing) - `fix/dry-buckets`: prompt DF to recheck requests for aid (e.g. "bring water" jobs) when a bucket is unclogged and becomes available for use +- `exterminate`: show descriptive names for the listed races in addition to their IDs ## Documentation - `gui/embark-anywhere`: add information about how the game determines world tile pathability and instructions for bridging two landmasses diff --git a/exterminate.lua b/exterminate.lua index 06b764eb9..cb893afe7 100644 --- a/exterminate.lua +++ b/exterminate.lua @@ -134,10 +134,12 @@ local function getMapRaces(opts) local map_races = {} for _, unit in pairs(df.global.world.units.active) do if not checkUnit(opts, unit) then goto continue end - local unit_race_name = dfhack.units.isUndead(unit) and "UNDEAD" or df.creature_raw.find(unit.race).creature_id + local craw = df.creature_raw.find(unit.race) + local unit_race_name = dfhack.units.isUndead(unit) and 'UNDEAD' or craw.creature_id local race = ensure_key(map_races, unit_race_name) race.id = unit.race race.name = unit_race_name + race.display_name = unit_race_name == 'UNDEAD' and '' or craw.name[0] race.count = (race.count or 0) + 1 ::continue:: end @@ -187,14 +189,20 @@ local map_races = getMapRaces(options) if not positionals[1] or positionals[1] == 'list' then local sorted_races = {} - for race, value in pairs(map_races) do - table.insert(sorted_races, { name = race, count = value.count }) + local max_width = 10 + for _,v in pairs(map_races) do + max_width = math.max(max_width, #v.name) + table.insert(sorted_races, v) end table.sort(sorted_races, function(a, b) return a.count > b.count end) - for _, race in ipairs(sorted_races) do - print(([[%4s %s]]):format(race.count, race.name)) + for _,v in ipairs(sorted_races) do + local name_str = v.name + if name_str ~= 'UNDEAD' then + name_str = ('%-'..tostring(max_width)..'s (%s)'):format(name_str, v.display_name) + end + print(('%4s %s'):format(v.count, name_str)) end return end From 5a67b828be37b3d399d1a4d3fc88afbb374d2e72 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 13 Sep 2024 14:37:41 -0700 Subject: [PATCH 2/2] don't display descriptive name if same as id --- exterminate.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exterminate.lua b/exterminate.lua index cb893afe7..0043febb9 100644 --- a/exterminate.lua +++ b/exterminate.lua @@ -199,7 +199,7 @@ if not positionals[1] or positionals[1] == 'list' then end) for _,v in ipairs(sorted_races) do local name_str = v.name - if name_str ~= 'UNDEAD' then + if name_str ~= 'UNDEAD' and v.display_name ~= string.lower(name_str):gsub('_', ' ') then name_str = ('%-'..tostring(max_width)..'s (%s)'):format(name_str, v.display_name) end print(('%4s %s'):format(v.count, name_str))