Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exterminate] show descriptive names for races #1302

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions exterminate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' 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))
end
return
end
Expand Down