Skip to content

Commit

Permalink
display actual names for unique beasts
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Sep 14, 2024
1 parent 49f9c7f commit 5c4a9b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Template for new versions:
- `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
- `exterminate`: show actual names for unique creatures such as forgotten beasts and titans
- `fix/ownership`: now also checks and fixes room ownership links

## Documentation
Expand Down
32 changes: 27 additions & 5 deletions exterminate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,23 @@ 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 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)
local race_name, display_name
if dfhack.units.isUndead(unit) then
race_name = 'UNDEAD'
display_name = 'UNDEAD'
else
local craw = df.creature_raw.find(unit.race)
race_name = craw.creature_id
if race_name:match('^FORGOTTEN_BEAST_[0-9]+$') or race_name:match('^TITAN_[0-9]+$') then
display_name = dfhack.units.getReadableName(unit)
else
display_name = craw.name[0]
end
end
local race = ensure_key(map_races, race_name)
race.id = unit.race
race.name = unit_race_name
race.display_name = unit_race_name == 'UNDEAD' and '' or craw.name[0]
race.name = race_name
race.display_name = display_name
race.count = (race.count or 0) + 1
::continue::
end
Expand Down Expand Up @@ -195,6 +206,17 @@ if not positionals[1] or positionals[1] == 'list' then
table.insert(sorted_races, v)
end
table.sort(sorted_races, function(a, b)
if a.count == b.count then
local asuffix, bsuffix = a.name:match('([0-9]+)$'), b.name:match('([0-9]+)$')
if asuffix and bsuffix then
local aname, bname = a.name:match('(.*)_[0-9]+$'), b.name:match('(.*)_[0-9]+$')
local anum, bnum = tonumber(asuffix), tonumber(bsuffix)
if aname == bname and anum and bnum then
return anum < bnum
end
end
return a.name < b.name
end
return a.count > b.count
end)
for _,v in ipairs(sorted_races) do
Expand Down

0 comments on commit 5c4a9b1

Please sign in to comment.