Skip to content

Commit dbce375

Browse files
committed
Merge remote-tracking branch 'master-spike/commute_sentence' into myk_justice
2 parents d61fc69 + 7d7baca commit dbce375

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Template for new versions:
2929
## New Tools
3030
- `fix/wildlife`: prevent wildlife from getting stuck when trying to exit the map. This fix needs to be enabled manually in `gui/control-panel` on the Bug Fixes tab since not all players want this bug to be fixed.
3131
- `immortal-cravings`: allow immortals to satisfy their cravings for food and drink
32+
- `justice`: various functions pertaining to the justice system, currently with a command to pardon a unit's prison sentence.
3233

3334
## New Features
3435
- `force`: support the ``Wildlife`` event to allow additional wildlife to enter the map

docs/justice.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
justice
2+
=======
3+
4+
.. dfhack-tool::
5+
:summary: Commands related to the justice system.
6+
:tags: fort armok units
7+
8+
This tool allows control over aspects of the justice system, such as the
9+
ability to pardon criminals.
10+
11+
Usage
12+
-----
13+
14+
::
15+
justice pardon [--unit <id>]
16+
17+
Pardon the selected unit or the one specified by unit id (if provided).
18+
Currently only applies to prison time and doesn't cancel beatings or
19+
hammerings.
20+
21+
22+
Options
23+
-------
24+
25+
``-u``, ``--unit <id>``
26+
Specifies the unit id of the target of the command.

justice.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
local argparse = require('argparse')
3+
4+
local function pardon_unit(unit)
5+
for _,punishment in ipairs(df.global.plotinfo.punishments) do
6+
if punishment.criminal == unit.id then
7+
punishment.prison_counter = 0
8+
return
9+
end
10+
end
11+
qerror('Unit is not currently serving a sentence!')
12+
end
13+
14+
local function command_pardon(unit_id)
15+
local unit = nil
16+
if not unit_id then
17+
unit = dfhack.gui.getSelectedUnit()
18+
if not unit then qerror("No unit selected!") end
19+
else
20+
unit = df.unit.find(unit_id)
21+
if not unit then qerror(("No unit with id %i"):format(unit_id)) end
22+
end
23+
if unit then pardon_unit(unit) end
24+
end
25+
26+
local unit_id = nil
27+
28+
local args = {...}
29+
30+
local positionals = argparse.processArgsGetopt(args,
31+
{'u', 'unit', hasArg=true, handler=function(optarg) unit_id = optarg end}
32+
)
33+
34+
local command = positionals[1]
35+
36+
if command == "pardon" then
37+
command_pardon(unit_id)
38+
elseif not command then
39+
qerror('Missing command')
40+
else
41+
qerror(("Unrecognised command: %s"):format(command))
42+
end

0 commit comments

Comments
 (0)