@@ -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