Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to commute the prison sentence of a convicted criminal #1200

Merged
merged 4 commits into from
Nov 28, 2024
Merged
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 @@ -29,6 +29,7 @@ Template for new versions:
## New Tools
- `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.
- `immortal-cravings`: allow immortals to satisfy their cravings for food and drink
- `justice`: various functions pertaining to the justice system, currently with a command to pardon a unit's prison sentence.

## New Features
- `force`: support the ``Wildlife`` event to allow additional wildlife to enter the map
Expand Down
26 changes: 26 additions & 0 deletions docs/justice.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
justice
=======

.. dfhack-tool::
:summary: Commands related to the justice system.
:tags: fort armok units

This tool allows control over aspects of the justice system, such as the
ability to pardon criminals.

Usage
-----

::
justice pardon [--unit <id>]

Pardon the selected unit or the one specified by unit id (if provided).
Currently only applies to prison time and doesn't cancel beatings or
hammerings.


Options
-------

``-u``, ``--unit <id>``
Specifies the unit id of the target of the command.
42 changes: 42 additions & 0 deletions justice.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

local argparse = require('argparse')

local function pardon_unit(unit)
for _,punishment in ipairs(df.global.plotinfo.punishments) do
if punishment.criminal == unit.id then
punishment.prison_counter = 0
return
end
end
qerror('Unit is not currently serving a sentence!')
end

local function command_pardon(unit_id)
local unit = nil
if not unit_id then
unit = dfhack.gui.getSelectedUnit()
if not unit then qerror("No unit selected!") end
else
unit = df.unit.find(unit_id)
if not unit then qerror(("No unit with id %i"):format(unit_id)) end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not unit then qerror(("No unit with id %i"):format(unit_id)) end
if not unit then qerror(("No unit with id %d"):format(unit_id)) end

end
if unit then pardon_unit(unit) end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if unit then pardon_unit(unit) end
pardon_unit(unit)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need this check because unit can still be nil if a unit wasn't found by either of the methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a unit was not found in either of the if branches above, then qerror will throw

end

local unit_id = nil

local args = {...}

local positionals = argparse.processArgsGetopt(args,
{'u', 'unit', hasArg=true, handler=function(optarg) unit_id = optarg end}
)

local command = positionals[1]

if command == "pardon" then
command_pardon(unit_id)
elseif not command then
qerror('Missing command')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
qerror('Missing command')
print(dfhack.script_help())

else
qerror(("Unrecognised command: %s"):format(command))
end