Skip to content

Commit 4795ff5

Browse files
committed
show descriptive names for races
still takes IDs on the commandline, though
1 parent ce7c714 commit 4795ff5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Template for new versions:
5757
- `position`: option to copy keyboard cursor position to the clipboard
5858
- `assign-minecarts`: reassign vehicles to routes where the vehicle has been destroyed (or has otherwise gone missing)
5959
- `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
60+
- `exterminate`: show descriptive names for the listed races in addition to their IDs
6061

6162
## Documentation
6263
- `gui/embark-anywhere`: add information about how the game determines world tile pathability and instructions for bridging two landmasses

exterminate.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ local function getMapRaces(opts)
134134
local map_races = {}
135135
for _, unit in pairs(df.global.world.units.active) do
136136
if not checkUnit(opts, unit) then goto continue end
137-
local unit_race_name = dfhack.units.isUndead(unit) and "UNDEAD" or df.creature_raw.find(unit.race).creature_id
137+
local craw = df.creature_raw.find(unit.race)
138+
local unit_race_name = dfhack.units.isUndead(unit) and 'UNDEAD' or craw.creature_id
138139
local race = ensure_key(map_races, unit_race_name)
139140
race.id = unit.race
140141
race.name = unit_race_name
142+
race.display_name = unit_race_name == 'UNDEAD' and '' or craw.name[0]
141143
race.count = (race.count or 0) + 1
142144
::continue::
143145
end
@@ -187,14 +189,20 @@ local map_races = getMapRaces(options)
187189

188190
if not positionals[1] or positionals[1] == 'list' then
189191
local sorted_races = {}
190-
for race, value in pairs(map_races) do
191-
table.insert(sorted_races, { name = race, count = value.count })
192+
local max_width = 10
193+
for _,v in pairs(map_races) do
194+
max_width = math.max(max_width, #v.name)
195+
table.insert(sorted_races, v)
192196
end
193197
table.sort(sorted_races, function(a, b)
194198
return a.count > b.count
195199
end)
196-
for _, race in ipairs(sorted_races) do
197-
print(([[%4s %s]]):format(race.count, race.name))
200+
for _,v in ipairs(sorted_races) do
201+
local name_str = v.name
202+
if name_str ~= 'UNDEAD' then
203+
name_str = ('%-'..tostring(max_width)..'s (%s)'):format(name_str, v.display_name)
204+
end
205+
print(('%4s %s'):format(v.count, name_str))
198206
end
199207
return
200208
end

0 commit comments

Comments
 (0)