Skip to content

Commit

Permalink
show descriptive names for races
Browse files Browse the repository at this point in the history
still takes IDs on the commandline, though
  • Loading branch information
myk002 committed Sep 13, 2024
1 parent ce7c714 commit 4795ff5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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' 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

0 comments on commit 4795ff5

Please sign in to comment.