Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Template for new versions:
## New Features

## Fixes
- `exterminate`: now works in arena mode; all active arena units are valid targets (there is no friendly/dangerous distinction in the arena), corpses are skipped, and the adventure arena player unit is never mass-exterminated

## Misc Improvements

Expand Down
6 changes: 6 additions & 0 deletions docs/exterminate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ exterminate
Kills any individual unit, or all undead, or all units of a given race. Caged
and chained creatures are ignored.

In arena mode, every living unit is a valid target regardless of hostility
(there is no friendly/dangerous distinction to protect), corpses are skipped,
and the player-controlled unit in adventure arena is never killed by mass
extermination. Since arena mode has no unit selection interface, ``exterminate
this`` there targets the unit under the look-around cursor.

Usage
-----

Expand Down
23 changes: 22 additions & 1 deletion exterminate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ local function checkUnit(opts, unit)
if opts.only_visible and not dfhack.units.isVisible(unit) then
return false
end
if not opts.include_friendly and not dfhack.units.isDanger(unit) and not dfhack.units.isWildlife(unit) then
-- the friendly/dangerous distinction doesn't exist in arena mode, where
-- units carry no invader or wildlife markers; every active unit is a
-- valid target except corpses and the adventure arena player unit
if opts.arena then
local adventurer = dfhack.world.getAdventurer()
if unit.flags2.killed or (adventurer and unit.id == adventurer.id) then
return false
end
elseif not opts.include_friendly and not dfhack.units.isDanger(unit) and not dfhack.units.isWildlife(unit) then
return false
end
if opts.selected_caste and opts.selected_caste ~= df.creature_raw.find(unit.race).caste[unit.caste].caste_id then
Expand Down Expand Up @@ -167,6 +175,7 @@ local options, args = {
only_visible = false,
include_friendly = false,
limit = -1,
arena = dfhack.world.isArena(),
}, {...}

local positionals = argparse.processArgsGetopt(args, {
Expand All @@ -188,6 +197,18 @@ end

if positionals[1] == "this" then
local selected_unit = dfhack.gui.getSelectedUnit()
if not selected_unit and options.arena and df.global.cursor.x ~= -30000 then
-- arena mode has no unit selection UI, but there is a look cursor
local units = dfhack.units.getUnitsInBox(
df.global.cursor.x, df.global.cursor.y, df.global.cursor.z,
df.global.cursor.x, df.global.cursor.y, df.global.cursor.z)
for _, u in ipairs(units) do
if not u.flags2.killed then
selected_unit = u
break
end
end
end
if not selected_unit then
qerror("Select a unit and run the script again.")
end
Expand Down
Loading