@@ -14,32 +14,24 @@ local function spawnLiquid(position, liquid_level, liquid_type, update_liquids)
14
14
map_block .flags .update_liquid_twice = update_liquids
15
15
end
16
16
17
- local function checkUnit (unit )
18
- return (unit .body .blood_count ~= 0 or unit .body .blood_max == 0 ) and
19
- not unit .flags1 .inactive and
20
- not unit .flags1 .caged and
21
- not unit .flags1 .chained
22
- end
23
-
24
- local function isUnitFriendly (unit )
25
- if dfhack .units .isDanger (unit ) then
17
+ local function checkUnit (opts , unit )
18
+ if not dfhack .units .isActive (unit ) or
19
+ (unit .body .blood_max ~= 0 and unit .body .blood_count == 0 ) or
20
+ unit .flags1 .caged or
21
+ unit .flags1 .chained
22
+ then
26
23
return false
27
24
end
28
- local adv = dfhack .world .getAdventurer ()
29
- if adv then
30
- if adv == unit or
31
- unit .relationship_ids .GroupLeader == adv .id or
32
- unit .relationship_ids .PetOwner == adv .id
33
- then
34
- return true
35
- end
25
+ if opts .only_visible and not dfhack .units .isVisible (unit ) then
26
+ return false
36
27
end
37
-
38
- return dfhack .units .isOwnCiv (unit ) or
39
- dfhack .units .isOwnGroup (unit ) or
40
- dfhack .units .isVisiting (unit ) or
41
- dfhack .units .isTame (unit ) or
42
- dfhack .units .isDomesticated (unit )
28
+ if not opts .include_friendly and not dfhack .units .isDanger (unit ) and not dfhack .units .isWildlife (unit ) then
29
+ return false
30
+ end
31
+ if opts .selected_caste and opts .selected_caste ~= df .creature_raw .find (unit .race ).caste [unit .caste ].caste_id then
32
+ return false
33
+ end
34
+ return true
43
35
end
44
36
45
37
killMethod = {
@@ -138,26 +130,17 @@ local function getRaceCastes(race_id)
138
130
return unit_castes
139
131
end
140
132
141
- local function getMapRaces (only_visible , include_friendly )
133
+ local function getMapRaces (opts )
142
134
local map_races = {}
143
135
for _ , unit in pairs (df .global .world .units .active ) do
144
- if only_visible and not dfhack .units .isVisible (unit ) then
145
- goto skipunit
146
- end
147
- if not include_friendly and isUnitFriendly (unit ) then
148
- goto skipunit
149
- end
150
- if dfhack .units .isActive (unit ) and checkUnit (unit ) then
151
- local unit_race_name = dfhack .units .isUndead (unit ) and " UNDEAD" or df .creature_raw .find (unit .race ).creature_id
152
-
153
- local race = ensure_key (map_races , unit_race_name )
154
- race .id = unit .race
155
- race .name = unit_race_name
156
- race .count = (race .count or 0 ) + 1
157
- end
158
- :: skipunit ::
136
+ if not checkUnit (opts , unit ) then goto continue end
137
+ local unit_race_name = dfhack .units .isUndead (unit ) and " UNDEAD" or df .creature_raw .find (unit .race ).creature_id
138
+ local race = ensure_key (map_races , unit_race_name )
139
+ race .id = unit .race
140
+ race .name = unit_race_name
141
+ race .count = (race .count or 0 ) + 1
142
+ :: continue::
159
143
end
160
-
161
144
return map_races
162
145
end
163
146
@@ -200,9 +183,9 @@ if positionals[1] == "this" then
200
183
return
201
184
end
202
185
203
- local map_races = getMapRaces (options . only_visible , options . include_friendly )
186
+ local map_races = getMapRaces (options )
204
187
205
- if not positionals [1 ] then
188
+ if not positionals [1 ] or positionals [ 1 ] == ' list ' then
206
189
local sorted_races = {}
207
190
for race , value in pairs (map_races ) do
208
191
table.insert (sorted_races , { name = race , count = value .count })
@@ -224,28 +207,19 @@ if race_name:lower() == 'undead' then
224
207
qerror (" No undead found on the map." )
225
208
end
226
209
for _ , unit in pairs (df .global .world .units .active ) do
227
- if dfhack .units .isUndead (unit ) and checkUnit (unit ) then
210
+ if dfhack .units .isUndead (unit ) and checkUnit (options , unit ) then
228
211
killUnit (unit , options .method )
229
212
count = count + 1
230
213
end
231
214
end
232
215
elseif positionals [1 ]:split (' :' )[1 ] == " all" then
233
- local selected_caste = positionals [1 ]:split (' :' )[2 ]
216
+ options . selected_caste = positionals [1 ]:split (' :' )[2 ]
234
217
235
218
for _ , unit in ipairs (df .global .world .units .active ) do
236
219
if options .limit > 0 and count >= options .limit then
237
220
break
238
221
end
239
- if not checkUnit (unit ) then
240
- goto skipunit
241
- end
242
- if options .only_visible and not dfhack .units .isVisible (unit ) then
243
- goto skipunit
244
- end
245
- if not options .include_friendly and isUnitFriendly (unit ) then
246
- goto skipunit
247
- end
248
- if selected_caste and selected_caste ~= df .creature_raw .find (unit .race ).caste [unit .caste ].caste_id then
222
+ if not checkUnit (options , unit ) then
249
223
goto skipunit
250
224
end
251
225
@@ -285,21 +259,13 @@ else
285
259
end
286
260
287
261
target = selected_race
262
+ options .selected_caste = selected_caste
288
263
289
264
for _ , unit in pairs (df .global .world .units .active ) do
290
265
if options .limit > 0 and count >= options .limit then
291
266
break
292
267
end
293
- if not checkUnit (unit ) then
294
- goto skipunit
295
- end
296
- if options .only_visible and not dfhack .units .isVisible (unit ) then
297
- goto skipunit
298
- end
299
- if not options .include_friendly and isUnitFriendly (unit ) then
300
- goto skipunit
301
- end
302
- if selected_caste and selected_caste ~= df .creature_raw .find (unit .race ).caste [unit .caste ].caste_id then
268
+ if not checkUnit (options , unit ) then
303
269
goto skipunit
304
270
end
305
271
0 commit comments