Skip to content

Commit 7db306b

Browse files
authored
Merge pull request DFHack#1025 from myk002/myk_exterminate
[exterminate] make race name matching case and space insensitive
2 parents c38da16 + 929f4f2 commit 7db306b

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Template for new versions:
4040
- `gui/launcher`: add interface for browsing and filtering commands by tags
4141
- `gui/launcher`: add support for history search (Alt-s hotkey) when in minimal mode
4242
- `gui/launcher`: developer mode hotkey restored to Ctrl-D
43+
- `exterminate`: make race name matching case and space insensitive
4344

4445
## Removed
4546

docs/exterminate.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ exterminate
66
:tags: fort armok units
77

88
Kills any unit, or all undead, or all units of a given race. You can target any
9-
unit on a revealed tile of the map, including ambushers, but caged/chained
10-
creatures cannot be killed with this tool.
9+
unit on a revealed tile of the map, including hidden ambushers, but caged or
10+
chained creatures cannot be killed with this tool.
1111

1212
Usage
1313
-----
@@ -19,6 +19,8 @@ Usage
1919
exterminate undead [<options>]
2020
exterminate <race>[:<caste>] [<options>]
2121

22+
Race and caste names are case insensitive.
23+
2224
Examples
2325
--------
2426

@@ -28,7 +30,7 @@ Examples
2830
List the targets on your map.
2931
``exterminate BIRD_RAVEN:MALE``
3032
Kill the ravens flying around the map (but only the male ones).
31-
``exterminate GOBLIN --method magma --only-visible``
33+
``exterminate goblin --method magma --only-visible``
3234
Kill all visible, hostile goblins on the map by boiling them in magma.
3335

3436
Options

exterminate.lua

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ if not positionals[1] then
170170
return
171171
end
172172

173-
local count = 0
174-
if positionals[1]:lower() == 'undead' then
173+
local count, target = 0, 'creature(s)'
174+
local race_name = table.concat(positionals, ' ')
175+
if race_name:lower() == 'undead' then
176+
target = 'undead'
175177
if not map_races.UNDEAD then
176178
qerror("No undead found on the map.")
177179
end
@@ -182,23 +184,38 @@ if positionals[1]:lower() == 'undead' then
182184
end
183185
end
184186
else
185-
local selected_race, selected_caste = positionals[1], nil
187+
local selected_race, selected_caste = race_name, nil
186188

187189
if string.find(selected_race, ':') then
188-
local tokens = positionals[1]:split(':')
190+
local tokens = selected_race:split(':')
189191
selected_race, selected_caste = tokens[1], tokens[2]
190192
end
191193

192194
if not map_races[selected_race] then
193-
qerror("No creatures of this race on the map.")
195+
local selected_race_upper = selected_race:upper()
196+
local selected_race_under = selected_race_upper:gsub(' ', '_')
197+
if map_races[selected_race_upper] then
198+
selected_race = selected_race_upper
199+
elseif map_races[selected_race_under] then
200+
selected_race = selected_race_under
201+
else
202+
qerror("No creatures of this race on the map.")
203+
end
194204
end
195205

196206
local race_castes = getRaceCastes(map_races[selected_race].id)
197207

198208
if selected_caste and not race_castes[selected_caste] then
199-
qerror("Invalid caste.")
209+
local selected_caste_upper = selected_caste:upper()
210+
if race_castes[selected_caste_upper] then
211+
selected_caste = selected_caste_upper
212+
else
213+
qerror("Invalid caste: " .. selected_caste)
214+
end
200215
end
201216

217+
target = selected_race
218+
202219
for _, unit in pairs(df.global.world.units.active) do
203220
if not checkUnit(unit) then
204221
goto skipunit
@@ -222,4 +239,4 @@ else
222239
end
223240
end
224241

225-
print(([[Exterminated %d creatures.]]):format(count))
242+
print(([[Exterminated %d %s.]]):format(count, target))

0 commit comments

Comments
 (0)