Skip to content

Commit a963f12

Browse files
authored
Merge pull request #1305 from myk002/myk_exterminate
[exterminate] display actual names for unique beasts
2 parents 49f9c7f + 5c4a9b1 commit a963f12

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Template for new versions:
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
6060
- `exterminate`: show descriptive names for the listed races in addition to their IDs
61+
- `exterminate`: show actual names for unique creatures such as forgotten beasts and titans
6162
- `fix/ownership`: now also checks and fixes room ownership links
6263

6364
## Documentation

exterminate.lua

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,23 @@ 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 craw = df.creature_raw.find(unit.race)
138-
local unit_race_name = dfhack.units.isUndead(unit) and 'UNDEAD' or craw.creature_id
139-
local race = ensure_key(map_races, unit_race_name)
137+
local race_name, display_name
138+
if dfhack.units.isUndead(unit) then
139+
race_name = 'UNDEAD'
140+
display_name = 'UNDEAD'
141+
else
142+
local craw = df.creature_raw.find(unit.race)
143+
race_name = craw.creature_id
144+
if race_name:match('^FORGOTTEN_BEAST_[0-9]+$') or race_name:match('^TITAN_[0-9]+$') then
145+
display_name = dfhack.units.getReadableName(unit)
146+
else
147+
display_name = craw.name[0]
148+
end
149+
end
150+
local race = ensure_key(map_races, race_name)
140151
race.id = unit.race
141-
race.name = unit_race_name
142-
race.display_name = unit_race_name == 'UNDEAD' and '' or craw.name[0]
152+
race.name = race_name
153+
race.display_name = display_name
143154
race.count = (race.count or 0) + 1
144155
::continue::
145156
end
@@ -195,6 +206,17 @@ if not positionals[1] or positionals[1] == 'list' then
195206
table.insert(sorted_races, v)
196207
end
197208
table.sort(sorted_races, function(a, b)
209+
if a.count == b.count then
210+
local asuffix, bsuffix = a.name:match('([0-9]+)$'), b.name:match('([0-9]+)$')
211+
if asuffix and bsuffix then
212+
local aname, bname = a.name:match('(.*)_[0-9]+$'), b.name:match('(.*)_[0-9]+$')
213+
local anum, bnum = tonumber(asuffix), tonumber(bsuffix)
214+
if aname == bname and anum and bnum then
215+
return anum < bnum
216+
end
217+
end
218+
return a.name < b.name
219+
end
198220
return a.count > b.count
199221
end)
200222
for _,v in ipairs(sorted_races) do

0 commit comments

Comments
 (0)